changeset 52298:1a4bd2bec861

Create and initialize a client leader window so session management doesn't restart Emacs twice.
author Jan Djärv <jan.h.d@swipnet.se>
date Thu, 21 Aug 2003 19:54:47 +0000
parents 3b67088aae99
children 127d2248385e
files src/ChangeLog src/Makefile.in src/xfns.c src/xsmfns.c src/xterm.c src/xterm.h
diffstat 6 files changed, 90 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Aug 21 17:24:58 2003 +0000
+++ b/src/ChangeLog	Thu Aug 21 19:54:47 2003 +0000
@@ -1,3 +1,19 @@
+2003-08-21  Jan Dj,Ad(Brv  <jan.h.d@swipnet.se>
+
+	* xterm.h (struct x_display_info): New fields: client_leader_window
+	and Xatom_wm_client_leader.
+
+	* xterm.c (x_initialize): Move call to x_session_initialize to ...
+	(x_term_init): ... here.  Initialize client_leader fields in dpyinfo.
+
+	* xsmfns.c (create_client_leader_window): New function.
+	(x_session_initialize): Call create_client_leader_window, take
+	dpyinfo as argument.
+
+	* xfns.c (Fx_create_frame): Set property WM_CLIENT_LEADER.
+
+	* Makefile.in (xsmfns.o): Add more depenedencies.
+
 2003-08-21  Dave Love  <fx@gnu.org>
 
 	* m/iris4d.h: Use _MIPS_SZLONG, not _LP64.
--- a/src/Makefile.in	Thu Aug 21 17:24:58 2003 +0000
+++ b/src/Makefile.in	Thu Aug 21 19:54:47 2003 +0000
@@ -1153,7 +1153,8 @@
 xselect.o: xselect.c process.h dispextern.h frame.h xterm.h blockinput.h \
   buffer.h atimer.h systime.h $(config_h)
 xrdb.o: xrdb.c $(config_h) epaths.h
-xsmfns.o: xsmfns.c $(config_h) systime.h sysselect.h termhooks.h
+xsmfns.o: xsmfns.c $(config_h) systime.h sysselect.h termhooks.h xterm.h \
+  lisp.h termopts.h
 gtkutil.o:  gtkutil.c gtkutil.h xterm.h lisp.h frame.h $(config_h) \
   blockinput.h window.h atimer.h termhooks.h
 
--- a/src/xfns.c	Thu Aug 21 17:24:58 2003 +0000
+++ b/src/xfns.c	Thu Aug 21 19:54:47 2003 +0000
@@ -3526,6 +3526,19 @@
 	;
     }
 
+  /* Set the WM leader property.  GTK does this itself, so this is not
+     needed when using GTK.  */
+  if (dpyinfo->client_leader_window != 0)
+    {
+      BLOCK_INPUT;
+      XChangeProperty (FRAME_X_DISPLAY (f),
+                       FRAME_OUTER_WINDOW (f),
+                       dpyinfo->Xatom_wm_client_leader,
+                       XA_WINDOW, 32, PropModeReplace,
+                       (char *) &dpyinfo->client_leader_window, 1);
+      UNBLOCK_INPUT;
+    }
+
   UNGCPRO;
 
   /* Make sure windows on this frame appear in calls to next-window
--- a/src/xsmfns.c	Thu Aug 21 17:24:58 2003 +0000
+++ b/src/xsmfns.c	Thu Aug 21 19:54:47 2003 +0000
@@ -24,6 +24,9 @@
 #ifdef HAVE_X_SM
 
 #include <X11/SM/SMlib.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
 #ifdef HAVE_STRING_H
 #include <string.h>
 #else
@@ -47,6 +50,7 @@
 #include "lisp.h"
 #include "termhooks.h"
 #include "termopts.h"
+#include "xterm.h"
 
 #ifndef MAXPATHLEN
 #define MAXPATHLEN 1024
@@ -403,9 +407,37 @@
 #endif /* ! defined (SIGIO) */
 }
 
+/* Create the client leader window.  */
+static void
+create_client_leader_window (dpyinfo, client_id)
+     struct x_display_info *dpyinfo;
+     char *client_id;
+{
+  Window w;
+  XClassHint class_hints;
+  Atom sm_id;
+
+  w = XCreateSimpleWindow (dpyinfo->display,
+                           dpyinfo->root_window,
+                           -1, -1, 1, 1,
+                           CopyFromParent, CopyFromParent, CopyFromParent);
+
+  class_hints.res_name = (char *) SDATA (Vx_resource_name);
+  class_hints.res_class = (char *) SDATA (Vx_resource_class);
+  XSetClassHint (dpyinfo->display, w, &class_hints);
+  XStoreName (dpyinfo->display, w, class_hints.res_name);
+
+  sm_id = XInternAtom (dpyinfo->display, "SM_CLIENT_ID", False);
+  XChangeProperty (dpyinfo->display, w, sm_id, XA_STRING, 8, PropModeReplace,
+                   client_id, strlen (client_id));
+
+  dpyinfo->client_leader_window = w;
+}
+
 /* Try to open a connection to the session manager. */
 void
-x_session_initialize ()
+x_session_initialize (dpyinfo)
+     struct x_display_info *dpyinfo;
 {
 #define SM_ERRORSTRING_LEN 512
   char errorstring[SM_ERRORSTRING_LEN];
@@ -466,7 +498,17 @@
                                 errorstring);
 
   if (smc_conn != 0)
-    Vx_session_id = make_string (client_id, strlen (client_id));
+    {
+      Vx_session_id = make_string (client_id, strlen (client_id));
+
+#ifdef USE_GTK
+      /* GTK creats a leader window by itself, but we need to tell
+         it about our client_id.  */
+      gdk_set_sm_client_id (client_id);
+#else
+      create_client_leader_window (dpyinfo, client_id);
+#endif
+    }
 }
 
 
--- a/src/xterm.c	Thu Aug 21 17:24:58 2003 +0000
+++ b/src/xterm.c	Thu Aug 21 19:54:47 2003 +0000
@@ -10136,7 +10136,7 @@
   if (!x_initialized)
     {
       x_initialize ();
-      x_initialized = 1;
+      ++x_initialized;
     }
 
 #ifdef USE_GTK
@@ -10152,8 +10152,6 @@
     if (x_initialized > 1)
       return 0;
 
-    x_initialized++;
-
     for (argc = 0; argc < NUM_ARGV; ++argc)
       argv[argc] = 0;
 
@@ -10343,6 +10341,7 @@
   dpyinfo->height = HeightOfScreen (dpyinfo->screen);
   dpyinfo->width = WidthOfScreen (dpyinfo->screen);
   dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen);
+  dpyinfo->client_leader_window = 0;
   dpyinfo->grabbed = 0;
   dpyinfo->reference_count = 0;
   dpyinfo->icon_bitmap_id = -1;
@@ -10412,6 +10411,8 @@
     = XInternAtom (dpyinfo->display, "WM_CONFIGURE_DENIED", False);
   dpyinfo->Xatom_wm_window_moved
     = XInternAtom (dpyinfo->display, "WM_MOVED", False);
+  dpyinfo->Xatom_wm_client_leader
+    = XInternAtom (dpyinfo->display, "WM_CLIENT_LEADER", False);
   dpyinfo->Xatom_editres
     = XInternAtom (dpyinfo->display, "Editres", False);
   dpyinfo->Xatom_CLIPBOARD
@@ -10566,6 +10567,12 @@
 #endif
   }
 
+#ifdef HAVE_X_SM
+  /* Only do this for the first display.  */
+  if (x_initialized == 1)
+    x_session_initialize (dpyinfo);
+#endif
+
   UNBLOCK_INPUT;
 
   return dpyinfo;
@@ -10779,10 +10786,6 @@
 #endif /* SIGWINCH */
 
   signal (SIGPIPE, x_connection_signal);
-
-#ifdef HAVE_X_SM
-  x_session_initialize ();
-#endif
 }
 
 
--- a/src/xterm.h	Thu Aug 21 17:24:58 2003 +0000
+++ b/src/xterm.h	Thu Aug 21 19:54:47 2003 +0000
@@ -183,6 +183,9 @@
   /* The root window of this screen.  */
   Window root_window;
 
+  /* Client leader window.  */
+  Window client_leader_window;
+
   /* The cursor to use for vertical scroll bars.  */
   Cursor vertical_scroll_bar_cursor;
 
@@ -289,6 +292,7 @@
   /* Other WM communication */
   Atom Xatom_wm_configure_denied; /* When our config request is denied */
   Atom Xatom_wm_window_moved;     /* When the WM moves us.  */
+  Atom Xatom_wm_client_leader;    /* Id of client leader window.  */
 
   /* EditRes protocol */
   Atom Xatom_editres;
@@ -1029,7 +1033,7 @@
 
 /* Defined in xsmfns.c */
 #ifdef HAVE_X_SM
-extern void x_session_initialize P_ ((void));
+extern void x_session_initialize P_ ((struct x_display_info *dpyinfo));
 extern int x_session_check_input P_ ((struct input_event *bufp,
                                       int *numchars));
 extern int x_session_have_connection P_ ((void));