Skip to content

Commit 8a2fa68

Browse files
committed
Default Display setting added
1 parent dec66da commit 8a2fa68

4 files changed

Lines changed: 62 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
77

88
project(PiP)
99

10-
add_compile_options(-fobjc-arc -Wno-deprecated-declarations -Wno-format)
10+
add_compile_options(-fobjc-arc -Wno-deprecated-declarations -Wno-format -mmacosx-version-min=14.0)
1111

1212
set(frameworks AVFoundation Cocoa VideoToolbox AudioToolbox CoreMedia QuartzCore OpenGL Metal MetalKit PIP SkyLight ScreenCaptureKit)
1313
list(TRANSFORM frameworks PREPEND "-framework ")

pip/preferences.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef enum{
1818
NSObject* getPref(NSString* key);
1919
NSObject* getPrefOption(NSString* key);
2020
void setPref(NSString* key, NSObject* val);
21+
NSArray* getDisplayList(void);
2122

2223
@interface Preferences : NSPanel<NSWindowDelegate, NSTableViewDelegate, NSTableViewDataSource>
2324

pip/preferences.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@
1414

1515
Preferences* global_pref = nil;
1616

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+
1730
typedef enum{
1831
OptionTypeNumber,
1932
OptionTypeSelect,
2033
OptionTypeCheckBox,
2134
OptionTypeTextInput,
35+
OptionTypeDisplaySelect,
2236
} OptionType;
2337

2438
#define OPTION(name, text, type, options, value, desc) \
@@ -28,6 +42,7 @@
2842
NSMutableArray* prefs = [NSMutableArray arrayWithArray:@[
2943
OPTION(hidpi, "Use HiDPI mode", CheckBox, [NSNull null], @1, @"on supported displays"),
3044
OPTION(renderer, "Display Renderer", Select, (@[@"Metal", @"Opengl"]), [NSNumber numberWithInt:DisplayRendererTypeOpenGL], [NSNull null]),
45+
OPTION(default_display, "Default Display", DisplaySelect, [NSNull null], @-1, [NSNull null]),
3146
#ifndef NO_AIRPLAY
3247
OPTION(airplay, "AirPlay Receiver", CheckBox, [NSNull null], @0, @"Use PiP as Airplay receiver"),
3348
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{
171186
setPref(sender.identifier, [NSNumber numberWithLong:index]);
172187
}
173188

189+
- (void)onDisplaySelect:(NSMenuItem*)sender{
190+
NSNumber* displayId = [sender representedObject];
191+
// NSLog(@"onDisplaySelect: %@ -> %@", sender.identifier, displayId);
192+
setPref(sender.identifier, displayId);
193+
}
194+
174195
- (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row{
175196
NSInteger col = [[tableView tableColumns] indexOfObject:tableColumn];
176197
// NSLog(@"row: %ld, col: %ld", row, col);
@@ -222,6 +243,27 @@ - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(null
222243
}
223244
case OptionTypeTextInput:
224245
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+
}
225267
}
226268
}
227269
if(!view) goto end;

pip/window.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,24 @@ - (id) initWithAirplay:(bool)enable andTitle:(NSString*)title{
10601060

10611061
[self setupNonHLSControls];
10621062

1063+
if(!is_airplay_session){
1064+
int defaultDisplayId = [(NSNumber*)getPref(@"default_display") intValue];
1065+
if(defaultDisplayId > 0){
1066+
NSArray* displays = getDisplayList();
1067+
for(NSDictionary* display in displays){
1068+
if([display[@"id"] intValue] == defaultDisplayId){
1069+
WindowSel* sel = [WindowSel getDefault];
1070+
sel.title = display[@"name"];
1071+
sel.dspId = defaultDisplayId;
1072+
NSMenuItem* item = [[NSMenuItem alloc] init];
1073+
[item setRepresentedObject:sel];
1074+
[self changeWindow:item];
1075+
break;
1076+
}
1077+
} // End of loop through displays
1078+
}
1079+
} // End of if not airplay session
1080+
10631081
return self;
10641082
}
10651083

0 commit comments

Comments
 (0)