From fe89aa31b05a55a236eb0d46a3f7990ed995836e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 15 Sep 2007 15:16:53 +0200 Subject: [PATCH] create statusbar.c and move things from draw.c --- Makefile | 2 +- awesome.c | 2 ++ client.c | 2 ++ client.h | 2 +- config.c | 2 ++ draw.c | 76 +++++-------------------------------------- draw.h | 3 +- event.c | 2 ++ layout.c | 2 ++ layouts/tile.c | 1 + statusbar.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ statusbar.h | 29 +++++++++++++++++ tag.c | 1 + 13 files changed, 140 insertions(+), 71 deletions(-) create mode 100644 statusbar.c create mode 100644 statusbar.h diff --git a/Makefile b/Makefile index a2855d4f7..19fb4f4c3 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c +SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o} all: options awesome diff --git a/awesome.c b/awesome.c index 56e8b102c..a3a3cffed 100644 --- a/awesome.c +++ b/awesome.c @@ -37,6 +37,8 @@ #include "layout.h" #include "tag.h" #include "screen.h" +#include "util.h" +#include "statusbar.h" Client *clients = NULL; Client *sel = NULL; diff --git a/client.c b/client.c index f2865ea01..6a415ddee 100644 --- a/client.c +++ b/client.c @@ -28,6 +28,8 @@ #include "awesome.h" #include "layout.h" #include "tag.h" +#include "util.h" +#include "statusbar.h" #include "layouts/floating.h" diff --git a/client.h b/client.h index 9a3fb795a..9dc449269 100644 --- a/client.h +++ b/client.h @@ -25,7 +25,7 @@ /* mask shorthands, used in event.c and client.c */ #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) -#include "draw.h" +#include "config.h" typedef struct Client Client; struct Client diff --git a/config.c b/config.c index 3a4b08d1c..794f655df 100644 --- a/config.c +++ b/config.c @@ -30,6 +30,8 @@ #include "awesome.h" #include "layout.h" #include "tag.h" +#include "util.h" +#include "draw.h" #include "layouts/tile.h" #include "layouts/spiral.h" #include "layouts/floating.h" diff --git a/draw.c b/draw.c index ee0672607..92f6b409b 100644 --- a/draw.c +++ b/draw.c @@ -20,13 +20,15 @@ */ #include "layout.h" +#include "util.h" +#include "draw.h" extern Client *clients, *sel, *stack; /* global client list and stack */ /* static */ -static void -drawtext(Display *disp, DC drawcontext, Statusbar * statusbar, const char *text, unsigned long col[ColLast]) +void +drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, unsigned long col[ColLast]) { int x, y, w, h; static char buf[256]; @@ -34,7 +36,7 @@ drawtext(Display *disp, DC drawcontext, Statusbar * statusbar, const char *text, XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h }; XSetForeground(disp, drawcontext.gc, col[ColBG]); - XFillRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1); + XFillRectangles(disp, drawable, drawcontext.gc, &r, 1); if(!text) return; w = 0; @@ -62,12 +64,12 @@ drawtext(Display *disp, DC drawcontext, Statusbar * statusbar, const char *text, } XSetForeground(disp, drawcontext.gc, col[ColFG]); if(drawcontext.font.set) - XmbDrawString(disp, statusbar->drawable, drawcontext.font.set, drawcontext.gc, x, y, buf, len); + XmbDrawString(disp, drawable, drawcontext.font.set, drawcontext.gc, x, y, buf, len); else - XDrawString(disp, statusbar->drawable, drawcontext.gc, x, y, buf, len); + XDrawString(disp, drawable, drawcontext.gc, x, y, buf, len); } -static void +void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp, DC drawcontext, Statusbar *statusbar) { int x; @@ -91,23 +93,6 @@ drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp, D } } -/** Check if at least a client is tagged with tag number t - * \param t tag number - * \return True or False - */ -static Bool -isoccupied(unsigned int t) -{ - Client *c; - - for(c = clients; c; c = c->next) - if(c->tags[t]) - return True; - return False; -} - -/* extern */ - unsigned int textnw(XFontSet set, XFontStruct *xfont, const char *text, unsigned int len) { @@ -121,48 +106,3 @@ textnw(XFontSet set, XFontStruct *xfont, const char *text, unsigned int len) return XTextWidth(xfont, text, len); } -void -drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf) -{ - int x, i; - drawcontext->x = drawcontext->y = 0; - for(i = 0; i < awesomeconf->ntags; i++) - { - drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i], drawcontext->font.height); - if(awesomeconf->selected_tags[i]) - { - drawtext(disp, *drawcontext, &awesomeconf->statusbar, awesomeconf->tags[i], drawcontext->sel); - drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar); - } - else - { - drawtext(disp, *drawcontext, &awesomeconf->statusbar, awesomeconf->tags[i], drawcontext->norm); - drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->norm, disp, *drawcontext, &awesomeconf->statusbar); - } - drawcontext->x += drawcontext->w; - } - drawcontext->w = awesomeconf->statusbar.width; - drawtext(disp, *drawcontext, &awesomeconf->statusbar, 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); - drawcontext->x = DisplayWidth(disp, DefaultScreen(disp)) - drawcontext->w; - if(drawcontext->x < x) - { - drawcontext->x = x; - drawcontext->w = DisplayWidth(disp, DefaultScreen(disp)) - x; - } - drawtext(disp, *drawcontext, &awesomeconf->statusbar, awesomeconf->statustext, drawcontext->norm); - if((drawcontext->w = drawcontext->x - x) > awesomeconf->statusbar.height) - { - drawcontext->x = x; - if(sel) - { - drawtext(disp, *drawcontext, &awesomeconf->statusbar, sel->name, drawcontext->sel); - drawsquare(sel->ismax, sel->isfloating, drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar); - } - else - drawtext(disp, *drawcontext, &awesomeconf->statusbar, NULL, drawcontext->norm); - } - XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, 0, 0); - XSync(disp, False); -} diff --git a/draw.h b/draw.h index da7d1b9f2..ce62f6db2 100644 --- a/draw.h +++ b/draw.h @@ -26,7 +26,8 @@ #define textw(set, xfont, text, height) (textnw(set, xfont, text, a_strlen(text)) + height) -void drawstatusbar(Display *, DC *, awesome_config *); /* draw the bar */ +void drawsquare(Bool, Bool, unsigned long *, Display *, DC, Statusbar *); +void drawtext(Display *, DC, Drawable, const char *, unsigned long *); unsigned int textnw(XFontSet, XFontStruct *, const char *, unsigned int); #endif diff --git a/event.c b/event.c index cc69c1077..655ac5b8c 100644 --- a/event.c +++ b/event.c @@ -30,6 +30,8 @@ #include "event.h" #include "layout.h" #include "tag.h" +#include "draw.h" +#include "statusbar.h" #include "layouts/tile.h" #include "layouts/floating.h" diff --git a/layout.c b/layout.c index 06d846236..1cc18390e 100644 --- a/layout.c +++ b/layout.c @@ -25,6 +25,8 @@ #include "awesome.h" #include "layout.h" #include "tag.h" +#include "util.h" +#include "statusbar.h" #include "layouts/floating.h" /* extern */ diff --git a/layouts/tile.c b/layouts/tile.c index 72fa4927b..8b884e4e2 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -21,6 +21,7 @@ #include +#include "util.h" #include "screen.h" #include "awesome.h" #include "tag.h" diff --git a/statusbar.c b/statusbar.c new file mode 100644 index 000000000..92f50c8ce --- /dev/null +++ b/statusbar.c @@ -0,0 +1,87 @@ +/* + * draw.c - draw functions + * + * Copyright © 2007 Julien Danjou + * + * 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 "layout.h" +#include "statusbar.h" +#include "draw.h" + +extern Client *clients, *sel, *stack; /* global client list and stack */ + +/** Check if at least a client is tagged with tag number t + * \param t tag number + * \return True or False + */ +static Bool +isoccupied(unsigned int t) +{ + Client *c; + + for(c = clients; c; c = c->next) + if(c->tags[t]) + return True; + return False; +} + +void +drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf) +{ + int x, i; + drawcontext->x = drawcontext->y = 0; + for(i = 0; i < awesomeconf->ntags; i++) + { + drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i], drawcontext->font.height); + if(awesomeconf->selected_tags[i]) + { + drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->sel); + drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar); + } + else + { + drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->norm); + drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->norm, disp, *drawcontext, &awesomeconf->statusbar); + } + 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); + drawcontext->x = DisplayWidth(disp, DefaultScreen(disp)) - drawcontext->w; + if(drawcontext->x < x) + { + drawcontext->x = x; + drawcontext->w = DisplayWidth(disp, DefaultScreen(disp)) - x; + } + 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); + drawsquare(sel->ismax, sel->isfloating, drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar); + } + else + drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, NULL, drawcontext->norm); + } + XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, 0, 0); + XSync(disp, False); +} diff --git a/statusbar.h b/statusbar.h new file mode 100644 index 000000000..9fcfe5082 --- /dev/null +++ b/statusbar.h @@ -0,0 +1,29 @@ +/* + * draw.h - draw functions header + * + * Copyright © 2007 Julien Danjou + * + * 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. + * + */ + +#ifndef AWESOME_STATUSBAR_H +#define AWESOME_STATUSBAR_H + +#include "config.h" + +void drawstatusbar(Display *, DC *, awesome_config *); + +#endif diff --git a/tag.c b/tag.c index f4d9ca316..bd818ccee 100644 --- a/tag.c +++ b/tag.c @@ -24,6 +24,7 @@ #include "layout.h" #include "tag.h" +#include "util.h" extern Client *sel; /* global client list */