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.
26 #include "statusbar.h"
33 extern AwesomeConf globalconf
;
36 statusbar_draw(int screen
)
38 int phys_screen
= get_phys_screen(screen
);
40 Widget
*widget
, *last_drawn
= NULL
;
41 int left
= 0, right
= 0;
43 vscreen
= globalconf
.screens
[screen
];
44 /* don't waste our time */
45 if(vscreen
.statusbar
->position
== BarOff
)
48 DrawCtx
*ctx
= draw_get_context(phys_screen
,
49 vscreen
.statusbar
->width
,
50 vscreen
.statusbar
->height
);
54 vscreen
.statusbar
->width
,
55 vscreen
.statusbar
->height
,
57 vscreen
.colors_normal
[ColBG
]);
58 for(widget
= vscreen
.statusbar
->widgets
; widget
; widget
= widget
->next
)
59 if (widget
->alignment
== AlignLeft
)
60 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
62 /* renders right widget from last to first */
63 for(widget
= vscreen
.statusbar
->widgets
; widget
; widget
= widget
->next
)
64 if (widget
->alignment
== AlignRight
&& last_drawn
== widget
->next
)
66 right
+= widget
->draw(widget
, ctx
, right
, (left
+ right
));
68 widget
= vscreen
.statusbar
->widgets
;
71 for(widget
= vscreen
.statusbar
->widgets
; widget
; widget
= widget
->next
)
72 if (widget
->alignment
== AlignFlex
)
73 left
+= widget
->draw(widget
, ctx
, left
, (left
+ right
));
75 if(vscreen
.statusbar
->position
== BarRight
76 || vscreen
.statusbar
->position
== BarLeft
)
79 if(vscreen
.statusbar
->position
== BarRight
)
83 vscreen
.statusbar
->height
,
90 vscreen
.statusbar
->width
);
92 vscreen
.statusbar
->drawable
= d
;
93 draw_free_context(ctx
);
97 vscreen
.statusbar
->drawable
= ctx
->drawable
;
98 /* just delete the struct, don't delete the drawable */
103 statusbar_display(screen
);
108 statusbar_display(int screen
)
110 VirtScreen vscreen
= globalconf
.screens
[screen
];
111 int phys_screen
= get_phys_screen(screen
);
113 if(vscreen
.statusbar
->position
== BarRight
114 || vscreen
.statusbar
->position
== BarLeft
)
115 XCopyArea(globalconf
.display
, vscreen
.statusbar
->drawable
,
116 vscreen
.statusbar
->window
,
117 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
118 vscreen
.statusbar
->height
,
119 vscreen
.statusbar
->width
, 0, 0);
121 XCopyArea(globalconf
.display
, vscreen
.statusbar
->drawable
,
122 vscreen
.statusbar
->window
,
123 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
124 vscreen
.statusbar
->width
, vscreen
.statusbar
->height
, 0, 0);
128 statusbar_init(int screen
)
131 XSetWindowAttributes wa
;
132 int phys_screen
= get_phys_screen(screen
);
133 Area area
= get_screen_area(screen
,
135 &globalconf
.screens
[screen
].padding
);
136 Statusbar
*statusbar
= globalconf
.screens
[screen
].statusbar
;
138 statusbar
->height
= globalconf
.screens
[screen
].font
->height
* 1.5;
140 for(widget
= statusbar
->widgets
; widget
; widget
= widget
->next
)
142 statusbar
->height
= MAX(statusbar
->height
, widget
->font
->height
);
144 if(statusbar
->position
== BarRight
|| statusbar
->position
== BarLeft
)
145 statusbar
->width
= area
.height
;
147 statusbar
->width
= area
.width
;
149 statusbar
->screen
= screen
;
151 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
152 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
153 wa
.cursor
= globalconf
.cursor
[CurNormal
];
154 wa
.override_redirect
= 1;
155 wa
.background_pixmap
= ParentRelative
;
156 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
157 if(statusbar
->dposition
== BarRight
|| statusbar
->dposition
== BarLeft
)
158 statusbar
->window
= XCreateWindow(globalconf
.display
,
159 RootWindow(globalconf
.display
,
165 DefaultDepth(globalconf
.display
,
168 DefaultVisual(globalconf
.display
,
175 statusbar
->window
= XCreateWindow(globalconf
.display
,
176 RootWindow(globalconf
.display
,
182 DefaultDepth(globalconf
.display
,
185 DefaultVisual(globalconf
.display
,
192 statusbar
->drawable
= XCreatePixmap(globalconf
.display
,
193 RootWindow(globalconf
.display
, phys_screen
),
194 statusbar
->width
, statusbar
->height
,
195 DefaultDepth(globalconf
.display
, phys_screen
));
198 XDefineCursor(globalconf
.display
,
200 globalconf
.cursor
[CurNormal
]);
202 widget_calculate_alignments(statusbar
->widgets
);
204 statusbar_update_position(screen
);
205 XMapRaised(globalconf
.display
, statusbar
->window
);
209 statusbar_update_position(int screen
)
212 Statusbar
*statusbar
= globalconf
.screens
[screen
].statusbar
;
213 Area area
= get_screen_area(statusbar
->screen
,
215 &globalconf
.screens
[screen
].padding
);
217 XMapRaised(globalconf
.display
, statusbar
->window
);
218 switch (statusbar
->position
)
221 XMoveWindow(globalconf
.display
,
227 XMoveWindow(globalconf
.display
,
229 area
.x
+ (area
.width
- statusbar
->height
),
233 XMoveWindow(globalconf
.display
,
236 area
.height
- statusbar
->height
);
239 XUnmapWindow(globalconf
.display
, statusbar
->window
);
242 XSync(globalconf
.display
, False
);
243 while(XCheckMaskEvent(globalconf
.display
, EnterWindowMask
, &ev
));
247 statusbar_get_position_from_str(const char * pos
)
249 if(!a_strncmp(pos
, "off", 3))
251 else if(!a_strncmp(pos
, "bottom", 6))
253 else if(!a_strncmp(pos
, "right", 5))
255 else if(!a_strncmp(pos
, "left", 4))
261 * \param screen Screen ID
263 * \ingroup ui_callback
266 uicb_statusbar_toggle(int screen
, char *arg
__attribute__ ((unused
)))
268 if(globalconf
.screens
[screen
].statusbar
->position
== BarOff
)
269 globalconf
.screens
[screen
].statusbar
->position
= (globalconf
.screens
[screen
].statusbar
->dposition
== BarOff
) ? BarTop
: globalconf
.screens
[screen
].statusbar
->dposition
;
271 globalconf
.screens
[screen
].statusbar
->position
= BarOff
;
272 statusbar_update_position(screen
);
276 /** Set statusbar position
277 * \param screen Screen ID
278 * \param arg off | bottom | right | left | top
279 * \ingroup ui_callback
282 uicb_statusbar_set_position(int screen
, char *arg
)
284 globalconf
.screens
[screen
].statusbar
->dposition
=
285 globalconf
.screens
[screen
].statusbar
->position
=
286 statusbar_get_position_from_str(arg
);
287 statusbar_update_position(screen
);
290 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80