Skip to content

Commit f9d4198

Browse files
committedDec 6, 2020
refactor: clean up GetDisplayFromID
1 parent 72186a4 commit f9d4198

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed
 

‎displays.mm

+13-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,20 @@ bool GetIsMonochrome() {
175175
// Returns the display object with the specified display id.
176176
Napi::Object GetDisplayFromID(const Napi::CallbackInfo &info) {
177177
uint32_t display_id = info[0].As<Napi::Number>().Uint32Value();
178-
NSScreen *screen = ScreenForID(display_id);
179178

180-
return screen ? BuildDisplay(info.Env(), screen) : Napi::Object();
179+
NSArray<NSScreen *> *screens = [NSScreen screens];
180+
181+
size_t num_displays = [screens count];
182+
for (size_t i = 0; i < num_displays; i++) {
183+
NSScreen *screen = [screens objectAtIndex:i];
184+
CGDirectDisplayID s_id = [[[screen deviceDescription]
185+
objectForKey:@"NSScreenNumber"] unsignedIntValue];
186+
if (s_id == display_id) {
187+
return BuildDisplay(info.Env(), screen);
188+
}
189+
}
190+
191+
return Napi::Object();
181192
}
182193

183194
// Initializes all functions exposed to JS.

0 commit comments

Comments
 (0)
Failed to load comments.