~ubuntu-branches/ubuntu/trusty/xfwm4/trusty

« back to all changes in this revision

Viewing changes to debian/patches/01_implement-session-handling.patch

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-04 15:17:29 UTC
  • mfrom: (1.1.26 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204151729-h9n8i0zeqr23ujtx
Tags: 4.7.2-0ubuntu1
* New upstream development release.
* Resync packaging with pkg-xfce svn: drop patch included upstream, drop
  unused overrides from debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
commit e08b248a5cec4ecf161a9a37642650ee48d3423b
2
 
Author: Nick Schermer <nick@xfce.org>
3
 
Date:   Fri Nov 26 15:33:07 2010 +0100
4
 
 
5
 
    Properly implement session handling.
6
 
    
7
 
    It turned out the session client was never properly
8
 
    hooked up in xfwm4, so a bunch of changes were needed for
9
 
    that:
10
 
    
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
14
 
      --help output.
15
 
    - Connect save-state-extended signal so Xfwm4 saves the window
16
 
      position again.
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.
21
 
    
22
 
    All in all this should restore the window positioning during login
23
 
    and fix the bunch of xfwm4 processes when saving the session.
24
 
 
25
 
diff --git a/src/Makefile.am b/src/Makefile.am
26
 
index c13a2b9..9cf486c 100644
27
 
--- a/src/Makefile.am
28
 
+++ b/src/Makefile.am
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\"
36
 
 
37
 
 xfwm4_LDADD =                                                          \
38
 
        $(GTK_LIBS)                                                     \
39
 
diff --git a/src/main.c b/src/main.c
40
 
index 15f0947..d97df06 100644
41
 
--- a/src/main.c
42
 
+++ b/src/main.c
43
 
@@ -32,6 +32,7 @@
44
 
 #include <gdk/gdkx.h>
45
 
 #include <gtk/gtk.h>
46
 
 #include <libxfce4util/libxfce4util.h>
47
 
+#include <libxfce4ui/libxfce4ui.h>
48
 
 
49
 
 #include <sys/stat.h>
50
 
 #include <sys/time.h>
51
 
@@ -91,6 +92,7 @@ static char revision[]="@(#)$ " PACKAGE " version " VERSION " revision " REVISIO
52
 
 #endif
53
 
 
54
 
 static DisplayInfo *main_display_info = NULL;
55
 
+static gint compositor = COMPOSITOR_MODE_MANUAL;
56
 
 
57
 
 static void
58
 
 cleanUp (void)
59
 
@@ -260,16 +262,6 @@ ensure_basedir_spec (void)
60
 
 }
61
 
 
62
 
 static void
63
 
-print_usage (void)
64
 
-{
65
 
-    g_print ("%s [--sm-client-id=ID] [--display=DISPLAY] "
66
 
-#ifdef HAVE_COMPOSITOR
67
 
-             "[--compositor=off|on|auto] "
68
 
-#endif
69
 
-             "[--daemon] [--replace] [--version|-V] [--help|-H]\n", PACKAGE);
70
 
-}
71
 
-
72
 
-static void
73
 
 print_version (void)
74
 
 {
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 */
78
 
 
79
 
 #ifdef HAVE_COMPOSITOR
80
 
-static gint
81
 
-parse_compositor (const gchar *s)
82
 
+static gboolean
83
 
+compositor_callback (const gchar  *name,
84
 
+                     const gchar  *value,
85
 
+                     gpointer      user_data,
86
 
+                     GError      **error)
87
 
 {
88
 
-    gchar *rvalue;
89
 
-    gint retval;
90
 
+    gboolean succeed = TRUE;
91
 
 
92
 
-    retval = COMPOSITOR_MODE_MANUAL;
93
 
-    rvalue = strrchr (s, '=');
94
 
-    if (rvalue)
95
 
+    g_return_val_if_fail (value != NULL, FALSE);
96
 
+
97
 
+    if (strcmp (value, "off") == 0)
98
 
     {
99
 
-        rvalue++;
100
 
-        if (!strcmp (rvalue, "off"))
101
 
-        {
102
 
-            retval = COMPOSITOR_MODE_OFF;
103
 
-        }
104
 
-        else if (!strcmp (rvalue, "auto"))
105
 
-        {
106
 
-            retval = COMPOSITOR_MODE_AUTO;
107
 
-        }
108
 
-        else if (!strcmp (rvalue, "on"))
109
 
-        {
110
 
-            retval = COMPOSITOR_MODE_MANUAL;
111
 
-        }
112
 
-        else
113
 
-        {
114
 
-            g_warning ("Unrecognized compositor option \"%s\"", rvalue);
115
 
-        }
116
 
+        compositor = COMPOSITOR_MODE_OFF;
117
 
+    }
118
 
+    else if (strcmp (value, "auto") == 0)
119
 
+    {
120
 
+        compositor = COMPOSITOR_MODE_AUTO;
121
 
+    }
122
 
+    else if (strcmp (value, "on") == 0)
123
 
+    {
124
 
+        compositor = COMPOSITOR_MODE_MANUAL;
125
 
+    }
126
 
+    else
127
 
+    {
128
 
+        g_set_error (error, 0, 0, "Unrecognized compositor option \"%s\"", value);
129
 
+        succeed = FALSE;
130
 
     }
131
 
 
132
 
-    return retval;
133
 
+    return succeed;
134
 
 }
135
 
 #endif /* HAVE_COMPOSITOR */
136
 
 
137
 
 static int
138
 
-initialize (int argc, char **argv, gint compositor_mode, gboolean replace_wm)
139
 
+initialize (gint compositor_mode, gboolean replace_wm)
140
 
 {
141
 
     struct sigaction act;
142
 
     long ws;
143
 
@@ -404,10 +395,6 @@ initialize (int argc, char **argv, gint compositor_mode, gboolean replace_wm)
144
 
 
145
 
     TRACE ("entering initialize");
146
 
 
147
 
-    xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
148
 
-
149
 
-    gtk_init (&argc, &argv);
150
 
-
151
 
     DBG ("xfwm4 starting, using GTK+-%d.%d.%d", gtk_major_version,
152
 
          gtk_minor_version, gtk_micro_version);
153
 
 
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);
157
 
 
158
 
-    return sessionStart (argc, argv, main_display_info);
159
 
+    return sessionStart (main_display_info);
160
 
 }
161
 
 
162
 
 int
163
 
 main (int argc, char **argv)
164
 
 {
165
 
-    gboolean daemon_mode;
166
 
-    gboolean replace_wm;
167
 
-    gint compositor;
168
 
+    gboolean daemon_mode = FALSE;
169
 
+    gboolean version = FALSE;
170
 
+    gboolean replace_wm = FALSE;
171
 
     int status;
172
 
-    int i;
173
 
+    GOptionContext *context;
174
 
+    GError *error = NULL;
175
 
+#ifndef HAVE_COMPOSITOR
176
 
+    gchar *compositor_foo = NULL;
177
 
+#endif
178
 
+    GOptionEntry option_entries[] =
179
 
+    {
180
 
+#ifdef HAVE_DAEMON
181
 
+        { "daemon", '\0', 0, G_OPTION_ARG_NONE, &daemon_mode, N_("Fork to the background"), NULL },
182
 
+#else
183
 
+        { "daemon", '\0', 0, G_OPTION_ARG_NONE, &daemon_mode, N_("Fork to the background (not supported)"), NULL },
184
 
+#endif
185
 
+#ifdef HAVE_COMPOSITOR
186
 
+        { "compositor", '\0', 0, G_OPTION_ARG_CALLBACK, compositor_callback, N_("Set the compositor mode"), "on|off|auto" },
187
 
+#else
188
 
+        { "compositor", '\0', 0, G_OPTION_ARG_STRING, &compositor_foo, N_("Set the compositor mode (not supported)"), "on|off|auto" },
189
 
+#endif
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 },
192
 
+        { NULL }
193
 
+    };
194
 
 
195
 
     DBG ("xfwm4 starting");
196
 
 
197
 
-    daemon_mode = FALSE;
198
 
-    replace_wm = FALSE;
199
 
-    compositor = -1;
200
 
-    for (i = 1; i < argc; i++)
201
 
+    xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
202
 
+
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))
208
 
     {
209
 
-        if (!strcmp (argv[i], "--daemon"))
210
 
-        {
211
 
-            daemon_mode = TRUE;
212
 
-        }
213
 
-#ifdef HAVE_COMPOSITOR
214
 
-        else if (!strncmp (argv[i], "--compositor=", strlen ("--compositor=")))
215
 
-        {
216
 
-            compositor = parse_compositor (argv[i]);
217
 
-        }
218
 
-#endif /* HAVE_COMPOSITOR */
219
 
-        else if (!strcmp (argv[i], "--replace"))
220
 
-        {
221
 
-            replace_wm = TRUE;
222
 
-        }
223
 
-        else if (!strcmp (argv[i], "--version") || !strcmp (argv[i], "-V"))
224
 
-        {
225
 
-            print_version ();
226
 
-            exit (0);
227
 
-        }
228
 
-        else if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-H"))
229
 
-        {
230
 
-            print_usage ();
231
 
-            exit (0);
232
 
-        }
233
 
+          g_print ("%s: %s.\n", PACKAGE_NAME, error->message);
234
 
+          g_print (_("Type \"%s --help\" for usage."), G_LOG_DOMAIN);
235
 
+          g_print ("\n");
236
 
+          g_error_free (error);
237
 
+
238
 
+          return EXIT_FAILURE;
239
 
+    }
240
 
+    g_option_context_free (context);
241
 
+
242
 
+    gtk_init (&argc, &argv);
243
 
+
244
 
+    if (G_UNLIKELY (version))
245
 
+    {
246
 
+         print_version ();
247
 
+         return EXIT_SUCCESS;
248
 
     }
249
 
 
250
 
-    status = initialize (argc, argv, compositor, replace_wm);
251
 
+    status = initialize (compositor, replace_wm);
252
 
     /*
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
257
 
--- a/src/session.c
258
 
+++ b/src/session.c
259
 
@@ -366,7 +366,7 @@ sessionSaveScreen (ScreenInfo *screen_info, FILE *f)
260
 
 }
261
 
 
262
 
 gboolean
263
 
-sessionSaveWindowStates (DisplayInfo *display_info, gchar * filename)
264
 
+sessionSaveWindowStates (DisplayInfo *display_info, const gchar * filename)
265
 
 {
266
 
     FILE *f;
267
 
     GSList *screens;
268
 
@@ -388,7 +388,7 @@ sessionSaveWindowStates (DisplayInfo *display_info, gchar * filename)
269
 
 }
270
 
 
271
 
 gboolean
272
 
-sessionLoadWindowStates (gchar * filename)
273
 
+sessionLoadWindowStates (const gchar * filename)
274
 
 {
275
 
     FILE *f;
276
 
     gchar s[4096], s1[4096];
277
 
@@ -705,95 +705,84 @@ sessionMatchWinToSM (Client * c)
278
 
     return FALSE;
279
 
 }
280
 
 
281
 
-static char *
282
 
-sessionBuildFilename(XfceSMClient *client_session)
283
 
-{
284
 
-    gchar *filename, *path, *file;
285
 
-    GError *error;
286
 
-
287
 
-    path = xfce_resource_save_location (XFCE_RESOURCE_CACHE, "sessions", FALSE);
288
 
-
289
 
-    error = NULL;
290
 
-    if (!xfce_mkdirhier(path, 0700, &error))
291
 
-    {
292
 
-        g_warning("Unable to create session dir %s: %s", path, error->message);
293
 
-        g_error_free (error);
294
 
-        g_free (path);
295
 
-        return NULL;
296
 
-    }
297
 
-
298
 
-    file = g_strdup_printf("xfwm4-%s", xfce_sm_client_get_client_id(client_session));
299
 
-    filename = g_build_filename (path, file, NULL);
300
 
-    g_free (file);
301
 
-    g_free (path);
302
 
-
303
 
-    return filename;
304
 
-}
305
 
-
306
 
 static void
307
 
 sessionLoad (DisplayInfo *display_info)
308
 
 {
309
 
-    XfceSMClient *session;
310
 
-    gchar *filename;
311
 
+    const gchar *filename;
312
 
 
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);
317
 
     if (filename)
318
 
     {
319
 
         sessionLoadWindowStates (filename);
320
 
-        g_free (filename);
321
 
     }
322
 
 }
323
 
 
324
 
-/*
325
 
 static void
326
 
-sessionSavePhase2 (gpointer data)
327
 
+sessionSavePhase2 (XfceSMClient *session,
328
 
+                   DisplayInfo *display_info)
329
 
 {
330
 
-    DisplayInfo *display_info;
331
 
-    XfceSMClient *session;
332
 
-    gchar *filename;
333
 
+    const gchar *filename;
334
 
+
335
 
+    g_return_if_fail (XFCE_IS_SM_CLIENT (session));
336
 
+    g_return_if_fail (session == display_info->session);
337
 
 
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);
343
 
     if (filename)
344
 
     {
345
 
         sessionSaveWindowStates (display_info, filename);
346
 
-        g_free (filename);
347
 
     }
348
 
 }
349
 
 
350
 
 static void
351
 
-sessionDie (gpointer data)
352
 
+sessionDie (XfceSMClient *session,
353
 
+            DisplayInfo *display_info)
354
 
 {
355
 
-    DisplayInfo *display_info;
356
 
+    g_return_if_fail (XFCE_IS_SM_CLIENT (session));
357
 
+    g_return_if_fail (session == display_info->session);
358
 
 
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;
362
 
+    /*
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.
366
 
+     */
367
 
+    DBG ("Session clients asked to quit");
368
 
     gtk_main_quit ();
369
 
 }
370
 
-*/
371
 
 
372
 
 int
373
 
-sessionStart (int argc, char **argv, DisplayInfo *display_info)
374
 
+sessionStart (DisplayInfo *display_info)
375
 
 {
376
 
     XfceSMClient *session;
377
 
+    GError *error = NULL;
378
 
 
379
 
-    display_info->session = xfce_sm_client_get_with_argv (argc, argv,
380
 
-                                                XFCE_SM_CLIENT_RESTART_IMMEDIATELY, 20);
381
 
-    session = display_info->session;
382
 
-    /*
383
 
-    session->data = (gpointer) display_info;
384
 
-    session->save_phase_2 = sessionSavePhase2;
385
 
-    session->die = sessionDie;
386
 
-    */
387
 
+    DBG ("Starting session client");
388
 
+
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);
392
 
 
393
 
-    if (xfce_sm_client_connect(session, NULL))
394
 
+    if (xfce_sm_client_connect(session, &error))
395
 
     {
396
 
+        display_info->session = session;
397
 
+
398
 
         sessionLoad (display_info);
399
 
+
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);
406
 
+
407
 
         return 1;
408
 
     }
409
 
+    else
410
 
+    {
411
 
+        g_warning ("Failed to connect to session manager: %s", error->message);
412
 
+        g_error_free (error);
413
 
+    }
414
 
 
415
 
     return 0;
416
 
 }
417
 
diff --git a/src/session.h b/src/session.h
418
 
index 598cdbf..7dc8ede 100644
419
 
--- a/src/session.h
420
 
+++ b/src/session.h
421
 
@@ -36,12 +36,12 @@
422
 
  *  Save window states to file which name is given in argument.
423
 
  */
424
 
 gboolean                sessionSaveWindowStates                 (DisplayInfo *,
425
 
-                                                                 gchar *);
426
 
+                                                                 const gchar *);
427
 
 
428
 
 /*
429
 
  *  Load window states to file which name is given in argument.
430
 
  */
431
 
-gboolean                sessionLoadWindowStates                 (gchar *);
432
 
+gboolean                sessionLoadWindowStates                 (const gchar *);
433
 
 
434
 
 /*
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.
439
 
  */
440
 
-int                     sessionStart                            (int,
441
 
-                                                                 char **,
442
 
-                                                                 DisplayInfo *);
443
 
+int                     sessionStart                            (DisplayInfo *);
444
 
 
445
 
 #endif /* INC_CLIENT_H */