Mercurial > emacs
annotate src/xsmfns.c @ 43843:b7df840b93fb
Remove documentation on setting up pcomplete.
author | Colin Walters <walters@gnu.org> |
---|---|
date | Mon, 11 Mar 2002 21:12:49 +0000 |
parents | 3d8039f847f5 |
children | 1690ab476469 |
rev | line source |
---|---|
43810
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
1 /* Session management module for systems which understand the X Session |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
2 management protocol. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
3 Copyright (C) 2002 Free Software Foundation, Inc. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
4 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
5 This file is part of GNU Emacs. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
6 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
7 GNU Emacs is free software; you can redistribute it and/or modify |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
8 it under the terms of the GNU General Public License as published by |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
9 the Free Software Foundation; either version 2, or (at your option) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
10 any later version. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
11 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
12 GNU Emacs is distributed in the hope that it will be useful, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
15 GNU General Public License for more details. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
16 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
18 along with GNU Emacs; see the file COPYING. If not, write to |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
20 Boston, MA 02111-1307, USA. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
21 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
22 #include <config.h> |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
23 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
24 #ifdef HAVE_X_SM |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
25 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
26 #include <X11/SM/SMlib.h> |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
27 #ifdef HAVE_STRING_H |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
28 #include <string.h> |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
29 #else |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
30 #ifdef HAVE_STRINGS_H |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
31 #include <strings.h> |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
32 #endif |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
33 #endif |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
34 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
35 #ifdef HAVE_UNISTD_H |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
36 #include <unistd.h> |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
37 #endif |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
38 #ifdef HAVE_STDLIB_H |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
39 #include <stdlib.h> |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
40 #endif |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
41 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
42 #include <sys/param.h> |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
43 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
44 #include "systime.h" |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
45 #include "sysselect.h" |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
46 #include "lisp.h" |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
47 #include "termhooks.h" |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
48 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
49 #ifndef MAXPATHLEN |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
50 #define MAXPATHLEN 1024 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
51 #endif /* not MAXPATHLEN */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
52 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
53 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
54 /* The user login name. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
55 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
56 extern Lisp_Object Vuser_login_name; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
57 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
58 /* This is the event used when save_session occurs */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
59 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
60 static struct input_event emacs_event; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
61 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
62 /* The descriptor that we use to check for data from the session manager. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
63 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
64 static int ice_fd = -1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
65 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
66 /* A flag that says if we are in shutdown interactions or not. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
67 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
68 static int doing_interact = False; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
69 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
70 /* The session manager object for the session manager connection */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
71 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
72 static SmcConn smc_conn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
73 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
74 /* The client session id for this session */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
75 static char *client_id; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
76 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
77 /* The full path name to the Emacs program */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
78 static char *emacs_program; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
79 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
80 /* The client session id for this session as a lisp object. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
81 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
82 Lisp_Object Vx_session_id; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
83 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
84 /* The id we had the previous session. This is only available if we |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
85 have been started by the session manager with SMID_OPT. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
86 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
87 Lisp_Object Vx_session_previous_id; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
88 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
89 /* The option we tell the session manager to start Emacs with when |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
90 restarting Emacs. The client_id is appended. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
91 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
92 #define SMID_OPT "--smid=" |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
93 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
94 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
95 /* Handle any messages from the session manager. If no connection is |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
96 open to a session manager, just return 0. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
97 Otherwise returns the number of events stored in buffer BUFP, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
98 which can hold up to *NUMCHARS characters. At most one event is |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
99 stored, an save_session_event. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
100 int |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
101 x_session_check_input (bufp, numchars) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
102 struct input_event *bufp; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
103 int *numchars; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
104 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
105 SELECT_TYPE read_fds; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
106 EMACS_TIME tmout; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
107 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
108 if (ice_fd == -1) return 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
109 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
110 FD_ZERO (&read_fds); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
111 FD_SET (ice_fd, &read_fds); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
112 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
113 tmout.tv_sec = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
114 tmout.tv_usec = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
115 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
116 /* Reset this so wo can check kind after callbacks have been called by |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
117 IceProcessMessages. The smc_interact_CB sets the kind to |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
118 save_session_event, but we don't know beforehand if that callback |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
119 will be called. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
120 emacs_event.kind = no_event; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
121 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
122 if (select (ice_fd+1, &read_fds, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
123 (SELECT_TYPE *)0, (SELECT_TYPE *)0, &tmout) < 0) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
124 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
125 ice_fd = -1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
126 return 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
127 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
128 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
129 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
130 if (FD_ISSET (ice_fd, &read_fds)) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
131 IceProcessMessages (SmcGetIceConnection (smc_conn), |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
132 (IceReplyWaitInfo *)0, (Bool *)0); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
133 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
134 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
135 /* Check if smc_interact_CB was called and we shall generate a |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
136 save_session event. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
137 if (*numchars > 0 && emacs_event.kind != no_event) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
138 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
139 bcopy (&emacs_event, bufp, sizeof (struct input_event)); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
140 bufp++; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
141 (*numchars)--; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
142 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
143 return 1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
144 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
145 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
146 return 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
147 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
148 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
149 /* Return non-zero if we have a connection to a session manager.*/ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
150 int |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
151 x_session_have_connection () |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
152 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
153 return ice_fd != -1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
154 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
155 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
156 /* This is called when the session manager says it is OK to interact with the |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
157 user. Here we set the kind to save_session so an event is generated. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
158 Then lisp code can interact with the user. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
159 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
160 smc_interact_CB (smcConn, clientData) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
161 SmcConn smcConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
162 SmPointer clientData; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
163 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
164 doing_interact = True; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
165 emacs_event.kind = save_session_event; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
166 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
167 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
168 /* This is called when the session manager tells us to save ourself. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
169 We set the required properties so the session manager can restart us, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
170 plus the current working directory property (not mandatory) so we |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
171 are started in the correct directory. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
172 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
173 If this is a shutdown and we can request to interact with the user, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
174 we do so, because we don't know what the lisp code might do. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
175 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
176 smc_save_yourself_CB (smcConn, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
177 clientData, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
178 saveType, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
179 shutdown, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
180 interactStyle, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
181 fast) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
182 SmcConn smcConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
183 SmPointer clientData; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
184 int saveType; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
185 Bool shutdown; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
186 int interactStyle; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
187 Bool fast; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
188 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
189 #define NR_PROPS 5 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
190 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
191 SmProp *props[NR_PROPS]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
192 SmProp prop_ptr[NR_PROPS]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
193 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
194 SmPropValue values[20]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
195 int val_idx = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
196 int props_idx = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
197 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
198 char cwd[MAXPATHLEN+1]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
199 char *smid_opt; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
200 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
201 /* How to start a new instance of Emacs */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
202 props[props_idx] = &prop_ptr[props_idx]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
203 props[props_idx]->name = SmCloneCommand; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
204 props[props_idx]->type = SmLISTofARRAY8; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
205 props[props_idx]->num_vals = 1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
206 props[props_idx]->vals = &values[val_idx++]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
207 props[props_idx]->vals[0].length = strlen (emacs_program); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
208 props[props_idx]->vals[0].value = emacs_program; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
209 ++props_idx; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
210 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
211 /* The name of the program */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
212 props[props_idx] = &prop_ptr[props_idx]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
213 props[props_idx]->name = SmProgram; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
214 props[props_idx]->type = SmARRAY8; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
215 props[props_idx]->num_vals = 1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
216 props[props_idx]->vals = &values[val_idx++]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
217 props[props_idx]->vals[0].length = strlen (XSTRING (Vinvocation_name)->data); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
218 props[props_idx]->vals[0].value = XSTRING (Vinvocation_name)->data; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
219 ++props_idx; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
220 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
221 /* How to restart Emacs (i.e.: /path/to/emacs --smid=xxxx). */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
222 props[props_idx] = &prop_ptr[props_idx]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
223 props[props_idx]->name = SmRestartCommand; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
224 props[props_idx]->type = SmLISTofARRAY8; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
225 props[props_idx]->num_vals = 2; /* 2 values: /path/to/emacs, --smid=xxx */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
226 props[props_idx]->vals = &values[val_idx]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
227 props[props_idx]->vals[0].length = strlen (emacs_program); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
228 props[props_idx]->vals[0].value = emacs_program; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
229 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
230 smid_opt = xmalloc (strlen (SMID_OPT) + strlen (client_id) + 1); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
231 strcpy (smid_opt, SMID_OPT); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
232 strcat (smid_opt, client_id); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
233 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
234 props[props_idx]->vals[1].length = strlen (smid_opt); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
235 props[props_idx]->vals[1].value = smid_opt; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
236 val_idx += 2; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
237 ++props_idx; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
238 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
239 /* User id */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
240 props[props_idx] = &prop_ptr[props_idx]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
241 props[props_idx]->name = SmUserID; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
242 props[props_idx]->type = SmARRAY8; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
243 props[props_idx]->num_vals = 1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
244 props[props_idx]->vals = &values[val_idx++]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
245 props[props_idx]->vals[0].length = strlen (XSTRING (Vuser_login_name)->data); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
246 props[props_idx]->vals[0].value = XSTRING (Vuser_login_name)->data; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
247 ++props_idx; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
248 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
249 /* The current directory property, not mandatory */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
250 #ifdef HAVE_GETCWD |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
251 if (getcwd (cwd, MAXPATHLEN+1) != 0) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
252 #else |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
253 if (getwd (cwd) != 0) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
254 #endif |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
255 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
256 props[props_idx] = &prop_ptr[props_idx]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
257 props[props_idx]->name = SmCurrentDirectory; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
258 props[props_idx]->type = SmARRAY8; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
259 props[props_idx]->num_vals = 1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
260 props[props_idx]->vals = &values[val_idx++]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
261 props[props_idx]->vals[0].length = strlen (cwd); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
262 props[props_idx]->vals[0].value = cwd; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
263 ++props_idx; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
264 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
265 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
266 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
267 SmcSetProperties (smcConn, props_idx, props); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
268 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
269 xfree (smid_opt); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
270 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
271 /* See if we maybe shall interact with the user. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
272 if (interactStyle != SmInteractStyleAny |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
273 || ! shutdown |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
274 || saveType == SmSaveLocal |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
275 || ! SmcInteractRequest (smcConn, SmDialogNormal, smc_interact_CB, 0)) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
276 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
277 /* No interaction, we are done saving ourself. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
278 SmcSaveYourselfDone (smcConn, True); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
279 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
280 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
281 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
282 /* According to the SM specification, this shall close the connection */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
283 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
284 smc_die_CB (smcConn, clientData) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
285 SmcConn smcConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
286 SmPointer clientData; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
287 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
288 SmcCloseConnection (smcConn, 0, 0); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
289 ice_fd = -1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
290 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
291 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
292 /* We don't use the next two but they are mandatory, leave them empty. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
293 According to the SM specification, we should not interact with the |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
294 user between smc_save_yourself_CB is called and until smc_save_complete_CB |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
295 is called. It seems like a lot of job to implement this and it doesn't |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
296 even seem necessary. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
297 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
298 smc_save_complete_CB (smcConn, clientData) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
299 SmcConn smcConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
300 SmPointer clientData; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
301 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
302 /* Empty */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
303 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
304 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
305 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
306 smc_shutdown_cancelled_CB (smcConn, clientData) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
307 SmcConn smcConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
308 SmPointer clientData; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
309 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
310 /* Empty */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
311 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
312 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
313 /* Error handlers for SM and ICE. We don't wan't to exit Emacs just |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
314 because there is some error in the session management. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
315 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
316 smc_error_handler (smcConn, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
317 swap, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
318 offendingMinorOpcode, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
319 offendingSequence, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
320 errorClass, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
321 severity, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
322 values) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
323 SmcConn smcConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
324 Bool swap; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
325 int offendingMinorOpcode; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
326 unsigned long offendingSequence; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
327 int errorClass; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
328 int severity; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
329 SmPointer values; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
330 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
331 /* Empty */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
332 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
333 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
334 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
335 ice_error_handler (iceConn, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
336 swap, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
337 offendingMinorOpcode, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
338 offendingSequence, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
339 errorClass, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
340 severity, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
341 values) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
342 IceConn iceConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
343 Bool swap; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
344 int offendingMinorOpcode; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
345 unsigned long offendingSequence; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
346 int errorClass; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
347 int severity; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
348 IcePointer values; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
349 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
350 /* Empty */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
351 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
352 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
353 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
354 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
355 ice_io_error_handler (iceConn) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
356 IceConn iceConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
357 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
358 /* Connection probably gone. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
359 ice_fd = -1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
360 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
361 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
362 /* This is called when the ICE connection is created or closed. The SM library |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
363 uses ICE as it transport protocol. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
364 static void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
365 ice_conn_watch_CB (iceConn, clientData, opening, watchData) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
366 IceConn iceConn; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
367 IcePointer clientData; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
368 Bool opening; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
369 IcePointer *watchData; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
370 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
371 if (! opening) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
372 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
373 ice_fd = -1; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
374 return; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
375 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
376 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
377 ice_fd = IceConnectionNumber (iceConn); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
378 #ifndef F_SETOWN_BUG |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
379 #ifdef F_SETOWN |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
380 #ifdef F_SETOWN_SOCK_NEG |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
381 /* stdin is a socket here */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
382 fcntl (ice_fd, F_SETOWN, -getpid ()); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
383 #else /* ! defined (F_SETOWN_SOCK_NEG) */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
384 fcntl (ice_fd, F_SETOWN, getpid ()); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
385 #endif /* ! defined (F_SETOWN_SOCK_NEG) */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
386 #endif /* ! defined (F_SETOWN) */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
387 #endif /* F_SETOWN_BUG */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
388 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
389 #ifdef SIGIO |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
390 if (interrupt_input) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
391 init_sigio (ice_fd); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
392 #endif /* ! defined (SIGIO) */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
393 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
394 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
395 /* Try to open a connection to the session manager. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
396 void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
397 x_session_initialize () |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
398 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
399 #define SM_ERRORSTRING_LEN 512 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
400 char errorstring[SM_ERRORSTRING_LEN]; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
401 char* previous_id = NULL; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
402 SmcCallbacks callbacks; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
403 int name_len = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
404 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
405 /* Check if we where started by the session manager. If so, we will |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
406 have a previous id. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
407 if (! EQ (Vx_session_previous_id, Qnil) && STRINGP (Vx_session_previous_id)) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
408 previous_id = XSTRING (Vx_session_previous_id)->data; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
409 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
410 /* Construct the path to the Emacs program. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
411 if (! EQ (Vinvocation_directory, Qnil)) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
412 name_len += strlen (XSTRING (Vinvocation_directory)->data); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
413 name_len += strlen (XSTRING (Vinvocation_name)->data); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
414 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
415 /* This malloc will not be freed, but it is only done once, and hopefully |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
416 not very large */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
417 emacs_program = xmalloc (name_len + 1); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
418 emacs_program[0] = '\0'; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
419 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
420 if (! EQ (Vinvocation_directory, Qnil)) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
421 strcpy (emacs_program, XSTRING (Vinvocation_directory)->data); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
422 strcat (emacs_program, XSTRING (Vinvocation_name)->data); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
423 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
424 /* The SM protocol says all callbacks are mandatory, so set up all |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
425 here and in the mask passed to SmcOpenConnection */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
426 callbacks.save_yourself.callback = smc_save_yourself_CB; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
427 callbacks.save_yourself.client_data = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
428 callbacks.die.callback = smc_die_CB; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
429 callbacks.die.client_data = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
430 callbacks.save_complete.callback = smc_save_complete_CB; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
431 callbacks.save_complete.client_data = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
432 callbacks.shutdown_cancelled.callback = smc_shutdown_cancelled_CB; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
433 callbacks.shutdown_cancelled.client_data = 0; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
434 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
435 /* Set error handlers. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
436 SmcSetErrorHandler (smc_error_handler); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
437 IceSetErrorHandler (ice_error_handler); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
438 IceSetIOErrorHandler (ice_io_error_handler); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
439 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
440 /* Install callback for when connection status changes. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
441 IceAddConnectionWatch (ice_conn_watch_CB, 0); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
442 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
443 /* Open the connection to the session manager. A failure is not |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
444 critical, it usualy means that no session manager is running. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
445 The errorstring is here for debugging. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
446 smc_conn = SmcOpenConnection (NULL, NULL, 1, 0, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
447 (SmcSaveYourselfProcMask| |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
448 SmcDieProcMask| |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
449 SmcSaveCompleteProcMask| |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
450 SmcShutdownCancelledProcMask), |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
451 &callbacks, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
452 previous_id, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
453 &client_id, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
454 SM_ERRORSTRING_LEN, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
455 errorstring); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
456 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
457 if (smc_conn != 0) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
458 Vx_session_id = make_string (client_id, strlen (client_id)); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
459 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
460 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
461 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
462 DEFUN ("handle-save-session", Fhandle_save_session, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
463 Shandle_save_session, 1, 1, "e", |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
464 doc: /* Handle the save_yourself event from a session manager. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
465 A session manager can tell Emacs that the window system is shutting down |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
466 by sending Emacs a save_yourself message. Emacs executes this function when |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
467 such an event occurs. This function then executes `emacs-session-save'. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
468 After that, this function informs the session manager that it can continue |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
469 or abort shutting down the window system depending on the return value |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
470 from `emacs-session-save' If the return value is non-nil the session manager |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
471 is told to abort the window system shutdown. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
472 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
473 Do not call this function yourself. */) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
474 (event) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
475 Lisp_Object event; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
476 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
477 /* Check doing_interact so that we don't do anything if someone called |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
478 this at the wrong time. */ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
479 if (doing_interact) |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
480 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
481 Bool cancel_shutdown = False; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
482 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
483 cancel_shutdown = ! EQ (call0 (intern ("emacs-session-save")), Qnil); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
484 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
485 SmcInteractDone (smc_conn, cancel_shutdown); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
486 SmcSaveYourselfDone (smc_conn, True); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
487 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
488 doing_interact = False; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
489 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
490 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
491 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
492 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
493 /*********************************************************************** |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
494 Initialization |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
495 ***********************************************************************/ |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
496 void |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
497 syms_of_xsmfns () |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
498 { |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
499 DEFVAR_LISP ("x-session-id", &Vx_session_id, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
500 doc: /* The session id Emacs got from the session manager for this session. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
501 Changing the value does not change the session id used by Emacs. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
502 The value is nil if no session manager is running. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
503 See also `x-session-previous-id', `emacs-save-session-functions', |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
504 `emacs-session-save' and `emacs-session-restore'." */); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
505 Vx_session_id = Qnil; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
506 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
507 DEFVAR_LISP ("x-session-previous-id", &Vx_session_previous_id, |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
508 doc: /* The previous session id Emacs got from session manager. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
509 If Emacs is running on a window system that has a session manager, the |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
510 session manager gives Emacs a session id. It is feasible for Emacs lisp |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
511 code to use the session id to save configuration in, for example, a file |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
512 with a file name based on the session id. If Emacs is running when the |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
513 window system is shut down, the session manager remembers that Emacs was |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
514 running and saves the session id Emacs had. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
515 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
516 When the window system is started again, the session manager restarts |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
517 Emacs and hands Emacs the session id it had the last time it was |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
518 running. This is now the previous session id and the value of this |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
519 variable. If configuration was saved in a file as stated above, the |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
520 previous session id shall be used to reconstruct the file name. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
521 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
522 The session id Emacs has while it is running is in the variable |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
523 `x-session-id'. The value of this variable and `x-session-id' may be the |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
524 same, depending on how the session manager works. |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
525 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
526 See also `emacs-save-session-functions', `emacs-session-save' and |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
527 `emacs-session-restore'." */); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
528 Vx_session_previous_id = Qnil; |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
529 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
530 defsubr (&Shandle_save_session); |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
531 } |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
532 |
3d8039f847f5
New file for X session management.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
533 #endif /* HAVE_X_SM */ |