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(globalconf
.display
, 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
);
91 XCopyArea(globalconf
.display
, d
,
92 vscreen
.statusbar
->window
,
93 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
94 vscreen
.statusbar
->height
,
95 vscreen
.statusbar
->width
, 0, 0);
96 XFreePixmap(globalconf
.display
, d
);
99 XCopyArea(globalconf
.display
, ctx
->drawable
,
100 vscreen
.statusbar
->window
,
101 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
102 vscreen
.statusbar
->width
, vscreen
.statusbar
->height
, 0, 0);
104 draw_free_context(ctx
);
105 XSync(globalconf
.display
, False
);
109 statusbar_init(int screen
)
111 XSetWindowAttributes wa
;
112 int phys_screen
= get_phys_screen(screen
);
113 Area area
= get_screen_area(screen
,
115 &globalconf
.screens
[screen
].padding
);
116 Statusbar
*statusbar
= globalconf
.screens
[screen
].statusbar
;
118 statusbar
->height
= globalconf
.screens
[screen
].font
->height
* 1.5;
120 if(statusbar
->position
== BarRight
|| statusbar
->position
== BarLeft
)
121 statusbar
->width
= area
.height
;
123 statusbar
->width
= area
.width
;
125 statusbar
->screen
= screen
;
127 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
128 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
129 wa
.cursor
= globalconf
.cursor
[CurNormal
];
130 wa
.override_redirect
= 1;
131 wa
.background_pixmap
= ParentRelative
;
132 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
133 if(statusbar
->dposition
== BarRight
|| statusbar
->dposition
== BarLeft
)
134 statusbar
->window
= XCreateWindow(globalconf
.display
,
135 RootWindow(globalconf
.display
,
141 DefaultDepth(globalconf
.display
,
144 DefaultVisual(globalconf
.display
,
151 statusbar
->window
= XCreateWindow(globalconf
.display
,
152 RootWindow(globalconf
.display
,
158 DefaultDepth(globalconf
.display
,
161 DefaultVisual(globalconf
.display
,
167 XDefineCursor(globalconf
.display
,
169 globalconf
.cursor
[CurNormal
]);
171 widget_calculate_alignments(statusbar
->widgets
);
173 statusbar_update_position(screen
);
174 XMapRaised(globalconf
.display
, statusbar
->window
);
178 statusbar_update_position(int screen
)
181 Statusbar
*statusbar
= globalconf
.screens
[screen
].statusbar
;
182 Area area
= get_screen_area(statusbar
->screen
,
184 &globalconf
.screens
[screen
].padding
);
186 XMapRaised(globalconf
.display
, statusbar
->window
);
187 switch (statusbar
->position
)
190 XMoveWindow(globalconf
.display
,
196 XMoveWindow(globalconf
.display
,
198 area
.x
+ (area
.width
- statusbar
->height
),
202 XMoveWindow(globalconf
.display
,
205 area
.height
- statusbar
->height
);
208 XUnmapWindow(globalconf
.display
, statusbar
->window
);
211 XSync(globalconf
.display
, False
);
212 while(XCheckMaskEvent(globalconf
.display
, EnterWindowMask
, &ev
));
216 statusbar_get_position_from_str(const char * pos
)
218 if(!a_strncmp(pos
, "off", 3))
220 else if(!a_strncmp(pos
, "bottom", 6))
222 else if(!a_strncmp(pos
, "right", 5))
224 else if(!a_strncmp(pos
, "left", 4))
230 * \param screen Screen ID
232 * \ingroup ui_callback
235 uicb_statusbar_toggle(int screen
, char *arg
__attribute__ ((unused
)))
237 if(globalconf
.screens
[screen
].statusbar
->position
== BarOff
)
238 globalconf
.screens
[screen
].statusbar
->position
= (globalconf
.screens
[screen
].statusbar
->dposition
== BarOff
) ? BarTop
: globalconf
.screens
[screen
].statusbar
->dposition
;
240 globalconf
.screens
[screen
].statusbar
->position
= BarOff
;
241 statusbar_update_position(screen
);
245 /** Set statusbar position
246 * \param screen Screen ID
247 * \param arg off | bottom | right | left | top
248 * \ingroup ui_callback
251 uicb_statusbar_set_position(int screen
, char *arg
)
253 globalconf
.screens
[screen
].statusbar
->dposition
=
254 globalconf
.screens
[screen
].statusbar
->position
=
255 statusbar_get_position_from_str(arg
);
256 statusbar_update_position(screen
);
259 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80