1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 windows.c for ObConf, the configuration tool for Openbox
4 Copyright (c) 2003-2008 Dana Jansens
5 Copyright (c) 2003 Tim Riley
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.
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.
17 See the COPYING file for a copy of the GNU General Public License.
23 static gboolean mapping = FALSE;
25 #define POPUP_NONPIXEL 0
26 #define POPUP_ALWAYS 1
29 #define POSITION_CENTER 0
30 #define POSITION_TOP 1
31 #define POSITION_FIXED 2
37 static void enable_stuff();
38 static void write_fixed_position(const gchar *coord);
40 void moveresize_setup_tab()
42 GtkWidget *w, *w1, *w2, *w3;
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);
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);
66 w = get_widget("resize_contents");
67 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
68 tree_get_bool("resize/drawContents", TRUE));
70 w = get_widget("resist_window");
71 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
72 tree_get_int("resistance/strength", 10));
74 w = get_widget("resist_edge");
75 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
76 tree_get_int("resistance/screen_edge_strength",
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;
85 gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
87 w = get_widget("drag_threshold");
88 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
89 tree_get_int("mouse/dragThreshold", 8));
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;
97 gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
99 w = get_widget("fixed_x_popup");
100 s = tree_get_string("resize/popupFixedPosition/x", "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;
107 gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
109 w = get_widget("fixed_x_pos");
110 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), MAX(atoi(s), 0));
112 w = get_widget("fixed_y_popup");
113 s = tree_get_string("resize/popupFixedPosition/y", "0");
115 if (!strcasecmp(s, "Center")) pos = EDGE_CENTER;
116 else if (opp) pos = EDGE_RIGHT;
117 else pos = EDGE_LEFT;
119 gtk_option_menu_set_history(GTK_OPTION_MENU(w), pos);
121 w = get_widget("fixed_y_pos");
122 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), MAX(atoi(s), 0));
124 i = tree_get_int("mouse/screenEdgeWarpTime", 400);
126 w = get_widget("warp_edge");
127 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), i != 0);
129 w = get_widget("warp_edge_time");
130 gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), i ? i : 400);
137 static void enable_stuff()
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);
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);
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);
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);
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);
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);
177 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
181 tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
184 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
188 tree_set_int("resistance/screen_edge_strength",
189 gtk_spin_button_get_value_as_int(w));
192 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
196 tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
199 void on_resize_popup_nonpixel_activate(GtkMenuItem *w, gpointer data)
203 tree_set_string("resize/popupShow", "NonPixel");
207 void on_resize_popup_always_activate(GtkMenuItem *w, gpointer data)
211 tree_set_string("resize/popupShow", "Always");
215 void on_resize_popup_never_activate(GtkMenuItem *w, gpointer data)
219 tree_set_string("resize/popupShow", "Never");
223 void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data)
227 tree_set_int("mouse/dragThreshold",
228 gtk_spin_button_get_value_as_int(w));
231 void on_resize_position_center_activate(GtkMenuItem *w, gpointer data)
235 tree_set_string("resize/popupPosition", "Center");
239 void on_resize_position_top_activate(GtkMenuItem *w, gpointer data)
243 tree_set_string("resize/popupPosition", "Top");
247 void on_resize_position_fixed_activate(GtkMenuItem *w, gpointer data)
251 tree_set_string("resize/popupPosition", "Fixed");
255 static void write_fixed_position(const gchar *coord)
263 g_assert(!strcmp(coord, "x") || !strcmp(coord, "y"));
265 popupname = g_strdup_printf("fixed_%s_popup", coord);
266 popup = get_widget(popupname);
269 edge = gtk_option_menu_get_history(GTK_OPTION_MENU(popup));
270 g_assert(edge == EDGE_CENTER || edge == EDGE_LEFT || edge == EDGE_RIGHT);
272 if (edge == EDGE_CENTER)
273 val = g_strdup("center");
279 spinname = g_strdup_printf("fixed_%s_pos", coord);
280 spin = get_widget(spinname);
283 i = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
285 if (edge == EDGE_LEFT)
286 val = g_strdup_printf("%d", i);
288 val = g_strdup_printf("-%d", i);
291 valname = g_strdup_printf("resize/popupFixedPosition/%s", coord);
292 tree_set_string(valname, val);
298 void on_fixed_x_position_left_activate(GtkMenuItem *w, gpointer data)
302 write_fixed_position("x");
306 void on_fixed_x_position_right_activate(GtkMenuItem *w, gpointer data)
310 write_fixed_position("x");
314 void on_fixed_x_position_center_activate(GtkMenuItem *w, gpointer data)
318 write_fixed_position("x");
322 void on_fixed_y_position_top_activate(GtkMenuItem *w, gpointer data)
326 write_fixed_position("y");
330 void on_fixed_y_position_bottom_activate(GtkMenuItem *w, gpointer data)
334 write_fixed_position("y");
338 void on_fixed_y_position_center_activate(GtkMenuItem *w, gpointer data)
342 write_fixed_position("y");
346 void on_fixed_x_pos_value_changed(GtkSpinButton *w, gpointer data)
350 write_fixed_position("x");
353 void on_fixed_y_pos_value_changed(GtkSpinButton *w, gpointer data)
357 write_fixed_position("y");
360 void on_warp_edge_toggled(GtkToggleButton *w, gpointer data)
364 if (gtk_toggle_button_get_active(w)) {
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)));
372 tree_set_int("mouse/screenEdgeWarpTime", 0);
376 void on_warp_edge_time_value_changed(GtkSpinButton *w, gpointer data)
380 tree_set_int("mouse/screenEdgeWarpTime",
381 gtk_spin_button_get_value_as_int(w));