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
)
38 XMapRaised(globalconf
.display
, statusbar
->sw
->window
);
40 /* Top and Bottom Statusbar have prio */
41 if(statusbar
->position
== Top
|| statusbar
->position
== Bottom
)
42 area
= screen_get_area(statusbar
->screen
,
44 &globalconf
.screens
[statusbar
->screen
].padding
);
46 area
= screen_get_area(statusbar
->screen
,
47 globalconf
.screens
[statusbar
->screen
].statusbar
,
48 &globalconf
.screens
[statusbar
->screen
].padding
);
50 switch(statusbar
->position
)
53 simplewindow_move(statusbar
->sw
, area
.x
, area
.y
);
56 simplewindow_move(statusbar
->sw
, area
.x
, (area
.y
+ area
.height
) - statusbar
->sw
->geometry
.height
);
59 simplewindow_move(statusbar
->sw
, area
.x
- statusbar
->sw
->geometry
.width
,
60 (area
.y
+ area
.height
) - statusbar
->sw
->geometry
.height
);
63 simplewindow_move(statusbar
->sw
, area
.x
+ area
.width
, area
.y
);
66 XUnmapWindow(globalconf
.display
, statusbar
->sw
->window
);
72 statusbar_draw(Statusbar
*statusbar
)
74 int phys_screen
= get_phys_screen(statusbar
->screen
);
76 int left
= 0, right
= 0;
77 Area rectangle
= { 0, 0, 0, 0, NULL
};
80 /* don't waste our time */
81 switch(statusbar
->position
)
88 /* we need a new pixmap this way [ ] to render */
89 XFreePixmap(globalconf
.display
, statusbar
->sw
->drawable
);
90 d
= XCreatePixmap(globalconf
.display
,
91 RootWindow(globalconf
.display
, phys_screen
),
92 statusbar
->width
, statusbar
->height
,
93 DefaultDepth(globalconf
.display
, phys_screen
));
94 statusbar
->sw
->drawable
= d
;
100 DrawCtx
*ctx
= draw_context_new(globalconf
.display
,
104 statusbar
->sw
->drawable
);
106 rectangle
.width
= statusbar
->width
;
107 rectangle
.height
= statusbar
->height
;
108 draw_rectangle(ctx
, rectangle
, True
,
109 globalconf
.screens
[statusbar
->screen
].colors_normal
[ColBG
]);
111 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
112 if (widget
->alignment
== AlignLeft
)
114 widget
->cache
.needs_update
= False
;
115 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
118 /* renders right widget from last to first */
119 for(widget
= *widget_list_last(&statusbar
->widgets
);
121 widget
= widget_list_prev(&statusbar
->widgets
, widget
))
122 if (widget
->alignment
== AlignRight
)
124 widget
->cache
.needs_update
= False
;
125 right
+= widget
->draw(widget
, ctx
, right
, (left
+ right
));
128 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
129 if (widget
->alignment
== AlignFlex
)
131 widget
->cache
.needs_update
= False
;
132 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
135 switch(statusbar
->position
)
138 d
= draw_rotate(ctx
, phys_screen
, M_PI_2
,
139 statusbar
->height
, 0);
140 XFreePixmap(globalconf
.display
, statusbar
->sw
->drawable
);
141 statusbar
->sw
->drawable
= d
;
144 d
= draw_rotate(ctx
, phys_screen
, - M_PI_2
,
145 0, statusbar
->width
);
146 XFreePixmap(globalconf
.display
, statusbar
->sw
->drawable
);
147 statusbar
->sw
->drawable
= d
;
153 draw_context_delete(ctx
);
155 statusbar_display(statusbar
);
159 statusbar_display(Statusbar
*statusbar
)
161 /* don't waste our time */
162 if(statusbar
->position
!= Off
)
163 simplewindow_refresh_drawable(statusbar
->sw
, get_phys_screen(statusbar
->screen
));
167 statusbar_preinit(Statusbar
*statusbar
)
171 if(statusbar
->height
<= 0)
173 /* 1.5 as default factor, it fits nice but no one know why */
174 statusbar
->height
= globalconf
.screens
[statusbar
->screen
].font
->height
* 1.5;
176 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
178 statusbar
->height
= MAX(statusbar
->height
, widget
->font
->height
* 1.5);
183 statusbar_init(Statusbar
*statusbar
)
186 int phys_screen
= get_phys_screen(statusbar
->screen
);
187 Area area
= screen_get_area(statusbar
->screen
,
188 globalconf
.screens
[statusbar
->screen
].statusbar
,
189 &globalconf
.screens
[statusbar
->screen
].padding
);
192 /* Top and Bottom Statusbar have prio */
193 for(sb
= globalconf
.screens
[statusbar
->screen
].statusbar
; sb
; sb
= sb
->next
)
198 area
.width
+= sb
->height
;
204 if(statusbar
->width
<= 0)
206 if(statusbar
->position
== Right
|| statusbar
->position
== Left
)
207 statusbar
->width
= area
.height
;
209 statusbar
->width
= area
.width
;
212 switch(statusbar
->dposition
)
217 simplewindow_new(globalconf
.display
, phys_screen
, 0, 0,
218 statusbar
->height
, statusbar
->width
, 0);
222 simplewindow_new(globalconf
.display
, phys_screen
, 0, 0,
223 statusbar
->width
, statusbar
->height
, 0);
227 widget_calculate_alignments(statusbar
->widgets
);
229 statusbar_update_position(statusbar
);
231 statusbar_draw(statusbar
);
238 Statusbar
*statusbar
;
241 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
242 for(statusbar
= globalconf
.screens
[screen
].statusbar
;
244 statusbar
= statusbar
->next
)
245 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
246 if(widget
->cache
.needs_update
)
248 statusbar_draw(statusbar
);
254 statusbar_get_position_from_str(const char *pos
)
256 if(!a_strncmp(pos
, "off", 3))
258 else if(!a_strncmp(pos
, "bottom", 6))
260 else if(!a_strncmp(pos
, "right", 5))
262 else if(!a_strncmp(pos
, "left", 4))
268 get_statusbar_byname(int screen
, const char *name
)
272 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
273 if(!a_strcmp(sb
->name
, name
))
280 statusbar_toggle(Statusbar
*statusbar
)
282 if(statusbar
->position
== Off
)
283 statusbar
->position
= (statusbar
->dposition
== Off
) ? Top
: statusbar
->dposition
;
285 statusbar
->position
= Off
;
287 statusbar_update_position(statusbar
);
288 globalconf
.screens
[statusbar
->screen
].need_arrange
= True
;
292 * \param screen Screen ID
293 * \param arg statusbar name
294 * \ingroup ui_callback
297 uicb_statusbar_toggle(int screen
, char *arg
)
299 Statusbar
*sb
= get_statusbar_byname(screen
, arg
);
302 statusbar_toggle(sb
);
304 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
305 statusbar_toggle(sb
);
308 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80