create statusbar.c and move things from draw.c
This commit is contained in:
parent
c5211cc8d1
commit
fe89aa31b0
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
include config.mk
|
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}
|
OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o}
|
||||||
|
|
||||||
all: options awesome
|
all: options awesome
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "statusbar.h"
|
||||||
|
|
||||||
Client *clients = NULL;
|
Client *clients = NULL;
|
||||||
Client *sel = NULL;
|
Client *sel = NULL;
|
||||||
|
|
2
client.c
2
client.c
|
@ -28,6 +28,8 @@
|
||||||
#include "awesome.h"
|
#include "awesome.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "statusbar.h"
|
||||||
|
|
||||||
#include "layouts/floating.h"
|
#include "layouts/floating.h"
|
||||||
|
|
||||||
|
|
2
client.h
2
client.h
|
@ -25,7 +25,7 @@
|
||||||
/* mask shorthands, used in event.c and client.c */
|
/* mask shorthands, used in event.c and client.c */
|
||||||
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
|
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
|
||||||
|
|
||||||
#include "draw.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef struct Client Client;
|
typedef struct Client Client;
|
||||||
struct Client
|
struct Client
|
||||||
|
|
2
config.c
2
config.c
|
@ -30,6 +30,8 @@
|
||||||
#include "awesome.h"
|
#include "awesome.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "draw.h"
|
||||||
#include "layouts/tile.h"
|
#include "layouts/tile.h"
|
||||||
#include "layouts/spiral.h"
|
#include "layouts/spiral.h"
|
||||||
#include "layouts/floating.h"
|
#include "layouts/floating.h"
|
||||||
|
|
76
draw.c
76
draw.c
|
@ -20,13 +20,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "draw.h"
|
||||||
|
|
||||||
extern Client *clients, *sel, *stack; /* global client list and stack */
|
extern Client *clients, *sel, *stack; /* global client list and stack */
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
||||||
static void
|
void
|
||||||
drawtext(Display *disp, DC drawcontext, Statusbar * statusbar, const char *text, unsigned long col[ColLast])
|
drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, unsigned long col[ColLast])
|
||||||
{
|
{
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
static char buf[256];
|
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 };
|
XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h };
|
||||||
|
|
||||||
XSetForeground(disp, drawcontext.gc, col[ColBG]);
|
XSetForeground(disp, drawcontext.gc, col[ColBG]);
|
||||||
XFillRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1);
|
XFillRectangles(disp, drawable, drawcontext.gc, &r, 1);
|
||||||
if(!text)
|
if(!text)
|
||||||
return;
|
return;
|
||||||
w = 0;
|
w = 0;
|
||||||
|
@ -62,12 +64,12 @@ drawtext(Display *disp, DC drawcontext, Statusbar * statusbar, const char *text,
|
||||||
}
|
}
|
||||||
XSetForeground(disp, drawcontext.gc, col[ColFG]);
|
XSetForeground(disp, drawcontext.gc, col[ColFG]);
|
||||||
if(drawcontext.font.set)
|
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
|
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)
|
drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp, DC drawcontext, Statusbar *statusbar)
|
||||||
{
|
{
|
||||||
int x;
|
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
|
unsigned int
|
||||||
textnw(XFontSet set, XFontStruct *xfont, const char *text, unsigned int len)
|
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);
|
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
3
draw.h
|
@ -26,7 +26,8 @@
|
||||||
|
|
||||||
#define textw(set, xfont, text, height) (textnw(set, xfont, text, a_strlen(text)) + height)
|
#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);
|
unsigned int textnw(XFontSet, XFontStruct *, const char *, unsigned int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
2
event.c
2
event.c
|
@ -30,6 +30,8 @@
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
#include "draw.h"
|
||||||
|
#include "statusbar.h"
|
||||||
#include "layouts/tile.h"
|
#include "layouts/tile.h"
|
||||||
#include "layouts/floating.h"
|
#include "layouts/floating.h"
|
||||||
|
|
||||||
|
|
2
layout.c
2
layout.c
|
@ -25,6 +25,8 @@
|
||||||
#include "awesome.h"
|
#include "awesome.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "statusbar.h"
|
||||||
#include "layouts/floating.h"
|
#include "layouts/floating.h"
|
||||||
|
|
||||||
/* extern */
|
/* extern */
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "awesome.h"
|
#include "awesome.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
Loading…
Reference in New Issue