2007-09-15 15:16:53 +02:00
|
|
|
/*
|
|
|
|
* draw.c - draw functions
|
|
|
|
*
|
|
|
|
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-24 17:08:47 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-09-15 15:16:53 +02:00
|
|
|
#include "layout.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "draw.h"
|
2007-09-15 15:26:51 +02:00
|
|
|
#include "screen.h"
|
|
|
|
#include "util.h"
|
2007-09-24 17:08:47 +02:00
|
|
|
#include "layouts/tile.h"
|
2007-09-15 15:16:53 +02:00
|
|
|
|
|
|
|
extern Client *clients, *sel, *stack; /* global client list and stack */
|
|
|
|
|
2007-09-16 16:58:44 +02:00
|
|
|
/** Check if at least a client is tagged with tag number t and is on screen
|
|
|
|
* screen
|
2007-09-15 15:16:53 +02:00
|
|
|
* \param t tag number
|
2007-09-16 16:58:44 +02:00
|
|
|
* \param screen screen number
|
2007-09-15 15:16:53 +02:00
|
|
|
* \return True or False
|
|
|
|
*/
|
|
|
|
static Bool
|
2007-09-16 16:58:44 +02:00
|
|
|
isoccupied(unsigned int t, int screen)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
|
|
|
|
for(c = clients; c; c = c->next)
|
2007-09-16 16:58:44 +02:00
|
|
|
if(c->tags[t] && c->screen == screen)
|
2007-09-15 15:16:53 +02:00
|
|
|
return True;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-09-24 16:23:49 +02:00
|
|
|
drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
|
|
|
int x, i;
|
2007-09-24 17:08:47 +02:00
|
|
|
|
2007-09-15 15:16:53 +02:00
|
|
|
drawcontext->x = drawcontext->y = 0;
|
|
|
|
for(i = 0; i < awesomeconf->ntags; i++)
|
|
|
|
{
|
2007-09-24 15:37:52 +02:00
|
|
|
drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i].name, drawcontext->font.height);
|
|
|
|
if(awesomeconf->tags[i].selected)
|
2007-09-15 15:16:53 +02:00
|
|
|
{
|
2007-09-24 15:37:52 +02:00
|
|
|
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i].name, drawcontext->sel);
|
2007-09-24 16:23:49 +02:00
|
|
|
if(isoccupied(i, awesomeconf->screen))
|
2007-09-20 20:11:33 +02:00
|
|
|
drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->sel[ColFG]);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-24 15:37:52 +02:00
|
|
|
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i].name, drawcontext->norm);
|
2007-09-24 16:23:49 +02:00
|
|
|
if(isoccupied(i, awesomeconf->screen))
|
2007-09-20 20:11:33 +02:00
|
|
|
drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->norm[ColFG]);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
|
|
|
drawcontext->x += drawcontext->w;
|
|
|
|
}
|
|
|
|
drawcontext->w = awesomeconf->statusbar.width;
|
|
|
|
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->current_layout->symbol, drawcontext->norm);
|
|
|
|
x = drawcontext->x + drawcontext->w;
|
|
|
|
drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->statustext, drawcontext->font.height);
|
2007-09-24 16:23:49 +02:00
|
|
|
drawcontext->x = DisplayWidth(disp, awesomeconf->screen) - drawcontext->w;
|
2007-09-15 15:16:53 +02:00
|
|
|
if(drawcontext->x < x)
|
|
|
|
{
|
|
|
|
drawcontext->x = x;
|
2007-09-24 16:23:49 +02:00
|
|
|
drawcontext->w = DisplayWidth(disp, awesomeconf->screen) - x;
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
|
|
|
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->statustext, drawcontext->norm);
|
|
|
|
if((drawcontext->w = drawcontext->x - x) > awesomeconf->statusbar.height)
|
|
|
|
{
|
|
|
|
drawcontext->x = x;
|
|
|
|
if(sel)
|
|
|
|
{
|
|
|
|
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->name, drawcontext->sel);
|
2007-09-20 20:11:33 +02:00
|
|
|
if(sel->isfloating)
|
|
|
|
drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->ismax, drawcontext->sel[ColFG]);
|
2007-09-15 15:16:53 +02:00
|
|
|
}
|
2007-09-24 17:08:47 +02:00
|
|
|
else if(IS_ARRANGE(layout_tile) || IS_ARRANGE(layout_tileleft))
|
|
|
|
{
|
|
|
|
char buf[256];
|
2007-09-24 20:23:05 +02:00
|
|
|
snprintf(buf, sizeof(buf), "nmaster: %d ncols: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncols, awesomeconf->mwfact);
|
2007-09-24 17:08:47 +02:00
|
|
|
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, buf, drawcontext->norm);
|
|
|
|
}
|
2007-09-15 15:16:53 +02:00
|
|
|
else
|
|
|
|
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, NULL, drawcontext->norm);
|
|
|
|
}
|
2007-09-24 16:23:49 +02:00
|
|
|
XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, awesomeconf->screen), awesomeconf->statusbar.height, 0, 0);
|
2007-09-15 15:16:53 +02:00
|
|
|
XSync(disp, False);
|
|
|
|
}
|
2007-09-15 15:26:51 +02:00
|
|
|
|
2007-09-15 22:25:49 +02:00
|
|
|
void
|
|
|
|
initstatusbar(Display *disp, int screen, DC *drawcontext, Statusbar *statusbar)
|
|
|
|
{
|
|
|
|
XSetWindowAttributes wa;
|
2007-09-27 17:12:51 +02:00
|
|
|
int real_screen;
|
2007-09-15 22:25:49 +02:00
|
|
|
|
2007-09-15 23:04:04 +02:00
|
|
|
statusbar->screen = screen;
|
|
|
|
|
2007-09-27 17:12:51 +02:00
|
|
|
if(XineramaIsActive(disp))
|
|
|
|
real_screen = DefaultScreen(disp);
|
|
|
|
else
|
|
|
|
real_screen = screen;
|
|
|
|
|
2007-09-15 22:25:49 +02:00
|
|
|
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
|
|
|
| EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
|
|
|
|
wa.cursor = drawcontext->cursor[CurNormal];
|
|
|
|
wa.override_redirect = 1;
|
|
|
|
wa.background_pixmap = ParentRelative;
|
|
|
|
wa.event_mask = ButtonPressMask | ExposureMask;
|
2007-09-27 17:12:51 +02:00
|
|
|
statusbar->window = XCreateWindow(disp, RootWindow(disp, screen), 0, 0, DisplayWidth(disp, real_screen),
|
|
|
|
statusbar->height, 0, DefaultDepth(disp, real_screen), CopyFromParent,
|
|
|
|
DefaultVisual(disp, real_screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
2007-09-15 22:25:49 +02:00
|
|
|
XDefineCursor(disp, statusbar->window, drawcontext->cursor[CurNormal]);
|
|
|
|
updatebarpos(disp, *statusbar);
|
|
|
|
XMapRaised(disp, statusbar->window);
|
|
|
|
statusbar->drawable = XCreatePixmap(disp,
|
2007-09-27 17:12:51 +02:00
|
|
|
RootWindow(disp, real_screen),
|
|
|
|
DisplayWidth(disp, real_screen),
|
2007-09-15 22:25:49 +02:00
|
|
|
statusbar->height,
|
2007-09-27 17:12:51 +02:00
|
|
|
DefaultDepth(disp, real_screen));
|
2007-09-15 22:25:49 +02:00
|
|
|
}
|
2007-09-15 15:26:51 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
updatebarpos(Display *disp, Statusbar statusbar)
|
|
|
|
{
|
|
|
|
XEvent ev;
|
|
|
|
ScreenInfo *si;
|
|
|
|
|
|
|
|
switch (statusbar.position)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
XMoveWindow(disp, statusbar.window, 0, 0);
|
|
|
|
break;
|
|
|
|
case BarBot:
|
2007-09-15 23:04:04 +02:00
|
|
|
si = get_display_info(disp, statusbar.screen, statusbar);
|
2007-09-15 15:26:51 +02:00
|
|
|
XMoveWindow(disp, statusbar.window, 0, si->height);
|
|
|
|
XFree(si);
|
|
|
|
break;
|
|
|
|
case BarOff:
|
|
|
|
XMoveWindow(disp, statusbar.window, 0, 0 - statusbar.height);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
XSync(disp, False);
|
|
|
|
while(XCheckMaskEvent(disp, EnterWindowMask, &ev));
|
|
|
|
}
|
2007-09-15 15:34:28 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
uicb_togglebar(Display *disp,
|
|
|
|
DC *drawcontext,
|
|
|
|
awesome_config *awesomeconf,
|
|
|
|
const char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
if(awesomeconf->statusbar.position == BarOff)
|
|
|
|
awesomeconf->statusbar.position = (awesomeconf->statusbar.position == BarOff) ? BarTop : awesomeconf->statusbar_default_position;
|
|
|
|
else
|
|
|
|
awesomeconf->statusbar.position = BarOff;
|
|
|
|
updatebarpos(disp, awesomeconf->statusbar);
|
2007-09-17 13:45:13 +02:00
|
|
|
arrange(disp, drawcontext, awesomeconf);
|
2007-09-15 15:34:28 +02:00
|
|
|
}
|
|
|
|
|