xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

app-main.m (3564B)


      1 /* app-main.m
      2  *
      3  * Copyright (c) 2002-2012 Apple Inc. All rights reserved.
      4  *
      5  * Permission is hereby granted, free of charge, to any person
      6  * obtaining a copy of this software and associated documentation files
      7  * (the "Software"), to deal in the Software without restriction,
      8  * including without limitation the rights to use, copy, modify, merge,
      9  * publish, distribute, sublicense, and/or sell copies of the Software,
     10  * and to permit persons to whom the Software is furnished to do so,
     11  * subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be
     14  * included in all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
     20  * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     23  * DEALINGS IN THE SOFTWARE.
     24  *
     25  * Except as contained in this notice, the name(s) of the above
     26  * copyright holders shall not be used in advertising or otherwise to
     27  * promote the sale, use or other dealings in this Software without
     28  * prior written authorization.
     29  */
     30 
     31 #include "pbproxy.h"
     32 #import "x-selection.h"
     33 
     34 #include <pthread.h>
     35 #include <unistd.h> /*for getpid*/
     36 #include <Cocoa/Cocoa.h>
     37 
     38 static const char *app_prefs_domain = BUNDLE_ID_PREFIX ".xpbproxy";
     39 CFStringRef app_prefs_domain_cfstr;
     40 
     41 /* Stubs */
     42 char *display = NULL;
     43 
     44 static void
     45 signal_handler(int sig)
     46 {
     47     switch (sig) {
     48     case SIGHUP:
     49         xpbproxy_prefs_reload = YES;
     50         break;
     51 
     52     default:
     53         _exit(EXIT_SUCCESS);
     54     }
     55 }
     56 
     57 void
     58 ErrorF(const char * f, ...)
     59 {
     60     va_list args;
     61 
     62     va_start(args, f);
     63     vfprintf(stderr, f, args);
     64     va_end(args);
     65 }
     66 
     67 /* TODO: Have this actually log to ASL */
     68 void
     69 xq_asl_log(int level, const char *subsystem, const char *file,
     70            const char *function, int line, const char *fmt,
     71            ...)
     72 {
     73 #ifdef DEBUG
     74     va_list args;
     75 
     76     va_start(args, fmt);
     77     vfprintf(stderr, fmt, args);
     78     va_end(args);
     79 #endif
     80 }
     81 
     82 int
     83 main(int argc, const char *argv[])
     84 {
     85     const char *s;
     86     int i;
     87 
     88 #ifdef DEBUG
     89     ErrorF("pid: %u\n", getpid());
     90 #endif
     91 
     92     xpbproxy_is_standalone = YES;
     93 
     94     if ((s = getenv("X11_PREFS_DOMAIN")))
     95         app_prefs_domain = s;
     96 
     97     for (i = 1; i < argc; i++) {
     98         if (strcmp(argv[i], "--prefs-domain") == 0 && i + 1 < argc) {
     99             app_prefs_domain = argv[++i];
    100         }
    101         else if (strcmp(argv[i], "--help") == 0) {
    102             ErrorF(
    103                 "usage: xpbproxy OPTIONS\n"
    104                 "Pasteboard proxying for X11.\n\n"
    105                 "--prefs-domain <domain>   Change the domain used for reading preferences\n"
    106                 "                          (default: %s)\n",
    107                 app_prefs_domain);
    108             return 0;
    109         }
    110         else {
    111             ErrorF("usage: xpbproxy OPTIONS...\n"
    112                    "Try 'xpbproxy --help' for more information.\n");
    113             return 1;
    114         }
    115     }
    116 
    117     app_prefs_domain_cfstr = CFStringCreateWithCString(NULL, app_prefs_domain,
    118                                                        kCFStringEncodingUTF8);
    119 
    120     signal(SIGINT, signal_handler);
    121     signal(SIGTERM, signal_handler);
    122     signal(SIGHUP, signal_handler);
    123     signal(SIGPIPE, SIG_IGN);
    124 
    125     return xpbproxy_run();
    126 }