]> icculus.org git repositories - dana/obconf.git/blob - src/moveresize.c
change the <active> option to the <monitor> option
[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
47     mapping = TRUE;
48
49     w1    = get_widget("resist_window");
50     w2    = get_widget("resist_edge");
51     w3    = get_widget("drag_threshold");
52     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
53     gtk_size_group_add_widget(group, w1);
54     gtk_size_group_add_widget(group, w2);
55     gtk_size_group_add_widget(group, w3);
56
57     w1    = get_widget("resist_window_label");
58     w2    = get_widget("resist_edge_label");
59     w3    = get_widget("drag_threshold_label");
60     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
61     gtk_size_group_add_widget(group, w1);
62     gtk_size_group_add_widget(group, w2);
63     gtk_size_group_add_widget(group, w3);
64
65     w = get_widget("resize_contents");
66     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
67                                  tree_get_bool("resize/drawContents", TRUE));
68
69     w = get_widget("resist_window");
70     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
71                               tree_get_int("resistance/strength", 10));
72
73     w = get_widget("resist_edge");
74     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
75                               tree_get_int("resistance/screen_edge_strength",
76                                            20));
77
78     w = get_widget("resize_popup");
79     s = tree_get_string("resize/popupShow", "NonPixel");
80     if (!strcasecmp(s, "Always"))     pos = POPUP_ALWAYS;
81     else if (!strcasecmp(s, "Never")) pos = POPUP_NEVER;
82     else                              pos = POPUP_NONPIXEL;
83     g_free(s);
84     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
85
86     w = get_widget("drag_threshold");
87     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
88                               tree_get_int("mouse/dragThreshold", 8));
89
90     w = get_widget("resize_position");
91     s = tree_get_string("resize/popupPosition", "Center");
92     if (!strcasecmp(s, "Top"))   pos = POSITION_TOP;
93     if (!strcasecmp(s, "Fixed")) pos = POSITION_FIXED;
94     else                         pos = POSITION_CENTER;
95     g_free(s);
96     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
97
98     w = get_widget("fixed_x_pos");
99     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
100                               tree_get_int("resize/popupFixedPosition/x", 0));
101
102     w = get_widget("fixed_y_pos");
103     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
104                               tree_get_int("resize/popupFixedPosition/y", 0));
105
106     i = tree_get_int("mouse/screenEdgeWarpTime", 400);
107
108     w = get_widget("warp_edge");
109     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), i != 0);
110
111     w = get_widget("warp_edge_time");
112     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), i ? i : 400);
113
114     enable_stuff();
115
116     mapping = FALSE;
117 }
118
119 static void enable_stuff()
120 {
121     GtkWidget *w;
122     gboolean b;
123
124     w = get_widget("resize_popup");
125     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) != POPUP_NEVER;
126     w = get_widget("resize_position");
127     gtk_widget_set_sensitive(w, b);
128
129     w = get_widget("warp_edge");
130     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
131     w = get_widget("warp_edge_time");
132     gtk_widget_set_sensitive(w, b);
133
134     w = get_widget("resize_position");
135     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) == POSITION_FIXED;
136     w = get_widget("fixed_x_popup");
137     gtk_widget_set_sensitive(w, b);
138     w = get_widget("fixed_y_popup");
139     gtk_widget_set_sensitive(w, b);
140     if (!b) {
141         w = get_widget("fixed_x_pos");
142         gtk_widget_set_sensitive(w, FALSE);
143         w = get_widget("fixed_y_pos");
144         gtk_widget_set_sensitive(w, FALSE);
145     }
146     else {
147         w = get_widget("fixed_x_popup");
148         b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) != EDGE_CENTER;
149         w = get_widget("fixed_x_pos");
150         gtk_widget_set_sensitive(w, b);
151
152         w = get_widget("fixed_y_popup");
153         b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) != EDGE_CENTER;
154         w = get_widget("fixed_y_pos");
155         gtk_widget_set_sensitive(w, b);
156     }
157 }
158
159 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
160 {
161     if (mapping) return;
162
163     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
164 }
165
166 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
167 {
168     if (mapping) return;
169
170     tree_set_int("resistance/screen_edge_strength",
171                  gtk_spin_button_get_value_as_int(w));
172 }
173
174 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
175 {
176     if (mapping) return;
177
178     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
179 }
180
181 void on_resize_popup_nonpixel_activate(GtkMenuItem *w, gpointer data)
182 {
183     if (mapping) return;
184
185     tree_set_string("resize/popupShow", "NonPixel");
186     enable_stuff();
187 }
188
189 void on_resize_popup_always_activate(GtkMenuItem *w, gpointer data)
190 {
191     if (mapping) return;
192
193     tree_set_string("resize/popupShow", "Always");
194     enable_stuff();
195 }
196
197 void on_resize_popup_never_activate(GtkMenuItem *w, gpointer data)
198 {
199     if (mapping) return;
200
201     tree_set_string("resize/popupShow", "Never");
202     enable_stuff();
203 }
204
205 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
206 {
207     if (mapping) return;
208
209     tree_set_int("mouse/dragThreshold",
210                  gtk_spin_button_get_value_as_int(w));
211 }
212
213 void on_resize_position_center_activate(GtkMenuItem *w, gpointer data)
214 {
215     if (mapping) return;
216
217     tree_set_string("resize/popupPosition", "Center");
218     enable_stuff();
219 }
220
221 void on_resize_position_top_activate(GtkMenuItem *w, gpointer data)
222 {
223     if (mapping) return;
224
225     tree_set_string("resize/popupPosition", "Top");
226     enable_stuff();
227 }
228
229 void on_resize_position_fixed_activate(GtkMenuItem *w, gpointer data)
230 {
231     if (mapping) return;
232
233     tree_set_string("resize/popupPosition", "Fixed");
234     enable_stuff();
235 }
236
237 static void write_fixed_position(const gchar *coord)
238 {
239     GtkWidget *popup;
240     gchar *popupname;
241     gchar *val;
242     gchar *valname;
243     gint edge;
244
245     g_assert(!strcmp(coord, "x") || !strcmp(coord, "y"));
246
247     popupname = g_strdup_printf("fixed_%s_popup", coord);
248     popup = get_widget(popupname);
249     g_free(popupname);
250
251     edge = gtk_option_menu_get_history(GTK_OPTION_MENU(popup));
252     g_assert(edge == EDGE_CENTER || edge == EDGE_LEFT || edge == EDGE_RIGHT);
253
254     if (edge == EDGE_CENTER)
255         val = g_strdup("center");
256     else {
257         GtkWidget *spin;
258         gchar *spinname;
259         gint i;
260
261         spinname = g_strdup_printf("fixed_%s_pos", coord);
262         spin = get_widget(spinname);
263         g_free(spinname);
264
265         i = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
266
267         if (edge == EDGE_LEFT)
268             val = g_strdup_printf("%d", i);
269         else
270             val = g_strdup_printf("-%d", i);
271     }
272
273     valname = g_strdup_printf("resize/popupFixedPosition/%s", coord);
274     tree_set_string(valname, val);
275     g_free(valname);
276     g_free(val);
277 }
278
279
280 void on_fixed_x_position_left_activate(GtkMenuItem *w, gpointer data)
281 {
282     if (mapping) return;
283
284     write_fixed_position("x");
285     enable_stuff();
286 }
287
288 void on_fixed_x_position_right_activate(GtkMenuItem *w, gpointer data)
289 {
290     if (mapping) return;
291
292     write_fixed_position("x");
293     enable_stuff();
294 }
295
296 void on_fixed_x_position_center_activate(GtkMenuItem *w, gpointer data)
297 {
298     if (mapping) return;
299
300     write_fixed_position("x");
301     enable_stuff();
302 }
303
304 void on_fixed_y_position_left_activate(GtkMenuItem *w, gpointer data)
305 {
306     if (mapping) return;
307
308     write_fixed_position("y");
309     enable_stuff();
310 }
311
312 void on_fixed_y_position_right_activate(GtkMenuItem *w, gpointer data)
313 {
314     if (mapping) return;
315
316     write_fixed_position("y");
317     enable_stuff();
318 }
319
320 void on_fixed_y_position_center_activate(GtkMenuItem *w, gpointer data)
321 {
322     if (mapping) return;
323
324     write_fixed_position("y");
325     enable_stuff();
326 }
327
328 void on_fixed_x_pos_value_changed(GtkSpinButton *w, gpointer data)
329 {
330     if (mapping) return;
331
332     write_fixed_position("x");
333 }
334
335 void on_fixed_y_pos_value_changed(GtkSpinButton *w, gpointer data)
336 {
337     if (mapping) return;
338
339     write_fixed_position("y");
340 }
341
342 void on_warp_edge_toggled(GtkToggleButton *w, gpointer data)
343 {
344     if (mapping) return;
345
346     if (gtk_toggle_button_get_active(w)) {
347         GtkWidget *w2;
348
349         w2 = get_widget("warp_edge_time");
350         tree_set_int("mouse/screenEdgeWarpTime",
351                      gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w2)));
352     }
353     else
354         tree_set_int("mouse/screenEdgeWarpTime", 0);
355     enable_stuff();
356 }
357
358 void on_warp_edge_time_value_changed(GtkSpinButton *w, gpointer data)
359 {
360     if (mapping) return;
361
362     tree_set_int("mouse/screenEdgeWarpTime",
363                  gtk_spin_button_get_value_as_int(w));
364 }
365