]> icculus.org git repositories - dana/obconf.git/blob - src/windows.c
add the margins tab
[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;
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     enable_stuff();
106
107     mapping = FALSE;
108 }
109
110 static void enable_stuff()
111 {
112     GtkWidget *w;
113     gboolean b;
114
115     w = get_widget("resize_popup");
116     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) != POPUP_NEVER;
117
118     w = get_widget("resize_position");
119     gtk_widget_set_sensitive(w, b);
120
121     w = get_widget("place_mouse");
122     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
123
124     w = get_widget("place_center");
125     gtk_widget_set_sensitive(w, !b);
126 }
127
128 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
129 {
130     if (mapping) return;
131
132     tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
133 }
134
135 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
136 {
137     if (mapping) return;
138
139     tree_set_string("placement/policy",
140                     (gtk_toggle_button_get_active(w) ?
141                      "UnderMouse" : "Smart"));
142     enable_stuff();
143 }
144
145 void on_place_center_toggled(GtkToggleButton *w, gpointer data)
146 {
147     if (mapping) return;
148
149     tree_set_bool("placement/center", gtk_toggle_button_get_active(w));
150 }
151
152 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
153 {
154     if (mapping) return;
155
156     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
157 }
158
159 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
160 {
161     if (mapping) return;
162
163     tree_set_int("resistance/screen_edge_strength",
164                  gtk_spin_button_get_value_as_int(w));
165 }
166
167 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
168 {
169     if (mapping) return;
170
171     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
172 }
173
174 void on_resize_popup_nonpixel_activate(GtkMenuItem *w, gpointer data)
175 {
176     if (mapping) return;
177
178     tree_set_string("resize/popupShow", "NonPixel");
179     enable_stuff();
180 }
181
182 void on_resize_popup_always_activate(GtkMenuItem *w, gpointer data)
183 {
184     if (mapping) return;
185
186     tree_set_string("resize/popupShow", "Always");
187     enable_stuff();
188 }
189
190 void on_resize_popup_never_activate(GtkMenuItem *w, gpointer data)
191 {
192     if (mapping) return;
193
194     tree_set_string("resize/popupShow", "Never");
195     enable_stuff();
196 }
197
198 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
199 {
200     if (mapping) return;
201
202     tree_set_int("mouse/dragThreshold",
203                  gtk_spin_button_get_value_as_int(w));
204 }
205
206 void on_resize_position_center_activate(GtkMenuItem *w, gpointer data)
207 {
208     if (mapping) return;
209
210     tree_set_string("resize/popupPosition", "Center");
211     enable_stuff();
212 }
213
214
215 void on_resize_position_top_activate(GtkMenuItem *w, gpointer data)
216 {
217     if (mapping) return;
218
219     tree_set_string("resize/popupPosition", "Top");
220     enable_stuff();
221 }
222