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