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));
64 w = get_widget("titlebar_doubleclick");
65 a = read_doubleclick_action();
66 if (a == TITLEBAR_CUSTOM) {
67 GtkWidget *i = gtk_menu_item_new_with_label(_("Custom actions"));
68 g_signal_connect(i, "activate",
69 G_CALLBACK (on_titlebar_doubleclick_custom_activate),
73 (gtk_option_menu_get_menu
74 (GTK_OPTION_MENU(w))), i);
76 gtk_option_menu_set_history(GTK_OPTION_MENU(w), a);
83 static void enable_stuff()
88 w = get_widget("focus_mouse");
89 b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
91 w = get_widget("focus_delay");
92 gtk_widget_set_sensitive(w, b);
93 w = get_widget("focus_delay_label");
94 gtk_widget_set_sensitive(w, b);
95 w = get_widget("focus_delay_label_units");
96 gtk_widget_set_sensitive(w, b);
97 w = get_widget("focus_raise");
98 gtk_widget_set_sensitive(w, b);
99 w = get_widget("focus_last");
100 gtk_widget_set_sensitive(w, b);
103 void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data)
109 b = gtk_toggle_button_get_active(w);
110 tree_set_bool("focus/followMouse", b);
115 void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data)
119 tree_set_int("focus/focusDelay", gtk_spin_button_get_value_as_int(w));
122 void on_focus_raise_toggled(GtkToggleButton *w, gpointer data)
126 tree_set_bool("focus/raiseOnFocus", gtk_toggle_button_get_active(w));
129 void on_focus_last_toggled(GtkToggleButton *w, gpointer data)
133 tree_set_bool("focus/focusLast", gtk_toggle_button_get_active(w));
136 void on_titlebar_doubleclick_maximize_activate(GtkMenuItem *w, gpointer data)
140 write_doubleclick_action(TITLEBAR_MAXIMIZE);
143 void on_titlebar_doubleclick_shade_activate(GtkMenuItem *w, gpointer data)
147 write_doubleclick_action(TITLEBAR_SHADE);
150 static void on_titlebar_doubleclick_custom_activate(GtkMenuItem *w,
155 write_doubleclick_action(TITLEBAR_CUSTOM);
158 void on_doubleclick_time_value_changed(GtkSpinButton *w, gpointer data)
162 tree_set_int("mouse/doubleClickTime",
163 gtk_spin_button_get_value_as_int(w));
166 static gint read_doubleclick_action()
168 xmlNodePtr n, top, c;
169 gint max = 0, shade = 0, other = 0;
171 top = tree_get_node("mouse/context:name=Titlebar"
172 "/mousebind:button=Left:action=DoubleClick", NULL);
175 /* save the current state */
176 saved_custom = xmlCopyNode(top, 1);
178 /* remove the namespace from all the nodes under saved_custom..
179 without recursion! */
187 while (c->parent && !c->parent->next)
194 if (!xmlStrcmp(n->name, (const xmlChar*)"action")) {
195 if (parse_attr_contains("ToggleMaximizeFull", n, "name"))
197 else if (parse_attr_contains("ToggleShade", n, "name"))
206 if (max == 1 && shade == 0 && other == 0)
207 return TITLEBAR_MAXIMIZE;
208 if (max == 0 && shade == 1 && other == 0)
209 return TITLEBAR_SHADE;
211 return TITLEBAR_CUSTOM;
214 static void write_doubleclick_action(gint a)
218 n = tree_get_node("mouse/context:name=Titlebar"
219 "/mousebind:button=Left:action=DoubleClick", NULL);
221 /* remove all children */
222 while (n->children) {
223 xmlUnlinkNode(n->children);
224 xmlFreeNode(n->children);
227 if (a == TITLEBAR_MAXIMIZE) {
228 n = xmlNewChild(n, NULL, "action", NULL);
229 xmlSetProp(n, "name", "ToggleMaximizeFull");
230 } else if (a == TITLEBAR_SHADE) {
231 n = xmlNewChild(n, NULL, "action", NULL);
232 xmlSetProp(n, "name", "ToggleShade");
234 xmlNodePtr c = saved_custom->children;
236 xmlAddChild(n, xmlCopyNode(c, 1));