]> icculus.org git repositories - dana/obconf.git/blob - src/moveresize.c
Load the rc.xml config file given on --config-file the same as Openbox (use the whole...
[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_option_menu_set_history(GTK_OPTION_MENU(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_option_menu_set_history(GTK_OPTION_MENU(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     g_free(s);
107     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
108
109     w = get_widget("fixed_x_pos");
110     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), MAX(atoi(s), 0));
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     g_free(s);
119     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
120
121     w = get_widget("fixed_y_pos");
122     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), MAX(atoi(s), 0));
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_option_menu_get_history(GTK_OPTION_MENU(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_option_menu_get_history(GTK_OPTION_MENU(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_option_menu_get_history(GTK_OPTION_MENU(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_option_menu_get_history(GTK_OPTION_MENU(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_nonpixel_activate(GtkMenuItem *w, gpointer data)
200 {
201     if (mapping) return;
202
203     tree_set_string("resize/popupShow", "NonPixel");
204     enable_stuff();
205 }
206
207 void on_resize_popup_always_activate(GtkMenuItem *w, gpointer data)
208 {
209     if (mapping) return;
210
211     tree_set_string("resize/popupShow", "Always");
212     enable_stuff();
213 }
214
215 void on_resize_popup_never_activate(GtkMenuItem *w, gpointer data)
216 {
217     if (mapping) return;
218
219     tree_set_string("resize/popupShow", "Never");
220     enable_stuff();
221 }
222
223 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
224 {
225     if (mapping) return;
226
227     tree_set_int("mouse/dragThreshold",
228                  gtk_spin_button_get_value_as_int(w));
229 }
230
231 void on_resize_position_center_activate(GtkMenuItem *w, gpointer data)
232 {
233     if (mapping) return;
234
235     tree_set_string("resize/popupPosition", "Center");
236     enable_stuff();
237 }
238
239 void on_resize_position_top_activate(GtkMenuItem *w, gpointer data)
240 {
241     if (mapping) return;
242
243     tree_set_string("resize/popupPosition", "Top");
244     enable_stuff();
245 }
246
247 void on_resize_position_fixed_activate(GtkMenuItem *w, gpointer data)
248 {
249     if (mapping) return;
250
251     tree_set_string("resize/popupPosition", "Fixed");
252     enable_stuff();
253 }
254
255 static void write_fixed_position(const gchar *coord)
256 {
257     GtkWidget *popup;
258     gchar *popupname;
259     gchar *val;
260     gchar *valname;
261     gint edge;
262
263     g_assert(!strcmp(coord, "x") || !strcmp(coord, "y"));
264
265     popupname = g_strdup_printf("fixed_%s_popup", coord);
266     popup = get_widget(popupname);
267     g_free(popupname);
268
269     edge = gtk_option_menu_get_history(GTK_OPTION_MENU(popup));
270     g_assert(edge == EDGE_CENTER || edge == EDGE_LEFT || edge == EDGE_RIGHT);
271
272     if (edge == EDGE_CENTER)
273         val = g_strdup("center");
274     else {
275         GtkWidget *spin;
276         gchar *spinname;
277         gint i;
278
279         spinname = g_strdup_printf("fixed_%s_pos", coord);
280         spin = get_widget(spinname);
281         g_free(spinname);
282
283         i = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
284
285         if (edge == EDGE_LEFT)
286             val = g_strdup_printf("%d", i);
287         else
288             val = g_strdup_printf("-%d", i);
289     }
290
291     valname = g_strdup_printf("resize/popupFixedPosition/%s", coord);
292     tree_set_string(valname, val);
293     g_free(valname);
294     g_free(val);
295 }
296
297
298 void on_fixed_x_position_left_activate(GtkMenuItem *w, gpointer data)
299 {
300     if (mapping) return;
301
302     write_fixed_position("x");
303     enable_stuff();
304 }
305
306 void on_fixed_x_position_right_activate(GtkMenuItem *w, gpointer data)
307 {
308     if (mapping) return;
309
310     write_fixed_position("x");
311     enable_stuff();
312 }
313
314 void on_fixed_x_position_center_activate(GtkMenuItem *w, gpointer data)
315 {
316     if (mapping) return;
317
318     write_fixed_position("x");
319     enable_stuff();
320 }
321
322 void on_fixed_y_position_top_activate(GtkMenuItem *w, gpointer data)
323 {
324     if (mapping) return;
325
326     write_fixed_position("y");
327     enable_stuff();
328 }
329
330 void on_fixed_y_position_bottom_activate(GtkMenuItem *w, gpointer data)
331 {
332     if (mapping) return;
333
334     write_fixed_position("y");
335     enable_stuff();
336 }
337
338 void on_fixed_y_position_center_activate(GtkMenuItem *w, gpointer data)
339 {
340     if (mapping) return;
341
342     write_fixed_position("y");
343     enable_stuff();
344 }
345
346 void on_fixed_x_pos_value_changed(GtkSpinButton *w, gpointer data)
347 {
348     if (mapping) return;
349
350     write_fixed_position("x");
351 }
352
353 void on_fixed_y_pos_value_changed(GtkSpinButton *w, gpointer data)
354 {
355     if (mapping) return;
356
357     write_fixed_position("y");
358 }
359
360 void on_warp_edge_toggled(GtkToggleButton *w, gpointer data)
361 {
362     if (mapping) return;
363
364     if (gtk_toggle_button_get_active(w)) {
365         GtkWidget *w2;
366
367         w2 = get_widget("warp_edge_time");
368         tree_set_int("mouse/screenEdgeWarpTime",
369                      gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w2)));
370     }
371     else
372         tree_set_int("mouse/screenEdgeWarpTime", 0);
373     enable_stuff();
374 }
375
376 void on_warp_edge_time_value_changed(GtkSpinButton *w, gpointer data)
377 {
378     if (mapping) return;
379
380     tree_set_int("mouse/screenEdgeWarpTime",
381                  gtk_spin_button_get_value_as_int(w));
382 }
383