1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 handlers.h for ObConf, the configuration tool for Openbox
4 Copyright (c) 2003-2007 Dana Jansens
5 Copyright (c) 2003 Tim Riley
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
24 #include "openbox/render.h"
30 static gboolean mapping;
32 static GtkListStore *desktop_store;
33 static int num_desktops;
34 static GList *desktop_names;
35 static GtkListStore *theme_store;
37 static void on_desktop_names_cell_edited(GtkCellRendererText *cell,
38 const gchar *path_string,
39 const gchar *new_text,
42 static void on_theme_names_selection_changed(GtkTreeSelection *sel,
46 void setup_behavior_tab()
48 GtkWidget *winresist, *edgeresist;
49 GtkWidget *winresist_l, *edgeresist_l;
50 GtkSizeGroup *group1, *group2;
52 winresist = glade_xml_get_widget(glade, "resist_window");
53 edgeresist = glade_xml_get_widget(glade, "resist_edge");
54 group1 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
56 gtk_size_group_add_widget(group1, winresist);
57 gtk_size_group_add_widget(group1, edgeresist);
59 winresist_l = glade_xml_get_widget(glade, "resist_window_label");
60 edgeresist_l = glade_xml_get_widget(glade, "resist_edge_label");
61 group2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
63 gtk_size_group_add_widget(group2, winresist_l);
64 gtk_size_group_add_widget(group2, edgeresist_l);
69 GtkWidget *posi, *dir;
70 GtkWidget *posi_l, *dir_l;
71 GtkSizeGroup *group1, *group2;
73 posi = glade_xml_get_widget(glade, "dock_position");
74 dir = glade_xml_get_widget(glade, "dock_direction");
75 group1 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
77 gtk_size_group_add_widget(group1, posi);
78 gtk_size_group_add_widget(group1, dir);
80 posi_l = glade_xml_get_widget(glade, "dock_position_label");
81 dir_l = glade_xml_get_widget(glade, "dock_direction_label");
82 group2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
84 gtk_size_group_add_widget(group2, posi_l);
85 gtk_size_group_add_widget(group2, dir_l);
90 gboolean on_main_window_delete_event(GtkWidget *w, GdkEvent *e, gpointer d)
96 void on_close_clicked()
101 void on_about_clicked()
106 parent = glade_xml_get_widget(glade, "main_window");
107 about = glade_xml_get_widget(glade, "about_window");
109 gtk_window_set_transient_for(GTK_WINDOW(about), GTK_WINDOW(parent));
110 gtk_widget_show(about);
113 void on_about_close_clicked()
117 about = glade_xml_get_widget(glade, "about_window");
119 gtk_widget_hide(about);
122 void on_about_window_delete_event()
126 about = glade_xml_get_widget(glade, "about_window");
128 gtk_widget_hide(about);
131 void setup_focus_mouse(GtkWidget *w)
137 b = tree_get_bool("focus/followMouse", FALSE);
138 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
141 GtkWidget *delay = glade_xml_get_widget(glade, "focus_delay");
142 GtkWidget *delay_l = glade_xml_get_widget(glade, "focus_delay_label");
143 GtkWidget *delay_u = glade_xml_get_widget(glade,
144 "focus_delay_label_units");
145 GtkWidget *raise = glade_xml_get_widget(glade, "focus_raise");
146 GtkWidget *last = glade_xml_get_widget(glade, "focus_last");
147 gtk_widget_set_sensitive(delay, b);
148 gtk_widget_set_sensitive(delay_l, b);
149 gtk_widget_set_sensitive(delay_u, b);
150 gtk_widget_set_sensitive(raise, b);
151 gtk_widget_set_sensitive(last, b);
157 void setup_focus_delay(GtkWidget *w)
160 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
161 tree_get_int("focus/focusDelay", 0));
165 void setup_focus_raise(GtkWidget *w)
168 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
169 tree_get_bool("focus/raiseOnFocus", FALSE));
173 void setup_focus_last(GtkWidget *w)
176 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
177 tree_get_bool("focus/focusLast", FALSE));
181 void setup_focus_new(GtkWidget *w)
184 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
185 tree_get_bool("focus/focusNew", TRUE));
189 void setup_place_mouse(GtkWidget *w)
194 s = tree_get_string("placement/policy", "Smart");
195 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
196 !g_ascii_strcasecmp(s, "UnderMouse"));
201 void setup_resist_window(GtkWidget *w)
204 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
205 tree_get_int("resistance/strength", 10));
209 void setup_resist_edge(GtkWidget *w)
212 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
213 tree_get_int("resistance/screen_edge_strength",
218 void setup_resize_contents(GtkWidget *w)
221 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
222 tree_get_bool("resize/drawContents", TRUE));
226 void setup_dock_position(GtkWidget *w)
233 s = tree_get_string("dock/position", "TopLeft");
236 if (!strcasecmp(s, "Top"))
237 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 1);
238 else if (!strcasecmp(s, "TopRight"))
239 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 2);
240 else if (!strcasecmp(s, "Left"))
241 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 3);
242 else if (!strcasecmp(s, "Right"))
243 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 4);
244 else if (!strcasecmp(s, "BottomLeft"))
245 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 5);
246 else if (!strcasecmp(s, "Bottom"))
247 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 6);
248 else if (!strcasecmp(s, "BottomRight"))
249 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 7);
250 else if (!strcasecmp(s, "Floating")) {
251 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 8);
254 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 0);
259 s = glade_xml_get_widget(glade, "dock_float_x");
260 gtk_widget_set_sensitive(s, f);
261 s = glade_xml_get_widget(glade, "dock_float_y");
262 gtk_widget_set_sensitive(s, f);
263 s = glade_xml_get_widget(glade, "dock_float_label");
264 gtk_widget_set_sensitive(s, f);
265 s = glade_xml_get_widget(glade, "dock_float_label_x");
266 gtk_widget_set_sensitive(s, f);
272 void setup_dock_float_x(GtkWidget *w)
276 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
277 tree_get_int("dock/floatingX", 0));
282 void setup_dock_float_y(GtkWidget *w)
286 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
287 tree_get_int("dock/floatingY", 0));
292 void setup_dock_stacking(GtkWidget *top, GtkWidget *normal, GtkWidget *bottom)
298 s = tree_get_string("dock/stacking", "Top");
300 if(!strcasecmp(s, "Normal"))
301 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal), TRUE);
302 else if(!strcasecmp(s, "Bottom"))
303 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bottom), TRUE);
305 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(top), TRUE);
311 void setup_dock_direction(GtkWidget *w)
317 s = tree_get_string("dock/direction", "Vertical");
319 if (!strcasecmp(s, "Horizontal"))
320 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 1);
322 gtk_option_menu_set_history(GTK_OPTION_MENU(w), 0);
328 void setup_dock_hide(GtkWidget *w)
334 b = tree_get_bool("dock/autoHide", FALSE);
335 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
338 GtkWidget *delay = glade_xml_get_widget(glade, "dock_hide_delay");
339 GtkWidget *delay_l = glade_xml_get_widget(glade, "dock_hide_label");
340 GtkWidget *delay_u = glade_xml_get_widget(glade,
341 "dock_hide_label_units");
342 gtk_widget_set_sensitive(delay, b);
343 gtk_widget_set_sensitive(delay_l, b);
344 gtk_widget_set_sensitive(delay_u, b);
350 void setup_dock_hide_delay(GtkWidget *w)
354 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
355 tree_get_int("dock/hideDelay", 300));
360 static void add_theme_dir(const gchar *dirname)
365 if ((dir = g_dir_open(dirname, 0, NULL))) {
366 while ((n = g_dir_read_name(dir))) {
369 full = g_build_filename(dirname, n, "openbox-3",
371 if (!g_file_test(full,
372 G_FILE_TEST_IS_REGULAR |
373 G_FILE_TEST_IS_SYMLINK))
379 themes = g_list_append(themes, g_strdup(n));
386 static void reset_theme_names(GtkWidget *w)
393 name = tree_get_string("theme/name", "TheBear");
395 for (it = themes; it; it = g_list_next(it))
400 p = g_build_filename(g_get_home_dir(), ".themes", NULL);
406 for (it = parse_xdg_data_dir_paths(); it; it = g_slist_next(it)) {
407 p = g_build_filename(it->data, "themes", NULL);
413 add_theme_dir(THEMEDIR);
415 themes = g_list_sort(themes, (GCompareFunc) strcasecmp);
417 gtk_list_store_clear(theme_store);
419 /* return to regular scheduled programming */
421 for (it = themes; it; it = next) {
424 next = g_list_next(it);
426 /* remove duplicates */
427 if (next && !strcmp(it->data, next->data)) {
429 themes = g_list_delete_link(themes, it);
433 gtk_list_store_append(theme_store, &iter);
434 gtk_list_store_set(theme_store, &iter,
439 if(!strcmp(name, it->data)) {
441 path = gtk_tree_path_new_from_indices(i, -1);
442 gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, NULL, FALSE);
443 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(w), path, NULL,
454 void setup_theme_names(GtkWidget *w)
456 GtkCellRenderer *render;
457 GtkTreeViewColumn *column;
458 GtkTreeSelection *select;
463 theme_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN);
464 gtk_tree_view_set_model(GTK_TREE_VIEW(w), GTK_TREE_MODEL(theme_store));
465 g_object_unref (theme_store);
467 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(w)),
468 GTK_SELECTION_SINGLE);
470 render = gtk_cell_renderer_text_new();
471 column = gtk_tree_view_column_new_with_attributes
472 ("Name", render, "text", 0, NULL);
473 gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
475 /* setup the selection handler */
476 select = gtk_tree_view_get_selection(GTK_TREE_VIEW (w));
477 gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
478 g_signal_connect (G_OBJECT(select), "changed",
479 G_CALLBACK(on_theme_names_selection_changed),
482 reset_theme_names(w);
487 void setup_title_layout(GtkWidget *w)
493 layout = tree_get_string("theme/titleLayout", "NLIMC");
494 gtk_entry_set_text(GTK_ENTRY(w), layout);
500 void setup_desktop_num(GtkWidget *w)
504 num_desktops = tree_get_int("desktops/number", 4);
505 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), num_desktops);
510 void setup_window_border(GtkWidget *w)
516 border = tree_get_bool("theme/keepBorder", TRUE);
517 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), border);
522 static void setup_font(GtkWidget *w, const gchar *place)
524 gchar *fontstring, *node;
525 gchar *name, **names;
532 node = g_strdup_printf("theme/font:place=%s/name", place);
533 name = tree_get_string(node, "Sans");
536 node = g_strdup_printf("theme/font:place=%s/size", place);
537 size = tree_get_string(node, "8");
540 node = g_strdup_printf("theme/font:place=%s/weight", place);
541 weight = tree_get_string(node, "");
544 node = g_strdup_printf("theme/font:place=%s/slant", place);
545 slant = tree_get_string(node, "");
548 /* get only the first font in the string */
549 names = g_strsplit(name, ",", 0);
551 name = g_strdup(names[0]);
554 /* don't use "normal" in the gtk string */
555 if (!g_ascii_strcasecmp(weight, "normal")) {
556 g_free(weight); weight = g_strdup("");
558 if (!g_ascii_strcasecmp(slant, "normal")) {
559 g_free(slant); slant = g_strdup("");
562 fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size);
563 gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontstring);
573 void setup_font_active(GtkWidget *w)
575 setup_font(w, "ActiveWindow");
578 void setup_font_inactive(GtkWidget *w)
580 setup_font(w, "InactiveWindow");
583 void setup_font_menu_header(GtkWidget *w)
585 setup_font(w, "MenuHeader");
588 void setup_font_menu_item(GtkWidget *w)
590 setup_font(w, "MenuItem");
593 void setup_font_display(GtkWidget *w)
595 setup_font(w, "OnScreenDisplay");
599 static void reset_desktop_names()
606 gtk_list_store_clear(desktop_store);
608 for (lit = desktop_names; lit; lit = g_list_next(lit))
610 g_list_free(desktop_names);
611 desktop_names = NULL;
614 n = tree_get_node("desktops/names", NULL)->children;
618 if (!xmlStrcmp(n->name, (const xmlChar*)"name")) {
619 name = parse_string(doc, n);
621 desktop_names = g_list_append(desktop_names, name);
623 gtk_list_store_append(desktop_store, &it);
624 gtk_list_store_set(desktop_store, &it,
625 0, (name[0] ? name : _("(Unnamed desktop)")),
634 while (i < num_desktops) {
635 gchar *name = g_strdup("");
637 desktop_names = g_list_append(desktop_names, name);
639 gtk_list_store_append(desktop_store, &it);
640 gtk_list_store_set(desktop_store, &it,
641 0, _("(Unnamed desktop)"),
648 void setup_desktop_names(GtkWidget *w)
650 GtkCellRenderer *render;
651 GtkTreeViewColumn *column;
655 desktop_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN);
656 gtk_tree_view_set_model(GTK_TREE_VIEW(w), GTK_TREE_MODEL(desktop_store));
657 g_object_unref (desktop_store);
659 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(w)),
660 GTK_SELECTION_SINGLE);
662 render = gtk_cell_renderer_text_new();
663 g_signal_connect(render, "edited",
664 G_CALLBACK (on_desktop_names_cell_edited),
667 column = gtk_tree_view_column_new_with_attributes
668 ("Name", render, "text", 0, "editable", 1, NULL);
669 gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
671 reset_desktop_names();
677 /***********************************************************************/
679 void on_window_border_toggled(GtkToggleButton *w, gpointer data)
685 b = gtk_toggle_button_get_active(w);
686 tree_set_bool("theme/keepBorder", b);
689 static void on_font_set(GtkFontButton *w, const gchar *place)
693 const gchar *size = NULL;
694 const gchar *bold = NULL;
695 const gchar *italic = NULL;
699 font = g_strdup(gtk_font_button_get_font_name(w));
700 while ((c = strrchr(font, ' '))) {
701 if (!bold && !italic && !size && atoi(c+1))
703 else if (!bold && !italic && !g_ascii_strcasecmp(c+1, "italic"))
705 else if (!bold && !g_ascii_strcasecmp(c+1, "bold"))
711 if (!bold) bold = "Normal";
712 if (!italic) italic = "Normal";
714 node = g_strdup_printf("theme/font:place=%s/name", place);
715 tree_set_string(node, font);
718 node = g_strdup_printf("theme/font:place=%s/size", place);
719 tree_set_string(node, size);
722 node = g_strdup_printf("theme/font:place=%s/weight", place);
723 tree_set_string(node, bold);
726 node = g_strdup_printf("theme/font:place=%s/slant", place);
727 tree_set_string(node, italic);
733 void on_font_active_font_set(GtkFontButton *w, gpointer data)
735 on_font_set(w, "ActiveWindow");
738 void on_font_inactive_font_set(GtkFontButton *w, gpointer data)
740 on_font_set(w, "InactiveWindow");
743 void on_font_menu_header_font_set(GtkFontButton *w, gpointer data)
745 on_font_set(w, "MenuHeader");
748 void on_font_menu_item_font_set(GtkFontButton *w, gpointer data)
750 on_font_set(w, "MenuItem");
753 void on_font_display_font_set(GtkFontButton *w, gpointer data)
755 on_font_set(w, "OnScreenDisplay");
758 void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data)
764 b = gtk_toggle_button_get_active(w);
765 tree_set_bool("focus/followMouse", b);
768 GtkWidget *delay = glade_xml_get_widget(glade, "focus_delay");
769 GtkWidget *delay_l = glade_xml_get_widget(glade, "focus_delay_label");
770 GtkWidget *delay_u = glade_xml_get_widget(glade,
771 "focus_delay_label_units");
772 GtkWidget *raise = glade_xml_get_widget(glade, "focus_raise");
773 GtkWidget *last = glade_xml_get_widget(glade, "focus_last");
774 gtk_widget_set_sensitive(delay, b);
775 gtk_widget_set_sensitive(delay_l, b);
776 gtk_widget_set_sensitive(delay_u, b);
777 gtk_widget_set_sensitive(raise, b);
778 gtk_widget_set_sensitive(last, b);
782 void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data)
786 tree_set_int("focus/focusDelay",
787 gtk_spin_button_get_value_as_int(w));
790 void on_focus_raise_toggled(GtkToggleButton *w, gpointer data)
794 tree_set_bool("focus/raiseOnFocus", gtk_toggle_button_get_active(w));
797 void on_focus_last_toggled(GtkToggleButton *w, gpointer data)
801 tree_set_bool("focus/focusLast", gtk_toggle_button_get_active(w));
804 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
808 tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
811 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
815 tree_set_string("placement/policy",
816 (gtk_toggle_button_get_active(w) ?
817 "UnderMouse" : "Smart"));
820 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
824 tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
827 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
831 tree_set_int("resistance/screen_edge_strength",
832 gtk_spin_button_get_value_as_int(w));
835 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
839 tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
842 void on_dock_top_left_activate(GtkMenuItem *w, gpointer data)
846 tree_set_string("dock/position", "TopLeft");
850 s = glade_xml_get_widget(glade, "dock_float_x");
851 gtk_widget_set_sensitive(s, FALSE);
852 s = glade_xml_get_widget(glade, "dock_float_y");
853 gtk_widget_set_sensitive(s, FALSE);
854 s = glade_xml_get_widget(glade, "dock_float_label");
855 gtk_widget_set_sensitive(s, FALSE);
856 s = glade_xml_get_widget(glade, "dock_float_label_x");
857 gtk_widget_set_sensitive(s, FALSE);
861 void on_dock_top_activate(GtkMenuItem *w, gpointer data)
865 tree_set_string("dock/position", "Top");
869 s = glade_xml_get_widget(glade, "dock_float_x");
870 gtk_widget_set_sensitive(s, FALSE);
871 s = glade_xml_get_widget(glade, "dock_float_y");
872 gtk_widget_set_sensitive(s, FALSE);
873 s = glade_xml_get_widget(glade, "dock_float_label");
874 gtk_widget_set_sensitive(s, FALSE);
875 s = glade_xml_get_widget(glade, "dock_float_label_x");
876 gtk_widget_set_sensitive(s, FALSE);
880 void on_dock_top_right_activate(GtkMenuItem *w, gpointer data)
884 tree_set_string("dock/position", "TopRight");
888 s = glade_xml_get_widget(glade, "dock_float_x");
889 gtk_widget_set_sensitive(s, FALSE);
890 s = glade_xml_get_widget(glade, "dock_float_y");
891 gtk_widget_set_sensitive(s, FALSE);
892 s = glade_xml_get_widget(glade, "dock_float_label");
893 gtk_widget_set_sensitive(s, FALSE);
894 s = glade_xml_get_widget(glade, "dock_float_label_x");
895 gtk_widget_set_sensitive(s, FALSE);
899 void on_dock_left_activate(GtkMenuItem *w, gpointer data)
903 tree_set_string("dock/position", "Left");
907 s = glade_xml_get_widget(glade, "dock_float_x");
908 gtk_widget_set_sensitive(s, FALSE);
909 s = glade_xml_get_widget(glade, "dock_float_y");
910 gtk_widget_set_sensitive(s, FALSE);
911 s = glade_xml_get_widget(glade, "dock_float_label");
912 gtk_widget_set_sensitive(s, FALSE);
913 s = glade_xml_get_widget(glade, "dock_float_label_x");
914 gtk_widget_set_sensitive(s, FALSE);
918 void on_dock_right_activate(GtkMenuItem *w, gpointer data)
922 tree_set_string("dock/position", "Right");
926 s = glade_xml_get_widget(glade, "dock_float_x");
927 gtk_widget_set_sensitive(s, FALSE);
928 s = glade_xml_get_widget(glade, "dock_float_y");
929 gtk_widget_set_sensitive(s, FALSE);
930 s = glade_xml_get_widget(glade, "dock_float_label");
931 gtk_widget_set_sensitive(s, FALSE);
932 s = glade_xml_get_widget(glade, "dock_float_label_x");
933 gtk_widget_set_sensitive(s, FALSE);
938 void on_dock_bottom_left_activate(GtkMenuItem *w, gpointer data)
942 tree_set_string("dock/position", "BottomLeft");
946 s = glade_xml_get_widget(glade, "dock_float_x");
947 gtk_widget_set_sensitive(s, FALSE);
948 s = glade_xml_get_widget(glade, "dock_float_y");
949 gtk_widget_set_sensitive(s, FALSE);
950 s = glade_xml_get_widget(glade, "dock_float_label");
951 gtk_widget_set_sensitive(s, FALSE);
952 s = glade_xml_get_widget(glade, "dock_float_label_x");
953 gtk_widget_set_sensitive(s, FALSE);
957 void on_dock_bottom_activate(GtkMenuItem *w, gpointer data)
961 tree_set_string("dock/position", "Bottom");
965 s = glade_xml_get_widget(glade, "dock_float_x");
966 gtk_widget_set_sensitive(s, FALSE);
967 s = glade_xml_get_widget(glade, "dock_float_y");
968 gtk_widget_set_sensitive(s, FALSE);
969 s = glade_xml_get_widget(glade, "dock_float_label");
970 gtk_widget_set_sensitive(s, FALSE);
971 s = glade_xml_get_widget(glade, "dock_float_label_x");
972 gtk_widget_set_sensitive(s, FALSE);
976 void on_dock_bottom_right_activate(GtkMenuItem *w, gpointer data)
980 tree_set_string("dock/position", "BottomRight");
984 s = glade_xml_get_widget(glade, "dock_float_x");
985 gtk_widget_set_sensitive(s, FALSE);
986 s = glade_xml_get_widget(glade, "dock_float_y");
987 gtk_widget_set_sensitive(s, FALSE);
988 s = glade_xml_get_widget(glade, "dock_float_label");
989 gtk_widget_set_sensitive(s, FALSE);
990 s = glade_xml_get_widget(glade, "dock_float_label_x");
991 gtk_widget_set_sensitive(s, FALSE);
995 void on_dock_floating_activate(GtkMenuItem *w, gpointer data)
999 tree_set_string("dock/position", "Floating");
1003 s = glade_xml_get_widget(glade, "dock_float_x");
1004 gtk_widget_set_sensitive(s, TRUE);
1005 s = glade_xml_get_widget(glade, "dock_float_y");
1006 gtk_widget_set_sensitive(s, TRUE);
1007 s = glade_xml_get_widget(glade, "dock_float_label");
1008 gtk_widget_set_sensitive(s, TRUE);
1009 s = glade_xml_get_widget(glade, "dock_float_label_x");
1010 gtk_widget_set_sensitive(s, TRUE);
1014 void on_dock_float_x_value_changed(GtkSpinButton *w, gpointer data)
1016 if (mapping) return;
1018 tree_set_int("dock/floatingX", gtk_spin_button_get_value_as_int(w));
1021 void on_dock_float_y_value_changed(GtkSpinButton *w, gpointer data)
1023 if (mapping) return;
1025 tree_set_int("dock/floatingY", gtk_spin_button_get_value_as_int(w));
1028 void on_dock_stacking_top_toggled(GtkToggleButton *w, gpointer data)
1030 if (mapping) return;
1032 if(gtk_toggle_button_get_active(w))
1033 tree_set_string("dock/stacking", "Top");
1036 void on_dock_stacking_normal_toggled(GtkToggleButton *w, gpointer data)
1038 if (mapping) return;
1040 if(gtk_toggle_button_get_active(w))
1041 tree_set_string("dock/stacking", "Normal");
1044 void on_dock_stacking_bottom_toggled(GtkToggleButton *w, gpointer data)
1046 if (mapping) return;
1048 if(gtk_toggle_button_get_active(w))
1049 tree_set_string("dock/stacking", "Bottom");
1052 void on_dock_horizontal_activate(GtkMenuItem *w, gpointer data)
1054 if (mapping) return;
1056 tree_set_string("dock/direction", "Horizontal");
1059 void on_dock_vertical_activate(GtkMenuItem *w, gpointer data)
1061 if (mapping) return;
1063 tree_set_string("dock/direction", "Vertical");
1066 void on_dock_hide_toggled(GtkToggleButton *w, gpointer data)
1068 if (mapping) return;
1070 tree_set_bool("dock/autoHide", gtk_toggle_button_get_active(w));
1072 GtkWidget *delay = glade_xml_get_widget(glade, "dock_hide_delay");
1073 GtkWidget *delay_l = glade_xml_get_widget(glade, "dock_hide_label");
1074 GtkWidget *delay_u = glade_xml_get_widget(glade,
1075 "dock_hide_label_units");
1076 gtk_widget_set_sensitive(delay, gtk_toggle_button_get_active(w));
1077 gtk_widget_set_sensitive(delay_l, gtk_toggle_button_get_active(w));
1078 gtk_widget_set_sensitive(delay_u, gtk_toggle_button_get_active(w));
1082 void on_dock_hide_delay_value_changed(GtkSpinButton *w, gpointer data)
1084 if (mapping) return;
1086 tree_set_int("dock/hideDelay",
1087 gtk_spin_button_get_value_as_int(w));
1090 void on_theme_name_changed(GtkOptionMenu *w, gpointer data)
1094 if (mapping) return;
1096 name = g_list_nth_data(themes, gtk_option_menu_get_history(w));
1099 tree_set_string("theme/name", name);
1102 void on_theme_names_selection_changed(GtkTreeSelection *sel, gpointer data)
1105 GtkTreeModel *model;
1108 if (mapping) return;
1110 if(gtk_tree_selection_get_selected(sel, &model, &iter)) {
1111 gtk_tree_model_get(model, &iter, 0, &name, -1);
1115 tree_set_string("theme/name", name);
1118 void on_title_layout_changed(GtkEntry *w, gpointer data)
1122 gboolean n, d, s, l, i, m, c;
1124 if (mapping) return;
1126 layout = g_strdup(gtk_entry_get_text(w));
1128 n = d = s = l = i = m = c = FALSE;
1130 for (it = layout; *it; ++it) {
1168 /* drop the letter */
1169 for (it2 = it; *it2; ++it2)
1177 gtk_entry_set_text(w, layout);
1178 tree_set_string("theme/titleLayout", layout);
1182 static void set_desktop_names()
1187 gint num = 0, last = -1;
1189 n = tree_get_node("desktops/names", NULL);
1190 while ((c = n->children)) {
1195 for (lit = desktop_names; lit; lit = g_list_next(lit)) {
1196 if (((gchar*)lit->data)[0]) /* not empty */
1202 for (lit = desktop_names; lit && num <= last; lit = g_list_next(lit)) {
1203 xmlNewTextChild(n, NULL, "name", lit->data);
1208 /* make openbox re-set the property */
1209 XDeleteProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1210 XInternAtom(GDK_DISPLAY(), "_NET_DESKTOP_NAMES", FALSE));
1213 static void set_desktop_number()
1217 tree_set_int("desktops/number", num_desktops);
1219 ce.xclient.type = ClientMessage;
1220 ce.xclient.message_type = XInternAtom(GDK_DISPLAY(),
1221 "_NET_NUMBER_OF_DESKTOPS",
1223 ce.xclient.display = GDK_DISPLAY();
1224 ce.xclient.window = GDK_ROOT_WINDOW();
1225 ce.xclient.format = 32;
1226 ce.xclient.data.l[0] = num_desktops;
1227 ce.xclient.data.l[1] = 0;
1228 ce.xclient.data.l[2] = 0;
1229 ce.xclient.data.l[3] = 0;
1230 ce.xclient.data.l[4] = 0;
1231 XSendEvent(GDK_DISPLAY(), GDK_ROOT_WINDOW(), FALSE,
1232 SubstructureNotifyMask | SubstructureRedirectMask,
1236 void on_desktop_num_value_changed(GtkSpinButton *w, gpointer data)
1238 if (mapping) return;
1240 num_desktops = gtk_spin_button_get_value(w);
1242 set_desktop_number();
1244 reset_desktop_names();
1247 static void on_desktop_names_cell_edited(GtkCellRendererText *cell,
1248 const gchar *path_string,
1249 const gchar *new_text,
1258 if (mapping) return;
1260 path = gtk_tree_path_new_from_string (path_string);
1261 gtk_tree_model_get_iter(GTK_TREE_MODEL(desktop_store), &it, path);
1263 gtk_tree_model_get(GTK_TREE_MODEL(desktop_store), &it, 0, &old_text, -1);
1266 i = gtk_tree_path_get_indices(path)[0];
1267 lit = g_list_nth(desktop_names, i);
1270 lit->data = g_strdup(new_text);
1271 if (new_text[0]) /* not empty */
1272 gtk_list_store_set(desktop_store, &it, 0, lit->data, -1);
1274 gtk_list_store_set(desktop_store, &it, 0, _("(Unnamed desktop)"), -1);
1276 set_desktop_names();
1279 void on_install_theme_clicked(GtkButton *w, gpointer data)
1284 GtkFileFilter *filter;
1286 d = gtk_file_chooser_dialog_new(_("Choose an Openbox theme"),
1287 GTK_WINDOW(mainwin),
1288 GTK_FILE_CHOOSER_ACTION_OPEN,
1289 GTK_STOCK_OK, GTK_RESPONSE_OK,
1290 GTK_STOCK_CANCEL, GTK_RESPONSE_NONE,
1293 gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(d), FALSE);
1294 filter = gtk_file_filter_new();
1295 gtk_file_filter_set_name(filter, _("Openbox theme archives"));
1296 gtk_file_filter_add_pattern(filter, "*.obt");
1297 //gtk_file_filter_add_pattern(filter, "*.tgz");
1298 //gtk_file_filter_add_pattern(filter, "*.tar.gz");
1299 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(d), filter);
1301 r = gtk_dialog_run(GTK_DIALOG(d));
1302 if (r == GTK_RESPONSE_OK)
1303 path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
1304 gtk_widget_destroy(d);
1307 handlers_install_theme(path);
1312 void on_theme_archive_clicked(GtkButton *w, gpointer data)
1318 d = gtk_file_chooser_dialog_new(_("Choose an Openbox theme"),
1319 GTK_WINDOW(mainwin),
1320 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1321 GTK_STOCK_OK, GTK_RESPONSE_OK,
1322 GTK_STOCK_CANCEL, GTK_RESPONSE_NONE,
1325 gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(d), FALSE);
1326 r = gtk_dialog_run(GTK_DIALOG(d));
1327 if (r == GTK_RESPONSE_OK)
1328 path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
1329 gtk_widget_destroy(d);
1332 theme_archive(path);
1337 void handlers_install_theme(gchar *path)
1341 if ((name = theme_install(path))) {
1347 w = glade_xml_get_widget(glade, "theme_names");
1349 reset_theme_names(w);
1352 /* go to the newly installed theme */
1353 for (it = themes, i = 0; it; it = g_list_next(it), ++i)
1354 if (!strcmp(it->data, name)) break;
1356 path = gtk_tree_path_new_from_indices(i, -1);
1357 gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, NULL, FALSE);
1358 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(w), path, NULL,