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