]> icculus.org git repositories - dana/obconf.git/blob - src/moveresize.c
fe69ed52cb2d501de7d5ffb3733abd295e81e69c
[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
32 static void enable_stuff();
33
34 void moveresize_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("resize_contents");
60     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
61                                  tree_get_bool("resize/drawContents", TRUE));
62
63     w = get_widget("resist_window");
64     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
65                               tree_get_int("resistance/strength", 10));
66
67     w = get_widget("resist_edge");
68     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
69                               tree_get_int("resistance/screen_edge_strength",
70                                            20));
71
72     w = get_widget("resize_popup");
73     s = tree_get_string("resize/popupShow", "NonPixel");
74     if (!strcasecmp(s, "Always"))     pos = POPUP_ALWAYS;
75     else if (!strcasecmp(s, "Never")) pos = POPUP_NEVER;
76     else                              pos = POPUP_NONPIXEL;
77     g_free(s);
78     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
79
80     w = get_widget("drag_threshold");
81     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
82                               tree_get_int("mouse/dragThreshold", 8));
83
84     w = get_widget("resize_position");
85     s = tree_get_string("resize/popupPosition", "Center");
86     if (!strcasecmp(s, "Top")) pos = POSITION_TOP;
87     else                       pos = POSITION_CENTER;
88     g_free(s);
89     gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
90
91     i = tree_get_int("mouse/screenEdgeWarpTime", 400);
92
93     w = get_widget("warp_edge");
94     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), i != 0);
95
96     w = get_widget("warp_edge_time");
97     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), i ? i : 400);
98
99     enable_stuff();
100
101     mapping = FALSE;
102 }
103
104 static void enable_stuff()
105 {
106     GtkWidget *w;
107     gboolean b;
108
109     w = get_widget("resize_popup");
110     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) != POPUP_NEVER;
111     w = get_widget("resize_position");
112     gtk_widget_set_sensitive(w, b);
113
114     w = get_widget("warp_edge");
115     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
116     w = get_widget("warp_edge_time");
117     gtk_widget_set_sensitive(w, b);
118 }
119
120 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
121 {
122     if (mapping) return;
123
124     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
125 }
126
127 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
128 {
129     if (mapping) return;
130
131     tree_set_int("resistance/screen_edge_strength",
132                  gtk_spin_button_get_value_as_int(w));
133 }
134
135 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
136 {
137     if (mapping) return;
138
139     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
140 }
141
142 void on_resize_popup_nonpixel_activate(GtkMenuItem *w, gpointer data)
143 {
144     if (mapping) return;
145
146     tree_set_string("resize/popupShow", "NonPixel");
147     enable_stuff();
148 }
149
150 void on_resize_popup_always_activate(GtkMenuItem *w, gpointer data)
151 {
152     if (mapping) return;
153
154     tree_set_string("resize/popupShow", "Always");
155     enable_stuff();
156 }
157
158 void on_resize_popup_never_activate(GtkMenuItem *w, gpointer data)
159 {
160     if (mapping) return;
161
162     tree_set_string("resize/popupShow", "Never");
163     enable_stuff();
164 }
165
166 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
167 {
168     if (mapping) return;
169
170     tree_set_int("mouse/dragThreshold",
171                  gtk_spin_button_get_value_as_int(w));
172 }
173
174 void on_resize_position_center_activate(GtkMenuItem *w, gpointer data)
175 {
176     if (mapping) return;
177
178     tree_set_string("resize/popupPosition", "Center");
179     enable_stuff();
180 }
181
182
183 void on_resize_position_top_activate(GtkMenuItem *w, gpointer data)
184 {
185     if (mapping) return;
186
187     tree_set_string("resize/popupPosition", "Top");
188     enable_stuff();
189 }
190
191 void on_warp_edge_toggled(GtkToggleButton *w, gpointer data)
192 {
193     if (mapping) return;
194
195     if (gtk_toggle_button_get_active(w)) {
196         GtkWidget *w2;
197
198         w2 = get_widget("warp_edge_time");
199         tree_set_int("mouse/screenEdgeWarpTime",
200                      gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w2)));
201     }
202     else
203         tree_set_int("mouse/screenEdgeWarpTime", 0);
204     enable_stuff();
205 }
206
207 void on_warp_edge_time_value_changed(GtkSpinButton *w, gpointer data)
208 {
209     if (mapping) return;
210
211     tree_set_int("mouse/screenEdgeWarpTime",
212                  gtk_spin_button_get_value_as_int(w));
213 }
214