2 * statusbar.c - statusbar functions
4 * Copyright © 2007-2008 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_position_update(Statusbar
*statusbar
)
39 if(statusbar
->position
== Off
)
41 XUnmapWindow(globalconf
.display
, statusbar
->sw
->window
);
45 XMapRaised(globalconf
.display
, statusbar
->sw
->window
);
47 /* Top and Bottom Statusbar have prio */
48 if(statusbar
->position
== Top
|| statusbar
->position
== Bottom
)
49 area
= screen_get_area(statusbar
->screen
,
51 &globalconf
.screens
[statusbar
->screen
].padding
);
53 area
= screen_get_area(statusbar
->screen
,
54 globalconf
.screens
[statusbar
->screen
].statusbar
,
55 &globalconf
.screens
[statusbar
->screen
].padding
);
57 for(sb
= globalconf
.screens
[statusbar
->screen
].statusbar
; sb
&& sb
!= statusbar
; sb
= sb
->next
)
61 if(sb
->position
== statusbar
->position
)
65 if(sb
->position
== statusbar
->position
)
66 area
.height
-= sb
->height
;
69 /* we need to re-add our own value removed in the
70 * screen_get_area computation */
71 if(statusbar
->position
== Left
72 || statusbar
->position
== Right
)
74 area
.x
-= statusbar
->sw
->geometry
.width
;
75 area
.width
+= statusbar
->sw
->geometry
.width
;
79 if(statusbar
->position
== Left
80 || statusbar
->position
== Right
)
81 area
.width
+= statusbar
->sw
->geometry
.width
;
87 switch(statusbar
->position
)
90 simplewindow_move(statusbar
->sw
, area
.x
, area
.y
);
93 simplewindow_move(statusbar
->sw
, area
.x
, (area
.y
+ area
.height
) - statusbar
->sw
->geometry
.height
);
96 simplewindow_move(statusbar
->sw
, area
.x
- statusbar
->sw
->geometry
.width
,
97 (area
.y
+ area
.height
) - statusbar
->sw
->geometry
.height
);
100 simplewindow_move(statusbar
->sw
, area
.x
+ area
.width
, area
.y
);
108 statusbar_draw(Statusbar
*statusbar
)
111 int left
= 0, right
= 0;
112 area_t rectangle
= { 0, 0, 0, 0, NULL
, NULL
};
114 rectangle
.width
= statusbar
->width
;
115 rectangle
.height
= statusbar
->height
;
116 draw_rectangle(statusbar
->ctx
, rectangle
, 1.0, True
,
117 globalconf
.screens
[statusbar
->screen
].styles
.normal
.bg
);
119 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
120 if (widget
->alignment
== AlignLeft
)
122 widget
->cache
.needs_update
= False
;
123 left
+= widget
->draw(widget
, statusbar
->ctx
, left
, (left
+ right
));
126 /* renders right widget from last to first */
127 for(widget
= *widget_list_last(&statusbar
->widgets
);
129 widget
= widget_list_prev(&statusbar
->widgets
, widget
))
130 if (widget
->alignment
== AlignRight
)
132 widget
->cache
.needs_update
= False
;
133 right
+= widget
->draw(widget
, statusbar
->ctx
, right
, (left
+ right
));
136 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
137 if (widget
->alignment
== AlignFlex
)
139 widget
->cache
.needs_update
= False
;
140 left
+= widget
->draw(widget
, statusbar
->ctx
, left
, (left
+ right
));
143 switch(statusbar
->position
)
146 draw_rotate(statusbar
->ctx
, statusbar
->sw
->drawable
,
147 statusbar
->ctx
->height
, statusbar
->ctx
->width
,
148 M_PI_2
, statusbar
->height
, 0);
151 draw_rotate(statusbar
->ctx
, statusbar
->sw
->drawable
,
152 statusbar
->ctx
->height
, statusbar
->ctx
->width
,
153 - M_PI_2
, 0, statusbar
->width
);
159 statusbar_display(statusbar
);
163 statusbar_display(Statusbar
*statusbar
)
165 /* don't waste our time */
166 if(statusbar
->position
!= Off
)
167 simplewindow_refresh_drawable(statusbar
->sw
, statusbar
->phys_screen
);
171 statusbar_preinit(Statusbar
*statusbar
)
173 if(statusbar
->height
<= 0)
174 /* 1.5 as default factor, it fits nice but no one knows why */
175 statusbar
->height
= 1.5 * MAX(globalconf
.screens
[statusbar
->screen
].styles
.normal
.font
->height
,
176 MAX(globalconf
.screens
[statusbar
->screen
].styles
.focus
.font
->height
,
177 globalconf
.screens
[statusbar
->screen
].styles
.urgent
.font
->height
));
181 statusbar_init(Statusbar
*statusbar
)
185 int phys_screen
= screen_virttophys(statusbar
->screen
);
186 area_t area
= screen_get_area(statusbar
->screen
,
187 globalconf
.screens
[statusbar
->screen
].statusbar
,
188 &globalconf
.screens
[statusbar
->screen
].padding
);
190 statusbar
->phys_screen
= phys_screen
;
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
->position
)
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_position_update(statusbar
);
231 switch(statusbar
->position
)
237 /* we need a new pixmap this way [ ] to render */
238 dw
= XCreatePixmap(globalconf
.display
,
239 RootWindow(globalconf
.display
, phys_screen
),
240 statusbar
->width
, statusbar
->height
,
241 DefaultDepth(globalconf
.display
, phys_screen
));
242 statusbar
->ctx
= draw_context_new(globalconf
.display
,
249 statusbar
->ctx
= draw_context_new(globalconf
.display
,
253 statusbar
->sw
->drawable
);
258 statusbar_draw(statusbar
);
265 Statusbar
*statusbar
;
268 for(screen
= 0; screen
< globalconf
.screens_info
->nscreen
; screen
++)
269 for(statusbar
= globalconf
.screens
[screen
].statusbar
;
271 statusbar
= statusbar
->next
)
272 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
273 if(widget
->cache
.needs_update
)
275 statusbar_draw(statusbar
);
281 statusbar_get_byname(int screen
, const char *name
)
285 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
286 if(!a_strcmp(sb
->name
, name
))
293 statusbar_toggle(Statusbar
*statusbar
)
295 if(statusbar
->position
== Off
)
296 statusbar
->position
= (statusbar
->dposition
== Off
) ? Top
: statusbar
->dposition
;
298 statusbar
->position
= Off
;
300 globalconf
.screens
[statusbar
->screen
].need_arrange
= True
;
304 * \param screen Screen ID
305 * \param arg statusbar name
306 * \ingroup ui_callback
309 uicb_statusbar_toggle(int screen
, char *arg
)
311 Statusbar
*sb
= statusbar_get_byname(screen
, arg
);
314 statusbar_toggle(sb
);
316 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
317 statusbar_toggle(sb
);
319 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
320 statusbar_position_update(sb
);
324 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80