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"
30 #include "layouts/tile.h"
32 /** Check if at least a client is tagged with tag number t and is on screen
35 * \param screen screen number
36 * \return True or False
39 isoccupied(Client
**head
, unsigned int t
, int screen
)
43 for(c
= *head
; c
; c
= c
->next
)
44 if(c
->tags
[t
] && c
->screen
== screen
)
50 drawstatusbar(awesome_config
*awesomeconf
)
52 int z
, i
, x
= 0, y
= 0, w
;
53 Client
*sel
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
56 /* don't waste our time */
57 if(awesomeconf
->statusbar
.position
== BarOff
)
60 drawable
= XCreatePixmap(awesomeconf
->display
,
61 RootWindow(awesomeconf
->display
, awesomeconf
->phys_screen
),
62 awesomeconf
->statusbar
.width
,
63 awesomeconf
->statusbar
.width
,
64 DefaultDepth(awesomeconf
->display
, awesomeconf
->phys_screen
));
66 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
68 w
= textwidth(awesomeconf
->display
, awesomeconf
->font
,
69 awesomeconf
->tags
[i
].name
);
70 if(awesomeconf
->tags
[i
].selected
)
72 drawtext(awesomeconf
->display
, awesomeconf
->phys_screen
,
74 awesomeconf
->statusbar
.height
,
76 awesomeconf
->statusbar
.width
,
77 awesomeconf
->statusbar
.height
,
79 awesomeconf
->tags
[i
].name
, awesomeconf
->colors_selected
);
80 if(isoccupied(awesomeconf
->clients
, i
, awesomeconf
->screen
))
81 drawrectangle(awesomeconf
->display
, awesomeconf
->phys_screen
,
83 (awesomeconf
->font
->height
+ 2) / 4,
84 (awesomeconf
->font
->height
+ 2) / 4,
86 awesomeconf
->statusbar
.width
,
87 awesomeconf
->statusbar
.height
,
89 awesomeconf
->colors_selected
[ColFG
]);
93 drawtext(awesomeconf
->display
, awesomeconf
->phys_screen
,
95 awesomeconf
->statusbar
.height
,
97 awesomeconf
->statusbar
.width
,
98 awesomeconf
->statusbar
.height
,
100 awesomeconf
->tags
[i
].name
, awesomeconf
->colors_normal
);
101 if(isoccupied(awesomeconf
->clients
, i
, awesomeconf
->screen
))
102 drawrectangle(awesomeconf
->display
, awesomeconf
->phys_screen
,
104 (awesomeconf
->font
->height
+ 2) / 4,
105 (awesomeconf
->font
->height
+ 2) / 4,
107 awesomeconf
->statusbar
.width
,
108 awesomeconf
->statusbar
.height
,
110 awesomeconf
->colors_normal
[ColFG
]);
114 drawtext(awesomeconf
->display
, awesomeconf
->phys_screen
,
115 x
, y
, awesomeconf
->statusbar
.txtlayoutwidth
,
116 awesomeconf
->statusbar
.height
,
118 awesomeconf
->statusbar
.width
,
119 awesomeconf
->statusbar
.height
,
121 get_current_layout(awesomeconf
->tags
, awesomeconf
->ntags
)->symbol
,
122 awesomeconf
->colors_normal
);
123 z
= x
+ awesomeconf
->statusbar
.txtlayoutwidth
;
124 w
= textwidth(awesomeconf
->display
, awesomeconf
->font
, awesomeconf
->statustext
);
125 x
= awesomeconf
->statusbar
.width
- w
;
129 w
= awesomeconf
->statusbar
.width
- z
;
131 drawtext(awesomeconf
->display
, awesomeconf
->phys_screen
,
133 awesomeconf
->statusbar
.height
,
135 awesomeconf
->statusbar
.width
,
136 awesomeconf
->statusbar
.height
,
138 awesomeconf
->statustext
, awesomeconf
->colors_normal
);
139 if((w
= x
- z
) > awesomeconf
->statusbar
.height
)
142 if(sel
&& sel
->screen
== awesomeconf
->screen
)
144 drawtext(awesomeconf
->display
, awesomeconf
->phys_screen
,
146 awesomeconf
->statusbar
.height
,
148 awesomeconf
->statusbar
.width
,
149 awesomeconf
->statusbar
.height
,
151 sel
->name
, awesomeconf
->colors_selected
);
153 drawcircle(awesomeconf
->display
, awesomeconf
->phys_screen
,
155 (awesomeconf
->font
->height
+ 2) / 4,
157 awesomeconf
->statusbar
.width
,
158 awesomeconf
->statusbar
.height
,
160 awesomeconf
->colors_selected
[ColFG
]);
163 drawtext(awesomeconf
->display
, awesomeconf
->phys_screen
,
165 awesomeconf
->statusbar
.height
,
167 awesomeconf
->statusbar
.width
,
168 awesomeconf
->statusbar
.height
,
170 NULL
, awesomeconf
->colors_normal
);
172 if(awesomeconf
->statusbar
.position
== BarRight
173 || awesomeconf
->statusbar
.position
== BarLeft
)
176 if(awesomeconf
->statusbar
.position
== BarRight
)
177 d
= draw_rotate(awesomeconf
->display
, awesomeconf
->phys_screen
,
178 drawable
, awesomeconf
->statusbar
.width
,
179 awesomeconf
->statusbar
.height
, M_PI_2
,
180 awesomeconf
->statusbar
.height
, 0);
182 d
= draw_rotate(awesomeconf
->display
, awesomeconf
->phys_screen
,
183 drawable
, awesomeconf
->statusbar
.width
,
184 awesomeconf
->statusbar
.height
, - M_PI_2
,
185 0, awesomeconf
->statusbar
.width
);
186 XCopyArea(awesomeconf
->display
, d
,
187 awesomeconf
->statusbar
.window
,
188 DefaultGC(awesomeconf
->display
, awesomeconf
->phys_screen
), 0, 0,
189 awesomeconf
->statusbar
.height
, awesomeconf
->statusbar
.width
, 0, 0);
190 XFreePixmap(awesomeconf
->display
, d
);
193 XCopyArea(awesomeconf
->display
, drawable
,
194 awesomeconf
->statusbar
.window
,
195 DefaultGC(awesomeconf
->display
, awesomeconf
->phys_screen
), 0, 0,
196 awesomeconf
->statusbar
.width
, awesomeconf
->statusbar
.height
, 0, 0);
197 XFreePixmap(awesomeconf
->display
, drawable
);
198 XSync(awesomeconf
->display
, False
);
202 initstatusbar(Display
*disp
, int screen
, Statusbar
*statusbar
, Cursor cursor
, XftFont
*font
, Layout
*layouts
, int nlayouts
)
204 XSetWindowAttributes wa
;
205 int i
, phys_screen
= get_phys_screen(disp
, screen
);
206 ScreenInfo
*si
= get_screen_info(disp
, screen
, NULL
);
208 statusbar
->height
= font
->height
* 1.5;
210 if(statusbar
->position
== BarRight
|| statusbar
->position
== BarLeft
)
211 statusbar
->width
= si
[screen
].height
;
213 statusbar
->width
= si
[screen
].width
;
217 statusbar
->screen
= screen
;
219 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
220 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
222 wa
.override_redirect
= 1;
223 wa
.background_pixmap
= ParentRelative
;
224 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
225 if(statusbar
->dposition
== BarRight
|| statusbar
->dposition
== BarLeft
)
226 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, phys_screen
), 0, 0,
229 0, DefaultDepth(disp
, phys_screen
), CopyFromParent
,
230 DefaultVisual(disp
, phys_screen
),
231 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
233 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, phys_screen
), 0, 0,
236 0, DefaultDepth(disp
, phys_screen
), CopyFromParent
,
237 DefaultVisual(disp
, phys_screen
),
238 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
239 XDefineCursor(disp
, statusbar
->window
, cursor
);
240 updatebarpos(disp
, *statusbar
);
241 XMapRaised(disp
, statusbar
->window
);
243 for(i
= 0; i
< nlayouts
; i
++)
244 statusbar
->txtlayoutwidth
= MAX(statusbar
->txtlayoutwidth
,
245 (textwidth(disp
, font
, layouts
[i
].symbol
)));
249 updatebarpos(Display
*disp
, Statusbar statusbar
)
252 ScreenInfo
*si
= get_screen_info(disp
, statusbar
.screen
, NULL
);
254 XMapRaised(disp
, statusbar
.window
);
255 switch (statusbar
.position
)
258 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].y_org
);
261 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
+ (si
[statusbar
.screen
].width
- statusbar
.height
), si
[statusbar
.screen
].y_org
);
264 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].height
- statusbar
.height
);
267 XUnmapWindow(disp
, statusbar
.window
);
272 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
276 uicb_togglebar(awesome_config
*awesomeconf
,
277 const char *arg
__attribute__ ((unused
)))
279 if(awesomeconf
->statusbar
.position
== BarOff
)
280 awesomeconf
->statusbar
.position
= (awesomeconf
->statusbar
.dposition
== BarOff
) ? BarTop
: awesomeconf
->statusbar
.dposition
;
282 awesomeconf
->statusbar
.position
= BarOff
;
283 updatebarpos(awesomeconf
->display
, awesomeconf
->statusbar
);
284 arrange(awesomeconf
);
289 uicb_setstatustext(awesome_config
*awesomeconf
, const char *arg
)
293 a_strncpy(awesomeconf
->statustext
, sizeof(awesomeconf
->statustext
), arg
, a_strlen(arg
));
295 drawstatusbar(awesomeconf
);
297 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99