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,77 +1174,72 @@ xpbproxy_x_thread(void *args)
void void
X11ApplicationMain(int argc, char **argv, char **envp) X11ApplicationMain(int argc, char **argv, char **envp)
{ {
NSAutoreleasePool *pool;
#ifdef DEBUG #ifdef DEBUG
while (access("/tmp/x11-block", F_OK) == 0) sleep(1); while (access("/tmp/x11-block", F_OK) == 0) sleep(1);
#endif #endif
pool = [[NSAutoreleasePool alloc] init]; @autoreleasepool {
X11App = (X11Application *)[X11Application sharedApplication]; X11App = (X11Application *)[X11Application sharedApplication];
init_ports(); init_ports();
app_prefs_domain_cfstr = app_prefs_domain_cfstr = (CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
(CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
if (app_prefs_domain_cfstr == NULL) { if (app_prefs_domain_cfstr == NULL) {
ErrorF( ErrorF("X11ApplicationMain: Unable to determine bundle identifier. Your installation of XQuartz may be broken.\n");
"X11ApplicationMain: Unable to determine bundle identifier. Your installation of XQuartz may be broken.\n"); app_prefs_domain_cfstr = CFSTR(BUNDLE_ID_PREFIX ".X11");
app_prefs_domain_cfstr = CFSTR(BUNDLE_ID_PREFIX ".X11"); }
}
[NSApp read_defaults]; [NSApp read_defaults];
[NSBundle loadNibNamed:@"main" owner:NSApp]; [NSBundle loadNibNamed:@"main" owner:NSApp];
[[NSNotificationCenter defaultCenter] addObserver:NSApp [NSNotificationCenter.defaultCenter addObserver:NSApp
selector:@selector (became_key:) selector:@selector (became_key:)
name: name:NSWindowDidBecomeKeyNotification
NSWindowDidBecomeKeyNotification object:nil]; object:nil];
/* /*
* The xpr Quartz mode is statically linked into this server. * The xpr Quartz mode is statically linked into this server.
* Initialize all the Quartz functions. * Initialize all the Quartz functions.
*/ */
QuartzModeBundleInit(); QuartzModeBundleInit();
/* Calculate the height of the menubar so we can avoid it. */ /* Calculate the height of the menubar so we can avoid it. */
aquaMenuBarHeight = [[NSApp mainMenu] menuBarHeight]; aquaMenuBarHeight = NSApp.mainMenu.menuBarHeight;
if (!aquaMenuBarHeight) { if (!aquaMenuBarHeight) {
NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0]; NSScreen* primaryScreen = NSScreen.screens[0];
aquaMenuBarHeight = NSHeight([primaryScreen frame]) - NSMaxY([primaryScreen visibleFrame]); aquaMenuBarHeight = NSHeight(primaryScreen.frame) - NSMaxY(primaryScreen.visibleFrame);
} }
eventTranslationQueue = dispatch_queue_create( eventTranslationQueue = dispatch_queue_create(BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", NULL);
BUNDLE_ID_PREFIX ".X11.NSEventsToX11EventsQueue", NULL); assert(eventTranslationQueue != NULL);
assert(eventTranslationQueue != NULL);
/* Set the key layout seed before we start the server */ /* Set the key layout seed before we start the server */
last_key_layout = TISCopyCurrentKeyboardLayoutInputSource(); last_key_layout = TISCopyCurrentKeyboardLayoutInputSource();
if (!last_key_layout) if (!last_key_layout) {
ErrorF( ErrorF("X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n");
"X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n"); }
if (!QuartsResyncKeymap(FALSE)) { if (!QuartsResyncKeymap(FALSE)) {
ErrorF("X11ApplicationMain: Could not build a valid keymap.\n"); ErrorF("X11ApplicationMain: Could not build a valid keymap.\n");
} }
/* Tell the server thread that it can proceed */ /* Tell the server thread that it can proceed */
QuartzInitServer(argc, argv, envp); QuartzInitServer(argc, argv, envp);
/* This must be done after QuartzInitServer because it can result in /* This must be done after QuartzInitServer because it can result in
* an mieqEnqueue() - <rdar://problem/6300249> * an mieqEnqueue() - <rdar://problem/6300249>
*/ */
check_xinitrc(); check_xinitrc();
create_thread(xpbproxy_x_thread, NULL); create_thread(xpbproxy_x_thread, NULL);
#if XQUARTZ_SPARKLE #if XQUARTZ_SPARKLE
[[X11App controller] setup_sparkle]; [[X11App controller] setup_sparkle];
[[SUUpdater sharedUpdater] resetUpdateCycle]; [[SUUpdater sharedUpdater] resetUpdateCycle];
// [[SUUpdater sharedUpdater] checkForUpdates:X11App]; // [[SUUpdater sharedUpdater] checkForUpdates:X11App];
#endif #endif
}
[pool release];
[NSApp run]; [NSApp run];
/* not reached */ /* not reached */
} }

View File

@ -78,55 +78,49 @@ x_error_handler(Display *dpy, XErrorEvent *errevent)
int int
xpbproxy_run(void) xpbproxy_run(void)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @autoreleasepool {
size_t i; size_t i;
for (i = 0, xpbproxy_dpy = NULL; !xpbproxy_dpy && i < 5; i++) { for (i = 0, xpbproxy_dpy = NULL; !xpbproxy_dpy && i < 5; i++) {
xpbproxy_dpy = XOpenDisplay(NULL); xpbproxy_dpy = XOpenDisplay(NULL);
if (!xpbproxy_dpy && display) { if (!xpbproxy_dpy && display) {
char _display[32]; char _display[32];
snprintf(_display, sizeof(_display), ":%s", display); snprintf(_display, sizeof(_display), ":%s", display);
setenv("DISPLAY", _display, TRUE); setenv("DISPLAY", _display, TRUE);
xpbproxy_dpy = XOpenDisplay(_display); xpbproxy_dpy = XOpenDisplay(_display);
}
if (!xpbproxy_dpy)
sleep(1);
}
if (xpbproxy_dpy == NULL) {
ErrorF("xpbproxy: can't open default display\n");
return EXIT_FAILURE;
}
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");
return EXIT_FAILURE;
}
xpbproxy_have_xfixes = XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_base,
&xpbproxy_xfixes_error_base);
XAppleWMSelectInput(xpbproxy_dpy, AppleWMActivationNotifyMask | AppleWMPasteboardNotifyMask);
_selection_object = [x_selection new];
if (!xpbproxy_input_register()) {
return EXIT_FAILURE;
} }
if (!xpbproxy_dpy)
sleep(1);
} }
if (xpbproxy_dpy == NULL) {
ErrorF("xpbproxy: can't open default display\n");
[pool release];
return EXIT_FAILURE;
}
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;
}
xpbproxy_have_xfixes =
XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_base,
&xpbproxy_xfixes_error_base);
XAppleWMSelectInput(xpbproxy_dpy, AppleWMActivationNotifyMask |
AppleWMPasteboardNotifyMask);
_selection_object = [[x_selection alloc] init];
if (!xpbproxy_input_register()) {
[pool release];
return EXIT_FAILURE;
}
[pool release];
CFRunLoopRun(); CFRunLoopRun();
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -89,14 +89,7 @@ x_event_apple_wm_notify(XAppleWMNotifyEvent *e)
static void static void
xpbproxy_process_xevents(void) xpbproxy_process_xevents(void)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; while (XPending(xpbproxy_dpy) != 0) { @autoreleasepool {
if (pool == nil) {
ErrorF("unable to allocate/init auto release pool!\n");
return;
}
while (XPending(xpbproxy_dpy) != 0) {
XEvent e; XEvent e;
XNextEvent(xpbproxy_dpy, &e); XNextEvent(xpbproxy_dpy, &e);
@ -134,9 +127,7 @@ xpbproxy_process_xevents(void)
} }
XFlush(xpbproxy_dpy); XFlush(xpbproxy_dpy);
} }}
[pool release];
} }
static BOOL static BOOL