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
, *stack
; /* global client list and stack */
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
)
55 drawcontext
->x
= drawcontext
->y
= 0;
56 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
58 drawcontext
->w
= textw(drawcontext
->font
.set
, drawcontext
->font
.xfont
, awesomeconf
->tags
[i
].name
, drawcontext
->font
.height
);
59 if(awesomeconf
->tags
[i
].selected
)
61 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->tags
[i
].name
, drawcontext
->sel
);
62 if(isoccupied(i
, awesomeconf
->screen
))
63 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
&& sel
->tags
[i
], drawcontext
->sel
[ColFG
]);
67 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->tags
[i
].name
, drawcontext
->norm
);
68 if(isoccupied(i
, awesomeconf
->screen
))
69 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
&& sel
->tags
[i
], drawcontext
->norm
[ColFG
]);
71 drawcontext
->x
+= drawcontext
->w
;
73 drawcontext
->w
= awesomeconf
->statusbar
.width
;
74 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->current_layout
->symbol
, drawcontext
->norm
);
75 x
= drawcontext
->x
+ drawcontext
->w
;
76 drawcontext
->w
= textw(drawcontext
->font
.set
, drawcontext
->font
.xfont
, awesomeconf
->statustext
, drawcontext
->font
.height
);
77 drawcontext
->x
= DisplayWidth(disp
, awesomeconf
->screen
) - drawcontext
->w
;
78 if(drawcontext
->x
< x
)
81 drawcontext
->w
= DisplayWidth(disp
, awesomeconf
->screen
) - x
;
83 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->statustext
, drawcontext
->norm
);
84 if((drawcontext
->w
= drawcontext
->x
- x
) > awesomeconf
->statusbar
.height
)
89 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
->name
, drawcontext
->sel
);
91 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
->ismax
, drawcontext
->sel
[ColFG
]);
93 else if(IS_ARRANGE(layout_tile
) || IS_ARRANGE(layout_tileleft
))
96 snprintf(buf
, sizeof(buf
), "nmaster: %d ncols: %d", awesomeconf
->nmaster
, awesomeconf
->ncols
);
97 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, buf
, drawcontext
->norm
);
100 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, NULL
, drawcontext
->norm
);
102 XCopyArea(disp
, awesomeconf
->statusbar
.drawable
, awesomeconf
->statusbar
.window
, drawcontext
->gc
, 0, 0, DisplayWidth(disp
, awesomeconf
->screen
), awesomeconf
->statusbar
.height
, 0, 0);
107 initstatusbar(Display
*disp
, int screen
, DC
*drawcontext
, Statusbar
*statusbar
)
109 XSetWindowAttributes wa
;
111 statusbar
->screen
= screen
;
113 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
114 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
115 wa
.cursor
= drawcontext
->cursor
[CurNormal
];
116 wa
.override_redirect
= 1;
117 wa
.background_pixmap
= ParentRelative
;
118 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
119 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, screen
), 0, 0, DisplayWidth(disp
, screen
),
120 statusbar
->height
, 0, DefaultDepth(disp
, screen
), CopyFromParent
,
121 DefaultVisual(disp
, screen
), CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
122 XDefineCursor(disp
, statusbar
->window
, drawcontext
->cursor
[CurNormal
]);
123 updatebarpos(disp
, *statusbar
);
124 XMapRaised(disp
, statusbar
->window
);
125 statusbar
->drawable
= XCreatePixmap(disp
,
126 RootWindow(disp
, screen
),
127 DisplayWidth(disp
, screen
),
129 DefaultDepth(disp
, screen
));
133 updatebarpos(Display
*disp
, Statusbar statusbar
)
138 switch (statusbar
.position
)
141 XMoveWindow(disp
, statusbar
.window
, 0, 0);
144 si
= get_display_info(disp
, statusbar
.screen
, statusbar
);
145 XMoveWindow(disp
, statusbar
.window
, 0, si
->height
);
149 XMoveWindow(disp
, statusbar
.window
, 0, 0 - statusbar
.height
);
153 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
157 uicb_togglebar(Display
*disp
,
159 awesome_config
*awesomeconf
,
160 const char *arg
__attribute__ ((unused
)))
162 if(awesomeconf
->statusbar
.position
== BarOff
)
163 awesomeconf
->statusbar
.position
= (awesomeconf
->statusbar
.position
== BarOff
) ? BarTop
: awesomeconf
->statusbar_default_position
;
165 awesomeconf
->statusbar
.position
= BarOff
;
166 updatebarpos(disp
, awesomeconf
->statusbar
);
167 arrange(disp
, drawcontext
, awesomeconf
);