version bump
[blackbox.git] / src / BlackboxResource.cc
blob27d1323a43f895c4c7871bb718cae28d43dbc90f
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // BlackboxResource.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 // Bradley T Hughes <bhughes at trolltech.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
25 #include "BlackboxResource.hh"
27 #include "blackbox.hh"
29 #include <Image.hh>
30 #include <Resource.hh>
32 #include <X11/Xlib.h>
33 #include <X11/Xutil.h>
34 #include <X11/cursorfont.h>
37 BlackboxResource::BlackboxResource(const std::string& rc): rc_file(rc) {
38 screen_resources = 0;
39 auto_raise_delay.tv_sec = auto_raise_delay.tv_usec = 0;
43 BlackboxResource::~BlackboxResource(void)
44 { delete [] screen_resources; }
47 void BlackboxResource::load(Blackbox& blackbox) {
48 if (screen_resources == 0) {
49 screen_resources = new ScreenResource[blackbox.screenCount()];
52 bt::Resource res(rc_file);
54 menu_file = bt::expandTilde(res.read("session.menuFile",
55 "Session.MenuFile",
56 DEFAULTMENU));
58 style_file = bt::expandTilde(res.read("session.styleFile",
59 "Session.StyleFile",
60 DEFAULTSTYLE));
62 unsigned int maxcolors = res.read("session.maximumColors",
63 "Session.MaximumColors",
64 ~0u);
65 if (maxcolors != ~0u)
66 bt::Image::setMaximumColors(maxcolors);
68 double_click_interval = res.read("session.doubleClickInterval",
69 "Session.DoubleClickInterval",
70 250l);
72 auto_raise_delay.tv_usec = res.read("session.autoRaiseDelay",
73 "Session.AutoRaiseDelay",
74 400l);
76 auto_raise_delay.tv_sec = auto_raise_delay.tv_usec / 1000;
77 auto_raise_delay.tv_usec -= (auto_raise_delay.tv_sec * 1000);
78 auto_raise_delay.tv_usec *= 1000;
80 bt::DitherMode dither_mode;
81 std::string str = res.read("session.imageDither",
82 "Session.ImageDither",
83 "OrderedDither");
84 if (!strcasecmp("ordered", str.c_str()) ||
85 !strcasecmp("fast", str.c_str()) ||
86 !strcasecmp("ordereddither", str.c_str()) ||
87 !strcasecmp("fastdither", str.c_str())) {
88 dither_mode = bt::OrderedDither;
89 } else if (!strcasecmp("floydsteinberg", str.c_str()) ||
90 !strcasecmp("quality", str.c_str()) ||
91 !strcasecmp("diffuse", str.c_str()) ||
92 !strcasecmp("floydsteinbergdither", str.c_str()) ||
93 !strcasecmp("qualitydither", str.c_str()) ||
94 !strcasecmp("diffusedither", str.c_str())) {
95 dither_mode = bt::FloydSteinbergDither;
96 } else if (!strcasecmp("no", str.c_str()) ||
97 !strcasecmp("nodither", str.c_str()) ||
98 !strcasecmp("off", str.c_str())) {
99 dither_mode = bt::NoDither;
100 } else {
101 dither_mode = bt::OrderedDither;
103 bt::Image::setDitherMode(dither_mode);
105 _cursors.pointer =
106 XCreateFontCursor(blackbox.XDisplay(), XC_left_ptr);
107 _cursors.move =
108 XCreateFontCursor(blackbox.XDisplay(), XC_fleur);
109 _cursors.resize_top_left =
110 XCreateFontCursor(blackbox.XDisplay(), XC_top_left_corner);
111 _cursors.resize_bottom_left =
112 XCreateFontCursor(blackbox.XDisplay(), XC_bottom_left_corner);
113 _cursors.resize_top_right =
114 XCreateFontCursor(blackbox.XDisplay(), XC_top_right_corner);
115 _cursors.resize_bottom_right =
116 XCreateFontCursor(blackbox.XDisplay(), XC_bottom_right_corner);
118 // window options
119 str = res.read("session.focusModel",
120 "Session.FocusModel",
121 res.read("session.screen0.focusModel",
122 "Session.Screen0.FocusModel",
123 "ClickToFocus"));
124 if (str.find("ClickToFocus") != std::string::npos) {
125 focus_model = ClickToFocusModel;
126 auto_raise = false;
127 click_raise = false;
128 } else {
129 focus_model = SloppyFocusModel;
130 auto_raise = (str.find("AutoRaise") != std::string::npos);
131 click_raise = (str.find("ClickRaise") != std::string::npos);
134 str = res.read("session.windowPlacement",
135 "Session.WindowPlacement",
136 res.read("session.screen0.windowPlacement",
137 "Session.Screen0.WindowPlacement",
138 "RowSmartPlacement"));
139 if (strcasecmp(str.c_str(), "ColSmartPlacement") == 0)
140 window_placement_policy = ColSmartPlacement;
141 else if (strcasecmp(str.c_str(), "CenterPlacement") == 0)
142 window_placement_policy = CenterPlacement;
143 else if (strcasecmp(str.c_str(), "CascadePlacement") == 0)
144 window_placement_policy = CascadePlacement;
145 else
146 window_placement_policy = RowSmartPlacement;
148 str = res.read("session.rowPlacementDirection",
149 "Session.RowPlacementDirection",
150 res.read("session.screen0.rowPlacementDirection",
151 "Session.Screen0.RowPlacementDirection",
152 "lefttoright"));
153 row_direction =
154 (strcasecmp(str.c_str(), "righttoleft") == 0) ? RightLeft : LeftRight;
156 str = res.read("session.colPlacementDirection",
157 "Session.ColPlacementDirection",
158 res.read("session.screen0.colPlacementDirection",
159 "Session.Screen0.ColPlacementDirection",
160 "toptobottom"));
161 col_direction =
162 (strcasecmp(str.c_str(), "bottomtotop") == 0) ? BottomTop : TopBottom;
164 ignore_shaded =
165 res.read("session.placementIgnoresShaded",
166 "Session.placementIgnoresShaded",
167 true);
169 opaque_move =
170 res.read("session.opaqueMove",
171 "Session.OpaqueMove",
172 true);
173 opaque_resize =
174 res.read("session.opaqueResize",
175 "Session.OpaqueResize",
176 true);
177 full_max =
178 res.read("session.fullMaximization",
179 "Session.FullMaximization",
180 res.read("session.screen0.fullMaximization",
181 "Session.Screen0.FullMaximization",
182 false));
183 focus_new_windows =
184 res.read("session.focusNewWindows",
185 "Session.FocusNewWindows",
186 res.read("session.screen0.focusNewWindows",
187 "Session.Screen0.FocusNewWindows",
188 true));
189 focus_last_window_on_workspace =
190 res.read("session.focusLastWindow",
191 "Session.focusLastWindow",
192 res.read("session.screen0.focusLastWindow",
193 "Session.Screen0.focusLastWindow",
194 true));
195 change_workspace_with_mouse_wheel =
196 res.read("session.changeWorkspaceWithMouseWheel",
197 "session.changeWorkspaceWithMouseWheel",
198 true);
199 shade_window_with_mouse_wheel =
200 res.read("session.shadeWindowWithMouseWheel",
201 "session.shadeWindowWithMouseWheel",
202 true);
203 toolbar_actions_with_mouse_wheel =
204 res.read("session.toolbarActionsWithMouseWheel",
205 "session.toolbarActionsWithMouseWheel",
206 true);
207 allow_scroll_lock =
208 res.read("session.disableBindingsWithScrollLock",
209 "Session.disableBindingsWithScrollLock",
210 res.read("session.screen0.disableBindingsWithScrollLock",
211 "Session.Screen0.disableBindingsWithScrollLock",
212 false));
213 edge_snap_threshold =
214 res.read("session.edgeSnapThreshold",
215 "Session.EdgeSnapThreshold",
216 res.read("session.screen0.edgeSnapThreshold",
217 "Session.Screen0.EdgeSnapThreshold",
218 0));
219 window_snap_threshold =
220 res.read("session.windowSnapThreshold",
221 "Session.windowSnapThreshold",
224 for (unsigned int i = 0; i < blackbox.screenCount(); ++i)
225 screen_resources[i].load(res, i);
229 void BlackboxResource::save(Blackbox& blackbox) {
230 bt::Resource res;
233 if (bt::Resource(rc_file).read("session.cacheLife",
234 "Session.CacheLife",
235 -1) == -1) {
236 res.merge(rc_file);
237 } else {
238 // we are converting from 0.65.0 to 0.70.0, let's take the liberty
239 // of generating a brand new rc file to make sure we throw out
240 // undeeded entries
244 res.write("session.menuFile", menuFilename());
246 res.write("session.styleFile", styleFilename());
248 res.write("session.maximumColors", bt::Image::maximumColors());
250 res.write("session.doubleClickInterval", double_click_interval);
252 res.write("session.autoRaiseDelay", ((auto_raise_delay.tv_sec * 1000ul) +
253 (auto_raise_delay.tv_usec / 1000ul)));
255 std::string str;
256 switch (bt::Image::ditherMode()) {
257 case bt::OrderedDither: str = "OrderedDither"; break;
258 case bt::FloydSteinbergDither: str = "FloydSteinbergDither"; break;
259 default: str = "NoDither"; break;
261 res.write("session.imageDither", str);
263 // window options
264 switch (focus_model) {
265 case SloppyFocusModel:
266 default:
267 str = "SloppyFocus";
268 if (auto_raise)
269 str += " AutoRaise";
270 if (click_raise)
271 str += " ClickRaise";
272 break;
273 case ClickToFocusModel:
274 str = "ClickToFocus";
275 break;
277 res.write("session.focusModel", str);
279 switch (window_placement_policy) {
280 case CascadePlacement:
281 str = "CascadePlacement";
282 break;
283 case CenterPlacement:
284 str = "CenterPlacement";
285 break;
286 case ColSmartPlacement:
287 str = "ColSmartPlacement";
288 break;
289 case RowSmartPlacement:
290 default:
291 str = "RowSmartPlacement";
292 break;
294 res.write("session.windowPlacement", str);
295 res.write("session.rowPlacementDirection",
296 (row_direction == LeftRight)
297 ? "LeftToRight"
298 : "RightToLeft");
299 res.write("session.colPlacementDirection",
300 (col_direction == TopBottom)
301 ? "TopToBottom"
302 : "BottomToTop");
304 res.write("session.placementIgnoresShaded", ignore_shaded);
306 res.write("session.opaqueMove", opaque_move);
307 res.write("session.opaqueResize", opaque_resize);
308 res.write("session.fullMaximization", full_max);
309 res.write("session.focusNewWindows", focus_new_windows);
310 res.write("session.focusLastWindow", focus_last_window_on_workspace);
311 res.write("session.changeWorkspaceWithMouseWheel",
312 change_workspace_with_mouse_wheel);
313 res.write("session.shadeWindowWithMouseWheel",
314 shade_window_with_mouse_wheel);
315 res.write("session.toolbarActionsWithMouseWheel",
316 toolbar_actions_with_mouse_wheel);
317 res.write("session.disableBindingsWithScrollLock", allow_scroll_lock);
318 res.write("session.edgeSnapThreshold", edge_snap_threshold);
319 res.write("session.windowSnapThreshold", window_snap_threshold);
321 for (unsigned int i = 0; i < blackbox.screenCount(); ++i)
322 screen_resources[i].save(res, blackbox.screenNumber(i));
324 res.save(rc_file);