xserver: Branch 'master' - 11 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Feb 19 06:32:57 UTC 2021


 hw/xquartz/Makefile.am       |    2 
 hw/xquartz/X11Application.h  |   15 -
 hw/xquartz/X11Application.m  |  315 +++++++++----------------------
 hw/xquartz/X11Controller.h   |   93 +++------
 hw/xquartz/X11Controller.m   |  436 +++++++++++++++++++------------------------
 hw/xquartz/applewm.c         |    2 
 hw/xquartz/pbproxy/main.m    |   66 ++----
 hw/xquartz/pbproxy/x-input.m |   13 -
 hw/xquartz/quartz.c          |   34 +++
 hw/xquartz/quartz.h          |   11 +
 hw/xquartz/quartzCocoa.m     |   66 ------
 hw/xquartz/quartzCommon.h    |   55 -----
 hw/xquartz/quartzRandR.c     |    1 
 hw/xquartz/quartzStartup.c   |    1 
 hw/xquartz/xpr/xprScreen.c   |    1 
 15 files changed, 418 insertions(+), 693 deletions(-)

New commits:
commit fe89c70e472a9da0541b798eea60c5362b49a99d
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 22:19:21 2021 -0800

    xquartz: Rewrite Window menu handling to not depend on X11App.windowsMenu.numberOfItems being correct in -awakeFromNib
    
    Fixes: https://github.com/XQuartz/XQuartz/issues/56
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index bf2d82df8..b5aeda647 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -63,7 +63,7 @@ extern char *bundle_id_prefix;
 
 @property (nonatomic, readwrite, strong) NSArray *apps;
 @property (nonatomic, readwrite, strong) NSMutableArray *table_apps;
- at property (nonatomic, readwrite, assign) NSInteger windows_menu_start;
+ at property (nonatomic, readwrite, assign) NSInteger windows_menu_nitems;
 @property (nonatomic, readwrite, assign) int checked_window_item;
 @property (nonatomic, readwrite, assign) x_list *pending_apps;
 @property (nonatomic, readwrite, assign) OSX_BOOL finished_launching;
@@ -114,8 +114,6 @@ extern char *bundle_id_prefix;
         selector: @selector(apps_table_done:)
             name: NSWindowWillCloseNotification
           object: self.apps_table.window];
-
-    self.windows_menu_start = X11App.windowsMenu.numberOfItems;
 }
 
 - (void) item_selected:sender
@@ -126,77 +124,6 @@ extern char *bundle_id_prefix;
                        AppleWMWindowMenuItem, [sender tag]);
 }
 
-- (void) remove_window_menu
-{
-    NSMenu *menu;
-    int count, i;
-
-    /* Work backwards so we don't mess up the indices */
-    menu = [X11App windowsMenu];
-    count = [menu numberOfItems];
-    for (i = count - 1; i >= self.windows_menu_start; i--)
-        [menu removeItemAtIndex:i];
-
-    NSMenu * const dock_menu = self.dock_menu;
-
-    count = [dock_menu indexOfItem:self.dock_window_separator];
-    for (i = 0; i < count; i++)
-        [dock_menu removeItemAtIndex:0];
-}
-
-- (void) install_window_menu:(NSArray *)list
-{
-    NSMenu *menu;
-    NSMenuItem *item;
-    int first, count, i;
-
-    menu = [X11App windowsMenu];
-    first = self.windows_menu_start + 1;
-    count = [list count];
-
-    // Push a Separator
-    if (count) {
-        [menu addItem:[NSMenuItem separatorItem]];
-    }
-
-    NSMenu * const dock_menu = self.dock_menu;
-    for (i = 0; i < count; i++) {
-        NSString *name, *shortcut;
-
-        name = [[list objectAtIndex:i] objectAtIndex:0];
-        shortcut = [[list objectAtIndex:i] objectAtIndex:1];
-
-        if (windowItemModMask == 0 || windowItemModMask == -1)
-            shortcut = @"";
-
-        item =
-            (NSMenuItem *)[menu addItemWithTitle:name action:
-                           @selector
-                           (item_selected:) keyEquivalent:shortcut];
-        [item setKeyEquivalentModifierMask:(NSUInteger)windowItemModMask];
-        [item setTarget:self];
-        [item setTag:i];
-        [item setEnabled:YES];
-
-        item = (NSMenuItem *)[dock_menu  insertItemWithTitle:name
-                                                      action:@selector
-                              (item_selected:) keyEquivalent:shortcut
-                                                     atIndex:i];
-        [item setKeyEquivalentModifierMask:(NSUInteger)windowItemModMask];
-        [item setTarget:self];
-        [item setTag:i];
-        [item setEnabled:YES];
-    }
-
-    int const checked_window_item = self.checked_window_item;
-    if (checked_window_item >= 0 && checked_window_item < count) {
-        item = (NSMenuItem *)[menu itemAtIndex:first + checked_window_item];
-        [item setState:NSOnState];
-        item = (NSMenuItem *)[dock_menu itemAtIndex:checked_window_item];
-        [item setState:NSOnState];
-    }
-}
-
 - (void) remove_apps_menu
 {
     NSMenu *menu;
@@ -282,25 +209,83 @@ extern char *bundle_id_prefix;
 
 - (void) set_window_menu:(NSArray *)list
 {
-    [self remove_window_menu];
-    [self install_window_menu:list];
+    NSMenu * const menu = X11App.windowsMenu;
+    NSMenu * const dock_menu = self.dock_menu;
 
-    DarwinSendDDXEvent(kXquartzControllerNotify, 1,
-                       AppleWMWindowMenuNotify);
+    /* First, remove the existing items from the Window Menu */
+    NSInteger itemsToRemove = self.windows_menu_nitems;
+    if (itemsToRemove > 0) {
+        NSInteger indexForRemoval = menu.numberOfItems - itemsToRemove - 1; /* we also want to remove the separator */
+
+        for (NSInteger i = 0 ; i < itemsToRemove + 1 ; i++) {
+            [menu removeItemAtIndex:indexForRemoval];
+        }
+
+        for (NSInteger i = 0 ; i < itemsToRemove; i++) {
+            [dock_menu removeItemAtIndex:0];
+        }
+    }
+
+    NSInteger const itemsToAdd = list.count;
+    self.windows_menu_nitems = itemsToAdd;
+
+    if (itemsToAdd > 0) {
+        NSMenuItem *item;
+
+        // Push a Separator
+        [menu addItem:[NSMenuItem separatorItem]];
+
+        for (NSInteger i = 0; i < itemsToAdd; i++) {
+            NSString *name, *shortcut;
+
+            name = list[i][0];
+            shortcut = list[i][1];
+
+            if (windowItemModMask == 0 || windowItemModMask == -1)
+                shortcut = @"";
+
+            item = (NSMenuItem *)[menu addItemWithTitle:name
+                                                 action:@selector(item_selected:)
+                                          keyEquivalent:shortcut];
+            [item setKeyEquivalentModifierMask:(NSUInteger)windowItemModMask];
+            [item setTarget:self];
+            [item setTag:i];
+            [item setEnabled:YES];
+
+            item = (NSMenuItem *)[dock_menu  insertItemWithTitle:name
+                                                          action:@selector(item_selected:)
+                                                   keyEquivalent:shortcut
+                                                         atIndex:i];
+            [item setKeyEquivalentModifierMask:(NSUInteger)windowItemModMask];
+            [item setTarget:self];
+            [item setTag:i];
+            [item setEnabled:YES];
+        }
+
+        int const checked_window_item = self.checked_window_item;
+        if (checked_window_item >= 0 && checked_window_item < itemsToAdd) {
+            NSInteger first = menu.numberOfItems - itemsToAdd;
+            item = (NSMenuItem *)[menu itemAtIndex:first + checked_window_item];
+            [item setState:NSOnState];
+
+            item = (NSMenuItem *)[dock_menu itemAtIndex:checked_window_item];
+            [item setState:NSOnState];
+        }
+    }
+
+    DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMWindowMenuNotify);
 }
 
 - (void) set_window_menu_check:(NSNumber *)nn
 {
-    NSMenu *menu;
+    NSMenu * const menu = X11App.windowsMenu;
+    NSMenu * const dock_menu = self.dock_menu;
     NSMenuItem *item;
-    int first, count;
-    int n = [nn intValue];
+    int n = nn.intValue;
 
-    menu = [X11App windowsMenu];
-    first = self.windows_menu_start + 1;
-    count = [menu numberOfItems] - first;
+    NSInteger const count = self.windows_menu_nitems;
+    NSInteger const first = menu.numberOfItems - count;
 
-    NSMenu * const dock_menu = self.dock_menu;
     int const checked_window_item = self.checked_window_item;
 
     if (checked_window_item >= 0 && checked_window_item < count) {
commit 41aed8f69634ec61ea0e40fff1cfdaf868be843e
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 15:41:29 2021 -0800

    xquartz: Convert X11Controller ivars into @properties
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 1dacea369..7923c337b 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -916,7 +916,7 @@ void
 X11ApplicationSetCanQuit(int state)
 {
     dispatch_async(dispatch_get_main_queue(), ^{
-        [X11App.controller set_can_quit:!!state];
+        X11App.controller.can_quit = !!state;
     });
 }
 
diff --git a/hw/xquartz/X11Controller.h b/hw/xquartz/X11Controller.h
index 139b035c4..d5be0e8b6 100644
--- a/hw/xquartz/X11Controller.h
+++ b/hw/xquartz/X11Controller.h
@@ -47,56 +47,42 @@
 #endif
 
 @interface X11Controller : NSObject <NSTableViewDataSource>
-{
-    IBOutlet NSPanel *prefs_panel;
-
-    IBOutlet NSButton *fake_buttons;
-    IBOutlet NSButton *enable_fullscreen;
-    IBOutlet NSButton *enable_fullscreen_menu;
-    IBOutlet NSTextField *enable_fullscreen_menu_text;
-    IBOutlet NSButton *enable_keyequivs;
-    IBOutlet NSButton *sync_keymap;
-    IBOutlet NSButton *option_sends_alt;
-    IBOutlet NSButton *scroll_in_device_direction;
-    IBOutlet NSButton *click_through;
-    IBOutlet NSButton *focus_follows_mouse;
-    IBOutlet NSButton *focus_on_new_window;
-    IBOutlet NSButton *enable_auth;
-    IBOutlet NSButton *enable_tcp;
-    IBOutlet NSButton *sync_pasteboard;
-    IBOutlet NSButton *sync_pasteboard_to_clipboard;
-    IBOutlet NSButton *sync_pasteboard_to_primary;
-    IBOutlet NSButton *sync_clipboard_to_pasteboard;
-    IBOutlet NSButton *sync_primary_immediately;
-    IBOutlet NSTextField *sync_text1;
-    IBOutlet NSTextField *sync_text2;
-    IBOutlet NSPopUpButton *depth;
-
-    IBOutlet NSMenuItem *x11_about_item;
-    IBOutlet NSMenuItem *dock_window_separator;
-    IBOutlet NSMenuItem *apps_separator;
-    IBOutlet NSMenuItem *toggle_fullscreen_item;
-#ifdef XQUARTZ_SPARKLE
-    NSMenuItem *check_for_updates_item; // Programmatically enabled
-#endif
-    IBOutlet NSMenuItem *copy_menu_item;
-    IBOutlet NSMenu *dock_apps_menu;
-    IBOutlet NSTableView *apps_table;
-
-    NSArray *apps;
-    NSMutableArray *table_apps;
-
-    IBOutlet NSMenu *dock_menu;
-
-    // This is where in the Windows menu we'll start (this will be the index of the separator)
-    NSInteger windows_menu_start;
-
-    int checked_window_item;
-    x_list *pending_apps;
-
-    OSX_BOOL finished_launching;
-    OSX_BOOL can_quit;
-}
+ at property (nonatomic, readwrite, strong) IBOutlet NSPanel *prefs_panel;
+
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *fake_buttons;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *enable_fullscreen;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *enable_fullscreen_menu;
+ at property (nonatomic, readwrite, strong) IBOutlet NSTextField *enable_fullscreen_menu_text;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *enable_keyequivs;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *sync_keymap;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *option_sends_alt;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *scroll_in_device_direction;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *click_through;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *focus_follows_mouse;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *focus_on_new_window;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *enable_auth;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *enable_tcp;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *sync_pasteboard;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *sync_pasteboard_to_clipboard;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *sync_pasteboard_to_primary;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *sync_clipboard_to_pasteboard;
+ at property (nonatomic, readwrite, strong) IBOutlet NSButton *sync_primary_immediately;
+ at property (nonatomic, readwrite, strong) IBOutlet NSTextField *sync_text1;
+ at property (nonatomic, readwrite, strong) IBOutlet NSTextField *sync_text2;
+ at property (nonatomic, readwrite, strong) IBOutlet NSPopUpButton *depth;
+
+ at property (nonatomic, readwrite, strong) IBOutlet NSMenuItem *x11_about_item;
+ at property (nonatomic, readwrite, strong) IBOutlet NSMenuItem *dock_window_separator;
+ at property (nonatomic, readwrite, strong) IBOutlet NSMenuItem *apps_separator;
+ at property (nonatomic, readwrite, strong) IBOutlet NSMenuItem *toggle_fullscreen_item;
+
+ at property (nonatomic, readwrite, strong) IBOutlet NSMenuItem *copy_menu_item;
+ at property (nonatomic, readwrite, strong) IBOutlet NSMenu *dock_apps_menu;
+ at property (nonatomic, readwrite, strong) IBOutlet NSTableView *apps_table;
+
+ at property (nonatomic, readwrite, strong) IBOutlet NSMenu *dock_menu;
+
+ at property (nonatomic, readwrite, assign) OSX_BOOL can_quit;
 
 - (void)set_window_menu:(NSArray *)list;
 - (void)set_window_menu_check:(NSNumber *)n;
@@ -106,7 +92,6 @@
 - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)
    update;
 #endif
-- (void)set_can_quit:(OSX_BOOL)state;
 - (void)server_ready;
 - (OSX_BOOL)application:(NSApplication *)app openFile:(NSString *)filename;
 
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 1e37fcceb..bf2d82df8 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -56,6 +56,19 @@
 extern aslclient aslc;
 extern char *bundle_id_prefix;
 
+ at interface X11Controller ()
+#ifdef XQUARTZ_SPARKLE
+ at property (nonatomic, readwrite, strong) NSMenuItem *check_for_updates_item; // Programatically enabled
+#endif
+
+ at property (nonatomic, readwrite, strong) NSArray *apps;
+ at property (nonatomic, readwrite, strong) NSMutableArray *table_apps;
+ at property (nonatomic, readwrite, assign) NSInteger windows_menu_start;
+ at property (nonatomic, readwrite, assign) int checked_window_item;
+ at property (nonatomic, readwrite, assign) x_list *pending_apps;
+ at property (nonatomic, readwrite, assign) OSX_BOOL finished_launching;
+ at end
+
 @implementation X11Controller
 
 - (void) awakeFromNib
@@ -100,9 +113,9 @@ extern char *bundle_id_prefix;
      addObserver: self
         selector: @selector(apps_table_done:)
             name: NSWindowWillCloseNotification
-          object: [apps_table window]];
+          object: self.apps_table.window];
 
-    windows_menu_start = [[X11App windowsMenu] numberOfItems];
+    self.windows_menu_start = X11App.windowsMenu.numberOfItems;
 }
 
 - (void) item_selected:sender
@@ -121,10 +134,12 @@ extern char *bundle_id_prefix;
     /* Work backwards so we don't mess up the indices */
     menu = [X11App windowsMenu];
     count = [menu numberOfItems];
-    for (i = count - 1; i >= windows_menu_start; i--)
+    for (i = count - 1; i >= self.windows_menu_start; i--)
         [menu removeItemAtIndex:i];
 
-    count = [dock_menu indexOfItem:dock_window_separator];
+    NSMenu * const dock_menu = self.dock_menu;
+
+    count = [dock_menu indexOfItem:self.dock_window_separator];
     for (i = 0; i < count; i++)
         [dock_menu removeItemAtIndex:0];
 }
@@ -136,7 +151,7 @@ extern char *bundle_id_prefix;
     int first, count, i;
 
     menu = [X11App windowsMenu];
-    first = windows_menu_start + 1;
+    first = self.windows_menu_start + 1;
     count = [list count];
 
     // Push a Separator
@@ -144,6 +159,7 @@ extern char *bundle_id_prefix;
         [menu addItem:[NSMenuItem separatorItem]];
     }
 
+    NSMenu * const dock_menu = self.dock_menu;
     for (i = 0; i < count; i++) {
         NSString *name, *shortcut;
 
@@ -172,6 +188,7 @@ extern char *bundle_id_prefix;
         [item setEnabled:YES];
     }
 
+    int const checked_window_item = self.checked_window_item;
     if (checked_window_item >= 0 && checked_window_item < count) {
         item = (NSMenuItem *)[menu itemAtIndex:first + checked_window_item];
         [item setState:NSOnState];
@@ -186,7 +203,10 @@ extern char *bundle_id_prefix;
     NSMenuItem *item;
     int i;
 
-    if (apps == nil || apps_separator == nil) return;
+    NSMenuItem * const apps_separator = self.apps_separator;
+    NSMenu * const dock_apps_menu = self.dock_apps_menu;
+
+    if (self.apps == nil || apps_separator == nil) return;
 
     menu = [apps_separator menu];
 
@@ -206,8 +226,7 @@ extern char *bundle_id_prefix;
         }
     }
 
-    [apps release];
-    apps = nil;
+    self.apps = nil;
 }
 
 - (void) prepend_apps_item:(NSArray *)list index:(int)i menu:(NSMenu *)menu
@@ -244,6 +263,9 @@ extern char *bundle_id_prefix;
 
     count = [list count];
 
+    NSMenuItem * const apps_separator = self.apps_separator;
+    NSMenu * const dock_apps_menu = self.dock_apps_menu;
+
     if (count == 0 || apps_separator == nil) return;
 
     menu = [apps_separator menu];
@@ -255,7 +277,7 @@ extern char *bundle_id_prefix;
             [self prepend_apps_item:list index:i menu:dock_apps_menu];
     }
 
-    apps = [list retain];
+    self.apps = list;
 }
 
 - (void) set_window_menu:(NSArray *)list
@@ -275,9 +297,12 @@ extern char *bundle_id_prefix;
     int n = [nn intValue];
 
     menu = [X11App windowsMenu];
-    first = windows_menu_start + 1;
+    first = self.windows_menu_start + 1;
     count = [menu numberOfItems] - first;
 
+    NSMenu * const dock_menu = self.dock_menu;
+    int const checked_window_item = self.checked_window_item;
+
     if (checked_window_item >= 0 && checked_window_item < count) {
         item = (NSMenuItem *)[menu itemAtIndex:first + checked_window_item];
         [item setState:NSOffState];
@@ -290,7 +315,7 @@ extern char *bundle_id_prefix;
         item = (NSMenuItem *)[dock_menu itemAtIndex:n];
         [item setState:NSOnState];
     }
-    checked_window_item = n;
+    self.checked_window_item = n;
 }
 
 - (void) set_apps_menu:(NSArray *)list
@@ -305,7 +330,7 @@ extern char *bundle_id_prefix;
     if (check_for_updates_item)
         return;  // already did it...
 
-    NSMenu *menu = [x11_about_item menu];
+    NSMenu *menu = [self.x11_about_item menu];
 
     check_for_updates_item =
         [menu insertItemWithTitle:NSLocalizedString(
@@ -326,7 +351,7 @@ extern char *bundle_id_prefix;
 - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)
    update
 {
-    //[self set_can_quit:YES];
+    //self.can_quit = YES;
 }
 
 #endif
@@ -438,6 +463,7 @@ extern char *bundle_id_prefix;
 {
     int tag;
     NSString *item;
+    NSArray * const apps = self.apps;
 
     tag = [sender tag] - 1;
     if (apps == nil || tag < 0 || tag >= [apps count])
@@ -451,12 +477,13 @@ extern char *bundle_id_prefix;
 - (IBAction) apps_table_show:sender
 {
     NSArray *columns;
-    NSMutableArray *oldapps = nil;
+    NSMutableArray *oldapps = self.table_apps;
+    NSTableView * const apps_table = self.apps_table;
 
-    if (table_apps != nil)
-        oldapps = table_apps;
+    NSMutableArray * const table_apps = [[NSMutableArray alloc] initWithCapacity:1];
+    self.table_apps = table_apps;
 
-    table_apps = [[NSMutableArray alloc] initWithCapacity:1];
+    NSArray * const apps = self.apps;
     if (apps != nil)
         [table_apps addObjectsFromArray:apps];
 
@@ -477,6 +504,8 @@ extern char *bundle_id_prefix;
 
 - (IBAction) apps_table_done:sender
 {
+    NSMutableArray * const table_apps = self.table_apps;
+    NSTableView * const apps_table = self.apps_table;
     [apps_table deselectAll:sender];    /* flush edits? */
 
     [self remove_apps_menu];
@@ -487,13 +516,14 @@ extern char *bundle_id_prefix;
 
     [[apps_table window] orderOut:sender];
 
-    [table_apps release];
-    table_apps = nil;
+    self.table_apps = nil;
 }
 
 - (IBAction) apps_table_new:sender
 {
     NSMutableArray *item;
+    NSMutableArray * const table_apps = self.table_apps;
+    NSTableView * const apps_table = self.apps_table;
 
     int row = [apps_table selectedRow], i;
 
@@ -521,6 +551,8 @@ extern char *bundle_id_prefix;
 
 - (IBAction) apps_table_duplicate:sender
 {
+    NSMutableArray * const table_apps = self.table_apps;
+    NSTableView * const apps_table = self.apps_table;
     int row = [apps_table selectedRow], i;
     NSObject *item;
 
@@ -545,6 +577,8 @@ extern char *bundle_id_prefix;
 
 - (IBAction) apps_table_delete:sender
 {
+    NSMutableArray * const table_apps = self.table_apps;
+    NSTableView * const apps_table = self.apps_table;
     int row = [apps_table selectedRow];
 
     if (row >= 0) {
@@ -567,6 +601,7 @@ extern char *bundle_id_prefix;
 
 - (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
 {
+    NSMutableArray * const table_apps = self.table_apps;
     if (table_apps == nil) return 0;
 
     return [table_apps count];
@@ -575,6 +610,7 @@ extern char *bundle_id_prefix;
 - (id)             tableView:(NSTableView *)tableView
    objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
 {
+    NSMutableArray * const table_apps = self.table_apps;
     NSArray *item;
     int col;
 
@@ -592,6 +628,7 @@ extern char *bundle_id_prefix;
 - (void) tableView:(NSTableView *)tableView setObjectValue:(id)object
     forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
 {
+    NSMutableArray * const table_apps = self.table_apps;
     NSMutableArray *item;
     int col;
 
@@ -652,11 +689,10 @@ extern char *bundle_id_prefix;
 
 - (IBAction) enable_fullscreen_changed:sender
 {
-    XQuartzRootlessDefault = ![enable_fullscreen intValue];
+    XQuartzRootlessDefault = !self.enable_fullscreen.intValue;
 
-    [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
-    [enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ?[
-         NSColor disabledControlTextColor] : [NSColor controlTextColor]];
+    [self.enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
+    [self.enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ? NSColor.disabledControlTextColor : NSColor.controlTextColor];
 
     DarwinSendDDXEvent(kXquartzSetRootless, 1, XQuartzRootlessDefault);
 
@@ -669,102 +705,85 @@ extern char *bundle_id_prefix;
     DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
 }
 
-- (void) set_can_quit:(OSX_BOOL)state
-{
-    can_quit = state;
-}
-
 - (IBAction)prefs_changed:sender
 {
     if (!sender)
         return;
 
-    if (sender == fake_buttons) {
-        darwinFakeButtons = [fake_buttons intValue];
+    if (sender == self.fake_buttons) {
+        darwinFakeButtons = self.fake_buttons.intValue;
         [NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons];
     }
-    else if (sender == enable_keyequivs) {
-        XQuartzEnableKeyEquivalents = [enable_keyequivs intValue];
+    else if (sender == self.enable_keyequivs) {
+        XQuartzEnableKeyEquivalents = self.enable_keyequivs.intValue;
         [NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:
          XQuartzEnableKeyEquivalents];
     }
-    else if (sender == sync_keymap) {
-        darwinSyncKeymap = [sync_keymap intValue];
+    else if (sender == self.sync_keymap) {
+        darwinSyncKeymap = self.sync_keymap.intValue;
         [NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap];
     }
-    else if (sender == enable_fullscreen_menu) {
-        XQuartzFullscreenMenu = [enable_fullscreen_menu intValue];
+    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 == option_sends_alt) {
+    else if (sender == self.option_sends_alt) {
         BOOL prev_opt_sends_alt = XQuartzOptionSendsAlt;
 
-        XQuartzOptionSendsAlt = [option_sends_alt intValue];
+        XQuartzOptionSendsAlt = self.option_sends_alt.intValue;
         [NSApp prefs_set_boolean:@PREFS_OPTION_SENDS_ALT value:
          XQuartzOptionSendsAlt];
 
         if (prev_opt_sends_alt != XQuartzOptionSendsAlt)
             QuartsResyncKeymap(TRUE);
     }
-    else if (sender == click_through) {
-        [NSApp prefs_set_boolean:@PREFS_CLICK_THROUGH value:[click_through
-                                                             intValue]];
+    else if (sender == self.click_through) {
+        [NSApp prefs_set_boolean:@PREFS_CLICK_THROUGH value:self.click_through.intValue];
     }
-    else if (sender == focus_follows_mouse) {
-        [NSApp prefs_set_boolean:@PREFS_FFM value:[focus_follows_mouse
-                                                   intValue]];
+    else if (sender == self.focus_follows_mouse) {
+        [NSApp prefs_set_boolean:@PREFS_FFM value:self.focus_follows_mouse.intValue];
     }
-    else if (sender == focus_on_new_window) {
-        [NSApp prefs_set_boolean:@PREFS_FOCUS_ON_NEW_WINDOW value:[
-             focus_on_new_window 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 == enable_auth) {
-        [NSApp prefs_set_boolean:@PREFS_NO_AUTH value:![enable_auth intValue]
-        ];
+    else if (sender == self.enable_auth) {
+        [NSApp prefs_set_boolean:@PREFS_NO_AUTH value:!self.enable_auth.intValue];
     }
-    else if (sender == enable_tcp) {
-        [NSApp prefs_set_boolean:@PREFS_NO_TCP value:![enable_tcp intValue]];
+    else if (sender == self.enable_tcp) {
+        [NSApp prefs_set_boolean:@PREFS_NO_TCP value:!self.enable_tcp.intValue];
     }
-    else if (sender == depth) {
-        [NSApp prefs_set_integer:@PREFS_DEPTH value:[depth selectedTag]];
+    else if (sender == self.depth) {
+        [NSApp prefs_set_integer:@PREFS_DEPTH value:self.depth.selectedTag];
     }
-    else if (sender == sync_pasteboard) {
-        BOOL pbproxy_active = [sync_pasteboard intValue];
+    else if (sender == self.sync_pasteboard) {
+        BOOL pbproxy_active = self.sync_pasteboard.intValue;
         [NSApp prefs_set_boolean:@PREFS_SYNC_PB value:pbproxy_active];
 
-        [sync_pasteboard_to_clipboard setEnabled:pbproxy_active];
-        [sync_pasteboard_to_primary setEnabled:pbproxy_active];
-        [sync_clipboard_to_pasteboard setEnabled:pbproxy_active];
-        [sync_primary_immediately setEnabled:pbproxy_active];
+        [self.sync_pasteboard_to_clipboard setEnabled:pbproxy_active];
+        [self.sync_pasteboard_to_primary setEnabled:pbproxy_active];
+        [self.sync_clipboard_to_pasteboard setEnabled:pbproxy_active];
+        [self.sync_primary_immediately setEnabled:pbproxy_active];
 
         // setEnabled doesn't do this...
-        [sync_text1 setTextColor:pbproxy_active ?[NSColor controlTextColor] :
-         [NSColor disabledControlTextColor]];
-        [sync_text2 setTextColor:pbproxy_active ?[NSColor controlTextColor] :
-         [NSColor disabledControlTextColor]];
+        [self.sync_text1 setTextColor:pbproxy_active ? NSColor.controlTextColor : NSColor.disabledControlTextColor];
+        [self.sync_text2 setTextColor:pbproxy_active ? NSColor.controlTextColor : NSColor.disabledControlTextColor];
     }
-    else if (sender == sync_pasteboard_to_clipboard) {
-        [NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD value:[
-             sync_pasteboard_to_clipboard intValue]];
+    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 == sync_pasteboard_to_primary) {
-        [NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_PRIMARY value:[
-             sync_pasteboard_to_primary 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 == sync_clipboard_to_pasteboard) {
-        [NSApp prefs_set_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB value:[
-             sync_clipboard_to_pasteboard 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 == sync_primary_immediately) {
-        [NSApp prefs_set_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT value:[
-             sync_primary_immediately 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 == scroll_in_device_direction) {
-        XQuartzScrollInDeviceDirection =
-            [scroll_in_device_direction intValue];
-        [NSApp prefs_set_boolean:@PREFS_SCROLL_IN_DEV_DIRECTION value:
-         XQuartzScrollInDeviceDirection];
+    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];
@@ -777,62 +796,42 @@ extern char *bundle_id_prefix;
     BOOL pbproxy_active =
         [NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES];
 
-    [scroll_in_device_direction setIntValue:XQuartzScrollInDeviceDirection];
-
-    [fake_buttons setIntValue:darwinFakeButtons];
-    [enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents];
-    [sync_keymap setIntValue:darwinSyncKeymap];
-    [option_sends_alt setIntValue:XQuartzOptionSendsAlt];
-    [click_through setIntValue:[NSApp prefs_get_boolean:@PREFS_CLICK_THROUGH
-                                default:NO]];
-    [focus_follows_mouse setIntValue:[NSApp prefs_get_boolean:@PREFS_FFM
-                                      default:NO]];
-    [focus_on_new_window setIntValue:[NSApp prefs_get_boolean:
-                                      @PREFS_FOCUS_ON_NEW_WINDOW default:YES]
-    ];
-
-    [enable_auth setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_AUTH default
-                               :NO]];
-    [enable_tcp setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_TCP default:
-                              NO]];
-
-    [depth selectItemAtIndex:[depth indexOfItemWithTag:[NSApp
-                                                        prefs_get_integer:
-                                                        @PREFS_DEPTH default:
-                                                        -1]]];
-
-    [sync_pasteboard setIntValue:pbproxy_active];
-    [sync_pasteboard_to_clipboard setIntValue:[NSApp prefs_get_boolean:
-                                               @PREFS_SYNC_PB_TO_CLIPBOARD
-                                               default:YES]];
-    [sync_pasteboard_to_primary setIntValue:[NSApp prefs_get_boolean:
-                                             @PREFS_SYNC_PB_TO_PRIMARY
-                                             default:YES]];
-    [sync_clipboard_to_pasteboard setIntValue:[NSApp prefs_get_boolean:
-                                               @PREFS_SYNC_CLIPBOARD_TO_PB
-                                               default:YES]];
-    [sync_primary_immediately setIntValue:[NSApp prefs_get_boolean:
-                                           @PREFS_SYNC_PRIMARY_ON_SELECT
-                                           default:NO]];
-
-    [sync_pasteboard_to_clipboard setEnabled:pbproxy_active];
-    [sync_pasteboard_to_primary setEnabled:pbproxy_active];
-    [sync_clipboard_to_pasteboard setEnabled:pbproxy_active];
-    [sync_primary_immediately setEnabled:pbproxy_active];
+    [self.scroll_in_device_direction setIntValue:XQuartzScrollInDeviceDirection];
+
+    [self.fake_buttons setIntValue:darwinFakeButtons];
+    [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.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.depth selectItemAtIndex:[self.depth indexOfItemWithTag:[NSApp prefs_get_integer:@PREFS_DEPTH default:-1]]];
+
+    [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 setEnabled:pbproxy_active];
+    [self.sync_pasteboard_to_primary setEnabled:pbproxy_active];
+    [self.sync_clipboard_to_pasteboard setEnabled:pbproxy_active];
+    [self.sync_primary_immediately setEnabled:pbproxy_active];
 
     // setEnabled doesn't do this...
-    [sync_text1 setTextColor:pbproxy_active ?[NSColor controlTextColor] : [
-         NSColor disabledControlTextColor]];
-    [sync_text2 setTextColor:pbproxy_active ?[NSColor controlTextColor] : [
-         NSColor disabledControlTextColor]];
+    [self.sync_text1 setTextColor:pbproxy_active ? NSColor.controlTextColor : NSColor.disabledControlTextColor];
+    [self.sync_text2 setTextColor:pbproxy_active ? NSColor.controlTextColor : NSColor.disabledControlTextColor];
 
-    [enable_fullscreen setIntValue:!XQuartzRootlessDefault];
-    [enable_fullscreen_menu setIntValue:XQuartzFullscreenMenu];
-    [enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
-    [enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ?[
-         NSColor disabledControlTextColor] : [NSColor controlTextColor]];
+    [self.enable_fullscreen setIntValue:!XQuartzRootlessDefault];
+    [self.enable_fullscreen_menu setIntValue:XQuartzFullscreenMenu];
+    [self.enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
+    [self.enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ? NSColor.disabledControlTextColor : NSColor.controlTextColor];
 
-    [prefs_panel makeKeyAndOrderFront:sender];
+    [self.prefs_panel makeKeyAndOrderFront:sender];
 }
 
 - (IBAction) quit:sender
@@ -848,11 +847,12 @@ extern char *bundle_id_prefix;
 - (OSX_BOOL) validateMenuItem:(NSMenuItem *)item
 {
     NSMenu *menu = [item menu];
+    NSMenu * const dock_menu = self.dock_menu;
 
-    if (item == toggle_fullscreen_item)
+    if (item == self.toggle_fullscreen_item)
         return !XQuartzIsRootless;
     else if (menu == [X11App windowsMenu] || menu == dock_menu
-             || (menu == [x11_about_item menu] && [item tag] == 42))
+             || (menu == [self.x11_about_item menu] && [item tag] == 42))
         return (AppleWMSelectedEvents() & AppleWMControllerNotifyMask) != 0;
     else
         return TRUE;
@@ -880,7 +880,7 @@ extern char *bundle_id_prefix;
     NSString *msg;
     NSString *title;
 
-    if (can_quit ||
+    if (self.can_quit ||
         [X11App prefs_get_boolean:@PREFS_NO_QUIT_ALERT default:NO])
         return NSTerminateNow;
 
@@ -919,26 +919,26 @@ extern char *bundle_id_prefix;
 {
     x_list *node;
 
-    finished_launching = YES;
+    self.finished_launching = YES;
 
-    for (node = pending_apps; node != NULL; node = node->next) {
+    for (node = self.pending_apps; node != NULL; node = node->next) {
         NSString *filename = node->data;
         [self launch_client:filename];
         [filename release];
     }
 
-    x_list_free(pending_apps);
-    pending_apps = NULL;
+    x_list_free(self.pending_apps);
+    self.pending_apps = NULL;
 }
 
 - (OSX_BOOL) application:(NSApplication *)app openFile:(NSString *)filename
 {
     const char *name = [filename UTF8String];
 
-    if (finished_launching)
+    if (self.finished_launching)
         [self launch_client:filename];
     else if (name[0] != ':')            /* ignore display names */
-        pending_apps = x_list_prepend(pending_apps, [filename retain]);
+        self.pending_apps = x_list_prepend(self.pending_apps, [filename retain]);
 
     /* FIXME: report failures. */
     return YES;
commit c2750e1fab774c8e6675ecf284124ff55b5be9cf
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 14:39:46 2021 -0800

    xquartz: Convert X11Application ivars into @properties
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index d636a3a69..d3ff4ebd0 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -37,13 +37,10 @@
 
 #import "X11Controller.h"
 
- at interface X11Application : NSApplication {
-    X11Controller *_controller;
+ at interface X11Application : NSApplication
 
-    unsigned int _x_active : 1;
-}
-
-- (void)set_controller:controller;
+ at property (nonatomic, readwrite, strong) X11Controller *controller;
+ at 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;
@@ -59,9 +56,6 @@
 - (void)prefs_set_array:(NSString *)key value:(NSArray *)value;
 - (void)prefs_set_string:(NSString *)key value:(NSString *)value;
 - (void)prefs_synchronize;
-
-- (X11Controller *)controller;
-- (OSX_BOOL)x_active;
 @end
 
 extern X11Application * X11App;
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 67c638b6d..1dacea369 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -106,6 +106,10 @@ CFStringRef app_prefs_domain_cfstr = NULL;
 - (void) sendX11NSEvent:(NSEvent *)e;
 @end
 
+ at interface X11Application ()
+ at property (nonatomic, readwrite, assign) OSX_BOOL x_active;
+ at end
+
 @implementation X11Application
 
 typedef struct message_struct message;
@@ -120,15 +124,9 @@ struct message_struct {
 Bool
 QuartzModeBundleInit(void);
 
-- (void) set_controller:obj
-{
-    if (_controller == nil) _controller = [obj retain];
-}
-
 - (void) dealloc
 {
-    if (_controller != nil) [_controller release];
-
+    self.controller = nil;
     [super dealloc];
 }
 
@@ -158,10 +156,12 @@ QuartzModeBundleInit(void);
 
 - (void) activateX:(OSX_BOOL)state
 {
-    if (_x_active == state)
+    OSX_BOOL const x_active = self.x_active;
+
+    if (x_active == state)
         return;
 
-    DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active);
+    DEBUG_LOG("state=%d, x_active=%d, \n", state, x_active);
     if (state) {
         if (bgMouseLocationUpdated) {
             DarwinSendPointerEvents(darwinPointer, MotionNotify, 0,
@@ -185,7 +185,7 @@ QuartzModeBundleInit(void);
         DarwinSendDDXEvent(kXquartzDeactivate, 0);
     }
 
-    _x_active = state;
+    self.x_active = state;
 }
 
 - (void) became_key:(NSWindow *)win
@@ -196,6 +196,7 @@ QuartzModeBundleInit(void);
 - (void) sendEvent:(NSEvent *)e
 {
     OSX_BOOL for_appkit, for_x;
+    OSX_BOOL const x_active = self.x_active;
 
     /* By default pass down the responder chain and to X. */
     for_appkit = YES;
@@ -211,13 +212,13 @@ QuartzModeBundleInit(void);
         if ([e window] != nil) {
             /* Pointer event has an (AppKit) window. Probably something for the kit. */
             for_x = NO;
-            if (_x_active) [self activateX:NO];
+            if (x_active) [self activateX:NO];
         }
         else if ([self modalWindow] == nil) {
             /* Must be an X window. Tell appkit windows to resign main/key */
             for_appkit = NO;
 
-            if (!_x_active && quartzProcs->IsX11Window([e windowNumber])) {
+            if (!x_active && quartzProcs->IsX11Window([e windowNumber])) {
                 if ([self respondsToSelector:@selector(_setKeyWindow:)] && [self respondsToSelector:@selector(_setMainWindow:)]) {
                     NSWindow *keyWindow = [self keyWindow];
                     if (keyWindow) {
@@ -434,7 +435,7 @@ QuartzModeBundleInit(void);
 
 - (void) set_apps_menu:(NSArray *)list
 {
-    [_controller set_apps_menu:list];
+    [self.controller set_apps_menu:list];
 }
 
 - (void) set_front_process:unused
@@ -457,7 +458,7 @@ QuartzModeBundleInit(void);
 
 - (void) launch_client:(NSString *)cmd
 {
-    (void)[_controller application:self openFile:cmd];
+    (void)[self.controller application:self openFile:cmd];
 }
 
 /* user preferences */
@@ -867,16 +868,6 @@ cfarray_to_nsarray(CFArrayRef in)
                        AppleWMCopyToPasteboard);
 }
 
-- (X11Controller *) controller
-{
-    return _controller;
-}
-
-- (OSX_BOOL) x_active
-{
-    return _x_active;
-}
-
 @end
 
 void
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index d489dde5d..1e37fcceb 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -64,7 +64,7 @@ extern char *bundle_id_prefix;
     NSArray *array;
 
     /* Point X11Application at ourself. */
-    [xapp set_controller:self];
+    xapp.controller = self;
 
     array = [xapp prefs_get_array:@PREFS_APPSMENU];
     if (array != nil) {
commit f51b97b0de2e562e341f2d72c5f00a74c71a159f
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 14:47:50 2021 -0800

    xquartz: Fold quartzCommon.h into quartz.h
    
    Everything declared in it comes from quartz.c, so match reality.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index c238fe909..342a998b2 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -45,7 +45,6 @@ EXTRA_DIST = \
 	darwinEvents.h \
 	keysym2ucs.h \
 	quartz.h \
-	quartzCommon.h \
 	quartzKeyboard.h \
 	quartzRandR.h \
 	sanitizedCarbon.h \
diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index b10d265f9..d636a3a69 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -31,6 +31,8 @@
 #ifndef X11APPLICATION_H
 #define X11APPLICATION_H 1
 
+#include <X11/Xdefs.h>
+
 #if __OBJC__
 
 #import "X11Controller.h"
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 0574f908a..67c638b6d 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -34,8 +34,6 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
-
 #import "X11Application.h"
 
 #include "darwin.h"
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index abef8156a..d489dde5d 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -34,8 +34,6 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
-
 #import "X11Controller.h"
 #import "X11Application.h"
 
diff --git a/hw/xquartz/applewm.c b/hw/xquartz/applewm.c
index cc91c9608..e743a861e 100644
--- a/hw/xquartz/applewm.c
+++ b/hw/xquartz/applewm.c
@@ -34,7 +34,7 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
+#include "quartz.h"
 
 #include "misc.h"
 #include "dixstruct.h"
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 477a85f96..233570a75 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -35,7 +35,6 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
 #include "quartzRandR.h"
 #include "inputstr.h"
 #include "quartz.h"
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index ddbf2e780..3a456f573 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -34,6 +34,9 @@
 #ifndef _QUARTZ_H
 #define _QUARTZ_H
 
+#include <X11/Xdefs.h>
+#include "privates.h"
+
 #include "screenint.h"
 #include "window.h"
 #include "pixmap.h"
@@ -127,6 +130,14 @@ extern Bool XQuartzOptionSendsAlt;   /* Alt or Mode_switch? */
 
 extern int32_t XQuartzShieldingWindowLevel; /* CGShieldingWindowLevel() or 0 */
 
+// Other shared data
+extern DevPrivateKeyRec quartzScreenKeyRec;
+#define quartzScreenKey (&quartzScreenKeyRec)
+extern int aquaMenuBarHeight;
+
+// Name of GLX bundle for native OpenGL
+extern const char      *quartzOpenGLBundle;
+
 Bool
 QuartzAddScreen(int index, ScreenPtr pScreen);
 Bool
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
deleted file mode 100644
index 13fbe55d8..000000000
--- a/hw/xquartz/quartzCommon.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * quartzCommon.h
- *
- * Common definitions used internally by all Quartz modes
- *
- * This file should be included before any X11 or IOKit headers
- * so that it can avoid symbol conflicts.
- *
- * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
- *                 All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifndef _QUARTZCOMMON_H
-#define _QUARTZCOMMON_H
-
-#include <X11/Xdefs.h>
-#include "privates.h"
-
-// Other shared data
-extern DevPrivateKeyRec quartzScreenKeyRec;
-#define quartzScreenKey (&quartzScreenKeyRec)
-extern int aquaMenuBarHeight;
-
-// Name of GLX bundle for native OpenGL
-extern const char      *quartzOpenGLBundle;
-
-#endif  /* _QUARTZCOMMON_H */
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index 795d1915c..3ecc0e771 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -35,7 +35,6 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
 #include "quartzRandR.h"
 #include "quartz.h"
 #include "darwin.h"
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index bb92b6d3c..732eba983 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -36,7 +36,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <CoreFoundation/CoreFoundation.h>
-#include "quartzCommon.h"
 #include "X11Controller.h"
 #include "darwin.h"
 #include "darwinEvents.h"
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index ec2cdaa0c..270d6eb00 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -33,7 +33,6 @@
 #include <dix-config.h>
 #endif
 
-#include "quartzCommon.h"
 #include "inputstr.h"
 #include "quartz.h"
 #include "quartzRandR.h"
commit 4b4500c48f06e7ef41cd94f417e49b3f4f1412ae
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 13:00:43 2021 -0800

    xquartz: Fold away some unnecessary hops to X11Controller through X11Application
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index 740a8070a..b10d265f9 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -42,7 +42,6 @@
 }
 
 - (void)set_controller:controller;
-- (void)set_window_menu:(NSArray *)list;
 
 - (CFPropertyListRef)prefs_get_copy:(NSString *)key CF_RETURNS_RETAINED;
 - (int)prefs_get_integer:(NSString *)key default:(int)def;
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index b1757b846..0574f908a 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -434,16 +434,6 @@ QuartzModeBundleInit(void);
     }
 }
 
-- (void) set_window_menu:(NSArray *)list
-{
-    [_controller set_window_menu:list];
-}
-
-- (void) set_window_menu_check:(NSNumber *)n
-{
-    [_controller set_window_menu_check:n];
-}
-
 - (void) set_apps_menu:(NSArray *)list
 {
     [_controller set_apps_menu:list];
@@ -457,16 +447,6 @@ QuartzModeBundleInit(void);
         [self activateX:YES];
 }
 
-- (void) set_can_quit:(NSNumber *)state
-{
-    [_controller set_can_quit:[state boolValue]];
-}
-
-- (void) server_ready:unused
-{
-    [_controller server_ready];
-}
-
 - (void) show_hide_menubar:(NSNumber *)state
 {
     /* Also shows/hides the dock */
@@ -922,7 +902,7 @@ X11ApplicationSetWindowMenu(int nitems, const char **items,
         }
 
         dispatch_async(dispatch_get_main_queue(), ^{
-            [X11App set_window_menu:allMenuItems];
+            [X11App.controller set_window_menu:allMenuItems];
         });
     }
 }
@@ -931,7 +911,7 @@ void
 X11ApplicationSetWindowMenuCheck(int idx)
 {
     dispatch_async(dispatch_get_main_queue(), ^{
-        [X11App set_window_menu_check:@(idx)];
+        [X11App.controller set_window_menu_check:@(idx)];
     });
 }
 
@@ -947,7 +927,7 @@ void
 X11ApplicationSetCanQuit(int state)
 {
     dispatch_async(dispatch_get_main_queue(), ^{
-        [X11App set_can_quit:@(state)];
+        [X11App.controller set_can_quit:!!state];
     });
 }
 
@@ -955,7 +935,7 @@ void
 X11ApplicationServerReady(void)
 {
     dispatch_async(dispatch_get_main_queue(), ^{
-        [X11App server_ready:nil];
+        [X11App.controller server_ready];
     });
 }
 
commit 39c0e1c0ab6a0a89a71f26446973c779ca7fd927
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 09:41:30 2021 -0800

    xquartz: Fold away array_with_strings_and_numbers and simplify with more modern Objective-C
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 1d281b9fe..b1757b846 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -901,48 +901,28 @@ cfarray_to_nsarray(CFArrayRef in)
 
 @end
 
-static NSArray *
-array_with_strings_and_numbers(int nitems, const char **items,
-                               const char *numbers)
-{
-    NSMutableArray *array, *subarray;
-    NSString *string, *number;
-    int i;
-
-    array = [[[NSMutableArray alloc] initWithCapacity:nitems] autorelease];
-
-    for (i = 0; i < nitems; i++) {
-        subarray = [[NSMutableArray alloc] initWithCapacity:2];
-
-        string = [[NSString alloc] initWithUTF8String:items[i]];
-        [subarray addObject:string];
-        [string release];
-
-        if (numbers[i] != 0) {
-            number = [[NSString alloc] initWithFormat:@"%d", numbers[i]];
-            [subarray addObject:number];
-            [number release];
-        }
-        else
-            [subarray addObject:@""];
-
-        [array addObject:subarray];
-        [subarray release];
-    }
-
-    return array;
-}
-
 void
 X11ApplicationSetWindowMenu(int nitems, const char **items,
                             const char *shortcuts)
 {
     @autoreleasepool {
-        NSArray *array = array_with_strings_and_numbers(nitems, items, shortcuts);
+        NSMutableArray <NSArray <NSString *> *> * const allMenuItems = [NSMutableArray array];
+
+        for (int i = 0; i < nitems; i++) {
+            NSMutableArray <NSString *> * const menuItem = [NSMutableArray array];
+            [menuItem addObject:@(items[i])];
+
+            if (shortcuts[i] == 0) {
+                [menuItem addObject:@""];
+            } else {
+                [menuItem addObject:[NSString stringWithFormat:@"%d", shortcuts[i]]];
+            }
+
+            [allMenuItems addObject:menuItem];
+        }
 
-        /* Send the array of strings over to the appkit thread */
         dispatch_async(dispatch_get_main_queue(), ^{
-            [X11App set_window_menu:array];
+            [X11App set_window_menu:allMenuItems];
         });
     }
 }
commit 87f8fe1f74f10faf0ffc84f03539799ad4c2465e
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 09:33:56 2021 -0800

    xqaurtz: Remove message_kit_thread() and use dispatch instead
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 2575cb2f8..1d281b9fe 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -117,60 +117,11 @@ struct message_struct {
     NSObject *arg;
 };
 
-static mach_port_t _port;
-
 /* Quartz mode initialization routine. This is often dynamically loaded
    but is statically linked into this X server. */
 Bool
 QuartzModeBundleInit(void);
 
-static void
-init_ports(void)
-{
-    kern_return_t r;
-    NSPort *p;
-
-    if (_port != MACH_PORT_NULL) return;
-
-    r = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &_port);
-    if (r != KERN_SUCCESS) return;
-
-    p = [NSMachPort portWithMachPort:_port];
-    [p setDelegate:NSApp];
-    [p scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:
-     NSDefaultRunLoopMode];
-}
-
-static void
-message_kit_thread(SEL selector, NSObject *arg)
-{
-    message msg;
-    kern_return_t r;
-
-    msg.hdr.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND, 0);
-    msg.hdr.msgh_size = sizeof(msg);
-    msg.hdr.msgh_remote_port = _port;
-    msg.hdr.msgh_local_port = MACH_PORT_NULL;
-    msg.hdr.msgh_reserved = 0;
-    msg.hdr.msgh_id = 0;
-
-    msg.selector = selector;
-    msg.arg = [arg retain];
-
-    r = mach_msg(&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size,
-                 0, MACH_PORT_NULL, 0, MACH_PORT_NULL);
-    if (r != KERN_SUCCESS)
-        ErrorF("%s: mach_msg failed: %x\n", __FUNCTION__, r);
-}
-
-- (void) handleMachMessage:(void *)_msg
-{
-    message *msg = _msg;
-
-    [self performSelector:msg->selector withObject:msg->arg];
-    [msg->arg release];
-}
-
 - (void) set_controller:obj
 {
     if (_controller == nil) _controller = [obj retain];
@@ -180,9 +131,6 @@ message_kit_thread(SEL selector, NSObject *arg)
 {
     if (_controller != nil) [_controller release];
 
-    if (_port != MACH_PORT_NULL)
-        mach_port_deallocate(mach_task_self(), _port);
-
     [super dealloc];
 }
 
@@ -961,9 +909,7 @@ array_with_strings_and_numbers(int nitems, const char **items,
     NSString *string, *number;
     int i;
 
-    /* (Can't autorelease on the X server thread) */
-
-    array = [[NSMutableArray alloc] initWithCapacity:nitems];
+    array = [[[NSMutableArray alloc] initWithCapacity:nitems] autorelease];
 
     for (i = 0; i < nitems; i++) {
         subarray = [[NSMutableArray alloc] initWithCapacity:2];
@@ -991,73 +937,65 @@ void
 X11ApplicationSetWindowMenu(int nitems, const char **items,
                             const char *shortcuts)
 {
-    NSArray *array;
-    array = array_with_strings_and_numbers(nitems, items, shortcuts);
-
-    /* Send the array of strings over to the appkit thread */
+    @autoreleasepool {
+        NSArray *array = array_with_strings_and_numbers(nitems, items, shortcuts);
 
-    message_kit_thread(@selector (set_window_menu:), array);
-    [array release];
+        /* Send the array of strings over to the appkit thread */
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [X11App set_window_menu:array];
+        });
+    }
 }
 
 void
 X11ApplicationSetWindowMenuCheck(int idx)
 {
-    NSNumber *n;
-
-    n = [[NSNumber alloc] initWithInt:idx];
-
-    message_kit_thread(@selector (set_window_menu_check:), n);
-
-    [n release];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [X11App set_window_menu_check:@(idx)];
+    });
 }
 
 void
 X11ApplicationSetFrontProcess(void)
 {
-    message_kit_thread(@selector (set_front_process:), nil);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [X11App set_front_process:nil];
+    });
 }
 
 void
 X11ApplicationSetCanQuit(int state)
 {
-    NSNumber *n;
-
-    n = [[NSNumber alloc] initWithBool:state];
-
-    message_kit_thread(@selector (set_can_quit:), n);
-
-    [n release];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [X11App set_can_quit:@(state)];
+    });
 }
 
 void
 X11ApplicationServerReady(void)
 {
-    message_kit_thread(@selector (server_ready:), nil);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [X11App server_ready:nil];
+    });
 }
 
 void
 X11ApplicationShowHideMenubar(int state)
 {
-    NSNumber *n;
-
-    n = [[NSNumber alloc] initWithBool:state];
-
-    message_kit_thread(@selector (show_hide_menubar:), n);
-
-    [n release];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [X11App show_hide_menubar:@(state)];
+    });
 }
 
 void
 X11ApplicationLaunchClient(const char *cmd)
 {
-    NSString *string;
-
-    string = [[NSString alloc] initWithUTF8String:cmd];
-
-    message_kit_thread(@selector (launch_client:), string);
-
-    [string release];
+    @autoreleasepool {
+        NSString *string = @(cmd);
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [X11App launch_client:string];
+        });
+    }
 }
 
 /* This is a special function in that it is run from the *SERVER* thread and
@@ -1180,7 +1118,6 @@ X11ApplicationMain(int argc, char **argv, char **envp)
 
     @autoreleasepool {
         X11App = (X11Application *)[X11Application sharedApplication];
-        init_ports();
 
         app_prefs_domain_cfstr = (CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
 
commit 94e4e173486c2a94ddcfd2d0515e1ee6731f6656
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Wed Feb 17 23:58:53 2021 -0800

    xquartz: Use objc_autoreleasePoolPush / objc_autoreleasePoolPop directly in QuartzBlockHandler
    
    It violates @autoreleasepool best practices, and this helps collapse quartzCocoa.m into quartz.c
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 85355a8ac..c238fe909 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -30,7 +30,6 @@ libXquartz_la_SOURCES = \
 	darwinXinput.c \
 	keysym2ucs.c \
 	quartz.c \
-	quartzCocoa.m \
 	quartzKeyboard.c \
 	quartzStartup.c \
 	quartzRandR.c
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 8a3c5a2d3..477a85f96 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -72,6 +72,15 @@
 #include <rootlessCommon.h>
 #include <Xplugin.h>
 
+// These are vended by the Objective-C runtime, but they are unfortunately
+// not available as API in the macOS SDK.  We are following suit with swift
+// and clang in declaring them inline here.  They canot be removed or changed
+// in the OS without major bincompat ramifications.
+//
+// These were added in macOS 10.7.
+void * _Nonnull objc_autoreleasePoolPush(void);
+void objc_autoreleasePoolPop(void * _Nonnull context);
+
 DevPrivateKeyRec quartzScreenKeyRec;
 int aquaMenuBarHeight = 0;
 QuartzModeProcsPtr quartzProcs = NULL;
@@ -143,6 +152,30 @@ QuartzSetupScreen(int index,
     return TRUE;
 }
 
+/*
+ * QuartzBlockHandler
+ *  Clean out any autoreleased objects.
+ */
+static void
+QuartzBlockHandler(void *blockData, void *pTimeout)
+{
+    static void *poolToken = NULL;
+
+    if (poolToken) {
+        objc_autoreleasePoolPop(poolToken);
+    }
+    poolToken = objc_autoreleasePoolPush();
+}
+
+/*
+ * QuartzWakeupHandler
+ */
+static void
+QuartzWakeupHandler(void *blockData, int result)
+{
+    /* nothing here */
+}
+
 /*
  * QuartzInitOutput
  *  Quartz display initialization.
diff --git a/hw/xquartz/quartzCocoa.m b/hw/xquartz/quartzCocoa.m
deleted file mode 100644
index ac6f67e2b..000000000
--- a/hw/xquartz/quartzCocoa.m
+++ /dev/null
@@ -1,66 +0,0 @@
-/**************************************************************
- *
- * Quartz-specific support for the Darwin X Server
- * that requires Cocoa and Objective-C.
- *
- * This file is separate from the parts of Quartz support
- * that use X include files to avoid symbol collisions.
- *
- * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
- *                 All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#include "sanitizedCocoa.h"
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "quartzCommon.h"
-#include "inputstr.h"
-
-#include "darwin.h"
-
-/*
- * QuartzBlockHandler
- *  Clean out any autoreleased objects.
- */
-void
-QuartzBlockHandler(void *blockData, void *pTimeout)
-{
-    static NSAutoreleasePool *aPool = nil;
-
-    [aPool release];
-    aPool = [[NSAutoreleasePool alloc] init];
-}
-
-/*
- * QuartzWakeupHandler
- */
-void
-QuartzWakeupHandler(void *blockData, int result)
-{
-    // nothing here
-}
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 721886b87..13fbe55d8 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -46,10 +46,4 @@ extern int aquaMenuBarHeight;
 // Name of GLX bundle for native OpenGL
 extern const char      *quartzOpenGLBundle;
 
-void
-QuartzBlockHandler(void *blockData, void *pTimeout);
-
-void
-QuartzWakeupHandler(void *blockData, int result);
-
 #endif  /* _QUARTZCOMMON_H */
commit fba421f700498fa382089df47942df36a2d75ce6
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Wed Feb 17 22:04:55 2021 -0800

    xquartz: Minor code modernization -- @autoreleasepool adoption
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index a009d6415..2575cb2f8 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -1174,77 +1174,72 @@ xpbproxy_x_thread(void *args)
 void
 X11ApplicationMain(int argc, char **argv, char **envp)
 {
-    NSAutoreleasePool *pool;
-
 #ifdef DEBUG
     while (access("/tmp/x11-block", F_OK) == 0) sleep(1);
 #endif
 
-    pool = [[NSAutoreleasePool alloc] init];
-    X11App = (X11Application *)[X11Application sharedApplication];
-    init_ports();
+    @autoreleasepool {
+        X11App = (X11Application *)[X11Application sharedApplication];
+        init_ports();
 
-    app_prefs_domain_cfstr =
-        (CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
+        app_prefs_domain_cfstr = (CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
 
-    if (app_prefs_domain_cfstr == NULL) {
-        ErrorF(
-            "X11ApplicationMain: Unable to determine bundle identifier.  Your installation of XQuartz may be broken.\n");
-        app_prefs_domain_cfstr = CFSTR(BUNDLE_ID_PREFIX ".X11");
-    }
+        if (app_prefs_domain_cfstr == NULL) {
+            ErrorF("X11ApplicationMain: Unable to determine bundle identifier.  Your installation of XQuartz may be broken.\n");
+            app_prefs_domain_cfstr = CFSTR(BUNDLE_ID_PREFIX ".X11");
+        }
 
-    [NSApp read_defaults];
-    [NSBundle loadNibNamed:@"main" owner:NSApp];
-    [[NSNotificationCenter defaultCenter] addObserver:NSApp
-                                             selector:@selector (became_key:)
-                                                 name:
-     NSWindowDidBecomeKeyNotification object:nil];
+        [NSApp read_defaults];
+        [NSBundle loadNibNamed:@"main" owner:NSApp];
+        [NSNotificationCenter.defaultCenter addObserver:NSApp
+                                               selector:@selector (became_key:)
+                                                   name:NSWindowDidBecomeKeyNotification
+                                                 object:nil];
 
-    /*
-     * The xpr Quartz mode is statically linked into this server.
-     * Initialize all the Quartz functions.
-     */
-    QuartzModeBundleInit();
+        /*
+         * The xpr Quartz mode is statically linked into this server.
+         * Initialize all the Quartz functions.
+         */
+        QuartzModeBundleInit();
 
-    /* Calculate the height of the menubar so we can avoid it. */
-    aquaMenuBarHeight = [[NSApp mainMenu] menuBarHeight];
-    if (!aquaMenuBarHeight) {
-        NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0];
-        aquaMenuBarHeight = NSHeight([primaryScreen frame]) - NSMaxY([primaryScreen visibleFrame]);
-    }
+        /* Calculate the height of the menubar so we can avoid it. */
+        aquaMenuBarHeight = NSApp.mainMenu.menuBarHeight;
+        if (!aquaMenuBarHeight) {
+            NSScreen* primaryScreen = NSScreen.screens[0];
+            aquaMenuBarHeight = NSHeight(primaryScreen.frame) - NSMaxY(primaryScreen.visibleFrame);
+        }
 
-    eventTranslationQueue = dispatch_queue_create(
-        BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", NULL);
-    assert(eventTranslationQueue != NULL);
+        eventTranslationQueue = dispatch_queue_create(BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", NULL);
+        assert(eventTranslationQueue != NULL);
 
-    /* Set the key layout seed before we start the server */
-    last_key_layout = TISCopyCurrentKeyboardLayoutInputSource();
+        /* Set the key layout seed before we start the server */
+        last_key_layout = TISCopyCurrentKeyboardLayoutInputSource();
 
-    if (!last_key_layout)
-        ErrorF(
-            "X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n");
+        if (!last_key_layout) {
+            ErrorF("X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n");
+        }
 
-    if (!QuartsResyncKeymap(FALSE)) {
-        ErrorF("X11ApplicationMain: Could not build a valid keymap.\n");
-    }
+        if (!QuartsResyncKeymap(FALSE)) {
+            ErrorF("X11ApplicationMain: Could not build a valid keymap.\n");
+        }
 
-    /* Tell the server thread that it can proceed */
-    QuartzInitServer(argc, argv, envp);
+        /* Tell the server thread that it can proceed */
+        QuartzInitServer(argc, argv, envp);
 
-    /* This must be done after QuartzInitServer because it can result in
-     * an mieqEnqueue() - <rdar://problem/6300249>
-     */
-    check_xinitrc();
+        /* This must be done after QuartzInitServer because it can result in
+         * an mieqEnqueue() - <rdar://problem/6300249>
+         */
+        check_xinitrc();
 
-    create_thread(xpbproxy_x_thread, NULL);
+        create_thread(xpbproxy_x_thread, NULL);
 
 #if XQUARTZ_SPARKLE
-    [[X11App controller] setup_sparkle];
-    [[SUUpdater sharedUpdater] resetUpdateCycle];
-    //    [[SUUpdater sharedUpdater] checkForUpdates:X11App];
+        [[X11App controller] setup_sparkle];
+        [[SUUpdater sharedUpdater] resetUpdateCycle];
+        //    [[SUUpdater sharedUpdater] checkForUpdates:X11App];
 #endif
+    }
 
-    [pool release];
     [NSApp run];
     /* not reached */
 }
diff --git a/hw/xquartz/pbproxy/main.m b/hw/xquartz/pbproxy/main.m
index 2d2f76108..92cde0437 100644
--- a/hw/xquartz/pbproxy/main.m
+++ b/hw/xquartz/pbproxy/main.m
@@ -78,55 +78,49 @@ x_error_handler(Display *dpy, XErrorEvent *errevent)
 int
 xpbproxy_run(void)
 {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    size_t i;
+    @autoreleasepool {
+        size_t i;
 
-    for (i = 0, xpbproxy_dpy = NULL; !xpbproxy_dpy && i < 5; i++) {
-        xpbproxy_dpy = XOpenDisplay(NULL);
+        for (i = 0, xpbproxy_dpy = NULL; !xpbproxy_dpy && i < 5; i++) {
+            xpbproxy_dpy = XOpenDisplay(NULL);
 
-        if (!xpbproxy_dpy && display) {
-            char _display[32];
-            snprintf(_display, sizeof(_display), ":%s", display);
-            setenv("DISPLAY", _display, TRUE);
+            if (!xpbproxy_dpy && display) {
+                char _display[32];
+                snprintf(_display, sizeof(_display), ":%s", display);
+                setenv("DISPLAY", _display, TRUE);
 
-            xpbproxy_dpy = XOpenDisplay(_display);
+                xpbproxy_dpy = XOpenDisplay(_display);
+            }
+            if (!xpbproxy_dpy)
+                sleep(1);
         }
-        if (!xpbproxy_dpy)
-            sleep(1);
-    }
 
-    if (xpbproxy_dpy == NULL) {
-        ErrorF("xpbproxy: can't open default display\n");
-        [pool release];
-        return EXIT_FAILURE;
-    }
+        if (xpbproxy_dpy == NULL) {
+            ErrorF("xpbproxy: can't open default display\n");
+            return EXIT_FAILURE;
+        }
 
-    XSetIOErrorHandler(x_io_error_handler);
-    XSetErrorHandler(x_error_handler);
+        XSetIOErrorHandler(x_io_error_handler);
+        XSetErrorHandler(x_error_handler);
 
-    if (!XAppleWMQueryExtension(xpbproxy_dpy, &xpbproxy_apple_wm_event_base,
-                                &xpbproxy_apple_wm_error_base)) {
-        ErrorF("xpbproxy: can't open AppleWM server extension\n");
-        [pool release];
-        return EXIT_FAILURE;
-    }
+        if (!XAppleWMQueryExtension(xpbproxy_dpy, &xpbproxy_apple_wm_event_base,
+                                    &xpbproxy_apple_wm_error_base)) {
+            ErrorF("xpbproxy: can't open AppleWM server extension\n");
+            return EXIT_FAILURE;
+        }
 
-    xpbproxy_have_xfixes =
-        XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_base,
-                             &xpbproxy_xfixes_error_base);
+        xpbproxy_have_xfixes = XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_base,
+                                                    &xpbproxy_xfixes_error_base);
 
-    XAppleWMSelectInput(xpbproxy_dpy, AppleWMActivationNotifyMask |
-                        AppleWMPasteboardNotifyMask);
+        XAppleWMSelectInput(xpbproxy_dpy, AppleWMActivationNotifyMask | AppleWMPasteboardNotifyMask);
 
-    _selection_object = [[x_selection alloc] init];
+        _selection_object = [x_selection new];
 
-    if (!xpbproxy_input_register()) {
-        [pool release];
-        return EXIT_FAILURE;
+        if (!xpbproxy_input_register()) {
+            return EXIT_FAILURE;
+        }
     }
 
-    [pool release];
-
     CFRunLoopRun();
 
     return EXIT_SUCCESS;
diff --git a/hw/xquartz/pbproxy/x-input.m b/hw/xquartz/pbproxy/x-input.m
index 71b46a8b3..3be9ce407 100644
--- a/hw/xquartz/pbproxy/x-input.m
+++ b/hw/xquartz/pbproxy/x-input.m
@@ -89,14 +89,7 @@ x_event_apple_wm_notify(XAppleWMNotifyEvent *e)
 static void
 xpbproxy_process_xevents(void)
 {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-    if (pool == nil) {
-        ErrorF("unable to allocate/init auto release pool!\n");
-        return;
-    }
-
-    while (XPending(xpbproxy_dpy) != 0) {
+    while (XPending(xpbproxy_dpy) != 0) { @autoreleasepool {
         XEvent e;
 
         XNextEvent(xpbproxy_dpy, &e);
@@ -134,9 +127,7 @@ xpbproxy_process_xevents(void)
         }
 
         XFlush(xpbproxy_dpy);
-    }
-
-    [pool release];
+    }}
 }
 
 static BOOL
commit 318f8a4a8a47a0ce4bbbf4290469e933602c9b30
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Wed Feb 17 20:55:06 2021 -0800

    xquartz: Remove some dead code for compatibility with older nibs
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Controller.h b/hw/xquartz/X11Controller.h
index 29008c593..139b035c4 100644
--- a/hw/xquartz/X11Controller.h
+++ b/hw/xquartz/X11Controller.h
@@ -72,12 +72,6 @@
     IBOutlet NSTextField *sync_text2;
     IBOutlet NSPopUpButton *depth;
 
-    IBOutlet NSMenuItem *window_separator;
-    // window_separator is DEPRECATED due to this radar:
-    // <rdar://problem/7088335> NSApplication releases the separator in the Windows menu even though it's an IBOutlet
-    // It is kept around for localization compatibility and is subject to removal "eventually"
-    // If it is !NULL (meaning it is in the nib), it is removed from the menu and released
-
     IBOutlet NSMenuItem *x11_about_item;
     IBOutlet NSMenuItem *dock_window_separator;
     IBOutlet NSMenuItem *apps_separator;
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index ad7a7871e..abef8156a 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -104,12 +104,6 @@ extern char *bundle_id_prefix;
             name: NSWindowWillCloseNotification
           object: [apps_table window]];
 
-    // Setup data about our Windows menu
-    if (window_separator) {
-        [[window_separator menu] removeItem:window_separator];
-        window_separator = nil;
-    }
-
     windows_menu_start = [[X11App windowsMenu] numberOfItems];
 }
 
commit 72a39dccf99191fbfbb4b399c446fd017d55f24e
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Feb 18 16:05:34 2021 -0800

    xquartz: Remove a workaround for AppKit versions older than Lion
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index c0604b773..ad7a7871e 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -785,16 +785,7 @@ extern char *bundle_id_prefix;
     BOOL pbproxy_active =
         [NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES];
 
-    // Remove preferences from the GUI which are not supported
-    // TODO: Change 1117 to NSAppKitVersionNumber10_7 when it is defined
-    if (scroll_in_device_direction && NSAppKitVersionNumber < 1117) {
-        [scroll_in_device_direction removeFromSuperview];
-        scroll_in_device_direction = nil;
-    }
-    else {
-        [scroll_in_device_direction setIntValue:
-         XQuartzScrollInDeviceDirection];
-    }
+    [scroll_in_device_direction setIntValue:XQuartzScrollInDeviceDirection];
 
     [fake_buttons setIntValue:darwinFakeButtons];
     [enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents];


More information about the xorg-commit mailing list