From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: [PATCH 7/9] Add alt_display to emacsclient for w32, ns Date: Tue, 07 Aug 2012 01:19:27 -0700 Message-ID: <7871883407e88939ff987b9ba718df5bbbac6692.1344326992.git.dancol@dancol.org> References: NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1344327600 920 80.91.229.3 (7 Aug 2012 08:20:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Aug 2012 08:20:00 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 07 10:20:01 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Syf1A-0003NO-IL for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2012 10:19:56 +0200 Original-Received: from localhost ([::1]:50924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf19-0001I4-H8 for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2012 04:19:55 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf0v-0000kA-FW for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Syf0n-0007kM-UD for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:41 -0400 Original-Received: from dancol.org ([96.126.100.184]:37135) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf0n-0007ie-LE for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:33 -0400 Original-Received: from dancol by dancol.org with local (Exim 4.72) (envelope-from ) id 1Syf0h-0006q8-7y for emacs-devel@gnu.org; Tue, 07 Aug 2012 01:19:27 -0700 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 96.126.100.184 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152240 Archived-At: --- lib-src/emacsclient.c | 127 ++++++++++++++++++++++++++++++------------------- 1 files changed, 78 insertions(+), 49 deletions(-) diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 83e357c..56914df 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -150,6 +150,9 @@ int current_frame = 1; /* The display on which Emacs should work. --display. */ const char *display = NULL; +/* The alternate display we should try if Emacs does not support display. */ +const char *alt_display = NULL; + /* The parent window ID, if we are opening a frame via XEmbed. */ char *parent_id = NULL; @@ -602,16 +605,29 @@ decode_options (int argc, char **argv) Without the -c option, we used to set `display' to $DISPLAY by default, but this changed the default behavior and is sometimes inconvenient. So we force users to use "--display $DISPLAY" if - they want Emacs to connect to their current display. */ + they want Emacs to connect to their current display. + + Some window systems have a notion of default display not + reflected in the DISPLAY variable. If the user didn't give us an + explicit display, try this platform-specific after trying the + display in DISPLAY (if any). */ if (!current_frame && !tty && !display) { - display = egetenv ("DISPLAY"); -#ifdef NS_IMPL_COCOA - /* Under Cocoa, we don't really use displays the same way as in X, - so provide a dummy. */ - if (!display || strlen (display) == 0) - display = "ns"; + /* Set these here so we use a default_display only when the user + didn't give us an explicit display. */ +#if defined (NS_IMPL_COCOA) + alt_display = "ns"; +#elif defined (HAVE_NTGUI) + alt_display = "windows"; #endif + + display = egetenv ("DISPLAY"); + } + + if (!display) + { + display = alt_display; + alt_display = NULL; } /* A null-string display is invalid. */ @@ -1562,8 +1578,10 @@ main (int argc, char **argv) progname = argv[0]; #ifdef HAVE_NTGUI - /* On Windows 7 and later, we need to explicitly associate emacsclient - with emacs so the UI behaves sensibly. */ + /* On Windows 7 and later, we need to explicitly associate + emacsclient with emacs so the UI behaves sensibly. This + association does no harm if we're not actually connecting to an + Emacs using a window display. */ w32_set_user_model_id (); #endif /* HAVE_NTGUI */ @@ -1602,6 +1620,7 @@ main (int argc, char **argv) } #ifdef HAVE_NTGUI + if (display && !strcmp (display, "windows")) w32_give_focus (); #endif /* HAVE_NTGUI */ @@ -1777,46 +1796,56 @@ main (int argc, char **argv) if (end_p != NULL) *end_p++ = '\0'; - if (strprefix ("-emacs-pid ", p)) - { - /* -emacs-pid PID: The process id of the Emacs process. */ - emacs_pid = strtol (p + strlen ("-emacs-pid"), NULL, 10); - } - else if (strprefix ("-window-system-unsupported ", p)) - { - /* -window-system-unsupported: Emacs was compiled without X - support. Try again on the terminal. */ - nowait = 0; - tty = 1; - goto retry; - } - else if (strprefix ("-print ", p)) - { - /* -print STRING: Print STRING on the terminal. */ - str = unquote_argument (p + strlen ("-print ")); - if (needlf) - printf ("\n"); - printf ("%s", str); - needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; - } - else if (strprefix ("-print-nonl ", p)) - { - /* -print-nonl STRING: Print STRING on the terminal. - Used to continue a preceding -print command. */ - str = unquote_argument (p + strlen ("-print-nonl ")); - printf ("%s", str); - needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; - } - else if (strprefix ("-error ", p)) - { - /* -error DESCRIPTION: Signal an error on the terminal. */ - str = unquote_argument (p + strlen ("-error ")); - if (needlf) - printf ("\n"); - fprintf (stderr, "*ERROR*: %s", str); - needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; - exit_status = EXIT_FAILURE; - } + if (strprefix ("-emacs-pid ", p)) + { + /* -emacs-pid PID: The process id of the Emacs process. */ + emacs_pid = strtol (p + strlen ("-emacs-pid"), NULL, 10); + } + else if (strprefix ("-window-system-unsupported ", p)) + { + /* -window-system-unsupported: Emacs was compiled without support + for whatever window system we tried. Try the alternate + display, or, failing that, try the terminal. */ + if (alt_display) + { + display = alt_display; + alt_display = NULL; + } + else + { + nowait = 0; + tty = 1; + } + + goto retry; + } + else if (strprefix ("-print ", p)) + { + /* -print STRING: Print STRING on the terminal. */ + str = unquote_argument (p + strlen ("-print ")); + if (needlf) + printf ("\n"); + printf ("%s", str); + needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; + } + else if (strprefix ("-print-nonl ", p)) + { + /* -print-nonl STRING: Print STRING on the terminal. + Used to continue a preceding -print command. */ + str = unquote_argument (p + strlen ("-print-nonl ")); + printf ("%s", str); + needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; + } + else if (strprefix ("-error ", p)) + { + /* -error DESCRIPTION: Signal an error on the terminal. */ + str = unquote_argument (p + strlen ("-error ")); + if (needlf) + printf ("\n"); + fprintf (stderr, "*ERROR*: %s", str); + needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; + exit_status = EXIT_FAILURE; + } #ifdef SIGSTOP else if (strprefix ("-suspend ", p)) { -- 1.7.2.5