|
14 | 14 |
|
15 | 15 | Preferences* global_pref = nil; |
16 | 16 |
|
| 17 | +NSArray* getDisplayList(void){ |
| 18 | + NSMutableArray* displays = [[NSMutableArray alloc] init]; |
| 19 | + [displays addObject:@{@"name": @"Ninguno", @"id": @-1}]; |
| 20 | + for(NSScreen* screen in [NSScreen screens]){ |
| 21 | + NSDictionary* dict = [screen deviceDescription]; |
| 22 | + CGDirectDisplayID did = [dict[@"NSScreenNumber"] intValue]; |
| 23 | + NSString* name = @"Display"; |
| 24 | + if (@available(macOS 10.15, *)) name = [screen localizedName]; |
| 25 | + [displays addObject:@{@"name": name, @"id": [NSNumber numberWithUnsignedInt:did]}]; |
| 26 | + } |
| 27 | + return displays; |
| 28 | +} |
| 29 | + |
17 | 30 | typedef enum{ |
18 | 31 | OptionTypeNumber, |
19 | 32 | OptionTypeSelect, |
20 | 33 | OptionTypeCheckBox, |
21 | 34 | OptionTypeTextInput, |
| 35 | + OptionTypeDisplaySelect, |
22 | 36 | } OptionType; |
23 | 37 |
|
24 | 38 | #define OPTION(name, text, type, options, value, desc) \ |
|
28 | 42 | NSMutableArray* prefs = [NSMutableArray arrayWithArray:@[ |
29 | 43 | OPTION(hidpi, "Use HiDPI mode", CheckBox, [NSNull null], @1, @"on supported displays"), |
30 | 44 | OPTION(renderer, "Display Renderer", Select, (@[@"Metal", @"Opengl"]), [NSNumber numberWithInt:DisplayRendererTypeOpenGL], [NSNull null]), |
| 45 | + OPTION(default_display, "Default Display", DisplaySelect, [NSNull null], @-1, [NSNull null]), |
31 | 46 | #ifndef NO_AIRPLAY |
32 | 47 | OPTION(airplay, "AirPlay Receiver", CheckBox, [NSNull null], @0, @"Use PiP as Airplay receiver"), |
33 | 48 | OPTION(airplay_scale_factor, "AirPlay Scale factor", Select, (@[@"1.00", @"2.00", @"3.00", @"Default"]), @3, [NSNull null]), |
@@ -171,6 +186,12 @@ - (void)onSelect:(NSMenuItem*)sender{ |
171 | 186 | setPref(sender.identifier, [NSNumber numberWithLong:index]); |
172 | 187 | } |
173 | 188 |
|
| 189 | +- (void)onDisplaySelect:(NSMenuItem*)sender{ |
| 190 | + NSNumber* displayId = [sender representedObject]; |
| 191 | +// NSLog(@"onDisplaySelect: %@ -> %@", sender.identifier, displayId); |
| 192 | + setPref(sender.identifier, displayId); |
| 193 | +} |
| 194 | + |
174 | 195 | - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row{ |
175 | 196 | NSInteger col = [[tableView tableColumns] indexOfObject:tableColumn]; |
176 | 197 | // NSLog(@"row: %ld, col: %ld", row, col); |
@@ -222,6 +243,27 @@ - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(null |
222 | 243 | } |
223 | 244 | case OptionTypeTextInput: |
224 | 245 | break; |
| 246 | + case OptionTypeDisplaySelect:{ |
| 247 | + NSPopUpButton* button = [[NSPopUpButton alloc] init]; |
| 248 | + button.translatesAutoresizingMaskIntoConstraints = false; |
| 249 | + button.menu = [[NSMenu alloc] init]; |
| 250 | + |
| 251 | + NSArray* displays = getDisplayList(); |
| 252 | + int savedDisplayId = [(NSNumber*)value intValue]; |
| 253 | + int selectedIndex = 0; |
| 254 | + for(int i = 0; i < displays.count; i++){ |
| 255 | + NSDictionary* display = displays[i]; |
| 256 | + NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:display[@"name"] action:@selector(onDisplaySelect:) keyEquivalent:@""]; |
| 257 | + item.target = self; |
| 258 | + item.identifier = key; |
| 259 | + item.representedObject = display[@"id"]; |
| 260 | + [button.menu addItem:item]; |
| 261 | + if([display[@"id"] intValue] == savedDisplayId) selectedIndex = i; |
| 262 | + } |
| 263 | + [button selectItem:[button.menu itemArray][selectedIndex]]; |
| 264 | + view = button; |
| 265 | + break; |
| 266 | + } |
225 | 267 | } |
226 | 268 | } |
227 | 269 | if(!view) goto end; |
|
0 commit comments