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 extern Client
*clients
, *sel
; /* global client list */
33 /** Check if at least a client is tagged with tag number t and is on screen
36 * \param screen screen number
37 * \return True or False
40 isoccupied(unsigned int t
, int screen
)
44 for(c
= clients
; c
; c
= c
->next
)
45 if(c
->tags
[t
] && c
->screen
== screen
)
51 drawstatusbar(Display
*disp
, DC
*drawcontext
, awesome_config
* awesomeconf
)
54 ScreenInfo
*si
= get_screen_info(disp
, awesomeconf
->screen
, NULL
);
56 drawcontext
->x
= drawcontext
->y
= 0;
57 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
59 drawcontext
->w
= textwidth(disp
, drawcontext
->font
, awesomeconf
->tags
[i
].name
, a_strlen(awesomeconf
->tags
[i
].name
)) + drawcontext
->font
->height
;
60 if(awesomeconf
->tags
[i
].selected
)
62 drawtext(disp
, awesomeconf
->phys_screen
, drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->tags
[i
].name
, drawcontext
->sel
, drawcontext
->text_selected
);
63 if(isoccupied(i
, awesomeconf
->screen
))
64 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
&& sel
->tags
[i
], drawcontext
->sel
[ColFG
]);
68 drawtext(disp
, awesomeconf
->phys_screen
, drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->tags
[i
].name
, drawcontext
->norm
, drawcontext
->text_normal
);
69 if(isoccupied(i
, awesomeconf
->screen
))
70 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
&& sel
->tags
[i
], drawcontext
->norm
[ColFG
]);
72 drawcontext
->x
+= drawcontext
->w
;
74 drawcontext
->w
= awesomeconf
->statusbar
.width
;
75 drawtext(disp
, awesomeconf
->phys_screen
, drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->current_layout
->symbol
, drawcontext
->norm
, drawcontext
->text_normal
);
76 x
= drawcontext
->x
+ drawcontext
->w
;
77 drawcontext
->w
= textwidth(disp
, drawcontext
->font
, awesomeconf
->statustext
, a_strlen(awesomeconf
->statustext
)) + drawcontext
->font
->height
;
78 drawcontext
->x
= si
[awesomeconf
->screen
].width
- drawcontext
->w
;
79 if(drawcontext
->x
< x
)
82 drawcontext
->w
= si
[awesomeconf
->screen
].width
- x
;
84 drawtext(disp
, awesomeconf
->phys_screen
, drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->statustext
, drawcontext
->norm
, drawcontext
->text_normal
);
85 if((drawcontext
->w
= drawcontext
->x
- x
) > awesomeconf
->statusbar
.height
)
90 drawtext(disp
, awesomeconf
->phys_screen
, drawcontext
, awesomeconf
->statusbar
.drawable
, sel
->name
, drawcontext
->sel
, drawcontext
->text_selected
);
92 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
->ismax
, drawcontext
->sel
[ColFG
]);
94 else if(IS_ARRANGE(layout_tile
) || IS_ARRANGE(layout_tileleft
))
97 snprintf(buf
, sizeof(buf
), "nmaster: %d ncols: %d mwfact: %.2lf", awesomeconf
->nmaster
, awesomeconf
->ncols
, awesomeconf
->mwfact
);
98 drawtext(disp
, awesomeconf
->phys_screen
, drawcontext
, awesomeconf
->statusbar
.drawable
, buf
, drawcontext
->norm
, drawcontext
->text_normal
);
101 drawtext(disp
, awesomeconf
->phys_screen
, drawcontext
, awesomeconf
->statusbar
.drawable
, NULL
, drawcontext
->norm
, drawcontext
->text_normal
);
103 XCopyArea(disp
, awesomeconf
->statusbar
.drawable
, awesomeconf
->statusbar
.window
, drawcontext
->gc
, 0, 0, si
[awesomeconf
->screen
].width
, awesomeconf
->statusbar
.height
, 0, 0);
108 initstatusbar(Display
*disp
, int screen
, DC
*drawcontext
, Statusbar
*statusbar
)
110 XSetWindowAttributes wa
;
114 phys_screen
= get_phys_screen(disp
, screen
);
116 statusbar
->screen
= screen
;
118 si
= get_screen_info(disp
, screen
, NULL
);
120 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
121 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
122 wa
.cursor
= drawcontext
->cursor
[CurNormal
];
123 wa
.override_redirect
= 1;
124 wa
.background_pixmap
= ParentRelative
;
125 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
126 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, phys_screen
), 0, 0, si
[screen
].width
,
127 statusbar
->height
, 0, DefaultDepth(disp
, phys_screen
), CopyFromParent
,
128 DefaultVisual(disp
, phys_screen
), CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
129 XDefineCursor(disp
, statusbar
->window
, drawcontext
->cursor
[CurNormal
]);
130 updatebarpos(disp
, *statusbar
);
131 XMapRaised(disp
, statusbar
->window
);
132 statusbar
->drawable
= XCreatePixmap(disp
,
133 RootWindow(disp
, phys_screen
),
136 DefaultDepth(disp
, phys_screen
));
140 updatebarpos(Display
*disp
, Statusbar statusbar
)
143 ScreenInfo
*si
= get_screen_info(disp
, statusbar
.screen
, NULL
);
145 switch (statusbar
.position
)
148 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].y_org
);
151 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].height
- statusbar
.height
);
154 XMoveWindow(disp
, statusbar
.window
, si
[statusbar
.screen
].x_org
, si
[statusbar
.screen
].y_org
- statusbar
.height
);
159 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
163 uicb_togglebar(Display
*disp
,
165 awesome_config
*awesomeconf
,
166 const char *arg
__attribute__ ((unused
)))
168 if(awesomeconf
->statusbar
.position
== BarOff
)
169 awesomeconf
->statusbar
.position
= (awesomeconf
->statusbar
.position
== BarOff
) ? BarTop
: awesomeconf
->statusbar_default_position
;
171 awesomeconf
->statusbar
.position
= BarOff
;
172 updatebarpos(disp
, awesomeconf
->statusbar
);
173 arrange(disp
, drawcontext
, awesomeconf
);