aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2011-02-01 09:53:03 +0100
committerJan Djärv2011-02-01 09:53:03 +0100
commit4df0af9b7b64caadfe8ea3b0fd3ccbd0d777256d (patch)
tree63d921b47061c9056cb18dcfe42e2715dfe78a9d /src
parenta4180391acf904dde6ec72bd37b8f908f69ac3e8 (diff)
downloademacs-4df0af9b7b64caadfe8ea3b0fd3ccbd0d777256d.tar.gz
emacs-4df0af9b7b64caadfe8ea3b0fd3ccbd0d777256d.zip
Use add/delete_read_fd in xsmfns to simplify. Also restart with initial_argv.
* xsmfns.c (ice_connection_closed): Call delete_read_fd. (x_session_check_input): Change args and return type so it can be used as argument to add_read_fd. Make static. Remove call to select. Call kbd_buffer_store_event for emacs_event. (smc_save_yourself_CB): Also store initial argv to SmRestartCommand. (ice_conn_watch_CB): Call add_read_fd. * xterm.c (XTread_socket): Remove HAVE_X_SM block with call to x_session_check_input. (x_session_initialized): Remove definition. (x_initialize): Remove setting of x_session_initialized. * xterm.h (x_session_check_input): Remove declaration.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/xsmfns.c145
-rw-r--r--src/xterm.c24
-rw-r--r--src/xterm.h1
4 files changed, 79 insertions, 107 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c0c09875121..f46ea50d30c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12011-02-01 Jan Djärv <jan.h.d@swipnet.se>
2
3 * xsmfns.c (ice_connection_closed): Call delete_read_fd.
4 (x_session_check_input): Change args and return type so it can be used
5 as argument to add_read_fd. Make static. Remove call to select.
6 Call kbd_buffer_store_event for emacs_event.
7 (smc_save_yourself_CB): Also store initial argv to SmRestartCommand.
8 (ice_conn_watch_CB): Call add_read_fd.
9
10 * xterm.c (XTread_socket): Remove HAVE_X_SM block with call to
11 x_session_check_input.
12 (x_session_initialized): Remove definition.
13 (x_initialize): Remove setting of x_session_initialized.
14
15 * xterm.h (x_session_check_input): Remove declaration.
16
12011-02-01 Paul Eggert <eggert@cs.ucla.edu> 172011-02-01 Paul Eggert <eggert@cs.ucla.edu>
2 18
3 format-time-string now supports subsecond time stamp resolution 19 format-time-string now supports subsecond time stamp resolution
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 15db459e149..825cec451d9 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -38,6 +38,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
38#include "termhooks.h" 38#include "termhooks.h"
39#include "termopts.h" 39#include "termopts.h"
40#include "xterm.h" 40#include "xterm.h"
41#include "process.h"
42#include "keyboard.h"
41 43
42/* This is the event used when SAVE_SESSION_EVENT occurs. */ 44/* This is the event used when SAVE_SESSION_EVENT occurs. */
43 45
@@ -82,28 +84,20 @@ static void
82ice_connection_closed (void) 84ice_connection_closed (void)
83{ 85{
84 if (ice_fd >= 0) 86 if (ice_fd >= 0)
85 delete_keyboard_wait_descriptor (ice_fd); 87 delete_read_fd (ice_fd);
86 ice_fd = -1; 88 ice_fd = -1;
87} 89}
88 90
89 91
90/* Handle any messages from the session manager. If no connection is 92/* Handle any messages from the session manager. If no connection is
91 open to a session manager, just return 0. 93 open to a session manager, just return. */
92 Otherwise returns 1 if SAVE_SESSION_EVENT is stored in buffer BUFP. */
93 94
94int 95static void
95x_session_check_input (struct input_event *bufp) 96x_session_check_input (int fd, void *data, int for_read)
96{ 97{
97 SELECT_TYPE read_fds;
98 EMACS_TIME tmout;
99 int ret; 98 int ret;
100 99
101 if (ice_fd == -1) return 0; 100 if (ice_fd == -1) return;
102 FD_ZERO (&read_fds);
103 FD_SET (ice_fd, &read_fds);
104
105 tmout.tv_sec = 0;
106 tmout.tv_usec = 0;
107 101
108 /* Reset this so wo can check kind after callbacks have been called by 102 /* Reset this so wo can check kind after callbacks have been called by
109 IceProcessMessages. The smc_interact_CB sets the kind to 103 IceProcessMessages. The smc_interact_CB sets the kind to
@@ -111,33 +105,21 @@ x_session_check_input (struct input_event *bufp)
111 will be called. */ 105 will be called. */
112 emacs_event.kind = NO_EVENT; 106 emacs_event.kind = NO_EVENT;
113 107
114 ret = select (ice_fd+1, &read_fds, 108 ret = IceProcessMessages (SmcGetIceConnection (smc_conn),
115 (SELECT_TYPE *)0, (SELECT_TYPE *)0, &tmout); 109 (IceReplyWaitInfo *)0, (Bool *)0);
116 110 if (ret != IceProcessMessagesSuccess)
117 if (ret < 0)
118 { 111 {
112 /* Either IO error or Connection closed. */
113 if (ret == IceProcessMessagesIOError)
114 IceCloseConnection (SmcGetIceConnection (smc_conn));
115
119 ice_connection_closed (); 116 ice_connection_closed ();
120 } 117 }
121 else if (ret > 0 && FD_ISSET (ice_fd, &read_fds))
122 {
123 ret = IceProcessMessages (SmcGetIceConnection (smc_conn),
124 (IceReplyWaitInfo *)0, (Bool *)0);
125 if (ret != IceProcessMessagesSuccess)
126 {
127 /* Either IO error or Connection closed. */
128 if (ret == IceProcessMessagesIOError)
129 IceCloseConnection (SmcGetIceConnection (smc_conn));
130
131 ice_connection_closed ();
132 }
133 }
134 118
135 /* Check if smc_interact_CB was called and we shall generate a 119 /* Check if smc_interact_CB was called and we shall generate a
136 SAVE_SESSION_EVENT. */ 120 SAVE_SESSION_EVENT. */
137 if (emacs_event.kind != NO_EVENT) 121 if (emacs_event.kind != NO_EVENT)
138 memcpy (bufp, &emacs_event, sizeof (struct input_event)); 122 kbd_buffer_store_event (&emacs_event);
139
140 return emacs_event.kind != NO_EVENT ? 1 : 0;
141} 123}
142 124
143/* Return non-zero if we have a connection to a session manager. */ 125/* Return non-zero if we have a connection to a session manager. */
@@ -181,11 +163,11 @@ smc_save_yourself_CB (SmcConn smcConn,
181 SmProp *props[NR_PROPS]; 163 SmProp *props[NR_PROPS];
182 SmProp prop_ptr[NR_PROPS]; 164 SmProp prop_ptr[NR_PROPS];
183 165
184 SmPropValue values[20]; 166 SmPropValue values[20], *vp;
185 int val_idx = 0; 167 int val_idx = 0, vp_idx = 0;
186 int props_idx = 0; 168 int props_idx = 0;
187 int i; 169 int i;
188 char *cwd = NULL; 170 char *cwd = get_current_dir_name ();
189 char *smid_opt, *chdir_opt = NULL; 171 char *smid_opt, *chdir_opt = NULL;
190 172
191 /* How to start a new instance of Emacs. */ 173 /* How to start a new instance of Emacs. */
@@ -208,40 +190,6 @@ smc_save_yourself_CB (SmcConn smcConn,
208 props[props_idx]->vals[0].value = SDATA (Vinvocation_name); 190 props[props_idx]->vals[0].value = SDATA (Vinvocation_name);
209 ++props_idx; 191 ++props_idx;
210 192
211 /* How to restart Emacs. */
212 props[props_idx] = &prop_ptr[props_idx];
213 props[props_idx]->name = xstrdup (SmRestartCommand);
214 props[props_idx]->type = xstrdup (SmLISTofARRAY8);
215 /* /path/to/emacs, --smid=xxx --no-splash --chdir=dir */
216 props[props_idx]->num_vals = 4;
217 props[props_idx]->vals = &values[val_idx];
218 props[props_idx]->vals[0].length = strlen (emacs_program);
219 props[props_idx]->vals[0].value = emacs_program;
220
221 smid_opt = xmalloc (strlen (SMID_OPT) + strlen (client_id) + 1);
222 strcpy (smid_opt, SMID_OPT);
223 strcat (smid_opt, client_id);
224
225 props[props_idx]->vals[1].length = strlen (smid_opt);
226 props[props_idx]->vals[1].value = smid_opt;
227
228 props[props_idx]->vals[2].length = strlen (NOSPLASH_OPT);
229 props[props_idx]->vals[2].value = NOSPLASH_OPT;
230
231 cwd = get_current_dir_name ();
232 if (cwd)
233 {
234 chdir_opt = xmalloc (strlen (CHDIR_OPT) + strlen (cwd) + 1);
235 strcpy (chdir_opt, CHDIR_OPT);
236 strcat (chdir_opt, cwd);
237
238 props[props_idx]->vals[3].length = strlen (chdir_opt);
239 props[props_idx]->vals[3].value = chdir_opt;
240 }
241
242 val_idx += cwd ? 4 : 3;
243 ++props_idx;
244
245 /* User id. */ 193 /* User id. */
246 props[props_idx] = &prop_ptr[props_idx]; 194 props[props_idx] = &prop_ptr[props_idx];
247 props[props_idx]->name = xstrdup (SmUserID); 195 props[props_idx]->name = xstrdup (SmUserID);
@@ -266,12 +214,53 @@ smc_save_yourself_CB (SmcConn smcConn,
266 } 214 }
267 215
268 216
217 /* How to restart Emacs. */
218 props[props_idx] = &prop_ptr[props_idx];
219 props[props_idx]->name = xstrdup (SmRestartCommand);
220 props[props_idx]->type = xstrdup (SmLISTofARRAY8);
221 /* /path/to/emacs, --smid=xxx --no-splash --chdir=dir ... */
222 i = 3 + initial_argc;
223 props[props_idx]->num_vals = i;
224 vp = (SmPropValue *) xmalloc (i * sizeof(*vp));
225 props[props_idx]->vals = vp;
226 props[props_idx]->vals[vp_idx].length = strlen (emacs_program);
227 props[props_idx]->vals[vp_idx++].value = emacs_program;
228
229 smid_opt = xmalloc (strlen (SMID_OPT) + strlen (client_id) + 1);
230 strcpy (smid_opt, SMID_OPT);
231 strcat (smid_opt, client_id);
232
233 props[props_idx]->vals[vp_idx].length = strlen (smid_opt);
234 props[props_idx]->vals[vp_idx++].value = smid_opt;
235
236 props[props_idx]->vals[vp_idx].length = strlen (NOSPLASH_OPT);
237 props[props_idx]->vals[vp_idx++].value = NOSPLASH_OPT;
238
239 if (cwd)
240 {
241 chdir_opt = xmalloc (strlen (CHDIR_OPT) + strlen (cwd) + 1);
242 strcpy (chdir_opt, CHDIR_OPT);
243 strcat (chdir_opt, cwd);
244
245 props[props_idx]->vals[vp_idx].length = strlen (chdir_opt);
246 props[props_idx]->vals[vp_idx++].value = chdir_opt;
247 }
248
249 for (i = 1; i < initial_argc; ++i)
250 {
251 props[props_idx]->vals[vp_idx].length = strlen (initial_argv[i]);
252 props[props_idx]->vals[vp_idx++].value = initial_argv[i];
253 }
254
255 ++props_idx;
256
269 SmcSetProperties (smcConn, props_idx, props); 257 SmcSetProperties (smcConn, props_idx, props);
270 258
271 xfree (smid_opt); 259 xfree (smid_opt);
272 xfree (chdir_opt); 260 xfree (chdir_opt);
261 xfree (cwd);
262 xfree (vp);
273 263
274 free (cwd);
275 for (i = 0; i < props_idx; ++i) 264 for (i = 0; i < props_idx; ++i)
276 { 265 {
277 xfree (props[i]->type); 266 xfree (props[i]->type);
@@ -355,7 +344,8 @@ ice_io_error_handler (IceConn iceConn)
355 uses ICE as it transport protocol. */ 344 uses ICE as it transport protocol. */
356 345
357static void 346static void
358ice_conn_watch_CB (IceConn iceConn, IcePointer clientData, int opening, IcePointer *watchData) 347ice_conn_watch_CB (IceConn iceConn, IcePointer clientData,
348 int opening, IcePointer *watchData)
359{ 349{
360 if (! opening) 350 if (! opening)
361 { 351 {
@@ -364,16 +354,7 @@ ice_conn_watch_CB (IceConn iceConn, IcePointer clientData, int opening, IcePoint
364 } 354 }
365 355
366 ice_fd = IceConnectionNumber (iceConn); 356 ice_fd = IceConnectionNumber (iceConn);
367#ifdef F_SETOWN 357 add_read_fd (ice_fd, x_session_check_input, NULL);
368 fcntl (ice_fd, F_SETOWN, getpid ());
369#endif /* ! defined (F_SETOWN) */
370
371#ifdef SIGIO
372 if (interrupt_input)
373 init_sigio (ice_fd);
374#endif /* ! defined (SIGIO) */
375
376 add_keyboard_wait_descriptor (ice_fd);
377} 358}
378 359
379/* Create the client leader window. */ 360/* Create the client leader window. */
diff --git a/src/xterm.c b/src/xterm.c
index b6e596b854a..936a5f6b24e 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -7036,23 +7036,6 @@ XTread_socket (struct terminal *terminal, int expected, struct input_event *hold
7036 7036
7037 ++handling_signal; 7037 ++handling_signal;
7038 7038
7039#ifdef HAVE_X_SM
7040 /* Only check session manager input for the primary display. */
7041 if (terminal->id == 1 && x_session_have_connection ())
7042 {
7043 struct input_event inev;
7044 BLOCK_INPUT;
7045 /* We don't need to EVENT_INIT (inev) here, as
7046 x_session_check_input copies an entire input_event. */
7047 if (x_session_check_input (&inev))
7048 {
7049 kbd_buffer_store_event_hold (&inev, hold_quit);
7050 count++;
7051 }
7052 UNBLOCK_INPUT;
7053 }
7054#endif
7055
7056 /* For debugging, this gives a way to fake an I/O error. */ 7039 /* For debugging, this gives a way to fake an I/O error. */
7057 if (terminal->display_info.x == XTread_socket_fake_io_error) 7040 if (terminal->display_info.x == XTread_socket_fake_io_error)
7058 { 7041 {
@@ -9750,10 +9733,6 @@ static int x_timeout_atimer_activated_flag;
9750 9733
9751static int x_initialized; 9734static int x_initialized;
9752 9735
9753#ifdef HAVE_X_SM
9754static int x_session_initialized;
9755#endif
9756
9757/* Test whether two display-name strings agree up to the dot that separates 9736/* Test whether two display-name strings agree up to the dot that separates
9758 the screen number from the server number. */ 9737 the screen number from the server number. */
9759static int 9738static int
@@ -10672,9 +10651,6 @@ x_initialize (void)
10672 last_tool_bar_item = -1; 10651 last_tool_bar_item = -1;
10673 any_help_event_p = 0; 10652 any_help_event_p = 0;
10674 ignore_next_mouse_click_timeout = 0; 10653 ignore_next_mouse_click_timeout = 0;
10675#ifdef HAVE_X_SM
10676 x_session_initialized = 0;
10677#endif
10678 10654
10679#ifdef USE_GTK 10655#ifdef USE_GTK
10680 current_count = -1; 10656 current_count = -1;
diff --git a/src/xterm.h b/src/xterm.h
index 4775655a7ff..48d68557796 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1076,7 +1076,6 @@ extern void widget_store_internal_border (Widget);
1076/* Defined in xsmfns.c */ 1076/* Defined in xsmfns.c */
1077#ifdef HAVE_X_SM 1077#ifdef HAVE_X_SM
1078extern void x_session_initialize (struct x_display_info *dpyinfo); 1078extern void x_session_initialize (struct x_display_info *dpyinfo);
1079extern int x_session_check_input (struct input_event *bufp);
1080extern int x_session_have_connection (void); 1079extern int x_session_have_connection (void);
1081extern void x_session_close (void); 1080extern void x_session_close (void);
1082#endif 1081#endif