]> icculus.org git repositories - dana/obconf.git/blob - src/moveresize.c
Stop using libglade
[dana/obconf.git] / src / moveresize.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-2008   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 #define POSITION_FIXED  2
32
33 #define EDGE_CENTER 0
34 #define EDGE_LEFT   1
35 #define EDGE_RIGHT  2
36
37 static void enable_stuff();
38 static void write_fixed_position(const gchar *coord);
39
40 void moveresize_setup_tab()
41 {
42     GtkWidget *w, *w1, *w2, *w3;
43     GtkSizeGroup *group;
44     gchar *s;
45     gint pos, i;
46     gboolean opp;
47
48     mapping = TRUE;
49
50     w1    = get_widget("resist_window");
51     w2    = get_widget("resist_edge");
52     w3    = get_widget("drag_threshold");
53     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
54     gtk_size_group_add_widget(group, w1);
55     gtk_size_group_add_widget(group, w2);
56     gtk_size_group_add_widget(group, w3);
57
58     w1    = get_widget("resist_window_label");
59     w2    = get_widget("resist_edge_label");
60     w3    = get_widget("drag_threshold_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     gtk_size_group_add_widget(group, w3);
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("resize_popup");
80     s = tree_get_string("resize/popupShow", "NonPixel");
81     if (!strcasecmp(s, "Always"))     pos = POPUP_ALWAYS;
82     else if (!strcasecmp(s, "Never")) pos = POPUP_NEVER;
83     else                              pos = POPUP_NONPIXEL;
84     g_free(s);
85     gtk_combo_box_set_active(GTK_COMBO_BOX(w), pos);
86
87     w = get_widget("drag_threshold");
88     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
89                               tree_get_int("mouse/dragThreshold", 8));
90
91     w = get_widget("resize_position");
92     s = tree_get_string("resize/popupPosition", "Center");
93     if (!strcasecmp(s, "Top"))   pos = POSITION_TOP;
94     if (!strcasecmp(s, "Fixed")) pos = POSITION_FIXED;
95     else                         pos = POSITION_CENTER;
96     g_free(s);
97     gtk_combo_box_set_active(GTK_COMBO_BOX(w), pos);
98
99     w = get_widget("fixed_x_popup");
100     s = tree_get_string("resize/popupFixedPosition/x", "0");
101     opp = s[0] == '-';
102     if (s[0] == '-' || s[0] == '+') ++s;
103     if (!strcasecmp(s, "Center")) pos = EDGE_CENTER;
104     else if (opp) pos = EDGE_RIGHT;
105     else pos = EDGE_LEFT;
106     gtk_combo_box_set_active(GTK_COMBO_BOX(w), pos);
107
108     w = get_widget("fixed_x_pos");
109     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), MAX(atoi(s), 0));
110     g_free(s);
111
112     w = get_widget("fixed_y_popup");
113     s = tree_get_string("resize/popupFixedPosition/y", "0");
114     opp = s[0] == '-';
115     if (!strcasecmp(s, "Center")) pos = EDGE_CENTER;
116     else if (opp) pos = EDGE_RIGHT;
117     else pos = EDGE_LEFT;
118     gtk_combo_box_set_active(GTK_COMBO_BOX(w), pos);
119
120     w = get_widget("fixed_y_pos");
121     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), MAX(atoi(s), 0));
122     g_free(s);
123
124     i = tree_get_int("mouse/screenEdgeWarpTime", 400);
125
126     w = get_widget("warp_edge");
127     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), i != 0);
128
129     w = get_widget("warp_edge_time");
130     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), i ? i : 400);
131
132     enable_stuff();
133
134     mapping = FALSE;
135 }
136
137 static void enable_stuff()
138 {
139     GtkWidget *w;
140     gboolean b;
141
142     w = get_widget("resize_popup");
143     b = gtk_combo_box_get_active(GTK_COMBO_BOX(w)) != POPUP_NEVER;
144     w = get_widget("resize_position");
145     gtk_widget_set_sensitive(w, b);
146
147     w = get_widget("warp_edge");
148     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
149     w = get_widget("warp_edge_time");
150     gtk_widget_set_sensitive(w, b);
151
152     w = get_widget("resize_position");
153     b = gtk_combo_box_get_active(GTK_COMBO_BOX(w)) == POSITION_FIXED;
154     w = get_widget("fixed_x_popup");
155     gtk_widget_set_sensitive(w, b);
156     w = get_widget("fixed_y_popup");
157     gtk_widget_set_sensitive(w, b);
158     if (!b) {
159         w = get_widget("fixed_x_pos");
160         gtk_widget_set_sensitive(w, FALSE);
161         w = get_widget("fixed_y_pos");
162         gtk_widget_set_sensitive(w, FALSE);
163     }
164     else {
165         w = get_widget("fixed_x_popup");
166         b = gtk_combo_box_get_active(GTK_COMBO_BOX(w)) != EDGE_CENTER;
167         w = get_widget("fixed_x_pos");
168         gtk_widget_set_sensitive(w, b);
169
170         w = get_widget("fixed_y_popup");
171         b = gtk_combo_box_get_active(GTK_COMBO_BOX(w)) != EDGE_CENTER;
172         w = get_widget("fixed_y_pos");
173         gtk_widget_set_sensitive(w, b);
174     }
175 }
176
177 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
178 {
179     if (mapping) return;
180
181     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
182 }
183
184 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
185 {
186     if (mapping) return;
187
188     tree_set_int("resistance/screen_edge_strength",
189                  gtk_spin_button_get_value_as_int(w));
190 }
191
192 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
193 {
194     if (mapping) return;
195
196     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
197 }
198
199 void on_resize_popup_changed(GtkComboBox *w, gpointer data)
200 {
201     if (mapping) return;
202
203     switch(gtk_combo_box_get_active(w)) {
204     case 0:
205       tree_set_string("resize/popupShow", "NonPixel");
206       break;
207     case 1:
208       tree_set_string("resize/popupShow", "Always");
209       break;
210     case 2:
211       tree_set_string("resize/popupShow", "Never");
212       break;
213     }
214     enable_stuff();
215 }
216
217 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
218 {
219     if (mapping) return;
220
221     tree_set_int("mouse/dragThreshold",
222                  gtk_spin_button_get_value_as_int(w));
223 }
224
225 void on_resize_position_changed(GtkComboBox *w, gpointer data)
226 {
227     if (mapping) return;
228
229     switch(gtk_combo_box_get_active(w)) {
230     case 0:
231       tree_set_string("resize/popupPosition", "Center");
232       break;
233     case 1:
234       tree_set_string("resize/popupPosition", "Top");
235       break;
236     case 2:
237       tree_set_string("resize/popupPosition", "Fixed");
238       break;
239     }
240     enable_stuff();
241 }
242
243 static void write_fixed_position(const gchar *coord)
244 {
245     GtkWidget *popup;
246     gchar *popupname;
247     gchar *val;
248     gchar *valname;
249     gint edge;
250
251     g_assert(!strcmp(coord, "x") || !strcmp(coord, "y"));
252
253     popupname = g_strdup_printf("fixed_%s_popup", coord);
254     popup = get_widget(popupname);
255     g_free(popupname);
256
257     edge = gtk_combo_box_get_active(GTK_COMBO_BOX(popup));
258     g_assert(edge == EDGE_CENTER || edge == EDGE_LEFT || edge == EDGE_RIGHT);
259
260     if (edge == EDGE_CENTER)
261         val = g_strdup("center");
262     else {
263         GtkWidget *spin;
264         gchar *spinname;
265         gint i;
266
267         spinname = g_strdup_printf("fixed_%s_pos", coord);
268         spin = get_widget(spinname);
269         g_free(spinname);
270
271         i = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
272
273         if (edge == EDGE_LEFT)
274             val = g_strdup_printf("%d", i);
275         else
276             val = g_strdup_printf("-%d", i);
277     }
278
279     valname = g_strdup_printf("resize/popupFixedPosition/%s", coord);
280     tree_set_string(valname, val);
281     g_free(valname);
282     g_free(val);
283 }
284
285
286 void on_fixed_x_position_changed(GtkComboBox *w, gpointer data)
287 {
288     if (mapping) return;
289
290     write_fixed_position("x");
291     enable_stuff();
292 }
293
294 void on_fixed_y_position_changed(GtkComboBox *w, gpointer data)
295 {
296     if (mapping) return;
297
298     write_fixed_position("y");
299     enable_stuff();
300 }
301
302 void on_fixed_x_pos_value_changed(GtkSpinButton *w, gpointer data)
303 {
304     if (mapping) return;
305
306     write_fixed_position("x");
307 }
308
309 void on_fixed_y_pos_value_changed(GtkSpinButton *w, gpointer data)
310 {
311     if (mapping) return;
312
313     write_fixed_position("y");
314 }
315
316 void on_warp_edge_toggled(GtkToggleButton *w, gpointer data)
317 {
318     if (mapping) return;
319
320     if (gtk_toggle_button_get_active(w)) {
321         GtkWidget *w2;
322
323         w2 = get_widget("warp_edge_time");
324         tree_set_int("mouse/screenEdgeWarpTime",
325                      gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w2)));
326     }
327     else
328         tree_set_int("mouse/screenEdgeWarpTime", 0);
329     enable_stuff();
330 }
331
332 void on_warp_edge_time_value_changed(GtkSpinButton *w, gpointer data)
333 {
334     if (mapping) return;
335
336     tree_set_int("mouse/screenEdgeWarpTime",
337                  gtk_spin_button_get_value_as_int(w));
338 }
339