comments
[dana/obconf.git] / src / dock.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    dock.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 POSITION_TOPLEFT     0
26 #define POSITION_TOP         1
27 #define POSITION_TOPRIGHT    2
28 #define POSITION_LEFT        3
29 #define POSITION_RIGHT       4
30 #define POSITION_BOTTOMLEFT  5
31 #define POSITION_BOTTOM      6
32 #define POSITION_BOTTOMRIGHT 7
33 #define POSITION_FLOATING    8
34
35 #define DIRECTION_VERTICAL   0
36 #define DIRECTION_HORIZONTAL 1
37
38 static void dock_enable_stuff();
39
40 void dock_setup_tab()
41 {
42     GtkWidget *w, *w1, *w2;
43     GtkSizeGroup *group;
44     gchar *s;
45     gint pos;
46
47     mapping = TRUE;
48
49     w1    = get_widget("dock_position");
50     w2    = get_widget("dock_direction");
51     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
52     gtk_size_group_add_widget(group, w1);
53     gtk_size_group_add_widget(group, w2);
54
55     w1    = get_widget("dock_position_label");
56     w2    = get_widget("dock_direction_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
61     w1    = get_widget("dock_hide_label");
62     w2    = get_widget("dock_show_label");
63     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
64     gtk_size_group_add_widget(group, w1);
65     gtk_size_group_add_widget(group, w2);
66
67     w1    = get_widget("dock_hide_delay");
68     w2    = get_widget("dock_show_delay");
69     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
70     gtk_size_group_add_widget(group, w1);
71     gtk_size_group_add_widget(group, w2);
72
73     w = get_widget("dock_position");
74     s = tree_get_string("dock/position", "TopLeft");
75     if (!strcasecmp(s, "Top"))              pos = POSITION_TOP;
76     else if (!strcasecmp(s, "TopRight"))    pos = POSITION_TOPRIGHT;
77     else if (!strcasecmp(s, "Left"))        pos = POSITION_LEFT;
78     else if (!strcasecmp(s, "Right"))       pos = POSITION_RIGHT;
79     else if (!strcasecmp(s, "BottomLeft"))  pos = POSITION_BOTTOMLEFT;
80     else if (!strcasecmp(s, "Bottom"))      pos = POSITION_BOTTOM;
81     else if (!strcasecmp(s, "BottomRight")) pos = POSITION_BOTTOMRIGHT;
82     else if (!strcasecmp(s, "Floating"))    pos = POSITION_FLOATING;
83     else                                    pos = POSITION_TOPLEFT;
84     g_free(s);
85     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
86
87     w = get_widget("dock_float_x");
88     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
89                               tree_get_int("dock/floatingX", 0));
90
91     w = get_widget("dock_float_y");
92     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
93                               tree_get_int("dock/floatingY", 0));
94
95     s = tree_get_string("dock/stacking", "Above");
96     if(!strcasecmp(s, "Normal"))
97         w = get_widget("dock_stack_normal");
98     else if(!strcasecmp(s, "Below"))
99         w = get_widget("dock_stack_bottom");
100     else
101         w = get_widget("dock_stack_top");
102     g_free(s);
103     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE);
104
105     w = get_widget("dock_direction");
106     s = tree_get_string("dock/direction", "Vertical");
107     if (!strcasecmp(s, "Horizontal")) pos = DIRECTION_HORIZONTAL;
108     else                              pos = DIRECTION_VERTICAL;
109     g_free(s);
110     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
111
112     w = get_widget("dock_nostrut");
113     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
114                                  tree_get_bool("dock/noStrut", FALSE));
115
116     w = get_widget("dock_hide");
117     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
118                                  tree_get_bool("dock/autoHide", FALSE));
119
120     w = get_widget("dock_hide_delay");
121     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
122                               tree_get_int("dock/hideDelay", 300));
123
124     w = get_widget("dock_show_delay");
125     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
126                               tree_get_int("dock/showDelay", 300));
127
128     dock_enable_stuff();
129
130     mapping = FALSE;
131 }
132
133 static void dock_enable_stuff()
134 {
135     GtkWidget *w, *s;
136     gboolean b;
137
138     w = get_widget("dock_position");
139     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) == POSITION_FLOATING;
140
141     s = get_widget("dock_float_x");
142     gtk_widget_set_sensitive(s, b);
143     s = get_widget("dock_float_y");
144     gtk_widget_set_sensitive(s, b);
145     s = get_widget("dock_float_label");
146     gtk_widget_set_sensitive(s, b);
147     s = get_widget("dock_float_label_x");
148     gtk_widget_set_sensitive(s, b);
149     s = get_widget("dock_nostrut");
150     gtk_widget_set_sensitive(s, !b);
151
152     w = get_widget("dock_hide");
153     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
154
155     s = get_widget("dock_hide_delay");
156     gtk_widget_set_sensitive(s, b);
157     s = get_widget("dock_hide_label");
158     gtk_widget_set_sensitive(s, b);
159     s = get_widget("dock_hide_label_units");
160     gtk_widget_set_sensitive(s, b);
161     s = get_widget("dock_show_delay");
162     gtk_widget_set_sensitive(s, b);
163     s = get_widget("dock_show_label");
164     gtk_widget_set_sensitive(s, b);
165     s = get_widget("dock_show_label_units");
166     gtk_widget_set_sensitive(s, b);
167 }
168
169 void on_dock_top_left_activate(GtkMenuItem *w, gpointer data)
170 {
171     if (mapping) return;
172
173     tree_set_string("dock/position", "TopLeft");
174     dock_enable_stuff();
175 }
176
177 void on_dock_top_activate(GtkMenuItem *w, gpointer data)
178 {
179     if (mapping) return;
180
181     tree_set_string("dock/position", "Top");
182     dock_enable_stuff();
183 }
184
185 void on_dock_top_right_activate(GtkMenuItem *w, gpointer data)
186 {
187     if (mapping) return;
188
189     tree_set_string("dock/position", "TopRight");
190     dock_enable_stuff();
191 }
192
193 void on_dock_left_activate(GtkMenuItem *w, gpointer data)
194 {
195     if (mapping) return;
196
197     tree_set_string("dock/position", "Left");
198     dock_enable_stuff();
199 }
200
201 void on_dock_right_activate(GtkMenuItem *w, gpointer data)
202 {
203     if (mapping) return;
204
205     tree_set_string("dock/position", "Right");
206     dock_enable_stuff();
207 }
208
209 void on_dock_bottom_left_activate(GtkMenuItem *w, gpointer data)
210 {
211     if (mapping) return;
212
213     tree_set_string("dock/position", "BottomLeft");
214     dock_enable_stuff();
215 }
216
217 void on_dock_bottom_activate(GtkMenuItem *w, gpointer data)
218 {
219     if (mapping) return;
220
221     tree_set_string("dock/position", "Bottom");
222     dock_enable_stuff();
223 }
224
225 void on_dock_bottom_right_activate(GtkMenuItem *w, gpointer data)
226 {
227     if (mapping) return;
228
229     tree_set_string("dock/position", "BottomRight");
230     dock_enable_stuff();
231 }
232
233 void on_dock_floating_activate(GtkMenuItem *w, gpointer data)
234 {
235     if (mapping) return;
236
237     tree_set_string("dock/position", "Floating");
238     dock_enable_stuff();
239 }
240
241 void on_dock_float_x_value_changed(GtkSpinButton *w, gpointer data)
242 {
243     if (mapping) return;
244
245     tree_set_int("dock/floatingX", gtk_spin_button_get_value_as_int(w));
246 }
247
248 void on_dock_float_y_value_changed(GtkSpinButton *w, gpointer data)
249 {
250     if (mapping) return;
251
252     tree_set_int("dock/floatingY", gtk_spin_button_get_value_as_int(w));
253 }
254
255 void on_dock_stacking_top_toggled(GtkToggleButton *w, gpointer data)
256 {
257     if (mapping) return;
258
259     if(gtk_toggle_button_get_active(w))
260         tree_set_string("dock/stacking", "Above");
261 }
262
263 void on_dock_stacking_normal_toggled(GtkToggleButton *w, gpointer data)
264 {
265     if (mapping) return;
266
267     if(gtk_toggle_button_get_active(w))
268         tree_set_string("dock/stacking", "Normal");
269 }
270
271 void on_dock_stacking_bottom_toggled(GtkToggleButton *w, gpointer data)
272 {
273     if (mapping) return;
274
275     if(gtk_toggle_button_get_active(w))
276         tree_set_string("dock/stacking", "Below");
277 }
278
279 void on_dock_horizontal_activate(GtkMenuItem *w, gpointer data)
280 {
281     if (mapping) return;
282
283     tree_set_string("dock/direction", "Horizontal");
284 }
285
286 void on_dock_vertical_activate(GtkMenuItem *w, gpointer data)
287 {
288     if (mapping) return;
289
290     tree_set_string("dock/direction", "Vertical");
291 }
292
293 void on_dock_nostrut_toggled(GtkToggleButton *w, gpointer data)
294 {
295     if (mapping) return;
296
297     tree_set_bool("dock/noStrut", gtk_toggle_button_get_active(w));
298 }
299
300 void on_dock_hide_toggled(GtkToggleButton *w, gpointer data)
301 {
302     if (mapping) return;
303
304     tree_set_bool("dock/autoHide", gtk_toggle_button_get_active(w));
305     dock_enable_stuff();
306 }
307
308 void on_dock_hide_delay_value_changed(GtkSpinButton *w, gpointer data)
309 {
310     if (mapping) return;
311
312     tree_set_int("dock/hideDelay",
313                  gtk_spin_button_get_value_as_int(w));
314 }
315
316 void on_dock_show_delay_value_changed(GtkSpinButton *w, gpointer data)
317 {
318     if (mapping) return;
319
320     tree_set_int("dock/showDelay",
321                  gtk_spin_button_get_value_as_int(w));
322 }
323