]> icculus.org git repositories - dana/obconf.git/blob - src/windows.c
update the year in the copyright
[dana/obconf.git] / src / windows.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    windows.c 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 #define POPUP_NONPIXEL 0
26 #define POPUP_ALWAYS   1
27 #define POPUP_NEVER    2
28
29 #define POSITION_CENTER 0
30 #define POSITION_TOP    1
31
32 #define PLACE_ON_ALL    0
33 #define PLACE_ON_ACTIVE 1
34
35 static void enable_stuff();
36
37 void windows_setup_tab()
38 {
39     GtkWidget *w, *w1, *w2, *w3;
40     GtkSizeGroup *group;
41     gchar *s;
42     gint pos, i;
43
44     mapping = TRUE;
45
46     w1    = get_widget("resist_window");
47     w2    = get_widget("resist_edge");
48     w3    = 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     gtk_size_group_add_widget(group, w3);
53
54     w1    = get_widget("resist_window_label");
55     w2    = get_widget("resist_edge_label");
56     w3    = get_widget("drag_threshold_label");
57     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
58     gtk_size_group_add_widget(group, w1);
59     gtk_size_group_add_widget(group, w2);
60     gtk_size_group_add_widget(group, w3);
61
62     w = get_widget("focus_new");
63     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
64                                  tree_get_bool("focus/focusNew", TRUE));
65
66     w = get_widget("resize_contents");
67     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
68                                  tree_get_bool("resize/drawContents", TRUE));
69
70     w = get_widget("resist_window");
71     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
72                               tree_get_int("resistance/strength", 10));
73
74     w = get_widget("resist_edge");
75     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
76                               tree_get_int("resistance/screen_edge_strength",
77                                            20));
78
79     w = get_widget("place_mouse");
80     s = tree_get_string("placement/policy", "Smart");
81     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
82                                  !g_ascii_strcasecmp(s, "UnderMouse"));
83     g_free(s);
84
85     w = get_widget("place_center");
86     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
87                                  tree_get_bool("placement/center", TRUE));
88
89     w = get_widget("place_active_popup");
90     if (tree_get_bool("placement/active", FALSE))
91         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_ACTIVE);
92     else
93         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_ALL);
94
95     w = get_widget("resize_popup");
96     s = tree_get_string("resize/popupShow", "NonPixel");
97     if (!strcasecmp(s, "Always"))     pos = POPUP_ALWAYS;
98     else if (!strcasecmp(s, "Never")) pos = POPUP_NEVER;
99     else                              pos = POPUP_NONPIXEL;
100     g_free(s);
101     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
102
103     w = get_widget("drag_threshold");
104     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
105                               tree_get_int("mouse/dragThreshold", 8));
106
107     w = get_widget("resize_position");
108     s = tree_get_string("resize/popupPosition", "Center");
109     if (!strcasecmp(s, "Top")) pos = POSITION_TOP;
110     else                       pos = POSITION_CENTER;
111     g_free(s);
112     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
113
114     i = tree_get_int("mouse/screenEdgeWarpTime", 400);
115
116     w = get_widget("warp_edge");
117     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), i != 0);
118
119     w = get_widget("warp_edge_time");
120     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), i ? i : 400);
121
122     enable_stuff();
123
124     mapping = FALSE;
125 }
126
127 static void enable_stuff()
128 {
129     GtkWidget *w;
130     gboolean b;
131
132     w = get_widget("resize_popup");
133     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) != POPUP_NEVER;
134     w = get_widget("resize_position");
135     gtk_widget_set_sensitive(w, b);
136
137     w = get_widget("place_mouse");
138     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
139     w = get_widget("place_center");
140     gtk_widget_set_sensitive(w, !b);
141
142     w = get_widget("warp_edge");
143     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
144     w = get_widget("warp_edge_time");
145     gtk_widget_set_sensitive(w, b);
146 }
147
148 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
149 {
150     if (mapping) return;
151
152     tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
153 }
154
155 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
156 {
157     if (mapping) return;
158
159     tree_set_string("placement/policy",
160                     (gtk_toggle_button_get_active(w) ?
161                      "UnderMouse" : "Smart"));
162     enable_stuff();
163 }
164
165 void on_place_center_toggled(GtkToggleButton *w, gpointer data)
166 {
167     if (mapping) return;
168
169     tree_set_bool("placement/center", gtk_toggle_button_get_active(w));
170 }
171
172 void on_place_active_popup_all_activate(GtkMenuItem *w, gpointer data)
173 {
174     if (mapping) return;
175
176     tree_set_bool("placement/active", FALSE);
177 }
178
179 void on_place_active_popup_active_activate(GtkMenuItem *w, gpointer data)
180 {
181     if (mapping) return;
182
183     tree_set_bool("placement/active", TRUE);
184 }
185
186 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
187 {
188     if (mapping) return;
189
190     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
191 }
192
193 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
194 {
195     if (mapping) return;
196
197     tree_set_int("resistance/screen_edge_strength",
198                  gtk_spin_button_get_value_as_int(w));
199 }
200
201 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
202 {
203     if (mapping) return;
204
205     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
206 }
207
208 void on_resize_popup_nonpixel_activate(GtkMenuItem *w, gpointer data)
209 {
210     if (mapping) return;
211
212     tree_set_string("resize/popupShow", "NonPixel");
213     enable_stuff();
214 }
215
216 void on_resize_popup_always_activate(GtkMenuItem *w, gpointer data)
217 {
218     if (mapping) return;
219
220     tree_set_string("resize/popupShow", "Always");
221     enable_stuff();
222 }
223
224 void on_resize_popup_never_activate(GtkMenuItem *w, gpointer data)
225 {
226     if (mapping) return;
227
228     tree_set_string("resize/popupShow", "Never");
229     enable_stuff();
230 }
231
232 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
233 {
234     if (mapping) return;
235
236     tree_set_int("mouse/dragThreshold",
237                  gtk_spin_button_get_value_as_int(w));
238 }
239
240 void on_resize_position_center_activate(GtkMenuItem *w, gpointer data)
241 {
242     if (mapping) return;
243
244     tree_set_string("resize/popupPosition", "Center");
245     enable_stuff();
246 }
247
248
249 void on_resize_position_top_activate(GtkMenuItem *w, gpointer data)
250 {
251     if (mapping) return;
252
253     tree_set_string("resize/popupPosition", "Top");
254     enable_stuff();
255 }
256
257 void on_warp_edge_toggled(GtkToggleButton *w, gpointer data)
258 {
259     if (mapping) return;
260
261     if (gtk_toggle_button_get_active(w)) {
262         GtkWidget *w2;
263
264         w2 = get_widget("warp_edge_time");
265         tree_set_int("mouse/screenEdgeWarpTime",
266                      gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w2)));
267     }
268     else
269         tree_set_int("mouse/screenEdgeWarpTime", 0);
270     enable_stuff();
271 }
272
273 void on_warp_edge_time_value_changed(GtkSpinButton *w, gpointer data)
274 {
275     if (mapping) return;
276
277     tree_set_int("mouse/screenEdgeWarpTime",
278                  gtk_spin_button_get_value_as_int(w));
279 }
280