2 * draw.c - draw 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"
29 #include "layouts/tile.h"
31 /** Check if at least a client is tagged with tag number t and is on screen
34 * \param screen screen number
35 * \return True or False
38 isoccupied(Client
**head
, unsigned int t
, int screen
)
42 for(c
= *head
; c
; c
= c
->next
)
43 if(c
->tags
[t
] && c
->screen
== screen
)
49 drawstatusbar(Display
*disp
, awesome_config
* awesomeconf
)
51 int z
, i
, x
= 0, y
= 0, w
;
53 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
55 w
= textwidth(disp
, awesomeconf
->font
,
56 awesomeconf
->tags
[i
].name
, a_strlen(awesomeconf
->tags
[i
].name
))
57 + awesomeconf
->font
->height
;
58 if(awesomeconf
->tags
[i
].selected
)
60 drawtext(disp
, awesomeconf
->phys_screen
,
62 awesomeconf
->statusbar
.height
,
63 awesomeconf
->statusbar
.drawable
,
64 awesomeconf
->statusbar
.width
,
65 awesomeconf
->statusbar
.height
,
67 awesomeconf
->tags
[i
].name
, awesomeconf
->colors_selected
);
68 if(isoccupied(awesomeconf
->clients
, i
, awesomeconf
->screen
))
69 drawrectangle(disp
, awesomeconf
->phys_screen
,
71 (awesomeconf
->font
->height
+ 2) / 4,
72 (awesomeconf
->font
->height
+ 2) / 4,
73 awesomeconf
->statusbar
.drawable
,
74 awesomeconf
->statusbar
.width
,
75 awesomeconf
->statusbar
.height
,
76 *awesomeconf
->client_sel
&& (*awesomeconf
->client_sel
)->tags
[i
],
77 awesomeconf
->colors_selected
[ColFG
]);
81 drawtext(disp
, awesomeconf
->phys_screen
,
83 awesomeconf
->statusbar
.height
,
84 awesomeconf
->statusbar
.drawable
,
85 awesomeconf
->statusbar
.width
,
86 awesomeconf
->statusbar
.height
,
88 awesomeconf
->tags
[i
].name
, awesomeconf
->colors_normal
);
89 if(isoccupied(awesomeconf
->clients
, i
, awesomeconf
->screen
))
90 drawrectangle(disp
, awesomeconf
->phys_screen
,
92 (awesomeconf
->font
->height
+ 2) / 4,
93 (awesomeconf
->font
->height
+ 2) / 4,
94 awesomeconf
->statusbar
.drawable
,
95 awesomeconf
->statusbar
.width
,
96 awesomeconf
->statusbar
.height
,
97 *awesomeconf
->client_sel
&& (*awesomeconf
->client_sel
)->tags
[i
],
98 awesomeconf
->colors_normal
[ColFG
]);
102 drawtext(disp
, awesomeconf
->phys_screen
,
103 x
, y
, awesomeconf
->statusbar
.txtlayoutwidth
,
104 awesomeconf
->statusbar
.height
,
105 awesomeconf
->statusbar
.drawable
,
106 awesomeconf
->statusbar
.width
,
107 awesomeconf
->statusbar
.height
,
109 awesomeconf
->current_layout
->symbol
, awesomeconf
->colors_normal
);
110 z
= x
+ awesomeconf
->statusbar
.txtlayoutwidth
;
111 w
= textwidth(disp
, awesomeconf
->font
, awesomeconf
->statustext
, a_strlen(awesomeconf
->statustext
))
112 + awesomeconf
->font
->height
;
113 x
= awesomeconf
->statusbar
.width
- w
;
117 w
= awesomeconf
->statusbar
.width
- z
;
119 drawtext(disp
, awesomeconf
->phys_screen
,
121 awesomeconf
->statusbar
.height
,
122 awesomeconf
->statusbar
.drawable
,
123 awesomeconf
->statusbar
.width
,
124 awesomeconf
->statusbar
.height
,
126 awesomeconf
->statustext
, awesomeconf
->colors_normal
);
127 if((w
= x
- z
) > awesomeconf
->statusbar
.height
)
130 if(*awesomeconf
->client_sel
)
132 drawtext(disp
, awesomeconf
->phys_screen
,
134 awesomeconf
->statusbar
.height
,
135 awesomeconf
->statusbar
.drawable
,
136 awesomeconf
->statusbar
.width
,
137 awesomeconf
->statusbar
.height
,
139 (*awesomeconf
->client_sel
)->name
, awesomeconf
->colors_selected
);
140 if((*awesomeconf
->client_sel
)->isfloating
)
141 drawcircle(disp
, awesomeconf
->phys_screen
,
143 (awesomeconf
->font
->height
+ 2) / 4,
144 awesomeconf
->statusbar
.drawable
,
145 awesomeconf
->statusbar
.width
,
146 awesomeconf
->statusbar
.height
,
147 (*awesomeconf
->client_sel
)->ismax
,
148 awesomeconf
->colors_selected
[ColFG
]);
150 else if(IS_ARRANGE(0, layout_tile
) || IS_ARRANGE(0, layout_tileleft
))
153 snprintf(buf
, sizeof(buf
), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf
->nmaster
, awesomeconf
->ncol
, awesomeconf
->mwfact
);
154 drawtext(disp
, awesomeconf
->phys_screen
,
156 awesomeconf
->statusbar
.height
,
157 awesomeconf
->statusbar
.drawable
,
158 awesomeconf
->statusbar
.width
,
159 awesomeconf
->statusbar
.height
,
161 buf
, awesomeconf
->colors_normal
);
164 drawtext(disp
, awesomeconf
->phys_screen
,
166 awesomeconf
->statusbar
.height
,
167 awesomeconf
->statusbar
.drawable
,
168 awesomeconf
->statusbar
.width
,
169 awesomeconf
->statusbar
.height
,
171 NULL
, awesomeconf
->colors_normal
);
173 XCopyArea(disp
, awesomeconf
->statusbar
.drawable
,
174 awesomeconf
->statusbar
.window
, DefaultGC(disp
, awesomeconf
->phys_screen
), 0, 0,
175 awesomeconf
->statusbar
.width
, awesomeconf
->statusbar
.height
, 0, 0);
180 initstatusbar(Display
*disp
, int screen
, Statusbar
*statusbar
, Cursor cursor
, XftFont
*font
, Layout
*layouts
, int nlayouts
)
182 XSetWindowAttributes wa
;
183 int i
, phys_screen
= get_phys_screen(disp
, screen
);
184 ScreenInfo
*si
= get_screen_info(disp
, screen
, NULL
);
186 statusbar
->width
= si
[screen
].width
;
187 statusbar
->height
= font
->height
+ 2;
190 statusbar
->screen
= screen
;
192 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
193 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
195 wa
.override_redirect
= 1;
196 wa
.background_pixmap
= ParentRelative
;
197 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
198 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, phys_screen
), 0, 0,
201 0, DefaultDepth(disp
, phys_screen
), CopyFromParent
,
202 DefaultVisual(disp
, phys_screen
),
203 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
204 XDefineCursor(disp
, statusbar
->window
, cursor
);
205 updatebarpos(disp
, *statusbar
);
206 XMapRaised(disp
, statusbar
->window
);
207 statusbar
->drawable
= XCreatePixmap(disp
,
208 RootWindow(disp
, phys_screen
),
211 DefaultDepth(disp
, phys_screen
));
213 for(i
= 0; i
< nlayouts
; i
++)
214 statusbar
->txtlayoutwidth
= MAX(statusbar
->txtlayoutwidth
,
215 (font
->height
+ textwidth(disp
, font
, layouts
[i
].symbol
, a_strlen(layouts
[i
].symbol
))));
219 updatebarpos(Display
*disp
, Statusbar statusbar
)
222 ScreenInfo
*si
= get_screen_info(disp
, statusbar
.screen
, NULL
);
224 switch (statusbar
.position
)
227 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].y_org
);
230 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].height
- statusbar
.height
);
233 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].y_org
- statusbar
.height
);
238 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
242 uicb_togglebar(awesome_config
*awesomeconf
,
243 const char *arg
__attribute__ ((unused
)))
245 if(awesomeconf
->statusbar
.position
== BarOff
)
246 awesomeconf
->statusbar
.position
= (awesomeconf
->statusbar_default_position
== BarOff
) ? BarTop
: awesomeconf
->statusbar_default_position
;
248 awesomeconf
->statusbar
.position
= BarOff
;
249 updatebarpos(awesomeconf
->display
, awesomeconf
->statusbar
);
250 arrange(awesomeconf
->display
, awesomeconf
);
255 uicb_setstatustext(awesome_config
*awesomeconf
, const char *arg
)
259 a_strncpy(awesomeconf
->statustext
, sizeof(awesomeconf
->statustext
), arg
, a_strlen(arg
));
261 drawstatusbar(awesomeconf
->display
, awesomeconf
);
263 // vim: filetype=c:expandtab:shiftwidth=6:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99