Skip to content

Commit bf276ec

Browse files
codebytereJohn Kleinschmidt
authored andcommitted
feat: add new components to Display structure (electron#16870)
* feat: add new components to Display structure * add internal property * expose colorDepth * add specs
1 parent 5a44cc5 commit bf276ec

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

atom/common/native_mate_converters/gfx_converter.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ bool Converter<gfx::Rect>::FromV8(v8::Isolate* isolate,
105105
return true;
106106
}
107107

108+
template <>
109+
struct Converter<display::Display::AccelerometerSupport> {
110+
static v8::Local<v8::Value> ToV8(
111+
v8::Isolate* isolate,
112+
const display::Display::AccelerometerSupport& val) {
113+
switch (val) {
114+
case display::Display::AccelerometerSupport::AVAILABLE:
115+
return StringToV8(isolate, "available");
116+
case display::Display::AccelerometerSupport::UNAVAILABLE:
117+
return StringToV8(isolate, "unavailable");
118+
default:
119+
return StringToV8(isolate, "unknown");
120+
}
121+
}
122+
};
123+
108124
template <>
109125
struct Converter<display::Display::TouchSupport> {
110126
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
@@ -128,10 +144,15 @@ v8::Local<v8::Value> Converter<display::Display>::ToV8(
128144
dict.Set("id", val.id());
129145
dict.Set("bounds", val.bounds());
130146
dict.Set("workArea", val.work_area());
147+
dict.Set("accelerometerSupport", val.accelerometer_support());
148+
dict.Set("monochrome", val.is_monochrome());
149+
dict.Set("colorDepth", val.color_depth());
150+
dict.Set("depthPerComponent", val.depth_per_component());
131151
dict.Set("size", val.size());
132152
dict.Set("workAreaSize", val.work_area_size());
133153
dict.Set("scaleFactor", val.device_scale_factor());
134154
dict.Set("rotation", val.RotationAsDegree());
155+
dict.Set("internal", val.IsInternal());
135156
dict.Set("touchSupport", val.touch_support());
136157
return dict.GetHandle();
137158
}

docs/api/structures/display.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
clock-wise degrees.
66
* `scaleFactor` Number - Output device's pixel scale factor.
77
* `touchSupport` String - Can be `available`, `unavailable`, `unknown`.
8+
* `monochrome` Boolean - Whether or not the display is a monochrome display.
9+
* `accelerometerSupport` String - Can be `available`, `unavailable`, `unknown`.
10+
* `colorDepth` Number - The number of bits per pixel.
11+
* `depthPerComponent` Number - The number of bits per color component.
812
* `bounds` [Rectangle](rectangle.md)
913
* `size` [Size](size.md)
1014
* `workArea` [Rectangle](rectangle.md)
1115
* `workAreaSize` [Size](size.md)
16+
* `internal` Boolean - `true` for an internal display and `false` for an external display
1217

1318
The `Display` object represents a physical display connected to the system. A
1419
fake `Display` may exist on a headless system, or a `Display` may correspond to

spec/api-screen-spec.js

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,77 @@
1-
const assert = require('assert')
1+
const { expect } = require('chai')
22
const { screen } = require('electron').remote
33

44
describe('screen module', () => {
55
describe('screen.getCursorScreenPoint()', () => {
66
it('returns a point object', () => {
77
const point = screen.getCursorScreenPoint()
8-
assert.strictEqual(typeof point.x, 'number')
9-
assert.strictEqual(typeof point.y, 'number')
8+
expect(point.x).to.be.a('number')
9+
expect(point.y).to.be.a('number')
1010
})
1111
})
1212

1313
describe('screen.getPrimaryDisplay()', () => {
1414
it('returns a display object', () => {
1515
const display = screen.getPrimaryDisplay()
16-
assert.strictEqual(typeof display.scaleFactor, 'number')
17-
assert(display.size.width > 0)
18-
assert(display.size.height > 0)
16+
expect(display).to.be.an('object')
17+
})
18+
19+
it('has the correct non-object properties', function () {
20+
if (process.platform === 'linux') this.skip()
21+
const display = screen.getPrimaryDisplay()
22+
23+
expect(display).to.have.a.property('scaleFactor').that.is.a('number')
24+
expect(display).to.have.a.property('id').that.is.a('number')
25+
expect(display).to.have.a.property('rotation').that.is.a('number')
26+
expect(display).to.have.a.property('touchSupport').that.is.a('string')
27+
expect(display).to.have.a.property('accelerometerSupport').that.is.a('string')
28+
expect(display).to.have.a.property('internal').that.is.a('boolean')
29+
expect(display).to.have.a.property('monochrome').that.is.a('boolean')
30+
expect(display).to.have.a.property('depthPerComponent').that.is.a('number')
31+
expect(display).to.have.a.property('colorDepth').that.is.a('number')
32+
})
33+
34+
it('has a size object property', function () {
35+
if (process.platform === 'linux') this.skip()
36+
const display = screen.getPrimaryDisplay()
37+
38+
expect(display).to.have.a.property('size').that.is.an('object')
39+
const size = display.size
40+
expect(size).to.have.a.property('width').that.is.greaterThan(0)
41+
expect(size).to.have.a.property('height').that.is.greaterThan(0)
42+
})
43+
44+
it('has a workAreaSize object property', function () {
45+
if (process.platform === 'linux') this.skip()
46+
const display = screen.getPrimaryDisplay()
47+
48+
expect(display).to.have.a.property('workAreaSize').that.is.an('object')
49+
const workAreaSize = display.workAreaSize
50+
expect(workAreaSize).to.have.a.property('width').that.is.greaterThan(0)
51+
expect(workAreaSize).to.have.a.property('height').that.is.greaterThan(0)
52+
})
53+
54+
it('has a bounds object property', function () {
55+
if (process.platform === 'linux') this.skip()
56+
const display = screen.getPrimaryDisplay()
57+
58+
expect(display).to.have.a.property('bounds').that.is.an('object')
59+
const bounds = display.bounds
60+
expect(bounds).to.have.a.property('x').that.is.a('number')
61+
expect(bounds).to.have.a.property('y').that.is.a('number')
62+
expect(bounds).to.have.a.property('width').that.is.greaterThan(0)
63+
expect(bounds).to.have.a.property('height').that.is.greaterThan(0)
64+
})
65+
66+
it('has a workArea object property', function () {
67+
const display = screen.getPrimaryDisplay()
68+
69+
expect(display).to.have.a.property('workArea').that.is.an('object')
70+
const workArea = display.workArea
71+
expect(workArea).to.have.a.property('x').that.is.a('number')
72+
expect(workArea).to.have.a.property('y').that.is.a('number')
73+
expect(workArea).to.have.a.property('width').that.is.greaterThan(0)
74+
expect(workArea).to.have.a.property('height').that.is.greaterThan(0)
1975
})
2076
})
2177
})

0 commit comments

Comments
 (0)