]> icculus.org git repositories - dana/obconf.git/blob - src/behavior.c
cleanup behavior.c
[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 static void behavior_enable_stuff();
26
27 void behavior_setup_tab()
28 {
29     GtkWidget *w, *winresist, *edgeresist;
30     GtkSizeGroup *group;
31     gchar *s;
32
33     winresist  = get_widget("resist_window");
34     edgeresist = get_widget("resist_edge");
35     group      = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
36     gtk_size_group_add_widget(group, winresist);
37     gtk_size_group_add_widget(group, edgeresist);
38
39     winresist  = get_widget("resist_window_label");
40     edgeresist = get_widget("resist_edge_label");
41     group      = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
42     gtk_size_group_add_widget(group, winresist);
43     gtk_size_group_add_widget(group, edgeresist);
44
45     w = get_widget("focus_mouse");
46     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
47                                  tree_get_bool("focus/followMouse", FALSE));
48
49     w = get_widget("focus_delay");
50     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
51                               tree_get_int("focus/focusDelay", 0));
52
53     w = get_widget("focus_raise");
54     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
55                                  tree_get_bool("focus/raiseOnFocus", FALSE));
56
57     w = get_widget("focus_last");
58     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
59                                  tree_get_bool("focus/focusLast", FALSE));
60
61     w = get_widget("focus_new");
62     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
63                                  tree_get_bool("focus/focusNew", TRUE));
64
65     w = get_widget("resize_contents");
66     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
67                                  tree_get_bool("resize/drawContents", TRUE));
68
69     w = get_widget("resist_window");
70     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
71                               tree_get_int("resistance/strength", 10));
72
73     w = get_widget("resist_edge");
74     gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
75                               tree_get_int("resistance/screen_edge_strength",
76                                            20));
77
78     w = get_widget("place_mouse");
79     s = tree_get_string("placement/policy", "Smart");
80     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
81                                  !g_ascii_strcasecmp(s, "UnderMouse"));
82     g_free(s);
83 }
84
85 static void behavior_enable_stuff()
86 {
87     GtkWidget *w;
88     gboolean b;
89
90     w = get_widget("focus_mouse");
91     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
92
93     w = get_widget("focus_delay");
94     gtk_widget_set_sensitive(w, b);
95     w = get_widget("focus_delay_label");
96     gtk_widget_set_sensitive(w, b);
97     w = get_widget("focus_delay_label_units");
98     gtk_widget_set_sensitive(w, b);
99     w = get_widget("focus_raise");
100     gtk_widget_set_sensitive(w, b);
101     w = get_widget("focus_last");
102     gtk_widget_set_sensitive(w, b);
103 }
104
105 void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data)
106 {
107     gboolean b;
108
109     if (mapping) return;
110
111     b = gtk_toggle_button_get_active(w);
112     tree_set_bool("focus/followMouse", b);
113
114     {
115         GtkWidget *delay   = get_widget("focus_delay");
116         GtkWidget *delay_l = get_widget("focus_delay_label");
117         GtkWidget *delay_u = get_widget("focus_delay_label_units");
118         GtkWidget *raise   = get_widget("focus_raise");
119         GtkWidget *last    = get_widget("focus_last");
120         gtk_widget_set_sensitive(delay, b);
121         gtk_widget_set_sensitive(delay_l, b);
122         gtk_widget_set_sensitive(delay_u, b);
123         gtk_widget_set_sensitive(raise, b);
124         gtk_widget_set_sensitive(last, b);
125     }
126 }
127
128 void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data)
129 {
130     if (mapping) return;
131
132     tree_set_int("focus/focusDelay",
133                  gtk_spin_button_get_value_as_int(w));
134 }
135
136 void on_focus_raise_toggled(GtkToggleButton *w, gpointer data)
137 {
138     if (mapping) return;
139
140     tree_set_bool("focus/raiseOnFocus", gtk_toggle_button_get_active(w));
141 }
142
143 void on_focus_last_toggled(GtkToggleButton *w, gpointer data)
144 {
145     if (mapping) return;
146
147     tree_set_bool("focus/focusLast", gtk_toggle_button_get_active(w));
148 }
149
150 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
151 {
152     if (mapping) return;
153
154     tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
155 }
156
157 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
158 {
159     if (mapping) return;
160
161     tree_set_string("placement/policy",
162                     (gtk_toggle_button_get_active(w) ?
163                      "UnderMouse" : "Smart"));
164 }
165
166 void on_resist_window_value_changed(GtkSpinButton *w, gpointer data)
167 {
168     if (mapping) return;
169
170     tree_set_int("resistance/strength", gtk_spin_button_get_value_as_int(w));
171 }
172
173 void on_resist_edge_value_changed(GtkSpinButton *w, gpointer data)
174 {
175     if (mapping) return;
176
177     tree_set_int("resistance/screen_edge_strength",
178                  gtk_spin_button_get_value_as_int(w));
179 }
180
181 void on_resize_contents_toggled(GtkToggleButton *w, gpointer data)
182 {
183     if (mapping) return;
184
185     tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w));
186 }