Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)

project(PiP)

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

set(frameworks Cocoa VideoToolbox AudioToolbox CoreMedia QuartzCore OpenGL Metal MetalKit PIP SkyLight)
list(TRANSFORM frameworks PREPEND "-framework ")
Expand Down
1 change: 1 addition & 0 deletions pip/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ typedef enum{
NSObject* getPref(NSString* key);
NSObject* getPrefOption(NSString* key);
void setPref(NSString* key, NSObject* val);
NSArray* getDisplayList(void);

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

Expand Down
42 changes: 42 additions & 0 deletions pip/preferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@

Preferences* global_pref = nil;

NSArray* getDisplayList(void){
NSMutableArray* displays = [[NSMutableArray alloc] init];
[displays addObject:@{@"name": @"Ninguno", @"id": @-1}];
for(NSScreen* screen in [NSScreen screens]){
NSDictionary* dict = [screen deviceDescription];
CGDirectDisplayID did = [dict[@"NSScreenNumber"] intValue];
NSString* name = @"Display";
if (@available(macOS 10.15, *)) name = [screen localizedName];
[displays addObject:@{@"name": name, @"id": [NSNumber numberWithUnsignedInt:did]}];
}
return displays;
}

typedef enum{
OptionTypeNumber,
OptionTypeSelect,
OptionTypeCheckBox,
OptionTypeTextInput,
OptionTypeDisplaySelect,
} OptionType;

#define OPTION(name, text, type, options, value, desc) \
Expand All @@ -25,6 +39,7 @@
return @[
OPTION(hidpi, "Use HiDPI mode", CheckBox, [NSNull null], @0, @"on supported displays"),
OPTION(renderer, "Display Renderer", Select, (@[@"Metal", @"Opengl"]), [NSNumber numberWithInt:DisplayRendererTypeOpenGL], [NSNull null]),
OPTION(default_display, "Default Display", DisplaySelect, [NSNull null], @-1, [NSNull null]),
#ifndef NO_AIRPLAY
OPTION(airplay, "AirPlay Receiver", CheckBox, [NSNull null], @1, @"Use PiP as Airplay receiver"),
OPTION(airplay_scale_factor, "AirPlay Scale factor", Select, (@[@"1.00", @"2.00", @"3.00", @"Default"]), @3, [NSNull null]),
Expand Down Expand Up @@ -152,6 +167,12 @@ - (void)onSelect:(NSMenuItem*)sender{
setPref(sender.identifier, [NSNumber numberWithLong:index]);
}

- (void)onDisplaySelect:(NSMenuItem*)sender{
NSNumber* displayId = [sender representedObject];
// NSLog(@"onDisplaySelect: %@ -> %@", sender.identifier, displayId);
setPref(sender.identifier, displayId);
}

- (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row{
NSInteger col = [[tableView tableColumns] indexOfObject:tableColumn];
// NSLog(@"row: %ld, col: %ld", row, col);
Expand Down Expand Up @@ -203,6 +224,27 @@ - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(null
}
case OptionTypeTextInput:
break;
case OptionTypeDisplaySelect:{
NSPopUpButton* button = [[NSPopUpButton alloc] init];
button.translatesAutoresizingMaskIntoConstraints = false;
button.menu = [[NSMenu alloc] init];

NSArray* displays = getDisplayList();
int savedDisplayId = [(NSNumber*)value intValue];
int selectedIndex = 0;
for(int i = 0; i < displays.count; i++){
NSDictionary* display = displays[i];
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:display[@"name"] action:@selector(onDisplaySelect:) keyEquivalent:@""];
item.target = self;
item.identifier = key;
item.representedObject = display[@"id"];
[button.menu addItem:item];
if([display[@"id"] intValue] == savedDisplayId) selectedIndex = i;
}
[button selectItem:[button.menu itemArray][selectedIndex]];
view = button;
break;
}
}
}
if(!view) goto end;
Expand Down
18 changes: 18 additions & 0 deletions pip/window.m
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,24 @@ - (id) initWithAirplay:(bool)enable andTitle:(NSString*)title{

[self resetPlaybackSate];

if(!is_airplay_session){
int defaultDisplayId = [(NSNumber*)getPref(@"default_display") intValue];
if(defaultDisplayId > 0){
NSArray* displays = getDisplayList();
for(NSDictionary* display in displays){
if([display[@"id"] intValue] == defaultDisplayId){
WindowSel* sel = [WindowSel getDefault];
sel.title = display[@"name"];
sel.dspId = defaultDisplayId;
NSMenuItem* item = [[NSMenuItem alloc] init];
[item setRepresentedObject:sel];
[self changeWindow:item];
break;
}
}
}
}

return self;
}

Expand Down