move uicb_togglebar to statusbar.c
[awesome.git] / statusbar.c
blobf5a40fa40df7f916242bed9331c25c80884f523e
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
31 * \param t tag number
32 * \return True or False
34 static Bool
35 isoccupied(unsigned int t)
37 Client *c;
39 for(c = clients; c; c = c->next)
40 if(c->tags[t])
41 return True;
42 return False;
45 void
46 drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf)
48 int x, i;
49 drawcontext->x = drawcontext->y = 0;
50 for(i = 0; i < awesomeconf->ntags; i++)
52 drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i], drawcontext->font.height);
53 if(awesomeconf->selected_tags[i])
55 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->sel);
56 drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar);
58 else
60 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->norm);
61 drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->norm, disp, *drawcontext, &awesomeconf->statusbar);
63 drawcontext->x += drawcontext->w;
65 drawcontext->w = awesomeconf->statusbar.width;
66 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->current_layout->symbol, drawcontext->norm);
67 x = drawcontext->x + drawcontext->w;
68 drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->statustext, drawcontext->font.height);
69 drawcontext->x = DisplayWidth(disp, DefaultScreen(disp)) - drawcontext->w;
70 if(drawcontext->x < x)
72 drawcontext->x = x;
73 drawcontext->w = DisplayWidth(disp, DefaultScreen(disp)) - x;
75 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->statustext, drawcontext->norm);
76 if((drawcontext->w = drawcontext->x - x) > awesomeconf->statusbar.height)
78 drawcontext->x = x;
79 if(sel)
81 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->name, drawcontext->sel);
82 drawsquare(sel->ismax, sel->isfloating, drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar);
84 else
85 drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, NULL, drawcontext->norm);
87 XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, 0, 0);
88 XSync(disp, False);
92 void
93 updatebarpos(Display *disp, Statusbar statusbar)
95 XEvent ev;
96 ScreenInfo *si;
98 switch (statusbar.position)
100 default:
101 XMoveWindow(disp, statusbar.window, 0, 0);
102 break;
103 case BarBot:
104 si = get_display_info(disp, statusbar);
105 XMoveWindow(disp, statusbar.window, 0, si->height);
106 XFree(si);
107 break;
108 case BarOff:
109 XMoveWindow(disp, statusbar.window, 0, 0 - statusbar.height);
110 break;
112 XSync(disp, False);
113 while(XCheckMaskEvent(disp, EnterWindowMask, &ev));
116 void
117 uicb_togglebar(Display *disp,
118 DC *drawcontext,
119 awesome_config *awesomeconf,
120 const char *arg __attribute__ ((unused)))
122 if(awesomeconf->statusbar.position == BarOff)
123 awesomeconf->statusbar.position = (awesomeconf->statusbar.position == BarOff) ? BarTop : awesomeconf->statusbar_default_position;
124 else
125 awesomeconf->statusbar.position = BarOff;
126 updatebarpos(disp, awesomeconf->statusbar);
127 arrange(disp, drawcontext, awesomeconf);