create statusbar.c and move things from draw.c

This commit is contained in:
Julien Danjou 2007-09-15 15:16:53 +02:00
parent c5211cc8d1
commit fe89aa31b0
13 changed files with 140 additions and 71 deletions

View File

@ -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

View File

@ -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;

View File

@ -28,6 +28,8 @@
#include "awesome.h"
#include "layout.h"
#include "tag.h"
#include "util.h"
#include "statusbar.h"
#include "layouts/floating.h"

View File

@ -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

View File

@ -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"

76
draw.c
View File

@ -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);
}

3
draw.h
View File

@ -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

View File

@ -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"

View File

@ -25,6 +25,8 @@
#include "awesome.h"
#include "layout.h"
#include "tag.h"
#include "util.h"
#include "statusbar.h"
#include "layouts/floating.h"
/* extern */

View File

@ -21,6 +21,7 @@
#include <stdio.h>
#include "util.h"
#include "screen.h"
#include "awesome.h"
#include "tag.h"

87
statusbar.c Normal file
View File

@ -0,0 +1,87 @@
/*
* 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 "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);
}

29
statusbar.h Normal file
View File

@ -0,0 +1,29 @@
/*
* draw.h - draw functions header
*
* 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.
*
*/
#ifndef AWESOME_STATUSBAR_H
#define AWESOME_STATUSBAR_H
#include "config.h"
void drawstatusbar(Display *, DC *, awesome_config *);
#endif

1
tag.c
View File

@ -24,6 +24,7 @@
#include "layout.h"
#include "tag.h"
#include "util.h"
extern Client *sel; /* global client list */