]> icculus.org git repositories - dana/obconf.git/blob - src/windows.c
don't set the theme preview if a null is returned (trying to fix bug #3285)
[dana/obconf.git] / src / windows.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 PLACE_ON_ALL    0
26 #define PLACE_ON_FIXED 0
27 #define PLACE_ON_ACTIVE 1
28 #define PLACE_ON_MOUSE 2
29
30 static void enable_stuff();
31
32 void windows_setup_tab()
33 {
34     GtkWidget *w;
35     gchar *s;
36
37     mapping = TRUE;
38
39     w = get_widget("focus_new");
40     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
41                                  tree_get_bool("focus/focusNew", TRUE));
42
43     w = get_widget("place_mouse");
44     s = tree_get_string("placement/policy", "Smart");
45     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
46                                  !g_ascii_strcasecmp(s, "UnderMouse"));
47     g_free(s);
48
49     w = get_widget("place_center");
50     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
51                                  tree_get_bool("placement/center", TRUE));
52
53     w = get_widget("place_active_popup");
54     s = tree_get_string("placement/monitor", "Any");
55     if (!g_ascii_strcasecmp(s, "Active"))
56         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_ACTIVE);
57     else if (!g_ascii_strcasecmp(s, "Mouse"))
58         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_MOUSE);
59     else
60         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_ALL);
61     g_free(s);
62
63     w = get_widget("primary_monitor_popup");
64     s = tree_get_string("placement/primaryMonitor", "");
65     if (!g_ascii_strcasecmp(s, "Active"))
66         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_ACTIVE);
67     else if (!g_ascii_strcasecmp(s, "Mouse"))
68         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_MOUSE);
69     else {
70         gtk_option_menu_set_history(GTK_OPTION_MENU(w), PLACE_ON_FIXED);
71
72         w = get_widget("fixed_monitor");
73         gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
74                                   tree_get_int("placement/primaryMonitor", 1));
75     }
76     g_free(s);
77
78     enable_stuff();
79
80     mapping = FALSE;
81 }
82
83 static void enable_stuff()
84 {
85     GtkWidget *w;
86     gboolean b;
87
88     w = get_widget("place_mouse");
89     b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
90
91     w = get_widget("place_center");
92     gtk_widget_set_sensitive(w, !b);
93
94     w = get_widget("primary_monitor_popup");
95     b = gtk_option_menu_get_history(GTK_OPTION_MENU(w)) == PLACE_ON_FIXED;
96     w = get_widget("fixed_monitor");
97     gtk_widget_set_sensitive(w, b);
98 }
99
100 void on_primary_monitor_active_activate(GtkMenuItem *w, gpointer data)
101 {
102     if (mapping) return;
103
104     tree_set_string("placement/primaryMonitor", "Active");
105     enable_stuff();
106 }
107
108 void on_primary_monitor_mouse_activate(GtkMenuItem *w, gpointer data)
109 {
110     if (mapping) return;
111
112     tree_set_string("placement/primaryMonitor", "Mouse");
113     enable_stuff();
114 }
115
116 void on_primary_monitor_fixed_activate(GtkMenuItem *w, gpointer data)
117 {
118     GtkWidget *w2;
119
120     if (mapping) return;
121
122     w2 = get_widget("fixed_monitor");
123     tree_set_int("placement/primaryMonitor",
124                  gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w2)));
125     enable_stuff();
126 }
127
128 void on_fixed_monitor_value_changed(GtkSpinButton *w, gpointer data)
129 {
130     if (mapping) return;
131
132     tree_set_int("placement/primaryMonitor",
133                  gtk_spin_button_get_value_as_int(w));
134 }
135
136 void on_focus_new_toggled(GtkToggleButton *w, gpointer data)
137 {
138     if (mapping) return;
139
140     tree_set_bool("focus/focusNew", gtk_toggle_button_get_active(w));
141 }
142
143 void on_place_mouse_toggled(GtkToggleButton *w, gpointer data)
144 {
145     if (mapping) return;
146
147     tree_set_string("placement/policy",
148                     (gtk_toggle_button_get_active(w) ?
149                      "UnderMouse" : "Smart"));
150     enable_stuff();
151 }
152
153 void on_place_center_toggled(GtkToggleButton *w, gpointer data)
154 {
155     if (mapping) return;
156
157     tree_set_bool("placement/center", gtk_toggle_button_get_active(w));
158 }
159
160 void on_place_active_popup_all_activate(GtkMenuItem *w, gpointer data)
161 {
162     if (mapping) return;
163
164     tree_set_string("placement/monitor", "Any");
165 }
166
167 void on_place_active_popup_active_activate(GtkMenuItem *w, gpointer data)
168 {
169     if (mapping) return;
170
171     tree_set_string("placement/monitor", "Active");
172 }
173
174 void on_place_active_popup_mouse_activate(GtkMenuItem *w, gpointer data)
175 {
176     if (mapping) return;
177
178     tree_set_string("placement/monitor", "Mouse");
179 }