]> icculus.org git repositories - dana/obconf.git/blob - src/behavior.c
add copyright comments
[dana/obconf.git] / src / behavior.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    behavior.h 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 void behavior_setup_tab()
26 {
27     GtkWidget *winresist, *edgeresist;
28     GtkWidget *winresist_l, *edgeresist_l;
29     GtkSizeGroup *group1, *group2;
30
31     winresist  = get_widget("resist_window");
32     edgeresist = get_widget("resist_edge");
33     group1     = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
34
35     gtk_size_group_add_widget(group1, winresist);
36     gtk_size_group_add_widget(group1, edgeresist);
37
38     winresist_l  = get_widget("resist_window_label");
39     edgeresist_l = get_widget("resist_edge_label");
40     group2       = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
41
42     gtk_size_group_add_widget(group2, winresist_l);
43     gtk_size_group_add_widget(group2, edgeresist_l);
44 }
45
46 void behavior_setup_focus_mouse(GtkWidget *w)
47 {
48     gboolean b;
49
50     mapping = TRUE;
51
52     b = tree_get_bool("focus/followMouse", FALSE);
53     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
54
55     {
56         GtkWidget *delay   = get_widget("focus_delay");
57         GtkWidget *delay_l = get_widget("focus_delay_label");
58         GtkWidget *delay_u = get_widget("focus_delay_label_units");
59         GtkWidget *raise   = get_widget("focus_raise");
60         GtkWidget *last    = get_widget("focus_last");
61
62         gtk_widget_set_sensitive(delay, b);
63         gtk_widget_set_sensitive(delay_l, b);
64         gtk_widget_set_sensitive(delay_u, b);
65         gtk_widget_set_sensitive(raise, b);
66         gtk_widget_set_sensitive(last, b);
67     }
68
69     mapping = FALSE;
70 }
71
72 void behavior_setup_focus_delay(GtkWidget *w)
73 {
74     mapping = TRUE;
75     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
76                               tree_get_int("focus/focusDelay", 0));
77     mapping = FALSE;
78 }
79
80 void behavior_setup_focus_raise(GtkWidget *w)
81 {
82     mapping = TRUE;
83     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
84                                  tree_get_bool("focus/raiseOnFocus", FALSE));
85     mapping = FALSE;
86 }
87
88 void behavior_setup_focus_last(GtkWidget *w)
89 {
90     mapping = TRUE;
91     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
92                                  tree_get_bool("focus/focusLast", FALSE));
93     mapping = FALSE;
94 }
95
96 void behavior_setup_focus_new(GtkWidget *w)
97 {
98     mapping = TRUE;
99     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
100                                  tree_get_bool("focus/focusNew", TRUE));
101     mapping = FALSE;
102 }
103
104 void behavior_setup_place_mouse(GtkWidget *w)
105 {
106     gchar *s;
107
108     mapping = TRUE;
109     s = tree_get_string("placement/policy", "Smart");
110     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
111                                  !g_ascii_strcasecmp(s, "UnderMouse"));
112     g_free(s);
113     mapping = FALSE;
114 }
115
116 void behavior_setup_resist_window(GtkWidget *w)
117 {
118     mapping = TRUE;
119     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
120                               tree_get_int("resistance/strength", 10));
121     mapping = FALSE;
122 }
123
124 void behavior_setup_resist_edge(GtkWidget *w)
125 {
126     mapping = TRUE;
127     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
128                               tree_get_int("resistance/screen_edge_strength",
129                                            20));
130     mapping = FALSE;
131 }
132
133 void behavior_setup_resize_contents(GtkWidget *w)
134 {
135     mapping = TRUE;
136     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
137                                  tree_get_bool("resize/drawContents", TRUE));
138     mapping = FALSE;
139 }
140
141 void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data)
142 {
143     gboolean b;
144
145     if (mapping) return;
146
147     b = gtk_toggle_button_get_active(w);
148     tree_set_bool("focus/followMouse", b);
149
150     {
151         GtkWidget *delay   = get_widget("focus_delay");
152         GtkWidget *delay_l = get_widget("focus_delay_label");
153         GtkWidget *delay_u = get_widget("focus_delay_label_units");
154         GtkWidget *raise   = get_widget("focus_raise");
155         GtkWidget *last    = get_widget("focus_last");
156         gtk_widget_set_sensitive(delay, b);
157         gtk_widget_set_sensitive(delay_l, b);
158         gtk_widget_set_sensitive(delay_u, b);
159         gtk_widget_set_sensitive(raise, b);
160         gtk_widget_set_sensitive(last, b);
161     }
162 }
163
164 void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data)
165 {
166     if (mapping) return;
167
168     tree_set_int("focus/focusDelay",
169                  gtk_spin_button_get_value_as_int(w));
170 }
171
172 void on_focus_raise_toggled(GtkToggleButton *w, gpointer data)
173 {
174     if (mapping) return;
175
176     tree_set_bool("focus/raiseOnFocus", gtk_toggle_button_get_active(w));
177 }
178
179 void on_focus_last_toggled(GtkToggleButton *w, gpointer data)
180 {
181     if (mapping) return;
182
183     tree_set_bool("focus/focusLast", gtk_toggle_button_get_active(w));
184 }
185
186 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
187 {
188     if (mapping) return;
189
190     tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
191 }
192
193 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
194 {
195     if (mapping) return;
196
197     tree_set_string("placement/policy",
198                     (gtk_toggle_button_get_active(w) ?
199                      "UnderMouse" : "Smart"));
200 }
201
202 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
203 {
204     if (mapping) return;
205
206     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
207 }
208
209 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
210 {
211     if (mapping) return;
212
213     tree_set_int("resistance/screen_edge_strength",
214                  gtk_spin_button_get_value_as_int(w));
215 }
216
217 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
218 {
219     if (mapping) return;
220
221     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
222 }