display layout nmaster/ncols vars in new tags without clients
[awesome.git] / statusbar.c
bloba8891c4c5b6ab670881780bcda6dcbb2872718a0
1 /*
2 * draw.c - draw functions
3 *
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 *
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.
22 #include <stdio.h>
24 #include "layout.h"
25 #include "statusbar.h"
26 #include "draw.h"
27 #include "screen.h"
28 #include "util.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
34 * screen
35 * \param t tag number
36 * \param screen screen number
37 * \return True or False
39 static Bool
40 isoccupied(unsigned int t, int screen)
42 Client *c;
44 for(c = clients; c; c = c->next)
45 if(c->tags[t] && c->screen == screen)
46 return True;
47 return False;
50 void
51 drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf)
53 int x, i;
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]);
65 else
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)
80 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)
86 drawcontext->x = x;
87 if(sel)
89 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->name, drawcontext->sel);
90 if(sel->isfloating)
91 drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->ismax, drawcontext->sel[ColFG]);
93 else if(IS_ARRANGE(layout_tile) || IS_ARRANGE(layout_tileleft))
95 char buf[256];
96 snprintf(buf, sizeof(buf), "nmaster: %d ncols: %d", awesomeconf->nmaster, awesomeconf->ncols);
97 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, buf, drawcontext->norm);
99 else
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);
103 XSync(disp, False);
106 void
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),
128 statusbar->height,
129 DefaultDepth(disp, screen));
132 void
133 updatebarpos(Display *disp, Statusbar statusbar)
135 XEvent ev;
136 ScreenInfo *si;
138 switch (statusbar.position)
140 default:
141 XMoveWindow(disp, statusbar.window, 0, 0);
142 break;
143 case BarBot:
144 si = get_display_info(disp, statusbar.screen, statusbar);
145 XMoveWindow(disp, statusbar.window, 0, si->height);
146 XFree(si);
147 break;
148 case BarOff:
149 XMoveWindow(disp, statusbar.window, 0, 0 - statusbar.height);
150 break;
152 XSync(disp, False);
153 while(XCheckMaskEvent(disp, EnterWindowMask, &ev));
156 void
157 uicb_togglebar(Display *disp,
158 DC *drawcontext,
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;
164 else
165 awesomeconf->statusbar.position = BarOff;
166 updatebarpos(disp, awesomeconf->statusbar);
167 arrange(disp, drawcontext, awesomeconf);