]>
Dogcows Code - chaz/openbox/blob - style.cc
277924d6d9b4e63d90f94c3af57b67d95efde838
3 #endif // HAVE_CONFIG_H
14 Style::Style() : font(NULL
)
18 Style::Style(BImageControl
*ctrl
)
19 : image_control(ctrl
), font(0),
20 screen_number(ctrl
->getScreenInfo()->getScreenNumber())
28 if (close_button
.mask
!= None
)
29 XFreePixmap(OBDisplay::display
, close_button
.mask
);
30 if (max_button
.mask
!= None
)
31 XFreePixmap(OBDisplay::display
, max_button
.mask
);
32 if (icon_button
.mask
!= None
)
33 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
34 if (stick_button
.mask
!= None
)
35 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
37 max_button
.mask
= None
;
38 close_button
.mask
= None
;
39 icon_button
.mask
= None
;
40 stick_button
.mask
= None
;
43 void Style::load(const Configuration
&style
) {
46 // load fonts/fontsets
50 font
= readDatabaseFont("window.", style
);
53 t_focus
= readDatabaseTexture("window.title.focus", "white", style
);
54 t_unfocus
= readDatabaseTexture("window.title.unfocus", "black", style
);
56 l_focus
= readDatabaseTexture("window.label.focus", "white", style
);
57 l_unfocus
= readDatabaseTexture("window.label.unfocus", "black", style
);
59 h_focus
= readDatabaseTexture("window.handle.focus", "white", style
);
60 h_unfocus
= readDatabaseTexture("window.handle.unfocus", "black", style
);
62 g_focus
= readDatabaseTexture("window.grip.focus", "white", style
);
63 g_unfocus
= readDatabaseTexture("window.grip.unfocus", "black", style
);
65 b_focus
= readDatabaseTexture("window.button.focus", "white", style
);
66 b_unfocus
= readDatabaseTexture("window.button.unfocus", "black", style
);
67 b_pressed
= readDatabaseTexture("window.button.pressed", "black", style
);
69 //if neither of these can be found, we will use the previous resource
70 b_pressed_focus
= readDatabaseTexture("window.button.pressed.focus",
71 "black", style
, true);
72 b_pressed_unfocus
= readDatabaseTexture("window.button.pressed.unfocus",
73 "black", style
, true);
75 if (close_button
.mask
!= None
)
76 XFreePixmap(OBDisplay::display
, close_button
.mask
);
77 if (max_button
.mask
!= None
)
78 XFreePixmap(OBDisplay::display
, max_button
.mask
);
79 if (icon_button
.mask
!= None
)
80 XFreePixmap(OBDisplay::display
, icon_button
.mask
);
81 if (stick_button
.mask
!= None
)
82 XFreePixmap(OBDisplay::display
, stick_button
.mask
);
84 close_button
.mask
= max_button
.mask
= icon_button
.mask
85 = icon_button
.mask
= None
;
87 readDatabaseMask("window.button.close.mask", close_button
, style
);
88 readDatabaseMask("window.button.max.mask", max_button
, style
);
89 readDatabaseMask("window.button.icon.mask", icon_button
, style
);
90 readDatabaseMask("window.button.stick.mask", stick_button
, style
);
92 // we create the window.frame texture by hand because it exists only to
93 // make the code cleaner and is not actually used for display
94 BColor color
= readDatabaseColor("window.frame.focusColor", "white",
96 f_focus
= BTexture("solid flat", screen_number
, image_control
);
97 f_focus
.setColor(color
);
99 color
= readDatabaseColor("window.frame.unfocusColor", "white", style
);
100 f_unfocus
= BTexture("solid flat", screen_number
, image_control
);
101 f_unfocus
.setColor(color
);
103 l_text_focus
= readDatabaseColor("window.label.focus.textColor",
105 l_text_unfocus
= readDatabaseColor("window.label.unfocus.textColor",
108 b_pic_focus
= readDatabaseColor("window.button.focus.picColor",
110 b_pic_unfocus
= readDatabaseColor("window.button.unfocus.picColor",
113 justify
= LeftJustify
;
115 if (style
.getValue("window.justify", s
)) {
116 if (s
== "right" || s
== "Right")
117 justify
= RightJustify
;
118 else if (s
== "center" || s
== "Center")
119 justify
= CenterJustify
;
123 if (t_focus
.texture() == BTexture::Parent_Relative
)
125 if (t_unfocus
.texture() == BTexture::Parent_Relative
)
126 t_unfocus
= f_unfocus
;
127 if (h_focus
.texture() == BTexture::Parent_Relative
)
129 if (h_unfocus
.texture() == BTexture::Parent_Relative
)
130 h_unfocus
= f_unfocus
;
132 border_color
= readDatabaseColor("borderColor", "black", style
);
134 // load bevel, border and handle widths
136 const ScreenInfo
*s_info
= OBDisplay::screenInfo(screen_number
);
137 unsigned int width
= s_info
->getRect().width();
139 if (! style
.getValue("handleWidth", handle_width
) ||
140 handle_width
> width
/2 || handle_width
== 0)
143 if (! style
.getValue("borderWidth", border_width
))
146 if (! style
.getValue("bevelWidth", bevel_width
)
147 || bevel_width
> width
/2 || bevel_width
== 0)
150 if (! style
.getValue("frameWidth", frame_width
)
151 || frame_width
> width
/2)
152 frame_width
= bevel_width
;
154 if (style
.getValue("rootCommand", s
))
155 bexec(s
, s_info
->displayString());
159 void Style::readDatabaseMask(const std::string
&rname
, PixmapMask
&pixmapMask
,
160 const Configuration
&style
) {
161 Window root_window
= OBDisplay::screenInfo(screen_number
)->getRootWindow();
163 int hx
, hy
; //ignored
164 int ret
= BitmapOpenFailed
; //default to failure.
166 if (style
.getValue(rname
, s
))
168 if (s
[0] != '/' && s
[0] != '~')
170 std::string xbmFile
= std::string("~/.openbox/buttons/") + s
;
171 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
172 expandTilde(xbmFile
).c_str(), &pixmapMask
.w
,
173 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
175 ret
= XReadBitmapFile(OBDisplay::display
, root_window
,
176 expandTilde(s
).c_str(), &pixmapMask
.w
,
177 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
179 if (ret
== BitmapSuccess
)
183 pixmapMask
.mask
= None
;
184 pixmapMask
.w
= pixmapMask
.h
= 0;
188 BTexture
Style::readDatabaseTexture(const std::string
&rname
,
189 const std::string
&default_color
,
190 const Configuration
&style
,
196 if (style
.getValue(rname
, s
))
197 texture
= BTexture(s
);
198 else if (allowNoTexture
) //no default
199 texture
.setTexture(BTexture::NoTexture
);
201 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
203 // associate this texture with this screen
204 texture
.setScreen(screen_number
);
205 texture
.setImageControl(image_control
);
207 if (texture
.texture() != BTexture::NoTexture
) {
208 texture
.setColor(readDatabaseColor(rname
+ ".color", default_color
,
210 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo", default_color
,
212 texture
.setBorderColor(readDatabaseColor(rname
+ ".borderColor",
213 default_color
, style
));
220 BColor
Style::readDatabaseColor(const std::string
&rname
,
221 const std::string
&default_color
,
222 const Configuration
&style
) {
225 if (style
.getValue(rname
, s
))
226 color
= BColor(s
, screen_number
);
228 color
= BColor(default_color
, screen_number
);
233 BFont
*Style::readDatabaseFont(const std::string
&rbasename
,
234 const Configuration
&style
) {
235 std::string fontname
;
240 if (style
.getValue(rbasename
+ "xft.font", s
) &&
241 style
.getValue(rbasename
+ "xft.size", i
)) {
242 std::string family
= s
;
245 bool dropShadow
= False
;
247 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
248 if (s
.find("bold") != std::string::npos
)
250 if (s
.find("italic") != std::string::npos
)
252 if (s
.find("shadow") != std::string::npos
)
256 unsigned char offset
= 1;
257 if (style
.getValue(rbasename
+ "xft.shadow.offset", s
)) {
258 offset
= atoi(s
.c_str()); //doesn't detect errors
259 if (offset
> CHAR_MAX
)
263 unsigned char tint
= 0x40;
264 if (style
.getValue(rbasename
+ "xft.shadow.tint", s
)) {
265 tint
= atoi(s
.c_str());
269 BFont
*b
= new BFont(screen_number
, family
, i
, bold
, italic
,
270 dropShadow
&& shadow_fonts
,
271 offset
, tint
, aa_fonts
);
277 if (style
.getValue(rbasename
+ "xft.font", s
))
278 printf("Unable to load font \"%s\". Exiting\n", s
.c_str());
280 printf("Font not defined by style. Exiting\n");
281 exit(2); // can't continue without a font
This page took 0.050205 seconds and 3 git commands to generate.