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
);
63 XSync(globalconf
.display
, False
);
67 statusbar_draw(Statusbar
*statusbar
)
69 int phys_screen
= get_phys_screen(statusbar
->screen
);
70 Widget
*widget
, *last_drawn
= NULL
;
71 int left
= 0, right
= 0;
73 /* don't waste our time */
74 if(statusbar
->position
== Off
)
77 XFreePixmap(globalconf
.display
, statusbar
->drawable
);
79 DrawCtx
*ctx
= draw_get_context(phys_screen
,
83 draw_rectangle(ctx
, 0, 0, statusbar
->width
, statusbar
->height
, True
,
84 globalconf
.screens
[statusbar
->screen
].colors_normal
[ColBG
]);
86 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
87 if (widget
->alignment
== AlignLeft
)
89 widget
->cache
.needs_update
= False
;
90 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
93 /* renders right widget from last to first */
94 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
95 if (widget
->alignment
== AlignRight
&& last_drawn
== widget
->next
)
97 widget
->cache
.needs_update
= False
;
98 right
+= widget
->draw(widget
, ctx
, right
, (left
+ right
));
100 widget
= statusbar
->widgets
;
103 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
104 if (widget
->alignment
== AlignFlex
)
106 widget
->cache
.needs_update
= False
;
107 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
110 if(statusbar
->position
== Right
111 || statusbar
->position
== Left
)
113 if(statusbar
->position
== Right
)
114 statusbar
->drawable
= draw_rotate(ctx
, phys_screen
, M_PI_2
, statusbar
->height
, 0);
116 statusbar
->drawable
= draw_rotate(ctx
, phys_screen
, - M_PI_2
, 0, statusbar
->width
);
118 draw_free_context(ctx
);
122 statusbar
->drawable
= ctx
->drawable
;
123 /* just delete the struct, don't delete the drawable */
127 statusbar_display(statusbar
);
131 statusbar_display(Statusbar
*statusbar
)
133 int phys_screen
= get_phys_screen(statusbar
->screen
);
135 /* don't waste our time */
136 if(statusbar
->position
== Off
)
139 if(statusbar
->position
== Right
140 || statusbar
->position
== Left
)
141 XCopyArea(globalconf
.display
, statusbar
->drawable
,
143 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
145 statusbar
->width
, 0, 0);
147 XCopyArea(globalconf
.display
, statusbar
->drawable
,
149 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
150 statusbar
->width
, statusbar
->height
, 0, 0);
154 statusbar_init(Statusbar
*statusbar
, int screen
)
157 XSetWindowAttributes wa
;
158 int phys_screen
= get_phys_screen(screen
);
159 Area area
= get_screen_area(statusbar
->screen
,
161 &globalconf
.screens
[screen
].padding
);
163 if(statusbar
->height
<= 0)
165 /* 1.5 as default factor, it fits nice but no one know why */
166 statusbar
->height
= globalconf
.screens
[screen
].font
->height
* 1.5;
168 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
170 statusbar
->height
= MAX(statusbar
->height
, widget
->font
->height
* 1.5);
173 if(statusbar
->width
<= 0)
175 if(statusbar
->position
== Right
|| statusbar
->position
== Left
)
176 statusbar
->width
= area
.height
;
178 statusbar
->width
= area
.width
;
181 statusbar
->screen
= screen
;
183 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
184 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
185 wa
.cursor
= globalconf
.cursor
[CurNormal
];
186 wa
.override_redirect
= 1;
187 wa
.background_pixmap
= ParentRelative
;
188 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
189 if(statusbar
->dposition
== Right
|| statusbar
->dposition
== Left
)
190 statusbar
->window
= XCreateWindow(globalconf
.display
,
191 RootWindow(globalconf
.display
,
197 DefaultDepth(globalconf
.display
,
200 DefaultVisual(globalconf
.display
,
207 statusbar
->window
= XCreateWindow(globalconf
.display
,
208 RootWindow(globalconf
.display
,
214 DefaultDepth(globalconf
.display
,
217 DefaultVisual(globalconf
.display
,
224 statusbar
->drawable
= XCreatePixmap(globalconf
.display
,
225 RootWindow(globalconf
.display
, phys_screen
),
226 statusbar
->width
, statusbar
->height
,
227 DefaultDepth(globalconf
.display
, phys_screen
));
230 XDefineCursor(globalconf
.display
,
232 globalconf
.cursor
[CurNormal
]);
234 widget_calculate_alignments(statusbar
->widgets
);
236 statusbar_update_position(statusbar
);
237 XMapRaised(globalconf
.display
, statusbar
->window
);
239 statusbar_draw(statusbar
);
246 Statusbar
*statusbar
;
249 for(screen
= 0; screen
< get_screen_count(); screen
++)
250 for(statusbar
= globalconf
.screens
[screen
].statusbar
;
252 statusbar
= statusbar
->next
)
253 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
254 if(widget
->cache
.needs_update
)
256 statusbar_draw(statusbar
);
262 statusbar_get_position_from_str(const char *pos
)
264 if(!a_strncmp(pos
, "off", 3))
266 else if(!a_strncmp(pos
, "bottom", 6))
268 else if(!a_strncmp(pos
, "right", 5))
270 else if(!a_strncmp(pos
, "left", 4))
276 get_statusbar_byname(int screen
, const char *name
)
280 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
281 if(!a_strcmp(sb
->name
, name
))
288 statusbar_toggle(Statusbar
*statusbar
)
290 if(statusbar
->position
== Off
)
291 statusbar
->position
= (statusbar
->dposition
== Off
) ? Top
: statusbar
->dposition
;
293 statusbar
->position
= Off
;
295 statusbar_update_position(statusbar
);
299 * \param screen Screen ID
300 * \param arg statusbar name
301 * \ingroup ui_callback
304 uicb_statusbar_toggle(int screen
, char *arg
)
306 Statusbar
*sb
= get_statusbar_byname(screen
, arg
);
309 statusbar_toggle(sb
);
311 for(sb
= globalconf
.screens
[screen
].statusbar
; sb
; sb
= sb
->next
)
312 statusbar_toggle(sb
);
317 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80