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_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_t rectangle
= { 0, 0, 0, 0, NULL
, 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
].styles
.normal
.bg
);
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
)
169 if(statusbar
->height
<= 0)
170 /* 1.5 as default factor, it fits nice but no one knows why */
171 statusbar
->height
= 1.5 * MAX(globalconf
.screens
[statusbar
->screen
].styles
.normal
.font
->height
,
172 MAX(globalconf
.screens
[statusbar
->screen
].styles
.focus
.font
->height
,
173 globalconf
.screens
[statusbar
->screen
].styles
.urgent
.font
->height
));
177 statusbar_init(Statusbar
*statusbar
)
180 int phys_screen
= get_phys_screen(statusbar
->screen
);
181 area_t area
= screen_get_area(statusbar
->screen
,
182 globalconf
.screens
[statusbar
->screen
].statusbar
,
183 &globalconf
.screens
[statusbar
->screen
].padding
);
186 /* Top and Bottom Statusbar have prio */
187 for(sb
= globalconf
.screens
[statusbar
->screen
].statusbar
; sb
; sb
= sb
->next
)
192 area
.width
+= sb
->height
;
198 if(statusbar
->width
<= 0)
200 if(statusbar
->position
== Right
|| statusbar
->position
== Left
)
201 statusbar
->width
= area
.height
;
203 statusbar
->width
= area
.width
;
206 switch(statusbar
->dposition
)
211 simplewindow_new(globalconf
.display
, phys_screen
, 0, 0,
212 statusbar
->height
, statusbar
->width
, 0);
216 simplewindow_new(globalconf
.display
, phys_screen
, 0, 0,
217 statusbar
->width
, statusbar
->height
, 0);
221 widget_calculate_alignments(statusbar
->widgets
);
223 statusbar_update_position(statusbar
);
225 statusbar_draw(statusbar
);
232 Statusbar
*statusbar
;
235 for(screen
= 0; screen
< globalconf
.screens_info
->nscreen
; screen
++)
236 for(statusbar
= globalconf
.screens
[screen
].statusbar
;
238 statusbar
= statusbar
->next
)
239 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
240 if(widget
->cache
.needs_update
)
242 statusbar_draw(statusbar
);
248 get_statusbar_byname(int screen
, const char *name
)
252 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
253 if(!a_strcmp(sb
->name
, name
))
260 statusbar_toggle(Statusbar
*statusbar
)
262 if(statusbar
->position
== Off
)
263 statusbar
->position
= (statusbar
->dposition
== Off
) ? Top
: statusbar
->dposition
;
265 statusbar
->position
= Off
;
267 statusbar_update_position(statusbar
);
268 globalconf
.screens
[statusbar
->screen
].need_arrange
= True
;
272 * \param screen Screen ID
273 * \param arg statusbar name
274 * \ingroup ui_callback
277 uicb_statusbar_toggle(int screen
, char *arg
)
279 Statusbar
*sb
= get_statusbar_byname(screen
, arg
);
282 statusbar_toggle(sb
);
284 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
285 statusbar_toggle(sb
);
288 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80