1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 mouse.c for ObConf, the configuration tool for Openbox
4 Copyright (c) 2007 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
24 static gboolean mapping = FALSE;
25 static xmlNodePtr saved_custom = NULL;
27 #define TITLEBAR_MAXIMIZE 0
28 #define TITLEBAR_SHADE 1
29 #define TITLEBAR_CUSTOM 2
31 static gint read_doubleclick_action();
32 static void write_doubleclick_action(gint a);
33 static void enable_stuff();
35 void mouse_setup_tab()
42 w = get_widget("focus_mouse");
43 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
44 tree_get_bool("focus/followMouse", FALSE));
46 w = get_widget("focus_delay");
47 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
48 tree_get_int("focus/focusDelay", 0));
50 w = get_widget("focus_raise");
51 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
52 tree_get_bool("focus/raiseOnFocus", FALSE));
54 w = get_widget("focus_notlast");
55 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
56 !tree_get_bool("focus/focusLast", TRUE));
58 w = get_widget("focus_under_mouse");
59 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
60 tree_get_bool("focus/underMouse", FALSE));
62 w = get_widget("doubleclick_time");
63 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
64 tree_get_int("mouse/doubleClickTime", 200));
67 w = get_widget("titlebar_doubleclick");
68 a = read_doubleclick_action();
69 if (a == TITLEBAR_CUSTOM) {
70 gtk_combo_box_text_append_text
71 (GTK_COMBO_BOX_TEXT(w), _("Custom actions"));
73 gtk_combo_box_set_active(GTK_COMBO_BOX(w), a);
80 static void enable_stuff()
85 w = get_widget("focus_mouse");
86 b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
88 w = get_widget("focus_delay");
89 gtk_widget_set_sensitive(w, b);
90 w = get_widget("focus_delay_label");
91 gtk_widget_set_sensitive(w, b);
92 w = get_widget("focus_delay_label_units");
93 gtk_widget_set_sensitive(w, b);
94 w = get_widget("focus_raise");
95 gtk_widget_set_sensitive(w, b);
96 w = get_widget("focus_notlast");
97 gtk_widget_set_sensitive(w, b);
98 w = get_widget("focus_under_mouse");
99 gtk_widget_set_sensitive(w, b);
102 void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data)
108 b = gtk_toggle_button_get_active(w);
109 tree_set_bool("focus/followMouse", b);
114 void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data)
118 tree_set_int("focus/focusDelay", gtk_spin_button_get_value_as_int(w));
121 void on_focus_raise_toggled(GtkToggleButton *w, gpointer data)
125 tree_set_bool("focus/raiseOnFocus", gtk_toggle_button_get_active(w));
128 void on_focus_notlast_toggled(GtkToggleButton *w, gpointer data)
132 tree_set_bool("focus/focusLast", !gtk_toggle_button_get_active(w));
135 void on_focus_under_mouse_toggled(GtkToggleButton *w, gpointer data)
139 tree_set_bool("focus/underMouse", gtk_toggle_button_get_active(w));
142 void on_titlebar_doubleclick_changed(GtkComboBox *w, gpointer data)
146 switch (gtk_combo_box_get_active(w)) {
148 write_doubleclick_action(TITLEBAR_MAXIMIZE);
151 write_doubleclick_action(TITLEBAR_SHADE);
154 write_doubleclick_action(TITLEBAR_CUSTOM);
159 void on_doubleclick_time_value_changed(GtkSpinButton *w, gpointer data)
163 tree_set_int("mouse/doubleClickTime",
164 gtk_spin_button_get_value_as_int(w));
167 static gint read_doubleclick_action()
169 xmlNodePtr n, top, c;
170 gint max = 0, shade = 0, other = 0;
172 top = tree_get_node("mouse/context:name=Titlebar"
173 "/mousebind:button=Left:action=DoubleClick", NULL);
176 /* save the current state */
177 saved_custom = xmlCopyNode(top, 1);
179 /* remove the namespace from all the nodes under saved_custom..
180 without recursion! */
188 while (c->parent && !c->parent->next)
195 if (!xmlStrcmp(n->name, (const xmlChar*)"action")) {
196 if (obt_xml_attr_contains(n, "name", "ToggleMaximizeFull"))
198 else if (obt_xml_attr_contains(n, "name", "ToggleShade"))
207 if (max == 1 && shade == 0 && other == 0)
208 return TITLEBAR_MAXIMIZE;
209 if (max == 0 && shade == 1 && other == 0)
210 return TITLEBAR_SHADE;
212 return TITLEBAR_CUSTOM;
215 static void write_doubleclick_action(gint a)
219 n = tree_get_node("mouse/context:name=Titlebar"
220 "/mousebind:button=Left:action=DoubleClick", NULL);
222 /* remove all children */
223 while (n->children) {
224 xmlUnlinkNode(n->children);
225 xmlFreeNode(n->children);
228 if (a == TITLEBAR_MAXIMIZE) {
229 n = xmlNewChild(n, NULL, "action", NULL);
230 xmlSetProp(n, "name", "ToggleMaximizeFull");
231 } else if (a == TITLEBAR_SHADE) {
232 n = xmlNewChild(n, NULL, "action", NULL);
233 xmlSetProp(n, "name", "ToggleShade");
235 xmlNodePtr c = saved_custom->children;
237 xmlAddChild(n, xmlCopyNode(c, 1));