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
.height
,
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
, drawable
,
178 awesomeconf
->statusbar
.width
, awesomeconf
->statusbar
.height
,
179 M_PI_2
, awesomeconf
->statusbar
.height
, 0);
181 d
= draw_rotate(awesomeconf
->display
, awesomeconf
->phys_screen
, drawable
,
182 awesomeconf
->statusbar
.width
, awesomeconf
->statusbar
.height
,
183 - M_PI_2
, 0, awesomeconf
->statusbar
.width
);
184 XCopyArea(awesomeconf
->display
, d
,
185 awesomeconf
->statusbar
.window
,
186 DefaultGC(awesomeconf
->display
, awesomeconf
->phys_screen
), 0, 0,
187 awesomeconf
->statusbar
.height
, awesomeconf
->statusbar
.width
, 0, 0);
188 XFreePixmap(awesomeconf
->display
, d
);
191 XCopyArea(awesomeconf
->display
, drawable
,
192 awesomeconf
->statusbar
.window
,
193 DefaultGC(awesomeconf
->display
, awesomeconf
->phys_screen
), 0, 0,
194 awesomeconf
->statusbar
.width
, awesomeconf
->statusbar
.height
, 0, 0);
195 XFreePixmap(awesomeconf
->display
, drawable
);
196 XSync(awesomeconf
->display
, False
);
200 initstatusbar(Display
*disp
, int screen
, Statusbar
*statusbar
, Cursor cursor
, XftFont
*font
, Layout
*layouts
, int nlayouts
)
202 XSetWindowAttributes wa
;
203 int i
, phys_screen
= get_phys_screen(disp
, screen
);
204 ScreenInfo
*si
= get_screen_info(disp
, screen
, NULL
);
206 statusbar
->height
= font
->height
* 1.5;
208 if(statusbar
->position
== BarRight
|| statusbar
->position
== BarLeft
)
209 statusbar
->width
= si
[screen
].height
;
211 statusbar
->width
= si
[screen
].width
;
215 statusbar
->screen
= screen
;
217 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
218 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
220 wa
.override_redirect
= 1;
221 wa
.background_pixmap
= ParentRelative
;
222 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
223 if(statusbar
->dposition
== BarRight
|| statusbar
->dposition
== BarLeft
)
224 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, phys_screen
), 0, 0,
227 0, DefaultDepth(disp
, phys_screen
), CopyFromParent
,
228 DefaultVisual(disp
, phys_screen
),
229 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
231 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, phys_screen
), 0, 0,
234 0, DefaultDepth(disp
, phys_screen
), CopyFromParent
,
235 DefaultVisual(disp
, phys_screen
),
236 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
237 XDefineCursor(disp
, statusbar
->window
, cursor
);
238 updatebarpos(disp
, *statusbar
);
239 XMapRaised(disp
, statusbar
->window
);
241 for(i
= 0; i
< nlayouts
; i
++)
242 statusbar
->txtlayoutwidth
= MAX(statusbar
->txtlayoutwidth
,
243 (textwidth(disp
, font
, layouts
[i
].symbol
)));
247 updatebarpos(Display
*disp
, Statusbar statusbar
)
250 ScreenInfo
*si
= get_screen_info(disp
, statusbar
.screen
, NULL
);
252 XMapRaised(disp
, statusbar
.window
);
253 switch (statusbar
.position
)
256 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].y_org
);
259 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
+ (si
[statusbar
.screen
].width
- statusbar
.height
), si
[statusbar
.screen
].y_org
);
262 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].height
- statusbar
.height
);
265 XUnmapWindow(disp
, statusbar
.window
);
270 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
274 uicb_togglebar(awesome_config
*awesomeconf
,
275 const char *arg
__attribute__ ((unused
)))
277 if(awesomeconf
->statusbar
.position
== BarOff
)
278 awesomeconf
->statusbar
.position
= (awesomeconf
->statusbar
.dposition
== BarOff
) ? BarTop
: awesomeconf
->statusbar
.dposition
;
280 awesomeconf
->statusbar
.position
= BarOff
;
281 updatebarpos(awesomeconf
->display
, awesomeconf
->statusbar
);
282 arrange(awesomeconf
);
287 uicb_setstatustext(awesome_config
*awesomeconf
, const char *arg
)
291 a_strncpy(awesomeconf
->statustext
, sizeof(awesomeconf
->statustext
), arg
, a_strlen(arg
));
293 drawstatusbar(awesomeconf
);
295 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99