2 * statusbar.c - statusbar functions
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "statusbar.h"
31 extern AwesomeConf globalconf
;
34 statusbar_update_position(Statusbar
*statusbar
)
36 Area area
= get_screen_area(statusbar
->screen
,
38 &globalconf
.screens
[statusbar
->screen
].padding
);
40 XMapRaised(globalconf
.display
, statusbar
->window
);
41 switch(statusbar
->position
)
44 XMoveWindow(globalconf
.display
, statusbar
->window
,
48 XMoveWindow(globalconf
.display
, statusbar
->window
,
49 area
.x
, (area
.y
+ area
.height
) - statusbar
->width
);
52 XMoveWindow(globalconf
.display
, statusbar
->window
,
53 area
.x
+ (area
.width
- statusbar
->height
), area
.y
);
56 XMoveWindow(globalconf
.display
, statusbar
->window
,
57 area
.x
, area
.height
- statusbar
->height
);
60 XUnmapWindow(globalconf
.display
, statusbar
->window
);
66 statusbar_draw(Statusbar
*statusbar
)
68 int phys_screen
= get_phys_screen(statusbar
->screen
);
69 Widget
*widget
, *last_drawn
= NULL
;
70 int left
= 0, right
= 0;
72 /* don't waste our time */
73 if(statusbar
->position
== Off
)
76 XFreePixmap(globalconf
.display
, statusbar
->drawable
);
78 DrawCtx
*ctx
= draw_get_context(phys_screen
,
82 draw_rectangle(ctx
, 0, 0, statusbar
->width
, statusbar
->height
, True
,
83 globalconf
.screens
[statusbar
->screen
].colors_normal
[ColBG
]);
85 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
86 if (widget
->alignment
== AlignLeft
)
88 widget
->cache
.needs_update
= False
;
89 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
92 /* renders right widget from last to first */
93 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
94 if (widget
->alignment
== AlignRight
&& last_drawn
== widget
->next
)
96 widget
->cache
.needs_update
= False
;
97 right
+= widget
->draw(widget
, ctx
, right
, (left
+ right
));
99 widget
= statusbar
->widgets
;
102 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
103 if (widget
->alignment
== AlignFlex
)
105 widget
->cache
.needs_update
= False
;
106 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
109 if(statusbar
->position
== Right
110 || statusbar
->position
== Left
)
112 if(statusbar
->position
== Right
)
113 statusbar
->drawable
= draw_rotate(ctx
, phys_screen
, M_PI_2
, statusbar
->height
, 0);
115 statusbar
->drawable
= draw_rotate(ctx
, phys_screen
, - M_PI_2
, 0, statusbar
->width
);
117 draw_free_context(ctx
);
121 statusbar
->drawable
= ctx
->drawable
;
122 /* just delete the struct, don't delete the drawable */
126 statusbar_display(statusbar
);
130 statusbar_display(Statusbar
*statusbar
)
132 int phys_screen
= get_phys_screen(statusbar
->screen
);
134 /* don't waste our time */
135 if(statusbar
->position
== Off
)
138 if(statusbar
->position
== Right
139 || statusbar
->position
== Left
)
140 XCopyArea(globalconf
.display
, statusbar
->drawable
,
142 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
144 statusbar
->width
, 0, 0);
146 XCopyArea(globalconf
.display
, statusbar
->drawable
,
148 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
149 statusbar
->width
, statusbar
->height
, 0, 0);
153 statusbar_init(Statusbar
*statusbar
, int screen
)
156 XSetWindowAttributes wa
;
157 int phys_screen
= get_phys_screen(screen
);
158 Area area
= get_screen_area(statusbar
->screen
,
160 &globalconf
.screens
[screen
].padding
);
162 if(statusbar
->height
<= 0)
164 /* 1.5 as default factor, it fits nice but no one know why */
165 statusbar
->height
= globalconf
.screens
[screen
].font
->height
* 1.5;
167 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
169 statusbar
->height
= MAX(statusbar
->height
, widget
->font
->height
* 1.5);
172 if(statusbar
->width
<= 0)
174 if(statusbar
->position
== Right
|| statusbar
->position
== Left
)
175 statusbar
->width
= area
.height
;
177 statusbar
->width
= area
.width
;
180 statusbar
->screen
= screen
;
182 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
183 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
184 wa
.cursor
= globalconf
.cursor
[CurNormal
];
185 wa
.override_redirect
= 1;
186 wa
.background_pixmap
= ParentRelative
;
187 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
188 if(statusbar
->dposition
== Right
|| statusbar
->dposition
== Left
)
189 statusbar
->window
= XCreateWindow(globalconf
.display
,
190 RootWindow(globalconf
.display
,
196 DefaultDepth(globalconf
.display
,
199 DefaultVisual(globalconf
.display
,
206 statusbar
->window
= XCreateWindow(globalconf
.display
,
207 RootWindow(globalconf
.display
,
213 DefaultDepth(globalconf
.display
,
216 DefaultVisual(globalconf
.display
,
223 statusbar
->drawable
= XCreatePixmap(globalconf
.display
,
224 RootWindow(globalconf
.display
, phys_screen
),
225 statusbar
->width
, statusbar
->height
,
226 DefaultDepth(globalconf
.display
, phys_screen
));
229 XDefineCursor(globalconf
.display
,
231 globalconf
.cursor
[CurNormal
]);
233 widget_calculate_alignments(statusbar
->widgets
);
235 statusbar_update_position(statusbar
);
236 XMapRaised(globalconf
.display
, statusbar
->window
);
238 statusbar_draw(statusbar
);
245 Statusbar
*statusbar
;
248 for(screen
= 0; screen
< globalconf
.nscreens
; screen
++)
249 for(statusbar
= globalconf
.screens
[screen
].statusbar
;
251 statusbar
= statusbar
->next
)
252 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
253 if(widget
->cache
.needs_update
)
255 statusbar_draw(statusbar
);
261 statusbar_get_position_from_str(const char *pos
)
263 if(!a_strncmp(pos
, "off", 3))
265 else if(!a_strncmp(pos
, "bottom", 6))
267 else if(!a_strncmp(pos
, "right", 5))
269 else if(!a_strncmp(pos
, "left", 4))
275 get_statusbar_byname(int screen
, const char *name
)
279 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
280 if(!a_strcmp(sb
->name
, name
))
287 statusbar_toggle(Statusbar
*statusbar
)
289 if(statusbar
->position
== Off
)
290 statusbar
->position
= (statusbar
->dposition
== Off
) ? Top
: statusbar
->dposition
;
292 statusbar
->position
= Off
;
294 statusbar_update_position(statusbar
);
298 * \param screen Screen ID
299 * \param arg statusbar name
300 * \ingroup ui_callback
303 uicb_statusbar_toggle(int screen
, char *arg
)
305 Statusbar
*sb
= get_statusbar_byname(screen
, arg
);
308 statusbar_toggle(sb
);
310 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
311 statusbar_toggle(sb
);
316 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80