r898: Applied Bernard Jungen's latest patch:
[rox-filer.git] / ROX-Filer / src / session.c
blob5b0908c2e64bae4d2afa868986e813f3c923b9e6
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,
59 filer_window->path);
60 g_ptr_array_add(restart_cmd, "-d");
61 g_ptr_array_add(restart_cmd, filer_window->path);
64 for(i = 0; i < PANEL_NUMBER_OF_SIDES; i++)
66 panel = current_panel[i];
67 if(!panel)
68 continue;
69 g_ptr_array_add(restart_cmd, types[panel->side]);
70 g_ptr_array_add(restart_cmd, panel->name);
73 if(pinboard)
75 g_ptr_array_add(restart_cmd, "-p");
76 g_ptr_array_add(restart_cmd, pinboard->name);
79 sc_set_list_of_array_prop(client, SmRestartCommand,
80 (gchar **)restart_cmd->pdata, restart_cmd->len);
82 g_ptr_array_free(restart_cmd, TRUE);
85 /* Callbacks for various SM messages */
87 gboolean save_yourself(SmClient *client)
89 save_state(client);
90 return TRUE;
93 void die(SmClient *client)
95 gtk_main_quit();
98 void session_init(gchar *client_id)
100 SmClient *client;
101 struct passwd *pw;
102 gchar *bin_path;
103 gchar *clone_cmd[2];
105 if (!sc_session_up())
106 return;
108 pw = getpwuid(euid);
109 bin_path = g_strconcat(app_dir, "/AppRun", NULL);
110 clone_cmd[0] = bin_path,
111 clone_cmd[1] = "-n";
113 client = sc_new(client_id);
115 if (!sc_connect(client))
117 sc_destroy(client);
118 return;
121 sc_set_array_prop(client, SmProgram, bin_path);
122 sc_set_array_prop(client, SmUserID, pw->pw_name);
123 sc_set_list_of_array_prop(client, SmCloneCommand, clone_cmd, 2);
124 sc_set_card_prop(client, SmRestartStyleHint, SmRestartIfRunning);
126 client->save_yourself_fn = &save_yourself;
127 client->shutdown_cancelled_fn = NULL;
128 client->save_complete_fn = NULL;
129 client->die_fn = &die;