]>
Dogcows Code - chaz/openbox/blob - otk/style.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
16 Style::Style() : font(NULL
)
20 Style::Style(BImageControl
*ctrl
)
21 : image_control(ctrl
), font(0),
22 screen_number(ctrl
->getScreenInfo()->screen())
30 if (close_button
.mask
!= None
)
31 XFreePixmap(OBDisplay::display
, close_button
.mask
);
32 if (max_button
.mask
!= None
)
33 XFreePixmap(OBDisplay::display
, max_button
.mask
);
34 if (icon_button
.mask
!= None
)
35 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
36 if (stick_button
.mask
!= None
)
37 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
39 max_button
.mask
= None
;
40 close_button
.mask
= None
;
41 icon_button
.mask
= None
;
42 stick_button
.mask
= None
;
45 void Style::load(const Configuration
&style
) {
48 // load fonts/fontsets
52 font
= readDatabaseFont("window.", style
);
55 t_focus
= readDatabaseTexture("window.title.focus", "white", style
);
56 t_unfocus
= readDatabaseTexture("window.title.unfocus", "black", style
);
58 l_focus
= readDatabaseTexture("window.label.focus", "white", style
);
59 l_unfocus
= readDatabaseTexture("window.label.unfocus", "black", style
);
61 h_focus
= readDatabaseTexture("window.handle.focus", "white", style
);
62 h_unfocus
= readDatabaseTexture("window.handle.unfocus", "black", style
);
64 g_focus
= readDatabaseTexture("window.grip.focus", "white", style
);
65 g_unfocus
= readDatabaseTexture("window.grip.unfocus", "black", style
);
67 b_focus
= readDatabaseTexture("window.button.focus", "white", style
);
68 b_unfocus
= readDatabaseTexture("window.button.unfocus", "black", style
);
70 //if neither of these can be found, we will use the previous resource
71 b_pressed_focus
= readDatabaseTexture("window.button.pressed.focus",
72 "black", style
, true);
73 if (b_pressed_focus
.texture() == BTexture::NoTexture
) {
74 b_pressed_focus
= readDatabaseTexture("window.button.pressed", "black",
78 b_pressed_unfocus
= readDatabaseTexture("window.button.pressed.unfocus",
79 "black", style
, true);
80 if (b_pressed_unfocus
.texture() == BTexture::NoTexture
) {
81 b_pressed_unfocus
= readDatabaseTexture("window.button.pressed", "black",
85 if (close_button
.mask
!= None
)
86 XFreePixmap(OBDisplay::display
, close_button
.mask
);
87 if (max_button
.mask
!= None
)
88 XFreePixmap(OBDisplay::display
, max_button
.mask
);
89 if (icon_button
.mask
!= None
)
90 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
91 if (stick_button
.mask
!= None
)
92 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
94 close_button
.mask
= max_button
.mask
= icon_button
.mask
95 = icon_button
.mask
= None
;
97 readDatabaseMask("window.button.close.mask", close_button
, style
);
98 readDatabaseMask("window.button.max.mask", max_button
, style
);
99 readDatabaseMask("window.button.icon.mask", icon_button
, style
);
100 readDatabaseMask("window.button.stick.mask", stick_button
, style
);
102 // we create the window.frame texture by hand because it exists only to
103 // make the code cleaner and is not actually used for display
104 BColor color
= readDatabaseColor("window.frame.focusColor", "white",
106 f_focus
= BTexture("solid flat", screen_number
, image_control
);
107 f_focus
.setColor(color
);
109 color
= readDatabaseColor("window.frame.unfocusColor", "white", style
);
110 f_unfocus
= BTexture("solid flat", screen_number
, image_control
);
111 f_unfocus
.setColor(color
);
113 l_text_focus
= readDatabaseColor("window.label.focus.textColor",
115 l_text_unfocus
= readDatabaseColor("window.label.unfocus.textColor",
118 b_pic_focus
= readDatabaseColor("window.button.focus.picColor",
120 b_pic_unfocus
= readDatabaseColor("window.button.unfocus.picColor",
123 justify
= LeftJustify
;
125 if (style
.getValue("window.justify", s
)) {
126 if (s
== "right" || s
== "Right")
127 justify
= RightJustify
;
128 else if (s
== "center" || s
== "Center")
129 justify
= CenterJustify
;
133 if (t_focus
.texture() == BTexture::Parent_Relative
)
135 if (t_unfocus
.texture() == BTexture::Parent_Relative
)
136 t_unfocus
= f_unfocus
;
137 if (h_focus
.texture() == BTexture::Parent_Relative
)
139 if (h_unfocus
.texture() == BTexture::Parent_Relative
)
140 h_unfocus
= f_unfocus
;
142 border_color
= readDatabaseColor("borderColor", "black", style
);
144 // load bevel, border and handle widths
146 const ScreenInfo
*s_info
= OBDisplay::screenInfo(screen_number
);
147 unsigned int width
= s_info
->rect().width();
149 if (! style
.getValue("handleWidth", handle_width
) ||
150 handle_width
> width
/2 || handle_width
== 0)
153 if (! style
.getValue("borderWidth", border_width
))
156 if (! style
.getValue("bevelWidth", bevel_width
)
157 || bevel_width
> width
/2 || bevel_width
== 0)
160 if (! style
.getValue("frameWidth", frame_width
)
161 || frame_width
> width
/2)
162 frame_width
= bevel_width
;
164 if (style
.getValue("rootCommand", s
))
165 bexec(s
, s_info
->displayString());
169 void Style::readDatabaseMask(const std::string
&rname
, PixmapMask
&pixmapMask
,
170 const Configuration
&style
) {
171 Window root_window
= OBDisplay::screenInfo(screen_number
)->rootWindow();
173 int hx
, hy
; //ignored
174 int ret
= BitmapOpenFailed
; //default to failure.
176 if (style
.getValue(rname
, s
)) {
177 if (s
[0] != '/' && s
[0] != '~') {
178 std::string xbmFile
= std::string("~/.openbox/buttons/") + s
;
179 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
180 expandTilde(xbmFile
).c_str(), &pixmapMask
.w
,
181 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
183 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
184 expandTilde(s
).c_str(), &pixmapMask
.w
,
185 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
187 if (ret
== BitmapSuccess
)
191 pixmapMask
.mask
= None
;
192 pixmapMask
.w
= pixmapMask
.h
= 0;
196 BTexture
Style::readDatabaseTexture(const std::string
&rname
,
197 const std::string
&default_color
,
198 const Configuration
&style
,
204 if (style
.getValue(rname
, s
))
205 texture
= BTexture(s
);
206 else if (allowNoTexture
) //no default
207 texture
.setTexture(BTexture::NoTexture
);
209 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
211 // associate this texture with this screen
212 texture
.setScreen(screen_number
);
213 texture
.setImageControl(image_control
);
215 if (texture
.texture() != BTexture::NoTexture
) {
216 texture
.setColor(readDatabaseColor(rname
+ ".color", default_color
,
218 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo", default_color
,
220 texture
.setBorderColor(readDatabaseColor(rname
+ ".borderColor",
221 default_color
, style
));
228 BColor
Style::readDatabaseColor(const std::string
&rname
,
229 const std::string
&default_color
,
230 const Configuration
&style
) {
233 if (style
.getValue(rname
, s
))
234 color
= BColor(s
, screen_number
);
236 color
= BColor(default_color
, screen_number
);
241 BFont
*Style::readDatabaseFont(const std::string
&rbasename
,
242 const Configuration
&style
) {
243 std::string fontstring
, s
;
245 // XXX: load all this font stuff from the style...
247 bool dropShadow
= True
;
249 unsigned char offset
= 1;
250 if (style
.getValue(rbasename
+ "xft.shadow.offset", s
)) {
251 offset
= atoi(s
.c_str()); //doesn't detect errors
252 if (offset
> CHAR_MAX
)
256 unsigned char tint
= 0x40;
257 if (style
.getValue(rbasename
+ "xft.shadow.tint", s
)) {
258 tint
= atoi(s
.c_str());
261 fontstring
= "Arial,Sans-9:bold";
263 // if this fails, it ::exit()'s
264 return new BFont(screen_number
, fontstring
, dropShadow
, offset
, tint
);
This page took 0.048805 seconds and 4 git commands to generate.