e715c33a8d61ddb816ee90049a37d5c984dcc019
[dana/obconf.git] / src / behavior.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    behavior.h for ObConf, the configuration tool for Openbox
4    Copyright (c) 2003-2007   Dana Jansens
5    Copyright (c) 2003        Tim Riley
6
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.
11
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.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "main.h"
21 #include "tree.h"
22
23 static gboolean mapping = FALSE;
24
25 static void behavior_enable_stuff();
26
27 void behavior_setup_tab()
28 {
29     GtkWidget *w, *w1, *w2;
30     GtkSizeGroup *group;
31     gchar *s;
32
33     mapping = TRUE;
34
35     w1    = get_widget("resist_window");
36     w2    = get_widget("resist_edge");
37     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
38     gtk_size_group_add_widget(group, w1);
39     gtk_size_group_add_widget(group, w2);
40
41     w1    = get_widget("resist_window_label");
42     w2    = get_widget("resist_edge_label");
43     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
44     gtk_size_group_add_widget(group, w1);
45     gtk_size_group_add_widget(group, w2);
46
47     w1    = get_widget("doubleclick_time");
48     w2    = get_widget("drag_threshold");
49     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
50     gtk_size_group_add_widget(group, w1);
51     gtk_size_group_add_widget(group, w2);
52
53     w1    = get_widget("doubleclick_time_label");
54     w2    = get_widget("drag_threshold_label");
55     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
56     gtk_size_group_add_widget(group, w1);
57     gtk_size_group_add_widget(group, w2);
58
59     w = get_widget("focus_mouse");
60     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
61                                  tree_get_bool("focus/followMouse", FALSE));
62
63     w = get_widget("focus_delay");
64     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
65                               tree_get_int("focus/focusDelay", 0));
66
67     w = get_widget("focus_raise");
68     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
69                                  tree_get_bool("focus/raiseOnFocus", FALSE));
70
71     w = get_widget("focus_last");
72     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
73                                  tree_get_bool("focus/focusLast", FALSE));
74
75     w = get_widget("focus_new");
76     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
77                                  tree_get_bool("focus/focusNew", TRUE));
78
79     w = get_widget("resize_contents");
80     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
81                                  tree_get_bool("resize/drawContents", TRUE));
82
83     w = get_widget("resist_window");
84     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
85                               tree_get_int("resistance/strength", 10));
86
87     w = get_widget("resist_edge");
88     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
89                               tree_get_int("resistance/screen_edge_strength",
90                                            20));
91
92     w = get_widget("place_mouse");
93     s = tree_get_string("placement/policy", "Smart");
94     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
95                                  !g_ascii_strcasecmp(s, "UnderMouse"));
96     g_free(s);
97
98     w = get_widget("doubleclick_time");
99     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
100                               tree_get_int("mouse/doubleClickTime", 200));
101
102     w = get_widget("drag_threshold");
103     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
104                               tree_get_int("mouse/dragThreshold", 3));
105
106     behavior_enable_stuff();
107
108     mapping = FALSE;
109 }
110
111 static void behavior_enable_stuff()
112 {
113     GtkWidget *w;
114     gboolean b;
115
116     w = get_widget("focus_mouse");
117     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
118
119     w = get_widget("focus_delay");
120     gtk_widget_set_sensitive(w, b);
121     w = get_widget("focus_delay_label");
122     gtk_widget_set_sensitive(w, b);
123     w = get_widget("focus_delay_label_units");
124     gtk_widget_set_sensitive(w, b);
125     w = get_widget("focus_raise");
126     gtk_widget_set_sensitive(w, b);
127     w = get_widget("focus_last");
128     gtk_widget_set_sensitive(w, b);
129 }
130
131 void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data)
132 {
133     gboolean b;
134
135     if (mapping) return;
136
137     b = gtk_toggle_button_get_active(w);
138     tree_set_bool("focus/followMouse", b);
139
140     behavior_enable_stuff();
141 }
142
143 void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data)
144 {
145     if (mapping) return;
146
147     tree_set_int("focus/focusDelay",
148                  gtk_spin_button_get_value_as_int(w));
149 }
150
151 void on_focus_raise_toggled(GtkToggleButton *w, gpointer data)
152 {
153     if (mapping) return;
154
155     tree_set_bool("focus/raiseOnFocus", gtk_toggle_button_get_active(w));
156 }
157
158 void on_focus_last_toggled(GtkToggleButton *w, gpointer data)
159 {
160     if (mapping) return;
161
162     tree_set_bool("focus/focusLast", gtk_toggle_button_get_active(w));
163 }
164
165 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
166 {
167     if (mapping) return;
168
169     tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
170 }
171
172 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
173 {
174     if (mapping) return;
175
176     tree_set_string("placement/policy",
177                     (gtk_toggle_button_get_active(w) ?
178                      "UnderMouse" : "Smart"));
179 }
180
181 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
182 {
183     if (mapping) return;
184
185     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
186 }
187
188 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
189 {
190     if (mapping) return;
191
192     tree_set_int("resistance/screen_edge_strength",
193                  gtk_spin_button_get_value_as_int(w));
194 }
195
196 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
197 {
198     if (mapping) return;
199
200     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
201 }
202
203 void on_doubleclick_time_value_changed(GtkSpinButton *w, gpointer data)
204 {
205     if (mapping) return;
206
207     tree_set_int("mouse/doubleClickTime",
208                  gtk_spin_button_get_value_as_int(w));
209 }
210
211 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
212 {
213     if (mapping) return;
214
215     tree_set_int("mouse/dragThreshold",
216                  gtk_spin_button_get_value_as_int(w));
217 }
218