summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-17 22:04:55 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-18 22:32:14 -0800
commitfba421f700498fa382089df47942df36a2d75ce6 (patch)
treea97fcb90edfca8d1c397dd3a182e9ded9f4ca784
parent318f8a4a8a47a0ce4bbbf4290469e933602c9b30 (diff)
xquartz: Minor code modernization -- @autoreleasepool adoption
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--hw/xquartz/X11Application.m97
-rw-r--r--hw/xquartz/pbproxy/main.m66
-rw-r--r--hw/xquartz/pbproxy/x-input.m13
3 files changed, 78 insertions, 98 deletions
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