aboutsummaryrefslogtreecommitdiffstats
path: root/src/xsmfns.c
diff options
context:
space:
mode:
authorKaroly Lorentey2004-10-31 02:05:24 +0000
committerKaroly Lorentey2004-10-31 02:05:24 +0000
commite0bc17abe6979d607e8de4684dddb96e53c60065 (patch)
treeb7cb7bc5df9f12138937fd958cdf4b9c2d19ee3a /src/xsmfns.c
parentf158167a84475d5fc41931531406821e6413afd7 (diff)
parent707994d2626cf0f01c3ece4028d73835068d64dc (diff)
downloademacs-e0bc17abe6979d607e8de4684dddb96e53c60065.tar.gz
emacs-e0bc17abe6979d607e8de4684dddb96e53c60065.zip
Merged in changes from CVS trunk.
Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-639 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-640 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-641 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-642 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-643 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-644 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-645 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-646 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-647 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-648 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-649 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-650 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-651 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-652 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-59 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-60 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-61 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-62 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-63 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-263
Diffstat (limited to 'src/xsmfns.c')
-rw-r--r--src/xsmfns.c82
1 files changed, 47 insertions, 35 deletions
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 080f998e779..27ab90c5432 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -74,33 +74,35 @@ static int ice_fd = -1;
74 74
75static int doing_interact = False; 75static int doing_interact = False;
76 76
77/* The session manager object for the session manager connection */ 77/* The session manager object for the session manager connection. */
78 78
79static SmcConn smc_conn; 79static SmcConn smc_conn;
80 80
81/* The client session id for this session */ 81/* The client session id for this session. */
82
82static char *client_id; 83static char *client_id;
83 84
84/* The full path name to the Emacs program */ 85/* The full path name to the Emacs program. */
86
85static char *emacs_program; 87static char *emacs_program;
86 88
87/* The client session id for this session as a lisp object. */ 89/* The client session id for this session as a lisp object. */
88 90
89Lisp_Object Vx_session_id; 91Lisp_Object Vx_session_id;
90 92
91/* The id we had the previous session. This is only available if we 93/* The id we had the previous session. This is only available if we
92 have been started by the session manager with SMID_OPT. */ 94 have been started by the session manager with SMID_OPT. */
93 95
94Lisp_Object Vx_session_previous_id; 96Lisp_Object Vx_session_previous_id;
95 97
96/* The option we tell the session manager to start Emacs with when 98/* The option we tell the session manager to start Emacs with when
97 restarting Emacs. The client_id is appended. */ 99 restarting Emacs. The client_id is appended. */
98 100
99#define SMID_OPT "--smid=" 101#define SMID_OPT "--smid="
100 102
101 103
102/* The option to start Emacs without the splash screen when 104/* The option to start Emacs without the splash screen when
103 restarting Emacs. */ 105 restarting Emacs. */
104 106
105#define NOSPLASH_OPT "--no-splash" 107#define NOSPLASH_OPT "--no-splash"
106 108
@@ -108,6 +110,7 @@ Lisp_Object Vx_session_previous_id;
108/* Handle any messages from the session manager. If no connection is 110/* Handle any messages from the session manager. If no connection is
109 open to a session manager, just return 0. 111 open to a session manager, just return 0.
110 Otherwise returns 1 if SAVE_SESSION_EVENT is stored in buffer BUFP. */ 112 Otherwise returns 1 if SAVE_SESSION_EVENT is stored in buffer BUFP. */
113
111int 114int
112x_session_check_input (bufp) 115x_session_check_input (bufp)
113 struct input_event *bufp; 116 struct input_event *bufp;
@@ -126,7 +129,7 @@ x_session_check_input (bufp)
126 /* Reset this so wo can check kind after callbacks have been called by 129 /* Reset this so wo can check kind after callbacks have been called by
127 IceProcessMessages. The smc_interact_CB sets the kind to 130 IceProcessMessages. The smc_interact_CB sets the kind to
128 SAVE_SESSION_EVENT, but we don't know beforehand if that callback 131 SAVE_SESSION_EVENT, but we don't know beforehand if that callback
129 will be called. */ 132 will be called. */
130 emacs_event.kind = NO_EVENT; 133 emacs_event.kind = NO_EVENT;
131 134
132 if (select (ice_fd+1, &read_fds, 135 if (select (ice_fd+1, &read_fds,
@@ -143,7 +146,7 @@ x_session_check_input (bufp)
143 146
144 147
145 /* Check if smc_interact_CB was called and we shall generate a 148 /* Check if smc_interact_CB was called and we shall generate a
146 SAVE_SESSION_EVENT. */ 149 SAVE_SESSION_EVENT. */
147 if (emacs_event.kind == NO_EVENT) 150 if (emacs_event.kind == NO_EVENT)
148 return 0; 151 return 0;
149 152
@@ -151,7 +154,8 @@ x_session_check_input (bufp)
151 return 1; 154 return 1;
152} 155}
153 156
154/* Return non-zero if we have a connection to a session manager.*/ 157/* Return non-zero if we have a connection to a session manager. */
158
155int 159int
156x_session_have_connection () 160x_session_have_connection ()
157{ 161{
@@ -160,7 +164,8 @@ x_session_have_connection ()
160 164
161/* This is called when the session manager says it is OK to interact with the 165/* This is called when the session manager says it is OK to interact with the
162 user. Here we set the kind to SAVE_SESSION_EVENT so an event is generated. 166 user. Here we set the kind to SAVE_SESSION_EVENT so an event is generated.
163 Then lisp code can interact with the user. */ 167 Then lisp code can interact with the user. */
168
164static void 169static void
165smc_interact_CB (smcConn, clientData) 170smc_interact_CB (smcConn, clientData)
166 SmcConn smcConn; 171 SmcConn smcConn;
@@ -176,7 +181,8 @@ smc_interact_CB (smcConn, clientData)
176 are started in the correct directory. 181 are started in the correct directory.
177 182
178 If this is a shutdown and we can request to interact with the user, 183 If this is a shutdown and we can request to interact with the user,
179 we do so, because we don't know what the lisp code might do. */ 184 we do so, because we don't know what the lisp code might do. */
185
180static void 186static void
181smc_save_yourself_CB (smcConn, 187smc_save_yourself_CB (smcConn,
182 clientData, 188 clientData,
@@ -203,7 +209,7 @@ smc_save_yourself_CB (smcConn,
203 char cwd[MAXPATHLEN+1]; 209 char cwd[MAXPATHLEN+1];
204 char *smid_opt; 210 char *smid_opt;
205 211
206 /* How to start a new instance of Emacs */ 212 /* How to start a new instance of Emacs. */
207 props[props_idx] = &prop_ptr[props_idx]; 213 props[props_idx] = &prop_ptr[props_idx];
208 props[props_idx]->name = SmCloneCommand; 214 props[props_idx]->name = SmCloneCommand;
209 props[props_idx]->type = SmLISTofARRAY8; 215 props[props_idx]->type = SmLISTofARRAY8;
@@ -213,7 +219,7 @@ smc_save_yourself_CB (smcConn,
213 props[props_idx]->vals[0].value = emacs_program; 219 props[props_idx]->vals[0].value = emacs_program;
214 ++props_idx; 220 ++props_idx;
215 221
216 /* The name of the program */ 222 /* The name of the program. */
217 props[props_idx] = &prop_ptr[props_idx]; 223 props[props_idx] = &prop_ptr[props_idx];
218 props[props_idx]->name = SmProgram; 224 props[props_idx]->name = SmProgram;
219 props[props_idx]->type = SmARRAY8; 225 props[props_idx]->type = SmARRAY8;
@@ -223,11 +229,11 @@ smc_save_yourself_CB (smcConn,
223 props[props_idx]->vals[0].value = SDATA (Vinvocation_name); 229 props[props_idx]->vals[0].value = SDATA (Vinvocation_name);
224 ++props_idx; 230 ++props_idx;
225 231
226 /* How to restart Emacs (i.e.: /path/to/emacs --smid=xxxx --no-splash). */ 232 /* How to restart Emacs (i.e.: /path/to/emacs --smid=xxxx --no-splash). */
227 props[props_idx] = &prop_ptr[props_idx]; 233 props[props_idx] = &prop_ptr[props_idx];
228 props[props_idx]->name = SmRestartCommand; 234 props[props_idx]->name = SmRestartCommand;
229 props[props_idx]->type = SmLISTofARRAY8; 235 props[props_idx]->type = SmLISTofARRAY8;
230 props[props_idx]->num_vals = 3; /* /path/to/emacs, --smid=xxx --no-splash */ 236 props[props_idx]->num_vals = 3; /* /path/to/emacs, --smid=xxx --no-splash */
231 props[props_idx]->vals = &values[val_idx]; 237 props[props_idx]->vals = &values[val_idx];
232 props[props_idx]->vals[0].length = strlen (emacs_program); 238 props[props_idx]->vals[0].length = strlen (emacs_program);
233 props[props_idx]->vals[0].value = emacs_program; 239 props[props_idx]->vals[0].value = emacs_program;
@@ -244,7 +250,7 @@ smc_save_yourself_CB (smcConn,
244 val_idx += 3; 250 val_idx += 3;
245 ++props_idx; 251 ++props_idx;
246 252
247 /* User id */ 253 /* User id. */
248 props[props_idx] = &prop_ptr[props_idx]; 254 props[props_idx] = &prop_ptr[props_idx];
249 props[props_idx]->name = SmUserID; 255 props[props_idx]->name = SmUserID;
250 props[props_idx]->type = SmARRAY8; 256 props[props_idx]->type = SmARRAY8;
@@ -254,7 +260,7 @@ smc_save_yourself_CB (smcConn,
254 props[props_idx]->vals[0].value = SDATA (Vuser_login_name); 260 props[props_idx]->vals[0].value = SDATA (Vuser_login_name);
255 ++props_idx; 261 ++props_idx;
256 262
257 /* The current directory property, not mandatory */ 263 /* The current directory property, not mandatory. */
258#ifdef HAVE_GETCWD 264#ifdef HAVE_GETCWD
259 if (getcwd (cwd, MAXPATHLEN+1) != 0) 265 if (getcwd (cwd, MAXPATHLEN+1) != 0)
260#else 266#else
@@ -276,18 +282,19 @@ smc_save_yourself_CB (smcConn,
276 282
277 xfree (smid_opt); 283 xfree (smid_opt);
278 284
279 /* See if we maybe shall interact with the user. */ 285 /* See if we maybe shall interact with the user. */
280 if (interactStyle != SmInteractStyleAny 286 if (interactStyle != SmInteractStyleAny
281 || ! shutdown 287 || ! shutdown
282 || saveType == SmSaveLocal 288 || saveType == SmSaveLocal
283 || ! SmcInteractRequest (smcConn, SmDialogNormal, smc_interact_CB, 0)) 289 || ! SmcInteractRequest (smcConn, SmDialogNormal, smc_interact_CB, 0))
284 { 290 {
285 /* No interaction, we are done saving ourself. */ 291 /* No interaction, we are done saving ourself. */
286 SmcSaveYourselfDone (smcConn, True); 292 SmcSaveYourselfDone (smcConn, True);
287 } 293 }
288} 294}
289 295
290/* According to the SM specification, this shall close the connection */ 296/* According to the SM specification, this shall close the connection. */
297
291static void 298static void
292smc_die_CB (smcConn, clientData) 299smc_die_CB (smcConn, clientData)
293 SmcConn smcConn; 300 SmcConn smcConn;
@@ -301,7 +308,8 @@ smc_die_CB (smcConn, clientData)
301 According to the SM specification, we should not interact with the 308 According to the SM specification, we should not interact with the
302 user between smc_save_yourself_CB is called and until smc_save_complete_CB 309 user between smc_save_yourself_CB is called and until smc_save_complete_CB
303 is called. It seems like a lot of job to implement this and it doesn't 310 is called. It seems like a lot of job to implement this and it doesn't
304 even seem necessary. */ 311 even seem necessary. */
312
305static void 313static void
306smc_save_complete_CB (smcConn, clientData) 314smc_save_complete_CB (smcConn, clientData)
307 SmcConn smcConn; 315 SmcConn smcConn;
@@ -319,7 +327,8 @@ smc_shutdown_cancelled_CB (smcConn, clientData)
319} 327}
320 328
321/* Error handlers for SM and ICE. We don't want to exit Emacs just 329/* Error handlers for SM and ICE. We don't want to exit Emacs just
322 because there is some error in the session management. */ 330 because there is some error in the session management. */
331
323static void 332static void
324smc_error_handler (smcConn, 333smc_error_handler (smcConn,
325 swap, 334 swap,
@@ -336,7 +345,7 @@ smc_error_handler (smcConn,
336 int severity; 345 int severity;
337 SmPointer values; 346 SmPointer values;
338{ 347{
339 /* Empty */ 348 /* Empty */
340} 349}
341 350
342static void 351static void
@@ -355,7 +364,7 @@ ice_error_handler (iceConn,
355 int severity; 364 int severity;
356 IcePointer values; 365 IcePointer values;
357{ 366{
358 /* Empty */ 367 /* Empty */
359} 368}
360 369
361 370
@@ -363,12 +372,13 @@ static void
363ice_io_error_handler (iceConn) 372ice_io_error_handler (iceConn)
364 IceConn iceConn; 373 IceConn iceConn;
365{ 374{
366 /* Connection probably gone. */ 375 /* Connection probably gone. */
367 ice_fd = -1; 376 ice_fd = -1;
368} 377}
369 378
370/* This is called when the ICE connection is created or closed. The SM library 379/* This is called when the ICE connection is created or closed. The SM library
371 uses ICE as it transport protocol. */ 380 uses ICE as it transport protocol. */
381
372static void 382static void
373ice_conn_watch_CB (iceConn, clientData, opening, watchData) 383ice_conn_watch_CB (iceConn, clientData, opening, watchData)
374 IceConn iceConn; 384 IceConn iceConn;
@@ -401,6 +411,7 @@ ice_conn_watch_CB (iceConn, clientData, opening, watchData)
401} 411}
402 412
403/* Create the client leader window. */ 413/* Create the client leader window. */
414
404static void 415static void
405create_client_leader_window (dpyinfo, client_id) 416create_client_leader_window (dpyinfo, client_id)
406 struct x_display_info *dpyinfo; 417 struct x_display_info *dpyinfo;
@@ -427,7 +438,8 @@ create_client_leader_window (dpyinfo, client_id)
427 dpyinfo->client_leader_window = w; 438 dpyinfo->client_leader_window = w;
428} 439}
429 440
430/* Try to open a connection to the session manager. */ 441/* Try to open a connection to the session manager. */
442
431void 443void
432x_session_initialize (dpyinfo) 444x_session_initialize (dpyinfo)
433 struct x_display_info *dpyinfo; 445 struct x_display_info *dpyinfo;
@@ -439,17 +451,17 @@ x_session_initialize (dpyinfo)
439 int name_len = 0; 451 int name_len = 0;
440 452
441 /* Check if we where started by the session manager. If so, we will 453 /* Check if we where started by the session manager. If so, we will
442 have a previous id. */ 454 have a previous id. */
443 if (! EQ (Vx_session_previous_id, Qnil) && STRINGP (Vx_session_previous_id)) 455 if (! EQ (Vx_session_previous_id, Qnil) && STRINGP (Vx_session_previous_id))
444 previous_id = SDATA (Vx_session_previous_id); 456 previous_id = SDATA (Vx_session_previous_id);
445 457
446 /* Construct the path to the Emacs program. */ 458 /* Construct the path to the Emacs program. */
447 if (! EQ (Vinvocation_directory, Qnil)) 459 if (! EQ (Vinvocation_directory, Qnil))
448 name_len += strlen (SDATA (Vinvocation_directory)); 460 name_len += strlen (SDATA (Vinvocation_directory));
449 name_len += strlen (SDATA (Vinvocation_name)); 461 name_len += strlen (SDATA (Vinvocation_name));
450 462
451 /* This malloc will not be freed, but it is only done once, and hopefully 463 /* This malloc will not be freed, but it is only done once, and hopefully
452 not very large */ 464 not very large */
453 emacs_program = xmalloc (name_len + 1); 465 emacs_program = xmalloc (name_len + 1);
454 emacs_program[0] = '\0'; 466 emacs_program[0] = '\0';
455 467
@@ -458,7 +470,7 @@ x_session_initialize (dpyinfo)
458 strcat (emacs_program, SDATA (Vinvocation_name)); 470 strcat (emacs_program, SDATA (Vinvocation_name));
459 471
460 /* The SM protocol says all callbacks are mandatory, so set up all 472 /* The SM protocol says all callbacks are mandatory, so set up all
461 here and in the mask passed to SmcOpenConnection */ 473 here and in the mask passed to SmcOpenConnection. */
462 callbacks.save_yourself.callback = smc_save_yourself_CB; 474 callbacks.save_yourself.callback = smc_save_yourself_CB;
463 callbacks.save_yourself.client_data = 0; 475 callbacks.save_yourself.client_data = 0;
464 callbacks.die.callback = smc_die_CB; 476 callbacks.die.callback = smc_die_CB;
@@ -468,17 +480,17 @@ x_session_initialize (dpyinfo)
468 callbacks.shutdown_cancelled.callback = smc_shutdown_cancelled_CB; 480 callbacks.shutdown_cancelled.callback = smc_shutdown_cancelled_CB;
469 callbacks.shutdown_cancelled.client_data = 0; 481 callbacks.shutdown_cancelled.client_data = 0;
470 482
471 /* Set error handlers. */ 483 /* Set error handlers. */
472 SmcSetErrorHandler (smc_error_handler); 484 SmcSetErrorHandler (smc_error_handler);
473 IceSetErrorHandler (ice_error_handler); 485 IceSetErrorHandler (ice_error_handler);
474 IceSetIOErrorHandler (ice_io_error_handler); 486 IceSetIOErrorHandler (ice_io_error_handler);
475 487
476 /* Install callback for when connection status changes. */ 488 /* Install callback for when connection status changes. */
477 IceAddConnectionWatch (ice_conn_watch_CB, 0); 489 IceAddConnectionWatch (ice_conn_watch_CB, 0);
478 490
479 /* Open the connection to the session manager. A failure is not 491 /* Open the connection to the session manager. A failure is not
480 critical, it usually means that no session manager is running. 492 critical, it usually means that no session manager is running.
481 The errorstring is here for debugging. */ 493 The errorstring is here for debugging. */
482 smc_conn = SmcOpenConnection (NULL, NULL, 1, 0, 494 smc_conn = SmcOpenConnection (NULL, NULL, 1, 0,
483 (SmcSaveYourselfProcMask| 495 (SmcSaveYourselfProcMask|
484 SmcDieProcMask| 496 SmcDieProcMask|