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.
22 #include <openbox/parse.h>
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 on_titlebar_doubleclick_custom_activate(GtkMenuItem *w,
35 static void enable_stuff();
37 void mouse_setup_tab()
44 w = get_widget("focus_mouse");
45 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
46 tree_get_bool("focus/followMouse", FALSE));
48 w = get_widget("focus_delay");
49 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
50 tree_get_int("focus/focusDelay", 0));
52 w = get_widget("focus_raise");
53 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
54 tree_get_bool("focus/raiseOnFocus", FALSE));
56 w = get_widget("focus_last");
57 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
58 tree_get_bool("focus/focusLast", FALSE));
60 w = get_widget("doubleclick_time");
61 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
62 tree_get_int("mouse/doubleClickTime", 200));
65 w = get_widget("titlebar_doubleclick");
66 a = read_doubleclick_action();
67 if (a == TITLEBAR_CUSTOM) {
68 GtkWidget *i = gtk_menu_item_new_with_label(_("Custom actions"));
69 g_signal_connect(i, "activate",
70 G_CALLBACK (on_titlebar_doubleclick_custom_activate),
74 (gtk_option_menu_get_menu
75 (GTK_OPTION_MENU(w))), i);
77 gtk_option_menu_set_history(GTK_OPTION_MENU(w), a);
84 static void enable_stuff()
89 w = get_widget("focus_mouse");
90 b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
92 w = get_widget("focus_delay");
93 gtk_widget_set_sensitive(w, b);
94 w = get_widget("focus_delay_label");
95 gtk_widget_set_sensitive(w, b);
96 w = get_widget("focus_delay_label_units");
97 gtk_widget_set_sensitive(w, b);
98 w = get_widget("focus_raise");
99 gtk_widget_set_sensitive(w, b);
100 w = get_widget("focus_last");
101 gtk_widget_set_sensitive(w, b);
104 void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data)
110 b = gtk_toggle_button_get_active(w);
111 tree_set_bool("focus/followMouse", b);
116 void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data)
120 tree_set_int("focus/focusDelay", gtk_spin_button_get_value_as_int(w));
123 void on_focus_raise_toggled(GtkToggleButton *w, gpointer data)
127 tree_set_bool("focus/raiseOnFocus", gtk_toggle_button_get_active(w));
130 void on_focus_last_toggled(GtkToggleButton *w, gpointer data)
134 tree_set_bool("focus/focusLast", gtk_toggle_button_get_active(w));
137 void on_titlebar_doubleclick_maximize_activate(GtkMenuItem *w, gpointer data)
141 write_doubleclick_action(TITLEBAR_MAXIMIZE);
144 void on_titlebar_doubleclick_shade_activate(GtkMenuItem *w, gpointer data)
148 write_doubleclick_action(TITLEBAR_SHADE);
151 static void on_titlebar_doubleclick_custom_activate(GtkMenuItem *w,
156 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 (parse_attr_contains("ToggleMaximizeFull", n, "name"))
198 else if (parse_attr_contains("ToggleShade", n, "name"))
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));