2
* Copyright (c) 2008 Brian Tarricone <bjt23@cornell.edu>
3
* Copyright (c) 2008 Stephan Arts <stephan@xfce.org>
4
* Copyright (c) 2008 Jannis Pohlmann <jannis@xfce.org>
5
* Copyright (c) 2008 Mike Massonnet <mmassonnet@xfce.org>
6
* Copyright (c) 2008 Olivier Fourdan <olivier@xfce.org>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Library General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
#include <glade/glade.h>
30
#include <dbus/dbus-glib.h>
31
#include <libwnck/libwnck.h>
33
#include <libxfce4util/libxfce4util.h>
34
#include <libxfcegui4/libxfcegui4.h>
35
#include <xfconf/xfconf.h>
36
#include "xfwm4-workspace-dialog_glade.h"
37
#include "monitor-icon.h"
39
#define WORKSPACES_CHANNEL "xfwm4"
41
#define WORKSPACE_NAMES_PROP "/general/workspace_names"
43
static GdkNativeWindow opt_socket_id = 0;
44
static gboolean opt_version = FALSE;
55
workspace_names_update_xfconf(gint workspace,
56
const gchar *new_name)
58
WnckScreen *screen = wnck_screen_get_default();
59
XfconfChannel *channel;
61
gboolean do_update_xfconf = TRUE;
63
channel = xfconf_channel_get(WORKSPACES_CHANNEL);
64
names = xfconf_channel_get_string_list(channel, WORKSPACE_NAMES_PROP);
67
/* the property doesn't exist; let's build one from scratch */
68
gint i, n_workspaces = wnck_screen_get_workspace_count(screen);
70
names = g_new(gchar *, n_workspaces + 1);
71
for(i = 0; i < n_workspaces; ++i) {
72
if(G_LIKELY(i != workspace))
73
names[i] = g_strdup_printf(_("Workspace %d"), i + 1);
75
names[i] = g_strdup(new_name);
77
names[n_workspaces] = NULL;
79
gint i, prop_len = g_strv_length(names);
80
gint n_workspaces = wnck_screen_get_workspace_count(screen);
82
if(prop_len < n_workspaces) {
83
/* the property exists, but it's smaller than the current
84
* actual number of workspaces */
85
names = g_realloc(names, sizeof(gchar *) * (n_workspaces + 1));
86
for(i = prop_len; i < n_workspaces; ++i) {
88
names[i] = g_strdup_printf(_("Workspace %d"), i + 1);
90
names[i] = g_strdup(new_name);
92
names[n_workspaces] = NULL;
94
/* here we may have a |names| array longer than the actual
95
* number of workspaces, but that's fine. the user might
96
* want to re-add a workspace or whatever, and may appreciate
97
* that we remember the old name. */
98
if(strcmp(names[workspace], new_name)) {
99
g_free(names[workspace]);
100
names[workspace] = g_strdup(new_name);
102
/* nothing's actually changed, so don't update the xfconf
103
* property. this saves us some trouble later. */
104
do_update_xfconf = FALSE;
110
xfconf_channel_set_string_list(channel, WORKSPACE_NAMES_PROP, (const gchar **)names);
116
treeview_ws_names_cell_edited (GtkCellRendererText *cell,
117
const gchar *path_string,
118
const gchar *new_name,
121
GtkTreeView *treeview;
125
gchar *old_name = NULL;
128
treeview = (GtkTreeView *) user_data;
129
model = gtk_tree_view_get_model(treeview);
130
path = gtk_tree_path_new_from_string (path_string);
131
gtk_tree_model_get_iter (model, &iter, path);
133
gtk_tree_model_get(model, &iter, COL_NUMBER, &ws_num, COL_NAME, &old_name, -1);
134
if(strcmp(old_name, new_name)) {
135
gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_NAME, new_name, -1);
136
workspace_names_update_xfconf(ws_num - 1, new_name);
141
gtk_tree_path_free (path);
146
xfconf_workspace_names_changed(XfconfChannel *channel,
147
const gchar *property,
151
GtkTreeView *treeview = user_data;
152
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
153
WnckScreen *screen = wnck_screen_get_default();
154
gint i, n_workspaces;
159
if(G_VALUE_TYPE(value) != dbus_g_type_get_collection("GPtrArray",
162
g_warning("(workspace names) Expected boxed GPtrArray property, got %s",
163
G_VALUE_TYPE_NAME(value));
167
names = g_value_get_boxed(value);
171
wnck_screen_force_update(screen);
172
n_workspaces = wnck_screen_get_workspace_count(screen);
173
for(i = 0; i < n_workspaces && i < names->len; ++i) {
174
GValue *val = g_ptr_array_index(names, i);
175
const gchar *new_name;
177
if(!G_VALUE_HOLDS_STRING(val)) {
178
g_warning("(workspace names) Expected string but got %s for item %d",
179
G_VALUE_TYPE_NAME(val), i);
183
new_name = g_value_get_string(val);
185
path = gtk_tree_path_new_from_indices(i, -1);
186
if(gtk_tree_model_get_iter(model, &iter, path)) {
187
gchar *old_name = NULL;
189
gtk_tree_model_get(model, &iter,
192
/* only update the names that have actually changed */
193
if(strcmp(old_name, new_name)) {
194
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
200
/* must be a new workspace */
201
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
202
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
208
gtk_tree_path_free(path);
211
/* if workspaces got destroyed, we need to remove them from the treeview */
212
path = gtk_tree_path_new_from_indices(n_workspaces, -1);
213
while(gtk_tree_model_get_iter(model, &iter, path))
214
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
215
gtk_tree_path_free(path);
219
workspace_dialog_setup_names_treeview(GladeXML *gxml,
220
XfconfChannel *channel)
222
GtkWidget *treeview, *dialog;
224
GtkCellRenderer *render;
225
GtkTreeViewColumn *col;
227
gint n_workspaces, i;
231
dialog = glade_xml_get_widget(gxml, "change_name_dialog");
232
g_object_set_data(G_OBJECT(dialog), "name-entry",
233
glade_xml_get_widget(gxml, "entry_name"));
234
g_signal_connect(G_OBJECT(dialog), "delete-event",
235
G_CALLBACK(gtk_true), NULL);
237
treeview = glade_xml_get_widget(gxml, "treeview_ws_names");
239
ls = gtk_list_store_new(N_COLS, G_TYPE_INT, G_TYPE_STRING);
241
render = gtk_cell_renderer_text_new();
242
col = gtk_tree_view_column_new_with_attributes("", render,
245
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
247
render = gtk_cell_renderer_text_new();
248
g_object_set(G_OBJECT(render),
250
"ellipsize", PANGO_ELLIPSIZE_END,
251
"ellipsize-set", TRUE,
253
col = gtk_tree_view_column_new_with_attributes(_("Workspace Name"),
257
g_signal_connect (render, "edited", G_CALLBACK (treeview_ws_names_cell_edited), treeview);
259
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
261
screen = wnck_screen_get_default();
262
wnck_screen_force_update(screen);
263
names = xfconf_channel_get_string_list(channel, WORKSPACE_NAMES_PROP);
265
n_workspaces = wnck_screen_get_workspace_count(screen);
268
for(; i < n_workspaces && names[i]; ++i) {
269
gtk_list_store_append(ls, &iter);
270
gtk_list_store_set(ls, &iter,
276
for(; i < n_workspaces; ++i) {
277
WnckWorkspace *space = wnck_screen_get_workspace(screen, i);
278
const char *name = wnck_workspace_get_name(space);
280
gtk_list_store_append(ls, &iter);
281
gtk_list_store_set(ls, &iter,
288
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(ls));
290
g_signal_connect(G_OBJECT(channel),
291
"property-changed::" WORKSPACE_NAMES_PROP,
292
G_CALLBACK(xfconf_workspace_names_changed), treeview);
296
workspace_dialog_configure_widgets (GladeXML *gxml,
297
XfconfChannel *channel)
306
GtkWidget *workspace_count_spinbutton = glade_xml_get_widget (gxml, "workspace_count_spinbutton");
308
GtkWidget *margin_top_spinbutton = glade_xml_get_widget (gxml, "margin_top_spinbutton");
309
GtkWidget *margin_right_spinbutton = glade_xml_get_widget (gxml, "margin_right_spinbutton");
310
GtkWidget *margin_bottom_spinbutton = glade_xml_get_widget (gxml, "margin_bottom_spinbutton");
311
GtkWidget *margin_left_spinbutton = glade_xml_get_widget (gxml, "margin_left_spinbutton");
313
/* Set monitor icon */
314
monitor = xfce_inline_icon_at_size (monitor_icon_data, -1, -1);
315
image = glade_xml_get_widget (gxml, "monitor_icon");
316
gtk_image_set_from_pixbuf (GTK_IMAGE (image), monitor);
317
g_object_unref (monitor);
319
/* Set max margins range */
320
wmax = gdk_screen_width () / 4;
321
hmax = gdk_screen_height () / 4;
323
gtk_spin_button_set_range (GTK_SPIN_BUTTON (margin_top_spinbutton), 0, wmax);
324
gtk_spin_button_set_range (GTK_SPIN_BUTTON (margin_right_spinbutton), 0, hmax);
325
gtk_spin_button_set_range (GTK_SPIN_BUTTON (margin_bottom_spinbutton), 0, wmax);
326
gtk_spin_button_set_range (GTK_SPIN_BUTTON (margin_left_spinbutton), 0, hmax);
328
/* Bind easy properties */
329
xfconf_g_property_bind (channel,
330
"/general/workspace_count",
332
(GObject *)workspace_count_spinbutton, "value");
334
xfconf_g_property_bind (channel,
335
"/general/margin_top",
337
(GObject *)margin_top_spinbutton, "value");
338
xfconf_g_property_bind (channel,
339
"/general/margin_right",
341
(GObject *)margin_right_spinbutton, "value");
342
xfconf_g_property_bind (channel,
343
"/general/margin_bottom",
345
(GObject *)margin_bottom_spinbutton, "value");
346
xfconf_g_property_bind (channel,
347
"/general/margin_left",
349
(GObject *)margin_left_spinbutton, "value");
351
workspace_dialog_setup_names_treeview(gxml, channel);
353
vbox = glade_xml_get_widget (gxml, "main-vbox");
355
gtk_widget_show_all(vbox);
359
static GOptionEntry entries[] =
361
{ "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &opt_socket_id, N_("Settings manager socket"), N_("SOCKET ID") },
362
{ "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_version, N_("Version information"), NULL },
368
main(int argc, gchar **argv)
373
GtkWidget *plug_child;
374
XfconfChannel *channel;
375
GError *cli_error = NULL;
377
xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
379
if(!gtk_init_with_args(&argc, &argv, _("."), entries, PACKAGE, &cli_error))
381
if (cli_error != NULL)
383
g_print (_("%s: %s\nTry %s --help to see a full list of available command line options.\n"), PACKAGE, cli_error->message, PACKAGE_NAME);
384
g_error_free (cli_error);
391
g_print("%s\n", PACKAGE_STRING);
395
if(!xfconf_init (&cli_error)) {
396
g_critical ("Failed to contact xfconfd: %s", cli_error->message);
397
g_error_free (cli_error);
401
channel = xfconf_channel_get(WORKSPACES_CHANNEL);
403
gxml = glade_xml_new_from_buffer (workspace_dialog_glade,
404
workspace_dialog_glade_length,
408
workspace_dialog_configure_widgets (gxml, channel);
410
if(opt_socket_id == 0) {
411
dialog = glade_xml_get_widget (gxml, "main-dialog");
413
while(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_HELP) {
414
/* FIXME: launch help */
417
gtk_widget_destroy(dialog);
419
/* Create plug widget */
420
plug = gtk_plug_new (opt_socket_id);
421
g_signal_connect (plug, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
422
gtk_widget_show (plug);
424
/* Get plug child widget */
425
plug_child = glade_xml_get_widget (gxml, "plug-child");
426
gtk_widget_reparent (plug_child, plug);
427
gtk_widget_show (plug_child);
429
/* Stop startup notification */
430
gdk_notify_startup_complete ();
432
/* Enter main loop */