all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Colascione <dancol@dancol.org>
To: emacs-devel@gnu.org
Subject: [PATCH 7/9] Add alt_display to emacsclient for w32, ns
Date: Tue, 07 Aug 2012 01:19:27 -0700	[thread overview]
Message-ID: <7871883407e88939ff987b9ba718df5bbbac6692.1344326992.git.dancol@dancol.org> (raw)
In-Reply-To: <cover.1344326992.git.dancol@dancol.org>

---
 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





  parent reply	other threads:[~2012-08-07  8:19 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07  8:19 [PATCH 0/9] Support Win32 GUI in Cygwin Emacs Daniel Colascione
2012-08-07  8:19 ` [PATCH 3/9] Implement cygw32 Daniel Colascione
2012-08-07 15:40   ` Stefan Monnier
2012-08-07 18:02   ` Eli Zaretskii
2012-08-07 20:11     ` Daniel Colascione
2012-08-08 17:15       ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 1/9] Under Remote Desktop, NUMCOLORS is unreliable; workaround Daniel Colascione
2012-08-07 17:07   ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 8/9] Generalize fork+exec logic, add DAEMON_MUST_EXEC Daniel Colascione
2012-08-07  8:19 ` [PATCH 4/9] Fix emacsclient to work with cygw32 Daniel Colascione
2012-08-07 18:14   ` Eli Zaretskii
2012-08-07 20:16     ` Daniel Colascione
2012-08-08  2:55       ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 5/9] Prevent crash if w32 used before it's initialized Daniel Colascione
2012-08-07 17:23   ` Eli Zaretskii
2012-08-07 17:28     ` Daniel Colascione
2012-08-07 18:11       ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 9/9] Detect window-system from display name Daniel Colascione
2012-08-07 15:50   ` Stefan Monnier
2012-08-07 17:09     ` Daniel Colascione
2012-08-07 20:01       ` Stefan Monnier
2012-08-07 20:19         ` Daniel Colascione
2012-08-07 22:52           ` Lennart Borgman
2012-08-07 22:54             ` Daniel Colascione
2012-08-07 23:02               ` Lennart Borgman
2012-08-07 18:18   ` Eli Zaretskii
2012-08-07 20:28     ` Daniel Colascione
2012-08-08 16:50   ` Eli Zaretskii
2012-08-07  8:19 ` Daniel Colascione [this message]
2012-08-07 15:22   ` [PATCH 7/9] Add alt_display to emacsclient for w32, ns Stefan Monnier
2012-08-07  8:19 ` [PATCH 6/9] Rename `w32' local to `nt' for clarity Daniel Colascione
2012-08-07 10:49   ` Lennart Borgman
2012-08-07 15:45   ` Stefan Monnier
2012-08-07 16:31     ` Eli Zaretskii
2012-08-07 16:40       ` Drew Adams
2012-08-07 17:07         ` Daniel Colascione
2012-08-07 20:00       ` Stefan Monnier
2012-08-08  2:50         ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 2/9] Refactor window-system configuration Daniel Colascione
2012-08-07 17:20   ` Eli Zaretskii
2012-08-07 17:31     ` Daniel Colascione
2012-08-07 20:47     ` Stefan Monnier
2012-08-07 17:22 ` [PATCH 0/9] Support Win32 GUI in Cygwin Emacs Eli Zaretskii
2012-08-07 17:29   ` Daniel Colascione
2012-08-07 18:10     ` Eli Zaretskii
2012-08-07 19:18       ` Eli Zaretskii
2012-08-07 20:15       ` Daniel Colascione
2012-08-07 20:24         ` Juanma Barranquero
2012-08-08  2:53         ` Eli Zaretskii
2012-08-08  2:33     ` Daniel Colascione
2012-08-08  3:03       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7871883407e88939ff987b9ba718df5bbbac6692.1344326992.git.dancol@dancol.org \
    --to=dancol@dancol.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.