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>
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"
30 #include <Resource.hh>
32 #include <X11/Xutil.h>
33 #include <X11/cursorfont.h>
36 BlackboxResource::BlackboxResource(const std::string
& rc
): rc_file(rc
) {
38 auto_raise_delay
.tv_sec
= auto_raise_delay
.tv_usec
= 0;
42 BlackboxResource::~BlackboxResource(void)
43 { delete [] screen_resources
; }
46 void BlackboxResource::load(Blackbox
& blackbox
) {
47 if (screen_resources
== 0) {
48 screen_resources
= new ScreenResource
[blackbox
.screenCount()];
51 bt::Resource
res(rc_file
);
53 menu_file
= bt::expandTilde(res
.read("session.menuFile",
57 style_file
= bt::expandTilde(res
.read("session.styleFile",
61 unsigned int maxcolors
= res
.read("session.maximumColors",
62 "Session.MaximumColors",
65 bt::Image::setMaximumColors(maxcolors
);
67 double_click_interval
= res
.read("session.doubleClickInterval",
68 "Session.DoubleClickInterval",
71 auto_raise_delay
.tv_usec
= res
.read("session.autoRaiseDelay",
72 "Session.AutoRaiseDelay",
75 auto_raise_delay
.tv_sec
= auto_raise_delay
.tv_usec
/ 1000;
76 auto_raise_delay
.tv_usec
-= (auto_raise_delay
.tv_sec
* 1000);
77 auto_raise_delay
.tv_usec
*= 1000;
79 bt::DitherMode dither_mode
;
80 std::string str
= res
.read("session.imageDither",
81 "Session.ImageDither",
83 if (!strcasecmp("ordered", str
.c_str()) ||
84 !strcasecmp("fast", str
.c_str()) ||
85 !strcasecmp("ordereddither", str
.c_str()) ||
86 !strcasecmp("fastdither", str
.c_str())) {
87 dither_mode
= bt::OrderedDither
;
88 } else if (!strcasecmp("floydsteinberg", str
.c_str()) ||
89 !strcasecmp("quality", str
.c_str()) ||
90 !strcasecmp("diffuse", str
.c_str()) ||
91 !strcasecmp("floydsteinbergdither", str
.c_str()) ||
92 !strcasecmp("qualitydither", str
.c_str()) ||
93 !strcasecmp("diffusedither", str
.c_str())) {
94 dither_mode
= bt::FloydSteinbergDither
;
95 } else if (!strcasecmp("no", str
.c_str()) ||
96 !strcasecmp("nodither", str
.c_str()) ||
97 !strcasecmp("off", str
.c_str())) {
98 dither_mode
= bt::NoDither
;
100 dither_mode
= bt::OrderedDither
;
102 bt::Image::setDitherMode(dither_mode
);
105 XCreateFontCursor(blackbox
.XDisplay(), XC_left_ptr
);
107 XCreateFontCursor(blackbox
.XDisplay(), XC_fleur
);
108 _cursors
.resize_top_left
=
109 XCreateFontCursor(blackbox
.XDisplay(), XC_top_left_corner
);
110 _cursors
.resize_bottom_left
=
111 XCreateFontCursor(blackbox
.XDisplay(), XC_bottom_left_corner
);
112 _cursors
.resize_top_right
=
113 XCreateFontCursor(blackbox
.XDisplay(), XC_top_right_corner
);
114 _cursors
.resize_bottom_right
=
115 XCreateFontCursor(blackbox
.XDisplay(), XC_bottom_right_corner
);
118 str
= res
.read("session.focusModel",
119 "Session.FocusModel",
120 res
.read("session.screen0.focusModel",
121 "Session.Screen0.FocusModel",
123 if (str
.find("ClickToFocus") != std::string::npos
) {
124 focus_model
= ClickToFocusModel
;
128 focus_model
= SloppyFocusModel
;
129 auto_raise
= (str
.find("AutoRaise") != std::string::npos
);
130 click_raise
= (str
.find("ClickRaise") != std::string::npos
);
133 str
= res
.read("session.windowPlacement",
134 "Session.WindowPlacement",
135 res
.read("session.screen0.windowPlacement",
136 "Session.Screen0.WindowPlacement",
137 "RowSmartPlacement"));
138 if (strcasecmp(str
.c_str(), "ColSmartPlacement") == 0)
139 window_placement_policy
= ColSmartPlacement
;
140 else if (strcasecmp(str
.c_str(), "CascadePlacement") == 0)
141 window_placement_policy
= CascadePlacement
;
143 window_placement_policy
= RowSmartPlacement
;
145 str
= res
.read("session.rowPlacementDirection",
146 "Session.RowPlacementDirection",
147 res
.read("session.screen0.rowPlacementDirection",
148 "Session.Screen0.RowPlacementDirection",
151 (strcasecmp(str
.c_str(), "righttoleft") == 0) ? RightLeft
: LeftRight
;
153 str
= res
.read("session.colPlacementDirection",
154 "Session.ColPlacementDirection",
155 res
.read("session.screen0.colPlacementDirection",
156 "Session.Screen0.ColPlacementDirection",
159 (strcasecmp(str
.c_str(), "bottomtotop") == 0) ? BottomTop
: TopBottom
;
162 res
.read("session.placementIgnoresShaded",
163 "Session.placementIgnoresShaded",
167 res
.read("session.opaqueMove",
168 "Session.OpaqueMove",
171 res
.read("session.opaqueResize",
172 "Session.OpaqueResize",
175 res
.read("session.fullMaximization",
176 "Session.FullMaximization",
177 res
.read("session.screen0.fullMaximization",
178 "Session.Screen0.FullMaximization",
181 res
.read("session.focusNewWindows",
182 "Session.FocusNewWindows",
183 res
.read("session.screen0.focusNewWindows",
184 "Session.Screen0.FocusNewWindows",
186 focus_last_window_on_workspace
=
187 res
.read("session.focusLastWindow",
188 "Session.focusLastWindow",
189 res
.read("session.screen0.focusLastWindow",
190 "Session.Screen0.focusLastWindow",
193 res
.read("session.disableBindingsWithScrollLock",
194 "Session.disableBindingsWithScrollLock",
195 res
.read("session.screen0.disableBindingsWithScrollLock",
196 "Session.Screen0.disableBindingsWithScrollLock",
198 edge_snap_threshold
=
199 res
.read("session.edgeSnapThreshold",
200 "Session.EdgeSnapThreshold",
201 res
.read("session.screen0.edgeSnapThreshold",
202 "Session.Screen0.EdgeSnapThreshold",
205 for (unsigned int i
= 0; i
< blackbox
.screenCount(); ++i
)
206 screen_resources
[i
].load(res
, i
);
210 void BlackboxResource::save(Blackbox
& blackbox
) {
214 if (bt::Resource(rc_file
).read("session.cacheLife",
219 // we are converting from 0.65.0 to 0.70.0, let's take the liberty
220 // of generating a brand new rc file to make sure we throw out
225 res
.write("session.menuFile", menuFilename());
227 res
.write("session.styleFile", styleFilename());
229 res
.write("session.maximumColors", bt::Image::maximumColors());
231 res
.write("session.doubleClickInterval", double_click_interval
);
233 res
.write("session.autoRaiseDelay", ((auto_raise_delay
.tv_sec
* 1000ul) +
234 (auto_raise_delay
.tv_usec
/ 1000ul)));
237 switch (bt::Image::ditherMode()) {
238 case bt::OrderedDither
: str
= "OrderedDither"; break;
239 case bt::FloydSteinbergDither
: str
= "FloydSteinbergDither"; break;
240 default: str
= "NoDither"; break;
242 res
.write("session.imageDither", str
);
245 switch (focus_model
) {
246 case SloppyFocusModel
:
252 str
+= " ClickRaise";
254 case ClickToFocusModel
:
255 str
= "ClickToFocus";
258 res
.write("session.focusModel", str
);
260 switch (window_placement_policy
) {
261 case CascadePlacement
:
262 str
= "CascadePlacement";
264 case ColSmartPlacement
:
265 str
= "ColSmartPlacement";
267 case RowSmartPlacement
:
269 str
= "RowSmartPlacement";
272 res
.write("session.windowPlacement", str
);
273 res
.write("session.rowPlacementDirection",
274 (row_direction
== LeftRight
)
277 res
.write("session.colPlacementDirection",
278 (col_direction
== TopBottom
)
282 res
.write("session.placementIgnoresShaded", ignore_shaded
);
284 res
.write("session.opaqueMove", opaque_move
);
285 res
.write("session.opaqueResize", opaque_resize
);
286 res
.write("session.fullMaximization", full_max
);
287 res
.write("session.focusNewWindows", focus_new_windows
);
288 res
.write("session.focusLastWindow", focus_last_window_on_workspace
);
289 res
.write("session.disableBindingsWithScrollLock", allow_scroll_lock
);
290 res
.write("session.edgeSnapThreshold", edge_snap_threshold
);
292 for (unsigned int i
= 0; i
< blackbox
.screenCount(); ++i
)
293 screen_resources
[i
].save(res
, blackbox
.screenNumber(i
));