Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / src / xsmfns.c
index 79dccfa..aae1971 100644 (file)
@@ -1,6 +1,6 @@
 /* Session management module for systems which understand the X Session
    management protocol.
-   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2002-2011
      Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -26,10 +26,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
-
 #include <sys/param.h>
 #include <stdio.h>
 #include <setjmp.h>
@@ -42,9 +39,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "termopts.h"
 #include "xterm.h"
 
-/* Avoid "differ in sign" warnings */
-#define SSDATA(x)  ((char *) SDATA (x))
-
 /* This is the event used when SAVE_SESSION_EVENT occurs.  */
 
 static struct input_event emacs_event;
@@ -69,15 +63,6 @@ static char *client_id;
 
 static char *emacs_program;
 
-/* The client session id for this session as a lisp object.  */
-
-Lisp_Object Vx_session_id;
-
-/* The id we had the previous session.  This is only available if we
-   have been started by the session manager with SMID_OPT.  */
-
-Lisp_Object Vx_session_previous_id;
-
 /* The option we tell the session manager to start Emacs with when
    restarting Emacs.  The client_id is appended.  */
 
@@ -172,6 +157,7 @@ smc_interact_CB (SmcConn smcConn, SmPointer clientData)
 {
   doing_interact = True;
   emacs_event.kind = SAVE_SESSION_EVENT;
+  emacs_event.arg = Qnil;
 }
 
 /* This is called when the session manager tells us to save ourselves.
@@ -243,7 +229,7 @@ smc_save_yourself_CB (SmcConn smcConn,
   props[props_idx]->vals[2].value = NOSPLASH_OPT;
 
   cwd = get_current_dir_name ();
-  if (cwd) 
+  if (cwd)
     {
       chdir_opt = xmalloc (strlen (CHDIR_OPT) + strlen (cwd) + 1);
       strcpy (chdir_opt, CHDIR_OPT);
@@ -308,8 +294,8 @@ smc_save_yourself_CB (SmcConn smcConn,
 static void
 smc_die_CB (SmcConn smcConn, SmPointer clientData)
 {
-  SmcCloseConnection (smcConn, 0, 0);
-  ice_connection_closed ();
+  emacs_event.kind = SAVE_SESSION_EVENT;
+  emacs_event.arg = Qt;
 }
 
 /* We don't use the next two but they are mandatory, leave them empty.
@@ -405,13 +391,13 @@ create_client_leader_window (struct x_display_info *dpyinfo, char *client_id)
                            -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);
+  class_hints.res_name = SSDATA (Vx_resource_name);
+  class_hints.res_class = SSDATA (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,
+  XChangeProperty (dpyinfo->display, w, dpyinfo->Xatom_SM_CLIENT_ID,
+                   XA_STRING, 8, PropModeReplace,
                    (unsigned char *)client_id, strlen (client_id));
 
   dpyinfo->client_leader_window = w;
@@ -522,9 +508,12 @@ is told to abort the window system shutdown.
 Do not call this function yourself. */)
   (Lisp_Object event)
 {
+  int kill_emacs = CONSP (event) && CONSP (XCDR (event))
+    && EQ (Qt, XCAR (XCDR (event)));
+
   /* Check doing_interact so that we don't do anything if someone called
      this at the wrong time. */
-  if (doing_interact)
+  if (doing_interact && ! kill_emacs)
     {
       Bool cancel_shutdown = False;
 
@@ -535,10 +524,21 @@ Do not call this function yourself. */)
 
       doing_interact = False;
     }
+  else if (kill_emacs)
+    {
+      /* We should not do user interaction here, but it is not easy to
+         prevent.  Fix this in next version.  */
+      Fkill_emacs (Qnil);
+
+      /* This will not be reached, but we want kill-emacs-hook to be run.  */
+      SmcCloseConnection (smc_conn, 0, 0);
+      ice_connection_closed ();
+    }
 
   return Qnil;
 }
 
+
 \f
 /***********************************************************************
                            Initialization
@@ -546,7 +546,7 @@ Do not call this function yourself. */)
 void
 syms_of_xsmfns (void)
 {
-  DEFVAR_LISP ("x-session-id", &Vx_session_id,
+  DEFVAR_LISP ("x-session-id", Vx_session_id,
     doc: /* The session id Emacs got from the session manager for this session.
 Changing the value does not change the session id used by Emacs.
 The value is nil if no session manager is running.
@@ -554,7 +554,7 @@ See also `x-session-previous-id', `emacs-save-session-functions',
 `emacs-session-save' and `emacs-session-restore'." */);
   Vx_session_id = Qnil;
 
-  DEFVAR_LISP ("x-session-previous-id", &Vx_session_previous_id,
+  DEFVAR_LISP ("x-session-previous-id", Vx_session_previous_id,
     doc: /* The previous session id Emacs got from session manager.
 If Emacs is running on a window system that has a session manager, the
 session manager gives Emacs a session id.  It is feasible for Emacs Lisp
@@ -581,6 +581,3 @@ See also `emacs-save-session-functions', `emacs-session-save' and
 }
 
 #endif /* HAVE_X_SM */
-
-/* arch-tag: 56a2c58c-adfa-430a-b772-130abd29fd2e
-   (do not change this comment) */