]> icculus.org git repositories - dana/obconf.git/blob - src/dock.c
split handlers.c into a bunch of files
[dana/obconf.git] / src / dock.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    handlers.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 void dock_setup_tab()
26 {
27     GtkWidget *posi, *dir;
28     GtkWidget *posi_l, *dir_l;
29     GtkSizeGroup *group1, *group2;
30
31     posi   = get_widget("dock_position");
32     dir    = get_widget("dock_direction");
33     group1 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
34
35     gtk_size_group_add_widget(group1, posi);
36     gtk_size_group_add_widget(group1, dir);
37
38     posi_l = get_widget("dock_position_label");
39     dir_l  = get_widget("dock_direction_label");
40     group2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
41
42     gtk_size_group_add_widget(group2, posi_l);
43     gtk_size_group_add_widget(group2, dir_l);
44 }
45
46 void dock_setup_position(GtkWidget *w)
47 {
48     gchar *s;
49     gboolean f;
50
51     mapping = TRUE;
52
53     s = tree_get_string("dock/position", "TopLeft");
54     f = FALSE;
55
56     if (!strcasecmp(s, "Top"))
57         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 1);
58     else if (!strcasecmp(s, "TopRight"))
59         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 2);
60     else if (!strcasecmp(s, "Left"))
61         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 3);
62     else if (!strcasecmp(s, "Right"))
63         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 4);
64     else if (!strcasecmp(s, "BottomLeft"))
65         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 5);
66     else if (!strcasecmp(s, "Bottom"))
67         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 6);
68     else if (!strcasecmp(s, "BottomRight"))
69         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 7);
70     else if (!strcasecmp(s, "Floating")) {
71         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 8);
72         f = TRUE;
73     } else
74         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 0);
75     g_free(s);
76
77     {
78         GtkWidget *s;
79         s = get_widget("dock_float_x");
80         gtk_widget_set_sensitive(s, f);
81         s = get_widget("dock_float_y");
82         gtk_widget_set_sensitive(s, f);
83         s = get_widget("dock_float_label");
84         gtk_widget_set_sensitive(s, f);
85         s = get_widget("dock_float_label_x");
86         gtk_widget_set_sensitive(s, f);
87     }
88
89     mapping = FALSE;
90 }
91
92 void dock_setup_float_x(GtkWidget *w)
93 {
94     mapping = TRUE;
95
96     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
97                               tree_get_int("dock/floatingX", 0));
98
99     mapping = FALSE;
100 }
101
102 void dock_setup_float_y(GtkWidget *w)
103 {
104     mapping = TRUE;
105
106     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
107                               tree_get_int("dock/floatingY", 0));
108
109     mapping = FALSE;
110 }
111
112 void dock_setup_stacking(GtkWidget *top, GtkWidget *normal, GtkWidget *bottom)
113 {
114     gchar *s;
115
116     mapping = TRUE;
117
118     s = tree_get_string("dock/stacking", "Top");
119
120     if(!strcasecmp(s, "Normal"))
121         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal), TRUE);
122     else if(!strcasecmp(s, "Bottom"))
123         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bottom), TRUE);
124     else
125         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(top), TRUE);
126     g_free(s);
127     
128     mapping = FALSE;
129 }
130
131 void dock_setup_direction(GtkWidget *w)
132 {
133     gchar *s;
134
135     mapping = TRUE;
136
137     s = tree_get_string("dock/direction", "Vertical");
138
139     if (!strcasecmp(s, "Horizontal"))
140         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 1);
141     else
142         gtk_option_menu_set_history(GTK_OPTION_MENU(w), 0);
143     g_free(s);
144
145     mapping = FALSE;
146 }
147
148 void dock_setup_hide(GtkWidget *w)
149 {
150     gboolean b;
151
152     mapping = TRUE;
153
154     b = tree_get_bool("dock/autoHide", FALSE);
155     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
156
157     {
158         GtkWidget *delay   = get_widget("dock_hide_delay");
159         GtkWidget *delay_l = get_widget("dock_hide_label");
160         GtkWidget *delay_u = get_widget("dock_hide_label_units");
161         gtk_widget_set_sensitive(delay, b);
162         gtk_widget_set_sensitive(delay_l, b);
163         gtk_widget_set_sensitive(delay_u, b);
164     }
165
166     mapping = FALSE;
167 }
168
169 void dock_setup_hide_delay(GtkWidget *w)
170 {
171     mapping = TRUE;
172
173     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
174                               tree_get_int("dock/hideDelay", 300));
175
176     mapping = FALSE;
177 }
178
179
180 void on_dock_top_left_activate(GtkMenuItem *w, gpointer data)
181 {
182     if (mapping) return;
183
184     tree_set_string("dock/position", "TopLeft");
185
186     {
187         GtkWidget *s;
188         s = get_widget("dock_float_x");
189         gtk_widget_set_sensitive(s, FALSE);
190         s = get_widget("dock_float_y");
191         gtk_widget_set_sensitive(s, FALSE);
192         s = get_widget("dock_float_label");
193         gtk_widget_set_sensitive(s, FALSE);
194         s = get_widget("dock_float_label_x");
195         gtk_widget_set_sensitive(s, FALSE);
196     }
197 }
198
199 void on_dock_top_activate(GtkMenuItem *w, gpointer data)
200 {
201     if (mapping) return;
202
203     tree_set_string("dock/position", "Top");
204
205     {
206         GtkWidget *s;
207         s = get_widget("dock_float_x");
208         gtk_widget_set_sensitive(s, FALSE);
209         s = get_widget("dock_float_y");
210         gtk_widget_set_sensitive(s, FALSE);
211         s = get_widget("dock_float_label");
212         gtk_widget_set_sensitive(s, FALSE);
213         s = get_widget("dock_float_label_x");
214         gtk_widget_set_sensitive(s, FALSE);
215     }
216 }
217
218 void on_dock_top_right_activate(GtkMenuItem *w, gpointer data)
219 {
220     if (mapping) return;
221
222     tree_set_string("dock/position", "TopRight");
223
224     {
225         GtkWidget *s;
226         s = get_widget("dock_float_x");
227         gtk_widget_set_sensitive(s, FALSE);
228         s = get_widget("dock_float_y");
229         gtk_widget_set_sensitive(s, FALSE);
230         s = get_widget("dock_float_label");
231         gtk_widget_set_sensitive(s, FALSE);
232         s = get_widget("dock_float_label_x");
233         gtk_widget_set_sensitive(s, FALSE);
234     }
235 }
236
237 void on_dock_left_activate(GtkMenuItem *w, gpointer data)
238 {
239     if (mapping) return;
240
241     tree_set_string("dock/position", "Left");
242
243     {
244         GtkWidget *s;
245         s = get_widget("dock_float_x");
246         gtk_widget_set_sensitive(s, FALSE);
247         s = get_widget("dock_float_y");
248         gtk_widget_set_sensitive(s, FALSE);
249         s = get_widget("dock_float_label");
250         gtk_widget_set_sensitive(s, FALSE);
251         s = get_widget("dock_float_label_x");
252         gtk_widget_set_sensitive(s, FALSE);
253     }
254 }
255
256 void on_dock_right_activate(GtkMenuItem *w, gpointer data)
257 {
258     if (mapping) return;
259
260     tree_set_string("dock/position", "Right");
261
262     {
263         GtkWidget *s;
264         s = get_widget("dock_float_x");
265         gtk_widget_set_sensitive(s, FALSE);
266         s = get_widget("dock_float_y");
267         gtk_widget_set_sensitive(s, FALSE);
268         s = get_widget("dock_float_label");
269         gtk_widget_set_sensitive(s, FALSE);
270         s = get_widget("dock_float_label_x");
271         gtk_widget_set_sensitive(s, FALSE);
272     }
273 }
274
275 void on_dock_bottom_left_activate(GtkMenuItem *w, gpointer data)
276 {
277     if (mapping) return;
278
279     tree_set_string("dock/position", "BottomLeft");
280
281     {
282         GtkWidget *s;
283         s = get_widget("dock_float_x");
284         gtk_widget_set_sensitive(s, FALSE);
285         s = get_widget("dock_float_y");
286         gtk_widget_set_sensitive(s, FALSE);
287         s = get_widget("dock_float_label");
288         gtk_widget_set_sensitive(s, FALSE);
289         s = get_widget("dock_float_label_x");
290         gtk_widget_set_sensitive(s, FALSE);
291     }
292 }
293
294 void on_dock_bottom_activate(GtkMenuItem *w, gpointer data)
295 {
296     if (mapping) return;
297
298     tree_set_string("dock/position", "Bottom");
299
300     {
301         GtkWidget *s;
302         s = get_widget("dock_float_x");
303         gtk_widget_set_sensitive(s, FALSE);
304         s = get_widget("dock_float_y");
305         gtk_widget_set_sensitive(s, FALSE);
306         s = get_widget("dock_float_label");
307         gtk_widget_set_sensitive(s, FALSE);
308         s = get_widget("dock_float_label_x");
309         gtk_widget_set_sensitive(s, FALSE);
310     }
311 }
312
313 void on_dock_bottom_right_activate(GtkMenuItem *w, gpointer data)
314 {
315     if (mapping) return;
316
317     tree_set_string("dock/position", "BottomRight");
318
319     {
320         GtkWidget *s;
321         s = get_widget("dock_float_x");
322         gtk_widget_set_sensitive(s, FALSE);
323         s = get_widget("dock_float_y");
324         gtk_widget_set_sensitive(s, FALSE);
325         s = get_widget("dock_float_label");
326         gtk_widget_set_sensitive(s, FALSE);
327         s = get_widget("dock_float_label_x");
328         gtk_widget_set_sensitive(s, FALSE);
329     }
330 }
331
332 void on_dock_floating_activate(GtkMenuItem *w, gpointer data)
333 {
334     if (mapping) return;
335
336     tree_set_string("dock/position", "Floating");
337
338     {
339         GtkWidget *s;
340         s = get_widget("dock_float_x");
341         gtk_widget_set_sensitive(s, TRUE);
342         s = get_widget("dock_float_y");
343         gtk_widget_set_sensitive(s, TRUE);
344         s = get_widget("dock_float_label");
345         gtk_widget_set_sensitive(s, TRUE);
346         s = get_widget("dock_float_label_x");
347         gtk_widget_set_sensitive(s, TRUE);
348     }
349 }
350
351 void on_dock_float_x_value_changed(GtkSpinButton *w, gpointer data)
352 {
353     if (mapping) return;
354
355     tree_set_int("dock/floatingX", gtk_spin_button_get_value_as_int(w));
356 }
357
358 void on_dock_float_y_value_changed(GtkSpinButton *w, gpointer data)
359 {
360     if (mapping) return;
361
362     tree_set_int("dock/floatingY", gtk_spin_button_get_value_as_int(w));
363 }
364
365 void on_dock_stacking_top_toggled(GtkToggleButton *w, gpointer data)
366 {
367     if (mapping) return;
368
369     if(gtk_toggle_button_get_active(w))
370         tree_set_string("dock/stacking", "Top");
371 }
372
373 void on_dock_stacking_normal_toggled(GtkToggleButton *w, gpointer data)
374 {
375     if (mapping) return;
376
377     if(gtk_toggle_button_get_active(w))
378         tree_set_string("dock/stacking", "Normal");
379 }
380
381 void on_dock_stacking_bottom_toggled(GtkToggleButton *w, gpointer data)
382 {
383     if (mapping) return;
384
385     if(gtk_toggle_button_get_active(w))
386         tree_set_string("dock/stacking", "Bottom");
387 }
388
389 void on_dock_horizontal_activate(GtkMenuItem *w, gpointer data)
390 {
391     if (mapping) return;
392
393     tree_set_string("dock/direction", "Horizontal");
394 }
395
396 void on_dock_vertical_activate(GtkMenuItem *w, gpointer data)
397 {
398     if (mapping) return;
399
400     tree_set_string("dock/direction", "Vertical");
401 }
402
403 void on_dock_hide_toggled(GtkToggleButton *w, gpointer data)
404 {
405     if (mapping) return;
406
407     tree_set_bool("dock/autoHide", gtk_toggle_button_get_active(w));
408     {
409         GtkWidget *delay   = glade_xml_get_widget(glade, "dock_hide_delay");
410         GtkWidget *delay_l = glade_xml_get_widget(glade, "dock_hide_label");
411         GtkWidget *delay_u = glade_xml_get_widget(glade, 
412                                                   "dock_hide_label_units");
413         gtk_widget_set_sensitive(delay, gtk_toggle_button_get_active(w));
414         gtk_widget_set_sensitive(delay_l, gtk_toggle_button_get_active(w));
415         gtk_widget_set_sensitive(delay_u, gtk_toggle_button_get_active(w));
416     }
417 }
418
419 void on_dock_hide_delay_value_changed(GtkSpinButton *w, gpointer data)
420 {
421     if (mapping) return;
422
423     tree_set_int("dock/hideDelay",
424                  gtk_spin_button_get_value_as_int(w));
425 }
426