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
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 */
}

View File

@ -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 == 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();
return EXIT_SUCCESS;

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