arrange() on maximize()
[awesome.git] / statusbar.c
blobcc92a442c7cfaba12cd61033a3c7cc9c27cefc6f
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 "layout.h"
23 #include "statusbar.h"
24 #include "draw.h"
25 #include "screen.h"
26 #include "util.h"
28 extern Client *clients, *sel, *stack; /* global client list and stack */
30 /** Check if at least a client is tagged with tag number t and is on screen
31 * screen
32 * \param t tag number
33 * \param screen screen number
34 * \return True or False
36 static Bool
37 isoccupied(unsigned int t, int screen)
39 Client *c;
41 for(c = clients; c; c = c->next)
42 if(c->tags[t] && c->screen == screen)
43 return True;
44 return False;
47 void
48 drawstatusbar(Display *disp, int screen, DC *drawcontext, awesome_config * awesomeconf)
50 int x, i;
51 drawcontext->x = drawcontext->y = 0;
52 for(i = 0; i < awesomeconf->ntags; i++)
54 drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i], drawcontext->font.height);
55 if(awesomeconf->selected_tags[i])
57 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->sel);
58 if(isoccupied(i, screen))
59 drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->sel[ColFG]);
61 else
63 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->norm);
64 if(isoccupied(i, screen))
65 drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->norm[ColFG]);
67 drawcontext->x += drawcontext->w;
69 drawcontext->w = awesomeconf->statusbar.width;
70 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->current_layout->symbol, drawcontext->norm);
71 x = drawcontext->x + drawcontext->w;
72 drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->statustext, drawcontext->font.height);
73 drawcontext->x = DisplayWidth(disp, screen) - drawcontext->w;
74 if(drawcontext->x < x)
76 drawcontext->x = x;
77 drawcontext->w = DisplayWidth(disp, screen) - x;
79 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->statustext, drawcontext->norm);
80 if((drawcontext->w = drawcontext->x - x) > awesomeconf->statusbar.height)
82 drawcontext->x = x;
83 if(sel)
85 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->name, drawcontext->sel);
86 if(sel->isfloating)
87 drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->ismax, drawcontext->sel[ColFG]);
89 else
90 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, NULL, drawcontext->norm);
92 XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, screen), awesomeconf->statusbar.height, 0, 0);
93 XSync(disp, False);
96 void
97 initstatusbar(Display *disp, int screen, DC *drawcontext, Statusbar *statusbar)
99 XSetWindowAttributes wa;
101 statusbar->screen = screen;
103 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
104 | EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
105 wa.cursor = drawcontext->cursor[CurNormal];
106 wa.override_redirect = 1;
107 wa.background_pixmap = ParentRelative;
108 wa.event_mask = ButtonPressMask | ExposureMask;
109 statusbar->window = XCreateWindow(disp, RootWindow(disp, screen), 0, 0, DisplayWidth(disp, screen),
110 statusbar->height, 0, DefaultDepth(disp, screen), CopyFromParent,
111 DefaultVisual(disp, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
112 XDefineCursor(disp, statusbar->window, drawcontext->cursor[CurNormal]);
113 updatebarpos(disp, *statusbar);
114 XMapRaised(disp, statusbar->window);
115 statusbar->drawable = XCreatePixmap(disp,
116 RootWindow(disp, screen),
117 DisplayWidth(disp, screen),
118 statusbar->height,
119 DefaultDepth(disp, screen));
122 void
123 updatebarpos(Display *disp, Statusbar statusbar)
125 XEvent ev;
126 ScreenInfo *si;
128 switch (statusbar.position)
130 default:
131 XMoveWindow(disp, statusbar.window, 0, 0);
132 break;
133 case BarBot:
134 si = get_display_info(disp, statusbar.screen, statusbar);
135 XMoveWindow(disp, statusbar.window, 0, si->height);
136 XFree(si);
137 break;
138 case BarOff:
139 XMoveWindow(disp, statusbar.window, 0, 0 - statusbar.height);
140 break;
142 XSync(disp, False);
143 while(XCheckMaskEvent(disp, EnterWindowMask, &ev));
146 void
147 uicb_togglebar(Display *disp,
148 DC *drawcontext,
149 awesome_config *awesomeconf,
150 const char *arg __attribute__ ((unused)))
152 if(awesomeconf->statusbar.position == BarOff)
153 awesomeconf->statusbar.position = (awesomeconf->statusbar.position == BarOff) ? BarTop : awesomeconf->statusbar_default_position;
154 else
155 awesomeconf->statusbar.position = BarOff;
156 updatebarpos(disp, awesomeconf->statusbar);
157 arrange(disp, drawcontext, awesomeconf);