xquartz: Minor code modernization -- @autoreleasepool adoption

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston Sequoia 2021-02-17 22:04:55 -08:00
parent 318f8a4a8a
commit fba421f700
3 changed files with 85 additions and 105 deletions

View File

@ -1174,31 +1174,27 @@ 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];
@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");
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
[NSNotificationCenter.defaultCenter addObserver:NSApp
selector:@selector (became_key:)
name:
NSWindowDidBecomeKeyNotification object:nil];
name:NSWindowDidBecomeKeyNotification
object:nil];
/*
* The xpr Quartz mode is statically linked into this server.
@ -1207,22 +1203,21 @@ X11ApplicationMain(int argc, char **argv, char **envp)
QuartzModeBundleInit();
/* Calculate the height of the menubar so we can avoid it. */
aquaMenuBarHeight = [[NSApp mainMenu] menuBarHeight];
aquaMenuBarHeight = NSApp.mainMenu.menuBarHeight;
if (!aquaMenuBarHeight) {
NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0];
aquaMenuBarHeight = NSHeight([primaryScreen frame]) - NSMaxY([primaryScreen visibleFrame]);
NSScreen* primaryScreen = NSScreen.screens[0];
aquaMenuBarHeight = NSHeight(primaryScreen.frame) - NSMaxY(primaryScreen.visibleFrame);
}
eventTranslationQueue = dispatch_queue_create(
BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", 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();
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");
@ -1243,8 +1238,8 @@ X11ApplicationMain(int argc, char **argv, char **envp)
[[SUUpdater sharedUpdater] resetUpdateCycle];
// [[SUUpdater sharedUpdater] checkForUpdates:X11App];
#endif
}
[pool release];
[NSApp run];
/* not reached */
}

View File

@ -78,7 +78,7 @@ x_error_handler(Display *dpy, XErrorEvent *errevent)
int
xpbproxy_run(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@autoreleasepool {
size_t i;
for (i = 0, xpbproxy_dpy = NULL; !xpbproxy_dpy && i < 5; i++) {
@ -97,7 +97,6 @@ xpbproxy_run(void)
if (xpbproxy_dpy == NULL) {
ErrorF("xpbproxy: can't open default display\n");
[pool release];
return EXIT_FAILURE;
}
@ -107,25 +106,20 @@ xpbproxy_run(void)
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;
}
xpbproxy_have_xfixes =
XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_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;
}
[pool release];
}
CFRunLoopRun();

View File

@ -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