]> icculus.org git repositories - dana/obconf.git/blob - src/windows.c
enable/disable stuff properly for the new screen edge warp option
[dana/obconf.git] / src / windows.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-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 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
32 static void enable_stuff();
33
34 void windows_setup_tab()
35 {
36     GtkWidget *w, *w1, *w2, *w3;
37     GtkSizeGroup *group;
38     gchar *s;
39     gint pos, i;
40
41     mapping = TRUE;
42
43     w1    = get_widget("resist_window");
44     w2    = get_widget("resist_edge");
45     w3    = get_widget("drag_threshold");
46     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
47     gtk_size_group_add_widget(group, w1);
48     gtk_size_group_add_widget(group, w2);
49     gtk_size_group_add_widget(group, w3);
50
51     w1    = get_widget("resist_window_label");
52     w2    = get_widget("resist_edge_label");
53     w3    = get_widget("drag_threshold_label");
54     group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
55     gtk_size_group_add_widget(group, w1);
56     gtk_size_group_add_widget(group, w2);
57     gtk_size_group_add_widget(group, w3);
58
59     w = get_widget("focus_new");
60     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
61                                  tree_get_bool("focus/focusNew", TRUE));
62
63     w = get_widget("resize_contents");
64     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
65                                  tree_get_bool("resize/drawContents", TRUE));
66
67     w = get_widget("resist_window");
68     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
69                               tree_get_int("resistance/strength", 10));
70
71     w = get_widget("resist_edge");
72     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
73                               tree_get_int("resistance/screen_edge_strength",
74                                            20));
75
76     w = get_widget("place_mouse");
77     s = tree_get_string("placement/policy", "Smart");
78     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
79                                  !g_ascii_strcasecmp(s, "UnderMouse"));
80     g_free(s);
81
82     w = get_widget("place_center");
83     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
84                                  tree_get_bool("placement/center", TRUE));
85
86     w = get_widget("resize_popup");
87     s = tree_get_string("resize/popupShow", "NonPixel");
88     if (!strcasecmp(s, "Always"))     pos = POPUP_ALWAYS;
89     else if (!strcasecmp(s, "Never")) pos = POPUP_NEVER;
90     else                              pos = POPUP_NONPIXEL;
91     g_free(s);
92     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
93
94     w = get_widget("drag_threshold");
95     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
96                               tree_get_int("mouse/dragThreshold", 8));
97
98     w = get_widget("resize_position");
99     s = tree_get_string("resize/popupPosition", "Center");
100     if (!strcasecmp(s, "Top")) pos = POSITION_TOP;
101     else                       pos = POSITION_CENTER;
102     g_free(s);
103     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
104
105     i = tree_get_int("mouse/screenEdgeWarpTime", 400);
106
107     w = get_widget("warp_edge");
108     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), i != 0);
109
110     w = get_widget("warp_edge_time");
111     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), i ? i : 400);
112
113     enable_stuff();
114
115     mapping = FALSE;
116 }
117
118 static void enable_stuff()
119 {
120     GtkWidget *w;
121     gboolean b;
122
123     w = get_widget("resize_popup");
124     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) != POPUP_NEVER;
125     w = get_widget("resize_position");
126     gtk_widget_set_sensitive(w, b);
127
128     w = get_widget("place_mouse");
129     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
130     w = get_widget("place_center");
131     gtk_widget_set_sensitive(w, !b);
132
133     w = get_widget("warp_edge");
134     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
135     w = get_widget("warp_edge_time");
136     gtk_widget_set_sensitive(w, b);
137 }
138
139 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
140 {
141     if (mapping) return;
142
143     tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
144 }
145
146 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
147 {
148     if (mapping) return;
149
150     tree_set_string("placement/policy",
151                     (gtk_toggle_button_get_active(w) ?
152                      "UnderMouse" : "Smart"));
153     enable_stuff();
154 }
155
156 void on_place_center_toggled(GtkToggleButton *w, gpointer data)
157 {
158     if (mapping) return;
159
160     tree_set_bool("placement/center", gtk_toggle_button_get_active(w));
161 }
162
163 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
164 {
165     if (mapping) return;
166
167     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
168 }
169
170 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
171 {
172     if (mapping) return;
173
174     tree_set_int("resistance/screen_edge_strength",
175                  gtk_spin_button_get_value_as_int(w));
176 }
177
178 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
179 {
180     if (mapping) return;
181
182     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
183 }
184
185 void on_resize_popup_nonpixel_activate(GtkMenuItem *w, gpointer data)
186 {
187     if (mapping) return;
188
189     tree_set_string("resize/popupShow", "NonPixel");
190     enable_stuff();
191 }
192
193 void on_resize_popup_always_activate(GtkMenuItem *w, gpointer data)
194 {
195     if (mapping) return;
196
197     tree_set_string("resize/popupShow", "Always");
198     enable_stuff();
199 }
200
201 void on_resize_popup_never_activate(GtkMenuItem *w, gpointer data)
202 {
203     if (mapping) return;
204
205     tree_set_string("resize/popupShow", "Never");
206     enable_stuff();
207 }
208
209 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
210 {
211     if (mapping) return;
212
213     tree_set_int("mouse/dragThreshold",
214                  gtk_spin_button_get_value_as_int(w));
215 }
216
217 void on_resize_position_center_activate(GtkMenuItem *w, gpointer data)
218 {
219     if (mapping) return;
220
221     tree_set_string("resize/popupPosition", "Center");
222     enable_stuff();
223 }
224
225
226 void on_resize_position_top_activate(GtkMenuItem *w, gpointer data)
227 {
228     if (mapping) return;
229
230     tree_set_string("resize/popupPosition", "Top");
231     enable_stuff();
232 }
233
234 void on_warp_edge_toggled(GtkToggleButton *w, gpointer data)
235 {
236     if (mapping) return;
237
238     if (gtk_toggle_button_get_active(w)) {
239         GtkWidget *w2;
240
241         w2 = get_widget("warp_edge_time");
242         tree_set_int("mouse/screenEdgeWarpTime",
243                      gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w2)));
244     }
245     else
246         tree_set_int("mouse/screenEdgeWarpTime", 0);
247     enable_stuff();
248 }
249
250 void on_warp_edge_time_value_changed(GtkSpinButton *w, gpointer data)
251 {
252     if (mapping) return;
253
254     tree_set_int("mouse/screenEdgeWarpTime",
255                  gtk_spin_button_get_value_as_int(w));
256 }
257