]>
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(ImageControl
*ctrl
)
21 : image_control(ctrl
), font(0),
22 screen_number(ctrl
->getScreenInfo()->screen())
30 if (close_button
.mask
!= None
)
31 XFreePixmap(**display
, close_button
.mask
);
32 if (max_button
.mask
!= None
)
33 XFreePixmap(**display
, max_button
.mask
);
34 if (icon_button
.mask
!= None
)
35 XFreePixmap(**display
, icon_button
.mask
);
36 if (stick_button
.mask
!= None
)
37 XFreePixmap(**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() == Texture::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() == Texture::NoTexture
) {
81 b_pressed_unfocus
= readDatabaseTexture("window.button.pressed", "black",
85 if (close_button
.mask
!= None
)
86 XFreePixmap(**display
, close_button
.mask
);
87 if (max_button
.mask
!= None
)
88 XFreePixmap(**display
, max_button
.mask
);
89 if (icon_button
.mask
!= None
)
90 XFreePixmap(**display
, icon_button
.mask
);
91 if (stick_button
.mask
!= None
)
92 XFreePixmap(**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 Color color
= readDatabaseColor("window.frame.focusColor", "white",
106 f_focus
= Texture("solid flat", screen_number
, image_control
);
107 f_focus
.setColor(color
);
109 color
= readDatabaseColor("window.frame.unfocusColor", "white", style
);
110 f_unfocus
= Texture("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() == Texture::Parent_Relative
)
135 if (t_unfocus
.texture() == Texture::Parent_Relative
)
136 t_unfocus
= f_unfocus
;
137 if (h_focus
.texture() == Texture::Parent_Relative
)
139 if (h_unfocus
.texture() == Texture::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
= display
->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
= display
->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(**display
, root_window
,
180 expandTilde(xbmFile
).c_str(), &pixmapMask
.w
,
181 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
182 if (ret
!= BitmapSuccess
) {
183 xbmFile
= std::string(BUTTONSDIR
) + "/" + s
;
184 ret
= XReadBitmapFile(**display
, root_window
,
185 xbmFile
.c_str(), &pixmapMask
.w
,
186 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
189 ret
= XReadBitmapFile(**display
, root_window
,
190 expandTilde(s
).c_str(), &pixmapMask
.w
,
191 &pixmapMask
.h
, &pixmapMask
.mask
, &hx
, &hy
);
193 if (ret
== BitmapSuccess
)
197 pixmapMask
.mask
= None
;
198 pixmapMask
.w
= pixmapMask
.h
= 0;
202 Texture
Style::readDatabaseTexture(const std::string
&rname
,
203 const std::string
&default_color
,
204 const Configuration
&style
,
210 if (style
.getValue(rname
, s
))
211 texture
= Texture(s
);
212 else if (allowNoTexture
) //no default
213 texture
.setTexture(Texture::NoTexture
);
215 texture
.setTexture(Texture::Solid
| Texture::Flat
);
217 // associate this texture with this screen
218 texture
.setScreen(screen_number
);
219 texture
.setImageControl(image_control
);
221 if (texture
.texture() != Texture::NoTexture
) {
222 texture
.setColor(readDatabaseColor(rname
+ ".color", default_color
,
224 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo", default_color
,
226 texture
.setBorderColor(readDatabaseColor(rname
+ ".borderColor",
227 default_color
, style
));
234 Color
Style::readDatabaseColor(const std::string
&rname
,
235 const std::string
&default_color
,
236 const Configuration
&style
) {
239 if (style
.getValue(rname
, s
))
240 color
= Color(s
, screen_number
);
242 color
= Color(default_color
, screen_number
);
247 Font
*Style::readDatabaseFont(const std::string
&rbasename
,
248 const Configuration
&style
) {
249 std::string fontstring
, s
;
251 // XXX: load all this font stuff from the style...
253 bool dropShadow
= True
;
255 unsigned char offset
= 1;
256 if (style
.getValue(rbasename
+ "xft.shadow.offset", s
)) {
257 offset
= atoi(s
.c_str()); //doesn't detect errors
258 if (offset
> CHAR_MAX
)
262 unsigned char tint
= 0x40;
263 if (style
.getValue(rbasename
+ "xft.shadow.tint", s
)) {
264 tint
= atoi(s
.c_str());
267 fontstring
= "Arial,Sans-9:bold";
269 // if this fails, it ::exit()'s
270 return new Font(screen_number
, fontstring
, dropShadow
, offset
, tint
);
This page took 0.044431 seconds and 4 git commands to generate.