awesome/statusbar.c

230 lines
8.8 KiB
C
Raw Normal View History

/*
* 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.
*
*/
#include <stdio.h>
#include "layout.h"
#include "statusbar.h"
#include "draw.h"
2007-09-15 15:26:51 +02:00
#include "screen.h"
#include "util.h"
#include "layouts/tile.h"
2007-10-03 00:15:50 +02:00
extern Client *clients, *sel; /* global client list */
/** Check if at least a client is tagged with tag number t and is on screen
* screen
* \param t tag number
* \param screen screen number
* \return True or False
*/
static Bool
isoccupied(unsigned int t, int screen)
{
Client *c;
for(c = clients; c; c = c->next)
if(c->tags[t] && c->screen == screen)
return True;
return False;
}
void
2007-10-10 14:09:36 +02:00
drawstatusbar(Display *disp, awesome_config * awesomeconf)
{
2007-10-09 22:35:44 +02:00
int z, i, x = 0, y = 0, w;
2007-10-01 20:58:29 +02:00
ScreenInfo *si = get_screen_info(disp, awesomeconf->screen, NULL);
2007-10-10 14:09:36 +02:00
GC gc;
gc = XCreateGC(awesomeconf->display, RootWindow(awesomeconf->display, awesomeconf->phys_screen), 0, 0);
XSetLineAttributes(awesomeconf->display, gc, 1, LineSolid, CapButt, JoinMiter);
for(i = 0; i < awesomeconf->ntags; i++)
{
w = textwidth(disp, awesomeconf->font,
awesomeconf->tags[i].name, a_strlen(awesomeconf->tags[i].name))
+ awesomeconf->font->height;
2007-09-24 15:37:52 +02:00
if(awesomeconf->tags[i].selected)
{
drawtext(disp, awesomeconf->phys_screen,
x, y, w,
awesomeconf->statusbar.height, gc,
awesomeconf->statusbar.drawable, awesomeconf->font,
awesomeconf->tags[i].name, awesomeconf->colors_selected);
if(isoccupied(i, awesomeconf->screen))
drawsquare(disp, awesomeconf->phys_screen,
x, y, (awesomeconf->font->height + 2) / 4,
awesomeconf->statusbar.drawable,
awesomeconf->statusbar.width,
awesomeconf->statusbar.height,
sel && sel->tags[i],
awesomeconf->colors_selected[ColFG]);
}
else
{
drawtext(disp, awesomeconf->phys_screen,
x, y, w,
awesomeconf->statusbar.height, gc,
awesomeconf->statusbar.drawable, awesomeconf->font,
awesomeconf->tags[i].name, awesomeconf->colors_normal);
if(isoccupied(i, awesomeconf->screen))
drawsquare(disp, awesomeconf->phys_screen,
x, y, (awesomeconf->font->height + 2) / 4,
awesomeconf->statusbar.drawable,
awesomeconf->statusbar.width,
awesomeconf->statusbar.height,
sel && sel->tags[i],
awesomeconf->colors_normal[ColFG]);
}
2007-10-09 22:35:44 +02:00
x += w;
}
drawtext(disp, awesomeconf->phys_screen,
x, y, awesomeconf->statusbar.txtlayoutwidth,
awesomeconf->statusbar.height, gc,
awesomeconf->statusbar.drawable, awesomeconf->font,
awesomeconf->current_layout->symbol, awesomeconf->colors_normal);
z = x + awesomeconf->statusbar.txtlayoutwidth;
w = textwidth(disp, awesomeconf->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext))
+ awesomeconf->font->height;
2007-10-09 22:35:44 +02:00
x = si[awesomeconf->screen].width - w;
if(x < z)
{
2007-10-09 22:35:44 +02:00
x = z;
w = si[awesomeconf->screen].width - z;
}
drawtext(disp, awesomeconf->phys_screen,
x, y, w,
awesomeconf->statusbar.height, gc,
awesomeconf->statusbar.drawable, awesomeconf->font,
awesomeconf->statustext, awesomeconf->colors_normal);
2007-10-09 22:35:44 +02:00
if((w = x - z) > awesomeconf->statusbar.height)
{
2007-10-09 22:35:44 +02:00
x = z;
if(sel)
{
drawtext(disp, awesomeconf->phys_screen,
x, y, w,
awesomeconf->statusbar.height, gc,
awesomeconf->statusbar.drawable, awesomeconf->font,
sel->name, awesomeconf->colors_selected);
2007-09-20 20:11:33 +02:00
if(sel->isfloating)
drawsquare(disp, awesomeconf->phys_screen,
x, y, (awesomeconf->font->height + 2) / 4,
awesomeconf->statusbar.drawable,
awesomeconf->statusbar.width,
awesomeconf->statusbar.height,
sel->ismax,
awesomeconf->colors_selected[ColFG]);
}
else if(IS_ARRANGE(0, layout_tile) || IS_ARRANGE(0, layout_tileleft))
{
char buf[256];
snprintf(buf, sizeof(buf), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncol, awesomeconf->mwfact);
drawtext(disp, awesomeconf->phys_screen,
x, y, w,
awesomeconf->statusbar.height, gc,
awesomeconf->statusbar.drawable, awesomeconf->font,
buf, awesomeconf->colors_normal);
}
else
drawtext(disp, awesomeconf->phys_screen,
x, y, w,
awesomeconf->statusbar.height, gc,
awesomeconf->statusbar.drawable, awesomeconf->font,
NULL, awesomeconf->colors_normal);
}
XCopyArea(disp, awesomeconf->statusbar.drawable,
awesomeconf->statusbar.window, gc, 0, 0,
si[awesomeconf->screen].width, awesomeconf->statusbar.height, 0, 0);
2007-10-10 14:09:36 +02:00
XFreeGC(awesomeconf->display, gc);
XSync(disp, False);
}
2007-09-15 15:26:51 +02:00
2007-09-15 22:25:49 +02:00
void
2007-10-10 13:29:46 +02:00
initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor)
2007-09-15 22:25:49 +02:00
{
XSetWindowAttributes wa;
2007-10-01 20:58:29 +02:00
int phys_screen;
ScreenInfo *si;
2007-09-15 22:25:49 +02:00
2007-10-01 15:23:05 +02:00
phys_screen = get_phys_screen(disp, screen);
statusbar->screen = screen;
2007-10-01 20:58:29 +02:00
si = get_screen_info(disp, screen, NULL);
2007-09-15 22:25:49 +02:00
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
| EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
2007-10-10 13:29:46 +02:00
wa.cursor = cursor;
2007-09-15 22:25:49 +02:00
wa.override_redirect = 1;
wa.background_pixmap = ParentRelative;
wa.event_mask = ButtonPressMask | ExposureMask;
2007-10-01 15:23:05 +02:00
statusbar->window = XCreateWindow(disp, RootWindow(disp, phys_screen), 0, 0, si[screen].width,
statusbar->height, 0, DefaultDepth(disp, phys_screen), CopyFromParent,
DefaultVisual(disp, phys_screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
2007-10-10 13:29:46 +02:00
XDefineCursor(disp, statusbar->window, cursor);
2007-09-15 22:25:49 +02:00
updatebarpos(disp, *statusbar);
XMapRaised(disp, statusbar->window);
statusbar->drawable = XCreatePixmap(disp,
2007-10-01 15:23:05 +02:00
RootWindow(disp, phys_screen),
si[screen].width,
2007-09-15 22:25:49 +02:00
statusbar->height,
2007-10-01 15:23:05 +02:00
DefaultDepth(disp, phys_screen));
statusbar->width = si[screen].width;
2007-09-15 22:25:49 +02:00
}
2007-09-15 15:26:51 +02:00
void
updatebarpos(Display *disp, Statusbar statusbar)
{
XEvent ev;
2007-10-01 20:58:29 +02:00
ScreenInfo *si = get_screen_info(disp, statusbar.screen, NULL);
2007-09-15 15:26:51 +02:00
switch (statusbar.position)
{
default:
XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].y_org);
2007-09-15 15:26:51 +02:00
break;
case BarBot:
XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].height - statusbar.height);
2007-09-15 15:26:51 +02:00
break;
case BarOff:
XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].y_org - statusbar.height);
2007-09-15 15:26:51 +02:00
break;
}
XFree(si);
2007-09-15 15:26:51 +02:00
XSync(disp, False);
while(XCheckMaskEvent(disp, EnterWindowMask, &ev));
}
2007-09-15 15:34:28 +02:00
void
uicb_togglebar(Display *disp,
awesome_config *awesomeconf,
const char *arg __attribute__ ((unused)))
{
if(awesomeconf->statusbar.position == BarOff)
awesomeconf->statusbar.position = (awesomeconf->statusbar_default_position == BarOff) ? BarTop : awesomeconf->statusbar_default_position;
2007-09-15 15:34:28 +02:00
else
awesomeconf->statusbar.position = BarOff;
updatebarpos(disp, awesomeconf->statusbar);
2007-10-10 14:09:36 +02:00
arrange(disp, awesomeconf);
2007-09-15 15:34:28 +02:00
}