Commits (15)
//
// NSUserDefaults+XQuartzDefaults.h
// XQuartz
//
// Created by Jeremy Huddleston Sequoia on 2021.02.19.
// Copyright (c) 2021 Apple Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
extern NSString * const XQuartzPrefKeyAppsMenu;
extern NSString * const XQuartzPrefKeyFakeButtons;
extern NSString * const XQuartzPrefKeyFakeButton2;
extern NSString * const XQuartzPrefKeyFakeButton3;
extern NSString * const XQuartzPrefKeyKeyEquivs;
extern NSString * const XQuartzPrefKeyFullscreenHotkeys;
extern NSString * const XQuartzPrefKeyFullscreenMenu;
extern NSString * const XQuartzPrefKeySyncKeymap;
extern NSString * const XQuartzPrefKeyDepth;
extern NSString * const XQuartzPrefKeyNoAuth;
extern NSString * const XQuartzPrefKeyNoTCP;
extern NSString * const XQuartzPrefKeyDoneXinitCheck;
extern NSString * const XQuartzPrefKeyNoQuitAlert;
extern NSString * const XQuartzPrefKeyNoRANDRAlert;
extern NSString * const XQuartzPrefKeyOptionSendsAlt;
extern NSString * const XQuartzPrefKeyAppKitModifiers;
extern NSString * const XQuartzPrefKeyWindowItemModifiers;
extern NSString * const XQuartzPrefKeyRootless;
extern NSString * const XQuartzPrefKeyRENDERExtension;
extern NSString * const XQuartzPrefKeyTESTExtension;
extern NSString * const XQuartzPrefKeyLoginShell;
extern NSString * const XQuartzPrefKeyClickThrough;
extern NSString * const XQuartzPrefKeyFocusFollowsMouse;
extern NSString * const XQuartzPrefKeyFocusOnNewWindow;
extern NSString * const XQuartzPrefKeyScrollInDeviceDirection;
extern NSString * const XQuartzPrefKeySyncPasteboard;
extern NSString * const XQuartzPrefKeySyncPasteboardToClipboard;
extern NSString * const XQuartzPrefKeySyncPasteboardToPrimary;
extern NSString * const XQuartzPrefKeySyncClipboardToPasteBoard;
extern NSString * const XQuartzPrefKeySyncPrimaryOnSelect;
@interface NSUserDefaults (XQuartzDefaults)
+ (NSUserDefaults *)globalDefaults;
+ (NSUserDefaults *)dockDefaults;
+ (NSUserDefaults *)xquartzDefaults;
@end
//
// NSUserDefaults+XQuartzDefaults.m
// XQuartz
//
// Created by Jeremy Huddleston Sequoia on 2021.02.19.
// Copyright (c) 2021 Apple Inc. All rights reserved.
//
#import "NSUserDefaults+XQuartzDefaults.h"
#import <dispatch/dispatch.h>
NSString * const XQuartzPrefKeyAppsMenu = @"apps_menu";
NSString * const XQuartzPrefKeyFakeButtons = @"enable_fake_buttons";
NSString * const XQuartzPrefKeyFakeButton2 = @"fake_button2";
NSString * const XQuartzPrefKeyFakeButton3 = @"fake_button3";
NSString * const XQuartzPrefKeyKeyEquivs = @"enable_key_equivalents";
NSString * const XQuartzPrefKeyFullscreenHotkeys = @"fullscreen_hotkeys";
NSString * const XQuartzPrefKeyFullscreenMenu = @"fullscreen_menu";
NSString * const XQuartzPrefKeySyncKeymap = @"sync_keymap";
NSString * const XQuartzPrefKeyDepth = @"depth";
NSString * const XQuartzPrefKeyNoAuth = @"no_auth";
NSString * const XQuartzPrefKeyNoTCP = @"nolisten_tcp";
NSString * const XQuartzPrefKeyDoneXinitCheck = @"done_xinit_check";
NSString * const XQuartzPrefKeyNoQuitAlert = @"no_quit_alert";
NSString * const XQuartzPrefKeyNoRANDRAlert = @"no_randr_alert";
NSString * const XQuartzPrefKeyOptionSendsAlt = @"option_sends_alt";
NSString * const XQuartzPrefKeyAppKitModifiers = @"appkit_modifiers";
NSString * const XQuartzPrefKeyWindowItemModifiers = @"window_item_modifiers";
NSString * const XQuartzPrefKeyRootless = @"rootless";
NSString * const XQuartzPrefKeyRENDERExtension = @"enable_render_extension";
NSString * const XQuartzPrefKeyTESTExtension = @"enable_test_extensions";
NSString * const XQuartzPrefKeyLoginShell = @"login_shell";
NSString * const XQuartzPrefKeyUpdateFeed = @"update_feed";
NSString * const XQuartzPrefKeyClickThrough = @"wm_click_through";
NSString * const XQuartzPrefKeyFocusFollowsMouse = @"wm_ffm";
NSString * const XQuartzPrefKeyFocusOnNewWindow = @"wm_focus_on_new_window";
NSString * const XQuartzPrefKeyScrollInDeviceDirection = @"scroll_in_device_direction";
NSString * const XQuartzPrefKeySyncPasteboard = @"sync_pasteboard";
NSString * const XQuartzPrefKeySyncPasteboardToClipboard = @"sync_pasteboard_to_clipboard";
NSString * const XQuartzPrefKeySyncPasteboardToPrimary = @"sync_pasteboard_to_primary";
NSString * const XQuartzPrefKeySyncClipboardToPasteBoard = @"sync_clipboard_to_pasteboard";
NSString * const XQuartzPrefKeySyncPrimaryOnSelect = @"sync_primary_on_select";
@implementation NSUserDefaults (XQuartzDefaults)
+ (NSUserDefaults *)globalDefaults
{
static dispatch_once_t once;
static NSUserDefaults *defaults;
dispatch_once(&once, ^{
NSString * const defaultsDomain = @".GlobalPreferences";
defaults = [[[NSUserDefaults alloc] initWithSuiteName:defaultsDomain] retain];
NSDictionary<NSString *, id> * const defaultDefaultsDict = @{
@"AppleSpacesSwitchOnActivate" : @(YES),
};
[defaults registerDefaults:defaultDefaultsDict];
});
return defaults;
}
+ (NSUserDefaults *)dockDefaults
{
static dispatch_once_t once;
static NSUserDefaults *defaults;
dispatch_once(&once, ^{
NSString * const defaultsDomain = @"com.apple.dock";
defaults = [[[NSUserDefaults alloc] initWithSuiteName:defaultsDomain] retain];
NSDictionary<NSString *, id> * const defaultDefaultsDict = @{
@"workspaces" : @(NO),
};
[defaults registerDefaults:defaultDefaultsDict];
});
return defaults;
}
+ (NSUserDefaults *)xquartzDefaults
{
static dispatch_once_t once;
static NSUserDefaults *defaults;
dispatch_once(&once, ^{
NSString * const defaultsDomain = @(BUNDLE_ID_PREFIX ".X11");
NSString * const defaultDefaultsDomain = NSBundle.mainBundle.bundleIdentifier;
if ([defaultsDomain isEqualToString:defaultDefaultsDomain]) {
defaults = [NSUserDefaults.standardUserDefaults retain];
} else {
defaults = [[[NSUserDefaults alloc] initWithSuiteName:defaultsDomain] retain];
}
NSArray * const defaultAppsMenu = @[
@[NSLocalizedString(@"Terminal", @"Terminal"), @"xterm", @"n"],
];
NSString *defaultWindowItemModifiers = @"command";
NSString * const defaultWindowItemModifiersLocalized = NSLocalizedString(@"window item modifiers", @"window item modifiers");
if (![defaultWindowItemModifiersLocalized isEqualToString:@"window item modifiers"]) {
defaultWindowItemModifiers = defaultWindowItemModifiersLocalized;
}
NSDictionary<NSString *, id> * const defaultDefaultsDict = @{
XQuartzPrefKeyAppsMenu : defaultAppsMenu,
XQuartzPrefKeyFakeButtons : @(NO),
// XQuartzPrefKeyFakeButton2 nil default
// XQuartzPrefKeyFakeButton3 nil default
XQuartzPrefKeyKeyEquivs : @(YES),
XQuartzPrefKeyFullscreenHotkeys : @(NO),
XQuartzPrefKeyFullscreenMenu : @(NO),
XQuartzPrefKeySyncKeymap : @(NO),
XQuartzPrefKeyDepth : @(-1),
XQuartzPrefKeyNoAuth : @(NO),
XQuartzPrefKeyNoTCP : @(NO),
XQuartzPrefKeyDoneXinitCheck : @(NO),
XQuartzPrefKeyNoQuitAlert : @(NO),
XQuartzPrefKeyNoRANDRAlert : @(NO),
XQuartzPrefKeyOptionSendsAlt : @(NO),
// XQuartzPrefKeyAppKitModifiers nil default
XQuartzPrefKeyWindowItemModifiers : defaultWindowItemModifiers,
XQuartzPrefKeyRootless : @(YES),
XQuartzPrefKeyRENDERExtension : @(YES),
XQuartzPrefKeyTESTExtension : @(NO),
XQuartzPrefKeyLoginShell : @"/bin/sh",
XQuartzPrefKeyClickThrough : @(NO),
XQuartzPrefKeyFocusFollowsMouse : @(NO),
XQuartzPrefKeyFocusOnNewWindow : @(YES),
XQuartzPrefKeyScrollInDeviceDirection : @(NO),
XQuartzPrefKeySyncPasteboard : @(YES),
XQuartzPrefKeySyncPasteboardToClipboard : @(YES),
XQuartzPrefKeySyncPasteboardToPrimary : @(YES),
XQuartzPrefKeySyncClipboardToPasteBoard : @(YES),
XQuartzPrefKeySyncPrimaryOnSelect : @(NO),
};
[defaults registerDefaults:defaultDefaultsDict];
});
return defaults;
}
@end
......@@ -42,20 +42,6 @@
@property (nonatomic, readwrite, strong) X11Controller *controller;
@property (nonatomic, readonly, assign) OSX_BOOL x_active;
- (CFPropertyListRef)prefs_get_copy:(NSString *)key CF_RETURNS_RETAINED;
- (int)prefs_get_integer:(NSString *)key default:(int)def;
- (const char *)prefs_get_string:(NSString *)key default:(const char *)def;
- (float)prefs_get_float:(NSString *)key default:(float)def;
- (int)prefs_get_boolean:(NSString *)key default:(int)def;
- (NSURL *)prefs_copy_url:(NSString *)key default:(NSURL *)def
NS_RETURNS_RETAINED;
- (NSArray *)prefs_get_array:(NSString *)key;
- (void)prefs_set_integer:(NSString *)key value:(int)value;
- (void)prefs_set_float:(NSString *)key value:(float)value;
- (void)prefs_set_boolean:(NSString *)key value:(int)value;
- (void)prefs_set_array:(NSString *)key value:(NSArray *)value;
- (void)prefs_set_string:(NSString *)key value:(NSString *)value;
- (void)prefs_synchronize;
@end
extern X11Application * X11App;
......@@ -84,40 +70,6 @@ X11ApplicationCanEnterRandR(void);
void
X11ApplicationMain(int argc, char **argv, char **envp);
#define PREFS_APPSMENU "apps_menu"
#define PREFS_FAKEBUTTONS "enable_fake_buttons"
#define PREFS_KEYEQUIVS "enable_key_equivalents"
#define PREFS_FULLSCREEN_HOTKEYS "fullscreen_hotkeys"
#define PREFS_FULLSCREEN_MENU "fullscreen_menu"
#define PREFS_SYNC_KEYMAP "sync_keymap"
#define PREFS_DEPTH "depth"
#define PREFS_NO_AUTH "no_auth"
#define PREFS_NO_TCP "nolisten_tcp"
#define PREFS_DONE_XINIT_CHECK "done_xinit_check"
#define PREFS_NO_QUIT_ALERT "no_quit_alert"
#define PREFS_NO_RANDR_ALERT "no_randr_alert"
#define PREFS_OPTION_SENDS_ALT "option_sends_alt"
#define PREFS_FAKE_BUTTON2 "fake_button2"
#define PREFS_FAKE_BUTTON3 "fake_button3"
#define PREFS_APPKIT_MODIFIERS "appkit_modifiers"
#define PREFS_WINDOW_ITEM_MODIFIERS "window_item_modifiers"
#define PREFS_ROOTLESS "rootless"
#define PREFS_RENDER_EXTENSION "enable_render_extension"
#define PREFS_TEST_EXTENSIONS "enable_test_extensions"
#define PREFS_XP_OPTIONS "xp_options"
#define PREFS_LOGIN_SHELL "login_shell"
#define PREFS_UPDATE_FEED "update_feed"
#define PREFS_CLICK_THROUGH "wm_click_through"
#define PREFS_FFM "wm_ffm"
#define PREFS_FOCUS_ON_NEW_WINDOW "wm_focus_on_new_window"
#define PREFS_SCROLL_IN_DEV_DIRECTION "scroll_in_device_direction"
extern Bool XQuartzScrollInDeviceDirection;
#define PREFS_SYNC_PB "sync_pasteboard"
#define PREFS_SYNC_PB_TO_CLIPBOARD "sync_pasteboard_to_clipboard"
#define PREFS_SYNC_PB_TO_PRIMARY "sync_pasteboard_to_primary"
#define PREFS_SYNC_CLIPBOARD_TO_PB "sync_clipboard_to_pasteboard"
#define PREFS_SYNC_PRIMARY_ON_SELECT "sync_primary_on_select"
#endif /* X11APPLICATION_H */
This diff is collapsed.
......@@ -36,6 +36,7 @@
#import "X11Controller.h"
#import "X11Application.h"
#import "NSUserDefaults+XQuartzDefaults.h"
#include "opaque.h"
#include "darwin.h"
......@@ -74,21 +75,19 @@ extern char *bundle_id_prefix;
- (void) awakeFromNib
{
X11Application *xapp = NSApp;
NSArray *array;
/* Point X11Application at ourself. */
xapp.controller = self;
array = [xapp prefs_get_array:@PREFS_APPSMENU];
if (array != nil) {
int count;
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
NSArray *appsMenu = [defaults arrayForKey:XQuartzPrefKeyAppsMenu];
if (appsMenu) {
int count = appsMenu.count;
/* convert from [TITLE1 COMMAND1 TITLE2 COMMAND2 ...]
to [[TITLE1 COMMAND1] [TITLE2 COMMAND2] ...] format. */
count = [array count];
if (count > 0
&& ![[array objectAtIndex:0] isKindOfClass:[NSArray class]]) {
if (count > 0 && ![appsMenu[0] isKindOfClass:NSArray.class]) {
int i;
NSMutableArray *copy, *sub;
......@@ -96,24 +95,24 @@ extern char *bundle_id_prefix;
for (i = 0; i < count / 2; i++) {
sub = [[NSMutableArray alloc] initWithCapacity:3];
[sub addObject:[array objectAtIndex:i * 2]];
[sub addObject:[array objectAtIndex:i * 2 + 1]];
[sub addObject:appsMenu[i * 2]];
[sub addObject:appsMenu[i * 2 + 1]];
[sub addObject:@""];
[copy addObject:sub];
[sub release];
}
array = copy;
appsMenu = copy;
[defaults setObject:appsMenu forKey:XQuartzPrefKeyAppsMenu];
}
[self set_apps_menu:array];
[self set_apps_menu:appsMenu];
}
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(apps_table_done:)
name: NSWindowWillCloseNotification
object: self.apps_table.window];
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(apps_table_done:)
name:NSWindowWillCloseNotification
object:self.apps_table.window];
}
- (void) item_selected:sender
......@@ -349,9 +348,12 @@ extern char *bundle_id_prefix;
int stdout_pipe[2];
int stderr_pipe[2];
newargv[0] = [X11App prefs_get_string:@PREFS_LOGIN_SHELL default:"/bin/sh"];
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
NSString * const shell = [defaults stringForKey:XQuartzPrefKeyLoginShell];
newargv[0] = shell.fileSystemRepresentation;
newargv[1] = "-c";
newargv[2] = [filename UTF8String];
newargv[2] = filename.fileSystemRepresentation;
newargv[3] = NULL;
s = getenv("DISPLAY");
......@@ -494,8 +496,8 @@ extern char *bundle_id_prefix;
[self remove_apps_menu];
[self install_apps_menu:table_apps];
[NSApp prefs_set_array:@PREFS_APPSMENU value:table_apps];
[NSApp prefs_synchronize];
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
[defaults setObject:table_apps forKey:XQuartzPrefKeyAppsMenu];
[[apps_table window] orderOut:sender];
......@@ -672,15 +674,15 @@ extern char *bundle_id_prefix;
- (IBAction) enable_fullscreen_changed:sender
{
XQuartzRootlessDefault = !self.enable_fullscreen.intValue;
XQuartzRootlessDefault = !self.enable_fullscreen.state;
[self.enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
[self.enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ? NSColor.disabledControlTextColor : NSColor.controlTextColor];
DarwinSendDDXEvent(kXquartzSetRootless, 1, XQuartzRootlessDefault);
[NSApp prefs_set_boolean:@PREFS_ROOTLESS value:XQuartzRootlessDefault];
[NSApp prefs_synchronize];
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
[defaults setBool:XQuartzRootlessDefault forKey:XQuartzPrefKeyRootless];
}
- (IBAction) toggle_fullscreen:sender
......@@ -693,55 +695,43 @@ extern char *bundle_id_prefix;
if (!sender)
return;
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
if (sender == self.fake_buttons) {
darwinFakeButtons = self.fake_buttons.intValue;
[NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons];
}
else if (sender == self.enable_keyequivs) {
XQuartzEnableKeyEquivalents = self.enable_keyequivs.intValue;
[NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:
XQuartzEnableKeyEquivalents];
}
else if (sender == self.sync_keymap) {
darwinSyncKeymap = self.sync_keymap.intValue;
[NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap];
}
else if (sender == self.enable_fullscreen_menu) {
XQuartzFullscreenMenu = self.enable_fullscreen_menu.intValue;
[NSApp prefs_set_boolean:@PREFS_FULLSCREEN_MENU value:
XQuartzFullscreenMenu];
}
else if (sender == self.option_sends_alt) {
darwinFakeButtons = !!self.fake_buttons.state;
[defaults setBool:darwinFakeButtons forKey:XQuartzPrefKeyFakeButtons];
} else if (sender == self.enable_keyequivs) {
XQuartzEnableKeyEquivalents = !!self.enable_keyequivs.state;
[defaults setBool:XQuartzEnableKeyEquivalents forKey:XQuartzPrefKeyKeyEquivs];
} else if (sender == self.sync_keymap) {
darwinSyncKeymap = !!self.sync_keymap.state;
[defaults setBool:darwinSyncKeymap forKey:XQuartzPrefKeySyncKeymap];
} else if (sender == self.enable_fullscreen_menu) {
XQuartzFullscreenMenu = !!self.enable_fullscreen_menu.state;
[defaults setBool:XQuartzFullscreenMenu forKey:XQuartzPrefKeyFullscreenMenu];
} else if (sender == self.option_sends_alt) {
BOOL prev_opt_sends_alt = XQuartzOptionSendsAlt;
XQuartzOptionSendsAlt = self.option_sends_alt.intValue;
[NSApp prefs_set_boolean:@PREFS_OPTION_SENDS_ALT value:
XQuartzOptionSendsAlt];
XQuartzOptionSendsAlt = !!self.option_sends_alt.state;
[defaults setBool:XQuartzOptionSendsAlt forKey:XQuartzPrefKeyOptionSendsAlt];
if (prev_opt_sends_alt != XQuartzOptionSendsAlt)
QuartsResyncKeymap(TRUE);
}
else if (sender == self.click_through) {
[NSApp prefs_set_boolean:@PREFS_CLICK_THROUGH value:self.click_through.intValue];
}
else if (sender == self.focus_follows_mouse) {
[NSApp prefs_set_boolean:@PREFS_FFM value:self.focus_follows_mouse.intValue];
}
else if (sender == self.focus_on_new_window) {
[NSApp prefs_set_boolean:@PREFS_FOCUS_ON_NEW_WINDOW value:self.focus_on_new_window.intValue];
}
else if (sender == self.enable_auth) {
[NSApp prefs_set_boolean:@PREFS_NO_AUTH value:!self.enable_auth.intValue];
}
else if (sender == self.enable_tcp) {
[NSApp prefs_set_boolean:@PREFS_NO_TCP value:!self.enable_tcp.intValue];
}
else if (sender == self.depth) {
[NSApp prefs_set_integer:@PREFS_DEPTH value:self.depth.selectedTag];
}
else if (sender == self.sync_pasteboard) {
} else if (sender == self.click_through) {
[defaults setBool:!!self.click_through.state forKey:XQuartzPrefKeyClickThrough];
} else if (sender == self.focus_follows_mouse) {
[defaults setBool:!!self.focus_follows_mouse.state forKey:XQuartzPrefKeyFocusFollowsMouse];
} else if (sender == self.focus_on_new_window) {
[defaults setBool:!!self.focus_on_new_window.state forKey:XQuartzPrefKeyFocusOnNewWindow];
} else if (sender == self.enable_auth) {
[defaults setBool:!self.enable_auth.state forKey:XQuartzPrefKeyNoAuth];
} else if (sender == self.enable_tcp) {
[defaults setBool:!self.enable_tcp.state forKey:XQuartzPrefKeyNoTCP];
} else if (sender == self.depth) {
[defaults setInteger:self.depth.selectedTag forKey:XQuartzPrefKeyDepth];
} else if (sender == self.sync_pasteboard) {
BOOL pbproxy_active = self.sync_pasteboard.intValue;
[NSApp prefs_set_boolean:@PREFS_SYNC_PB value:pbproxy_active];
[defaults setBool:pbproxy_active forKey:XQuartzPrefKeySyncPasteboard];
[self.sync_pasteboard_to_clipboard setEnabled:pbproxy_active];
[self.sync_pasteboard_to_primary setEnabled:pbproxy_active];
......@@ -751,33 +741,27 @@ extern char *bundle_id_prefix;
// setEnabled doesn't do this...
[self.sync_text1 setTextColor:pbproxy_active ? NSColor.controlTextColor : NSColor.disabledControlTextColor];
[self.sync_text2 setTextColor:pbproxy_active ? NSColor.controlTextColor : NSColor.disabledControlTextColor];
} else if (sender == self.sync_pasteboard_to_clipboard) {
[defaults setBool:!!self.sync_pasteboard_to_clipboard.state forKey:XQuartzPrefKeySyncPasteboardToClipboard];
} else if (sender == self.sync_pasteboard_to_primary) {
[defaults setBool:!!self.sync_pasteboard_to_primary.state forKey:XQuartzPrefKeySyncPasteboardToPrimary];
} else if (sender == self.sync_clipboard_to_pasteboard) {
[defaults setBool:!!self.sync_clipboard_to_pasteboard.state forKey:XQuartzPrefKeySyncClipboardToPasteBoard];
} else if (sender == self.sync_primary_immediately) {
[defaults setBool:!!self.sync_primary_immediately.state forKey:XQuartzPrefKeySyncPrimaryOnSelect];
} else if (sender == self.scroll_in_device_direction) {
XQuartzScrollInDeviceDirection = !!self.scroll_in_device_direction.state;
[defaults setBool:XQuartzScrollInDeviceDirection forKey:XQuartzPrefKeyScrollInDeviceDirection];
}
else if (sender == self.sync_pasteboard_to_clipboard) {
[NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD value:self.sync_pasteboard_to_clipboard.intValue];
}
else if (sender == self.sync_pasteboard_to_primary) {
[NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_PRIMARY value:self.sync_pasteboard_to_primary.intValue];
}
else if (sender == self.sync_clipboard_to_pasteboard) {
[NSApp prefs_set_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB value:self.sync_clipboard_to_pasteboard.intValue];
}
else if (sender == self.sync_primary_immediately) {
[NSApp prefs_set_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT value:self.sync_primary_immediately.intValue];
}
else if (sender == self.scroll_in_device_direction) {
XQuartzScrollInDeviceDirection = self.scroll_in_device_direction.intValue;
[NSApp prefs_set_boolean:@PREFS_SCROLL_IN_DEV_DIRECTION value:XQuartzScrollInDeviceDirection];
}
[NSApp prefs_synchronize];
DarwinSendDDXEvent(kXquartzReloadPreferences, 0);
}
- (IBAction) prefs_show:sender
{
BOOL pbproxy_active =
[NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES];
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
BOOL pbproxy_active = [defaults boolForKey:XQuartzPrefKeySyncPasteboard];
[self.scroll_in_device_direction setIntValue:XQuartzScrollInDeviceDirection];
......@@ -785,20 +769,20 @@ extern char *bundle_id_prefix;
[self.enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents];
[self.sync_keymap setIntValue:darwinSyncKeymap];
[self.option_sends_alt setIntValue:XQuartzOptionSendsAlt];
[self.click_through setIntValue:[NSApp prefs_get_boolean:@PREFS_CLICK_THROUGH default:NO]];
[self.focus_follows_mouse setIntValue:[NSApp prefs_get_boolean:@PREFS_FFM default:NO]];
[self.focus_on_new_window setIntValue:[NSApp prefs_get_boolean:@PREFS_FOCUS_ON_NEW_WINDOW default:YES]];
[self.click_through setIntValue:[defaults boolForKey:XQuartzPrefKeyClickThrough]];
[self.focus_follows_mouse setIntValue:[defaults boolForKey:XQuartzPrefKeyFocusFollowsMouse]];
[self.focus_on_new_window setIntValue:[defaults boolForKey:XQuartzPrefKeyFocusOnNewWindow]];
[self.enable_auth setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_AUTH default:NO]];
[self.enable_tcp setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_TCP default:NO]];
[self.enable_auth setIntValue:![defaults boolForKey:XQuartzPrefKeyNoAuth]];
[self.enable_tcp setIntValue:![defaults boolForKey:XQuartzPrefKeyNoTCP]];
[self.depth selectItemAtIndex:[self.depth indexOfItemWithTag:[NSApp prefs_get_integer:@PREFS_DEPTH default:-1]]];
[self.depth selectItemAtIndex:[self.depth indexOfItemWithTag:[defaults integerForKey:XQuartzPrefKeyDepth]]];
[self.sync_pasteboard setIntValue:pbproxy_active];
[self.sync_pasteboard_to_clipboard setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD default:YES]];
[self.sync_pasteboard_to_primary setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PB_TO_PRIMARY default:YES]];
[self.sync_clipboard_to_pasteboard setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB default:YES]];
[self.sync_primary_immediately setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT default:NO]];
[self.sync_pasteboard_to_clipboard setIntValue:[defaults boolForKey:XQuartzPrefKeySyncPasteboardToClipboard]];
[self.sync_pasteboard_to_primary setIntValue:[defaults boolForKey:XQuartzPrefKeySyncPasteboardToPrimary]];
[self.sync_clipboard_to_pasteboard setIntValue:[defaults boolForKey:XQuartzPrefKeySyncClipboardToPasteBoard]];
[self.sync_primary_immediately setIntValue:[defaults boolForKey:XQuartzPrefKeySyncPrimaryOnSelect]];
[self.sync_pasteboard_to_clipboard setEnabled:pbproxy_active];
[self.sync_pasteboard_to_primary setEnabled:pbproxy_active];
......@@ -863,9 +847,11 @@ extern char *bundle_id_prefix;
NSString *msg;
NSString *title;
if (self.can_quit ||
[X11App prefs_get_boolean:@PREFS_NO_QUIT_ALERT default:NO])
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
if (self.can_quit || [defaults boolForKey:XQuartzPrefKeyNoQuitAlert]) {
return NSTerminateNow;
}
/* Make sure we're frontmost. */
[NSApp activateIgnoringOtherApps:YES];
......@@ -887,8 +873,6 @@ extern char *bundle_id_prefix;
- (void) applicationWillTerminate:(NSNotification *)aNotification _X_NORETURN
{
[X11App prefs_synchronize];
/* shutdown the X server, it will exit () for us. */
DarwinSendDDXEvent(kXquartzQuit, 0);
......
......@@ -31,17 +31,17 @@
#ifdef XQUARTZ_SPARKLE
<key>SUEnableAutomaticChecks</key>
<true/>
<key>SUPublicDSAKeyFile</key>
<string>sparkle.pem</string>
<key>SUPublicEDKey</key>
<string>XQUARTZ_SPARKLE_PUBLIC_EDKEY</string>
<key>SUFeedURL</key>
<string>XQUARTZ_SPARKLE_FEED_URL</string>
#endif
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>NSHumanReadableCopyright</key>
<string>© 2003-2021 Apple Inc.
<string>© 2003-2022 Apple Inc.
© 2003 XFree86 Project, Inc.
© 2003-2021 X.org Foundation, Inc.
© 2003-2022 X.org Foundation, Inc.
</string>
<key>NSMainNibFile</key>
<string>main</string>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- This file contains system-wide defaults for the Apple X11 server -->
<plist version="1.0">
<dict>
<key>apps_menu</key>
<array>
<array>
<string>Terminal</string>
<string>xterm</string>
<string>n</string>
</array>
<array>
<string>xman</string>
<string>xman</string>
<string></string>
</array>
<array>
<string>xlogo</string>
<string>xlogo</string>
<string></string>
</array>
</array>
</dict>
</plist>
......@@ -13,6 +13,7 @@ if build_sparkle
cpp_defs += [
'-DXQUARTZ_SPARKLE',
'-DXQUARTZ_SPARKLE_FEED_URL=@0@'.format(xquartz_sparkle_feed_url),
'-DXQUARTZ_SPARKLE_PUBLIC_EDKEY=@0@'.format(xquartz_sparkle_public_edkey),
]
endif
......
......@@ -4,22 +4,35 @@ apple_applications_dir = get_option('apple-applications-dir')
apple_application_name = get_option('apple-application-name')
bundle_id_prefix = get_option('bundle-id-prefix')
xquartz_sparkle_feed_url = get_option('sparkle-feed-url')
xquartz_sparkle_public_edkey = get_option('sparkle-public-edkey')
bundle_version_string = meson.project_version() # CFBundleShortVersionString
bundle_version = release # CFBundleVersion
bundle_version_string = get_option('bundle-version-string') # CFBundleShortVersionString
if bundle_version_string == 'auto'
bundle_version_string = meson.project_version()
endif
bundle_version = get_option('bundle-version') # CFBundleVersion
if bundle_version == 'auto'
version_arr = bundle_version_string.split('.')
version_major = version_arr[0].to_int()
version_minor = version_arr[1].to_int()
version_tiny = version_arr[2].to_int()
bundle_version = '@0@.@1@.@2@'.format(version_major, version_minor, version_tiny)
endif
bundle_id_def = '-DBUNDLE_ID_PREFIX="@0@"'.format(bundle_id_prefix)
bundle_root = join_paths(apple_applications_dir, apple_application_name + '.app')
# using sparkle update framework?
build_sparkle = xquartz_sparkle_feed_url != ''
build_sparkle = xquartz_sparkle_feed_url != '' and xquartz_sparkle_public_edkey != ''
if build_sparkle
sparkle = dependency('Sparkle', method: 'extraframework')
endif
# libxquartz
srcs_libxquartz = [
'NSUserDefaults+XQuartzDefaults.m',
'X11Application.m',
'X11Controller.m',
'applewm.c',
......
......@@ -31,13 +31,6 @@
#include "pbproxy.h"
#import "x-selection.h"
#include <pthread.h>
#include <unistd.h> /*for getpid*/
#include <Cocoa/Cocoa.h>
static const char *app_prefs_domain = BUNDLE_ID_PREFIX ".xpbproxy";
CFStringRef app_prefs_domain_cfstr;
/* Stubs */
char *display = NULL;
......@@ -82,41 +75,8 @@ xq_asl_log(int level, const char *subsystem, const char *file,
int
main(int argc, const char *argv[])
{
const char *s;
int i;
#ifdef DEBUG
ErrorF("pid: %u\n", getpid());
#endif
xpbproxy_is_standalone = YES;
if ((s = getenv("X11_PREFS_DOMAIN")))
app_prefs_domain = s;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--prefs-domain") == 0 && i + 1 < argc) {
app_prefs_domain = argv[++i];
}
else if (strcmp(argv[i], "--help") == 0) {
ErrorF(
"usage: xpbproxy OPTIONS\n"
"Pasteboard proxying for X11.\n\n"
"--prefs-domain <domain> Change the domain used for reading preferences\n"
" (default: %s)\n",
app_prefs_domain);
return 0;
}
else {
ErrorF("usage: xpbproxy OPTIONS...\n"
"Try 'xpbproxy --help' for more information.\n");
return 1;
}
}
app_prefs_domain_cfstr = CFStringCreateWithCString(NULL, app_prefs_domain,
kCFStringEncodingUTF8);
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
signal(SIGHUP, signal_handler);
......
......@@ -8,9 +8,11 @@ endif
libapplewm_dep = dependency('applewm', version: '>=1.4')
libxpbproxy = static_library('xpbproxy',
['main.m',
['../NSUserDefaults+XQuartzDefaults.m',
'main.m',
'x-input.m',
'x-selection.m'],
include_directories: ['..'],
dependencies: [applewmproto_dep, libapplewm_dep, dependency('xfixes'), dependency('x11')],
objc_args: pbproxy_defs,
)
......
......@@ -38,6 +38,8 @@
#import <AppKit/NSImage.h>
#import <AppKit/NSBitmapImageRep.h>
#import "NSUserDefaults+XQuartzDefaults.h"
/*
* The basic design of the pbproxy code is as follows.
*
......@@ -99,18 +101,6 @@ dump_prefs()
}
#endif
extern CFStringRef app_prefs_domain_cfstr;
static BOOL
prefs_get_bool(CFStringRef key, BOOL defaultValue)
{
Boolean value, ok;
value = CFPreferencesGetAppBooleanValue(key, app_prefs_domain_cfstr, &ok);
return ok ? (BOOL)value : defaultValue;
}
static void
init_propdata(struct propdata *pdata)
{
......@@ -1394,35 +1384,18 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete,
- (void) reload_preferences
{
/*
* It's uncertain how we could handle the synchronization failing, so cast to void.
* The prefs_get_bool should fall back to defaults if the org.x.X11 plist doesn't exist or is invalid.
*/
(void)CFPreferencesAppSynchronize(app_prefs_domain_cfstr);
NSUserDefaults * const defaults = NSUserDefaults.xquartzDefaults;
#ifdef STANDALONE_XPBPROXY
if (xpbproxy_is_standalone)
pbproxy_prefs.active = YES;
else
#endif
pbproxy_prefs.active = prefs_get_bool(CFSTR(
"sync_pasteboard"),
pbproxy_prefs.active);
pbproxy_prefs.primary_on_grab =
prefs_get_bool(CFSTR(
"sync_primary_on_select"),
pbproxy_prefs.primary_on_grab);
pbproxy_prefs.clipboard_to_pasteboard =
prefs_get_bool(CFSTR(
"sync_clipboard_to_pasteboard"),
pbproxy_prefs.clipboard_to_pasteboard);
pbproxy_prefs.pasteboard_to_primary =
prefs_get_bool(CFSTR(
"sync_pasteboard_to_primary"),
pbproxy_prefs.pasteboard_to_primary);
pbproxy_prefs.pasteboard_to_clipboard =
prefs_get_bool(CFSTR(
"sync_pasteboard_to_clipboard"),
pbproxy_prefs.pasteboard_to_clipboard);
pbproxy_prefs.active = [defaults boolForKey:XQuartzPrefKeySyncPasteboard];
pbproxy_prefs.primary_on_grab = [defaults boolForKey:XQuartzPrefKeySyncPrimaryOnSelect];
pbproxy_prefs.clipboard_to_pasteboard = [defaults boolForKey:XQuartzPrefKeySyncClipboardToPasteBoard];
pbproxy_prefs.pasteboard_to_primary = [defaults boolForKey:XQuartzPrefKeySyncPasteboardToPrimary];
pbproxy_prefs.pasteboard_to_clipboard = [defaults boolForKey:XQuartzPrefKeySyncPasteboardToClipboard];
/* This is used for debugging. */
//dump_prefs();
......
......@@ -85,14 +85,16 @@ int aquaMenuBarHeight = 0;
QuartzModeProcsPtr quartzProcs = NULL;
const char *quartzOpenGLBundle = NULL;
Bool XQuartzFullscreenDisableHotkeys = TRUE;
Bool XQuartzOptionSendsAlt = FALSE;
Bool XQuartzEnableKeyEquivalents = TRUE;
/* These are initialized by X11Application with default values set in NSUserDefaults+XQuartzDefaults */
Bool XQuartzFullscreenDisableHotkeys;
Bool XQuartzOptionSendsAlt;
Bool XQuartzEnableKeyEquivalents;
Bool XQuartzFullscreenMenu;
Bool XQuartzRootlessDefault;
Bool XQuartzFullscreenVisible = FALSE;
Bool XQuartzRootlessDefault = TRUE;
Bool XQuartzIsRootless = TRUE;
Bool XQuartzServerVisible = FALSE;
Bool XQuartzFullscreenMenu = FALSE;
int32_t XQuartzShieldingWindowLevel = 0;
......
......@@ -276,7 +276,15 @@ xwl_present_flips_stop(WindowPtr window)
xwl_present_free_idle_vblank(vblank);
if (xwl_present_window->flip_active) {
xwl_present_free_idle_vblank(xwl_present_window->flip_active);
struct xwl_present_event *event;
vblank = xwl_present_window->flip_active;
event = xwl_present_event_from_id((uintptr_t)vblank);
if (event->pixmap)
xwl_present_free_idle_vblank(vblank);
else
xwl_present_free_event(event);
xwl_present_window->flip_active = NULL;
}
......
......@@ -120,8 +120,14 @@ option('apple-application-name', type: 'string', value: 'X11',
description: 'Application name')
option('bundle-id-prefix', type: 'string', value: 'org.x',
description: 'RDNS prefix for bundle identifier')
option('bundle-version', type: 'string', value: 'auto',
description: 'The CFBundleVersion for the application bundle')
option('bundle-version-string', type: 'string', value: 'auto',
description: 'The CFBundleShortVersionString for the application bundle')
option('sparkle-feed-url', type: 'string',
description: 'Feed URL for autoupdating with the Sparkle Framework (default: disabled)')
option('sparkle-public-edkey', type: 'string',
description: 'Public EdDSA key for verifying updates from the Sparkle feed (default: disabled)')
option('xpbproxy', type: 'boolean', value: false,
description: 'Build a standalone X pasteboard proxy')
......
......@@ -51,11 +51,6 @@
#include "rootlessCommon.h"
#include "rootlessWindow.h"
/* In milliseconds */
#ifndef ROOTLESS_REDISPLAY_DELAY
#define ROOTLESS_REDISPLAY_DELAY 10
#endif
extern int RootlessMiValidateTree(WindowPtr pRoot, WindowPtr pChild,
VTKind kind);
extern Bool RootlessCreateGC(GCPtr pGC);
......
......@@ -40,15 +40,73 @@
#endif
#include <dlfcn.h>
static void
print_registers(int frame, unw_cursor_t cursor)
{
const struct {
const char *name;
int regnum;
} regs[] = {
#if UNW_TARGET_X86_64
{ "rax", UNW_X86_64_RAX },
{ "rbx", UNW_X86_64_RBX },
{ "rcx", UNW_X86_64_RCX },
{ "rdx", UNW_X86_64_RDX },
{ "rsi", UNW_X86_64_RSI },
{ "rdi", UNW_X86_64_RDI },
{ "rbp", UNW_X86_64_RBP },
{ "rsp", UNW_X86_64_RSP },
{ " r8", UNW_X86_64_R8 },
{ " r9", UNW_X86_64_R9 },
{ "r10", UNW_X86_64_R10 },
{ "r11", UNW_X86_64_R11 },
{ "r12", UNW_X86_64_R12 },
{ "r13", UNW_X86_64_R13 },
{ "r14", UNW_X86_64_R14 },
{ "r15", UNW_X86_64_R15 },
#endif
};
const int num_regs = sizeof(regs) / sizeof(*regs);
int ret, i;
if (num_regs == 0)
return;
/*
* Advance the cursor from the signal frame to the one that triggered the
* signal.
*/
frame++;
ret = unw_step(&cursor);
if (ret < 0) {
ErrorFSigSafe("unw_step failed: %s [%d]\n", unw_strerror(ret), ret);
return;
}
ErrorFSigSafe("\n");
ErrorFSigSafe("Registers at frame #%d:\n", frame);
for (i = 0; i < num_regs; i++) {
uint64_t val;
ret = unw_get_reg(&cursor, regs[i].regnum, &val);
if (ret < 0) {
ErrorFSigSafe("unw_get_reg(%s) failed: %s [%d]\n",
regs[i].name, unw_strerror(ret), ret);
} else {
ErrorFSigSafe(" %s: 0x%" PRIx64 "\n", regs[i].name, val);
}
}
}
void
xorg_backtrace(void)
{
unw_cursor_t cursor;
unw_cursor_t cursor, signal_cursor;
unw_context_t context;
unw_word_t ip;
unw_word_t off;
unw_proc_info_t pip;
int ret, i = 0;
int ret, i = 0, signal_frame = -1;
char procname[256];
const char *filename;
Dl_info dlinfo;
......@@ -97,14 +155,26 @@ xorg_backtrace(void)
else
filename = "?";
ErrorFSigSafe("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
ret == -UNW_ENOMEM ? "..." : "", (int)off,
(void *)(uintptr_t)(ip));
if (unw_is_signal_frame(&cursor)) {
signal_cursor = cursor;
signal_frame = i;
ErrorFSigSafe("%u: <signal handler called>\n", i++);
} else {
ErrorFSigSafe("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname,
ret == -UNW_ENOMEM ? "..." : "", (int)off,
(void *)(uintptr_t)(ip));
}
ret = unw_step(&cursor);
if (ret < 0)
ErrorFSigSafe("unw_step failed: %s [%d]\n", unw_strerror(ret), ret);
}
if (signal_frame >= 0)
print_registers(signal_frame, signal_cursor);
ErrorFSigSafe("\n");
}
#else /* HAVE_LIBUNWIND */
......
......@@ -79,6 +79,8 @@ SOFTWARE.
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#ifndef WIN32
#include <sys/socket.h>
......@@ -989,15 +991,34 @@ MakeClientGrabPervious(ClientPtr client)
void
ListenOnOpenFD(int fd, int noxauth)
{
char port[256];
char port[PATH_MAX];
XtransConnInfo ciptr;
const char *display_env = getenv("DISPLAY");
if (display_env && (strncmp(display_env, "/tmp/launch", 11) == 0)) {
/* Make the path the launchd socket if our DISPLAY is set right */
strcpy(port, display_env);
/* First check if display_env matches a <absolute path to unix socket>[.<screen number>] scheme (eg: launchd) */
if (display_env && display_env[0] == '/') {
struct stat sbuf;
strlcpy(port, display_env, sizeof(port));
/* If the path exists, we don't have do do anything else.
* If it doesn't, we need to check for a .<screen number> to strip off and recheck.
*/
if (0 != stat(port, &sbuf)) {
char *dot = strrchr(port, '.');
if (dot) {
*dot = '\0';
if (0 != stat(port, &sbuf)) {
display_env = NULL;
}
} else {
display_env = NULL;
}
}
}
else {
if (!display_env) {
/* Just some default so things don't break and die. */
snprintf(port, sizeof(port), ":%d", atoi(display));
}
......