r821: Fixed some bugs in the session handling.
[rox-filer.git] / ROX-Filer / src / session.c
blob100b7640d9bf7530f3e37a7cabe7a6b85f8b056d
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2001, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* session.c - XSMP client support */
24 #include <stdio.h>
25 #include <fcntl.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <gtk/gtk.h>
29 #include <X11/SM/SMlib.h>
30 #include <pwd.h>
31 #include "global.h"
32 #include "filer.h"
33 #include "main.h"
34 #include "pinboard.h"
35 #include "panel.h"
36 #include "sc.h"
38 void save_state(SmClient *client)
40 FilerWindow *filer_window;
41 Panel *panel;
42 Pinboard *pinboard = current_pinboard;
43 GList *list;
44 GPtrArray *restart_cmd = g_ptr_array_new();
45 SmPropValue *program;
46 gchar *types[] = { "-t", "-b", "-l", "-r" };
47 gint i, nvals;
49 sc_get_prop_value(client, SmProgram, &program, &nvals);
50 g_ptr_array_add(restart_cmd, program->value);
52 g_ptr_array_add(restart_cmd, "-c");
53 g_ptr_array_add(restart_cmd, client->id);
55 for(list = all_filer_windows; list != NULL; list = g_list_next(list))
57 filer_window = (FilerWindow *)list->data;
58 gdk_window_set_role(filer_window->window->window, filer_window->path);
59 g_ptr_array_add(restart_cmd, "-d");
60 g_ptr_array_add(restart_cmd, filer_window->path);
63 for(i = 0; i < PANEL_NUMBER_OF_SIDES; i++)
65 panel = current_panel[i];
66 if(!panel)
67 continue;
68 g_ptr_array_add(restart_cmd, types[panel->side]);
69 g_ptr_array_add(restart_cmd, panel->name);
72 if(pinboard)
74 g_ptr_array_add(restart_cmd, "-p");
75 g_ptr_array_add(restart_cmd, pinboard->name);
78 sc_set_list_of_array_prop(client, SmRestartCommand,
79 (gchar **)restart_cmd->pdata, restart_cmd->len);
81 g_ptr_array_free(restart_cmd, TRUE);
84 /* Callbacks for various SM messages */
86 gboolean save_yourself(SmClient *client)
88 save_state(client);
89 return TRUE;
92 void shutdown_cancelled(SmClient *client)
96 void save_complete(SmClient *client)
100 void die(SmClient *client)
102 gtk_main_quit();
105 void session_init(gchar *client_id)
107 SmClient *client;
108 struct passwd *pw;
109 gchar *bin_path;
110 gchar *clone_cmd[2];
112 if (!sc_session_up())
113 return;
115 pw = getpwuid(euid);
116 bin_path = g_strconcat(app_dir, "/AppRun", NULL);
117 clone_cmd[0] = bin_path,
118 clone_cmd[1] = "-n";
120 client = sc_new(client_id);
122 if (!sc_connect(client))
124 sc_destroy(client);
125 return;
128 sc_set_array_prop(client, SmProgram, bin_path);
129 sc_set_array_prop(client, SmUserID, pw->pw_name);
130 sc_set_list_of_array_prop(client, SmCloneCommand, clone_cmd, 2);
131 sc_set_card_prop(client, SmRestartStyleHint, SmRestartIfRunning);
133 client->save_yourself_fn = &save_yourself;
134 client->shutdown_cancelled_fn = &shutdown_cancelled;
135 client->save_complete_fn = &save_complete;
136 client->die_fn = &die;