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