1
commit e08b248a5cec4ecf161a9a37642650ee48d3423b
2
Author: Nick Schermer <nick@xfce.org>
3
Date: Fri Nov 26 15:33:07 2010 +0100
5
Properly implement session handling.
7
It turned out the session client was never properly
8
hooked up in xfwm4, so a bunch of changes were needed for
11
- Use GOptionContext, so we can use xfce_sm_client_get_option_group
12
for properly initializing the session options. Also added the
13
other options that were manually parsed by Xfwm4 for a nice
15
- Connect save-state-extended signal so Xfwm4 saves the window
17
- Use xfce_sm_client_get_state_file for the state file location,
18
basically the same as the Xfwm4 implementation.
19
- Do no change the restart style during quit.
20
- Change priority to XFCE_SM_CLIENT_PRIORITY_WM.
22
All in all this should restore the window positioning during login
23
and fix the bunch of xfwm4 processes when saving the session.
25
diff --git a/src/Makefile.am b/src/Makefile.am
26
index c13a2b9..9cf486c 100644
29
@@ -93,7 +93,8 @@ xfwm4_CFLAGS = \
30
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
31
-DDATADIR=\"$(datadir)\" \
32
-DLIBDIR=\"$(libdir)\" \
33
- -DPACKAGE_DATADIR=\"$(pkgdatadir)\"
34
+ -DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
35
+ -DG_LOG_DOMAIN=\"xfwm4\"
39
diff --git a/src/main.c b/src/main.c
40
index 15f0947..d97df06 100644
46
#include <libxfce4util/libxfce4util.h>
47
+#include <libxfce4ui/libxfce4ui.h>
51
@@ -91,6 +92,7 @@ static char revision[]="@(#)$ " PACKAGE " version " VERSION " revision " REVISIO
54
static DisplayInfo *main_display_info = NULL;
55
+static gint compositor = COMPOSITOR_MODE_MANUAL;
59
@@ -260,16 +262,6 @@ ensure_basedir_spec (void)
65
- g_print ("%s [--sm-client-id=ID] [--display=DISPLAY] "
66
-#ifdef HAVE_COMPOSITOR
67
- "[--compositor=off|on|auto] "
69
- "[--daemon] [--replace] [--version|-V] [--help|-H]\n", PACKAGE);
75
g_print ("\tThis is %s version %s (revision %s) for Xfce %s\n",
76
@@ -362,41 +354,40 @@ get_default_compositor (DisplayInfo *display_info)
77
#endif /* HAVE_COMPOSITOR */
79
#ifdef HAVE_COMPOSITOR
81
-parse_compositor (const gchar *s)
83
+compositor_callback (const gchar *name,
90
+ gboolean succeed = TRUE;
92
- retval = COMPOSITOR_MODE_MANUAL;
93
- rvalue = strrchr (s, '=');
95
+ g_return_val_if_fail (value != NULL, FALSE);
97
+ if (strcmp (value, "off") == 0)
100
- if (!strcmp (rvalue, "off"))
102
- retval = COMPOSITOR_MODE_OFF;
104
- else if (!strcmp (rvalue, "auto"))
106
- retval = COMPOSITOR_MODE_AUTO;
108
- else if (!strcmp (rvalue, "on"))
110
- retval = COMPOSITOR_MODE_MANUAL;
114
- g_warning ("Unrecognized compositor option \"%s\"", rvalue);
116
+ compositor = COMPOSITOR_MODE_OFF;
118
+ else if (strcmp (value, "auto") == 0)
120
+ compositor = COMPOSITOR_MODE_AUTO;
122
+ else if (strcmp (value, "on") == 0)
124
+ compositor = COMPOSITOR_MODE_MANUAL;
128
+ g_set_error (error, 0, 0, "Unrecognized compositor option \"%s\"", value);
135
#endif /* HAVE_COMPOSITOR */
138
-initialize (int argc, char **argv, gint compositor_mode, gboolean replace_wm)
139
+initialize (gint compositor_mode, gboolean replace_wm)
141
struct sigaction act;
143
@@ -404,10 +395,6 @@ initialize (int argc, char **argv, gint compositor_mode, gboolean replace_wm)
145
TRACE ("entering initialize");
147
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
149
- gtk_init (&argc, &argv);
151
DBG ("xfwm4 starting, using GTK+-%d.%d.%d", gtk_major_version,
152
gtk_minor_version, gtk_micro_version);
154
@@ -526,52 +513,66 @@ initialize (int argc, char **argv, gint compositor_mode, gboolean replace_wm)
155
main_display_info->xfilter = eventFilterInit ((gpointer) main_display_info);
156
eventFilterPush (main_display_info->xfilter, xfwm4_event_filter, (gpointer) main_display_info);
158
- return sessionStart (argc, argv, main_display_info);
159
+ return sessionStart (main_display_info);
163
main (int argc, char **argv)
165
- gboolean daemon_mode;
166
- gboolean replace_wm;
168
+ gboolean daemon_mode = FALSE;
169
+ gboolean version = FALSE;
170
+ gboolean replace_wm = FALSE;
173
+ GOptionContext *context;
174
+ GError *error = NULL;
175
+#ifndef HAVE_COMPOSITOR
176
+ gchar *compositor_foo = NULL;
178
+ GOptionEntry option_entries[] =
181
+ { "daemon", '\0', 0, G_OPTION_ARG_NONE, &daemon_mode, N_("Fork to the background"), NULL },
183
+ { "daemon", '\0', 0, G_OPTION_ARG_NONE, &daemon_mode, N_("Fork to the background (not supported)"), NULL },
185
+#ifdef HAVE_COMPOSITOR
186
+ { "compositor", '\0', 0, G_OPTION_ARG_CALLBACK, compositor_callback, N_("Set the compositor mode"), "on|off|auto" },
188
+ { "compositor", '\0', 0, G_OPTION_ARG_STRING, &compositor_foo, N_("Set the compositor mode (not supported)"), "on|off|auto" },
190
+ { "replace", '\0', 0, G_OPTION_ARG_NONE, &replace_wm, N_("Replace the existing window manager"), NULL },
191
+ { "version", 'V', 0, G_OPTION_ARG_NONE, &version, N_("Print version information and exit"), NULL },
195
DBG ("xfwm4 starting");
197
- daemon_mode = FALSE;
198
- replace_wm = FALSE;
200
- for (i = 1; i < argc; i++)
201
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
203
+ context = g_option_context_new (_("[ARGUMENTS...]"));
204
+ g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE);
205
+ g_option_context_add_group (context, gtk_get_option_group (FALSE));
206
+ g_option_context_add_group (context, xfce_sm_client_get_option_group (argc, argv));
207
+ if (!g_option_context_parse (context, &argc, &argv, &error))
209
- if (!strcmp (argv[i], "--daemon"))
211
- daemon_mode = TRUE;
213
-#ifdef HAVE_COMPOSITOR
214
- else if (!strncmp (argv[i], "--compositor=", strlen ("--compositor=")))
216
- compositor = parse_compositor (argv[i]);
218
-#endif /* HAVE_COMPOSITOR */
219
- else if (!strcmp (argv[i], "--replace"))
223
- else if (!strcmp (argv[i], "--version") || !strcmp (argv[i], "-V"))
228
- else if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-H"))
233
+ g_print ("%s: %s.\n", PACKAGE_NAME, error->message);
234
+ g_print (_("Type \"%s --help\" for usage."), G_LOG_DOMAIN);
236
+ g_error_free (error);
238
+ return EXIT_FAILURE;
240
+ g_option_context_free (context);
242
+ gtk_init (&argc, &argv);
244
+ if (G_UNLIKELY (version))
247
+ return EXIT_SUCCESS;
250
- status = initialize (argc, argv, compositor, replace_wm);
251
+ status = initialize (compositor, replace_wm);
253
status < 0 => Error, cancel execution
254
status == 0 => Run w/out session manager
255
diff --git a/src/session.c b/src/session.c
256
index 41a2719..257f89f 100644
259
@@ -366,7 +366,7 @@ sessionSaveScreen (ScreenInfo *screen_info, FILE *f)
263
-sessionSaveWindowStates (DisplayInfo *display_info, gchar * filename)
264
+sessionSaveWindowStates (DisplayInfo *display_info, const gchar * filename)
268
@@ -388,7 +388,7 @@ sessionSaveWindowStates (DisplayInfo *display_info, gchar * filename)
272
-sessionLoadWindowStates (gchar * filename)
273
+sessionLoadWindowStates (const gchar * filename)
276
gchar s[4096], s1[4096];
277
@@ -705,95 +705,84 @@ sessionMatchWinToSM (Client * c)
282
-sessionBuildFilename(XfceSMClient *client_session)
284
- gchar *filename, *path, *file;
287
- path = xfce_resource_save_location (XFCE_RESOURCE_CACHE, "sessions", FALSE);
290
- if (!xfce_mkdirhier(path, 0700, &error))
292
- g_warning("Unable to create session dir %s: %s", path, error->message);
293
- g_error_free (error);
298
- file = g_strdup_printf("xfwm4-%s", xfce_sm_client_get_client_id(client_session));
299
- filename = g_build_filename (path, file, NULL);
307
sessionLoad (DisplayInfo *display_info)
309
- XfceSMClient *session;
311
+ const gchar *filename;
313
- session = display_info->session;
314
- filename = sessionBuildFilename(session);
315
+ filename = xfce_sm_client_get_state_file (display_info->session);
316
+ DBG ("Restoring session from \"%s\"", filename);
319
sessionLoadWindowStates (filename);
326
-sessionSavePhase2 (gpointer data)
327
+sessionSavePhase2 (XfceSMClient *session,
328
+ DisplayInfo *display_info)
330
- DisplayInfo *display_info;
331
- XfceSMClient *session;
333
+ const gchar *filename;
335
+ g_return_if_fail (XFCE_IS_SM_CLIENT (session));
336
+ g_return_if_fail (session == display_info->session);
338
- display_info = (DisplayInfo *) data;
339
- session = display_info->session;
340
- filename = sessionBuildFilename(session);
341
+ filename = xfce_sm_client_get_state_file (display_info->session);
342
+ DBG ("Saving session to \"%s\"", filename);
345
sessionSaveWindowStates (display_info, filename);
351
-sessionDie (gpointer data)
352
+sessionDie (XfceSMClient *session,
353
+ DisplayInfo *display_info)
355
- DisplayInfo *display_info;
356
+ g_return_if_fail (XFCE_IS_SM_CLIENT (session));
357
+ g_return_if_fail (session == display_info->session);
359
- display_info = (DisplayInfo *) data;
360
- xfce_sm_client_set_restart_style(display_info->session, XFCE_SM_CLIENT_RESTART_NORMAL);
361
- display_info->quit = TRUE;
363
+ * Do not change the session restart style to NORMAL here, else
364
+ * xfwm4 will never be restarted the next time we login. just
365
+ * gracefully quit the application.
367
+ DBG ("Session clients asked to quit");
373
-sessionStart (int argc, char **argv, DisplayInfo *display_info)
374
+sessionStart (DisplayInfo *display_info)
376
XfceSMClient *session;
377
+ GError *error = NULL;
379
- display_info->session = xfce_sm_client_get_with_argv (argc, argv,
380
- XFCE_SM_CLIENT_RESTART_IMMEDIATELY, 20);
381
- session = display_info->session;
383
- session->data = (gpointer) display_info;
384
- session->save_phase_2 = sessionSavePhase2;
385
- session->die = sessionDie;
387
+ DBG ("Starting session client");
389
+ session = xfce_sm_client_get ();
390
+ xfce_sm_client_set_restart_style (session, XFCE_SM_CLIENT_RESTART_IMMEDIATELY);
391
+ xfce_sm_client_set_priority (session, XFCE_SM_CLIENT_PRIORITY_WM);
393
- if (xfce_sm_client_connect(session, NULL))
394
+ if (xfce_sm_client_connect(session, &error))
396
+ display_info->session = session;
398
sessionLoad (display_info);
400
+ /* save-state-extended is special for window managers to store
401
+ * the window positions of all the clients */
402
+ g_signal_connect (G_OBJECT (session), "save-state-extended",
403
+ G_CALLBACK (sessionSavePhase2), display_info);
404
+ g_signal_connect (G_OBJECT (session), "quit",
405
+ G_CALLBACK (sessionDie), display_info);
411
+ g_warning ("Failed to connect to session manager: %s", error->message);
412
+ g_error_free (error);
417
diff --git a/src/session.h b/src/session.h
418
index 598cdbf..7dc8ede 100644
422
* Save window states to file which name is given in argument.
424
gboolean sessionSaveWindowStates (DisplayInfo *,
429
* Load window states to file which name is given in argument.
431
-gboolean sessionLoadWindowStates (gchar *);
432
+gboolean sessionLoadWindowStates (const gchar *);
435
* Free allocated structure. Should be called before xfwm4 dies
436
@@ -58,8 +58,6 @@ gboolean sessionMatchWinToSM (Client *);
437
* Initiate session, connect to session manager and
438
* load saved states if the connection succeeds.
440
-int sessionStart (int,
443
+int sessionStart (DisplayInfo *);
445
#endif /* INC_CLIENT_H */