use drawrectangle to draw background in statusbar, fix coords of rectangles and compute colors correctly
This commit is contained in:
parent
f6ea98649c
commit
1f5a6e918b
13
draw.c
13
draw.c
|
@ -21,23 +21,22 @@
|
|||
|
||||
#include <cairo.h>
|
||||
#include <cairo-xlib.h>
|
||||
#include <math.h>
|
||||
#include "layout.h"
|
||||
#include "util.h"
|
||||
#include "draw.h"
|
||||
|
||||
void
|
||||
drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable drawable, XftFont *font, const char *text, XColor color[ColLast])
|
||||
drawtext(Display *disp, int screen, int x, int y, int w, int h, Drawable drawable, int dw, int dh, XftFont *font, const char *text, XColor color[ColLast])
|
||||
{
|
||||
int nw = 0;
|
||||
static char buf[256];
|
||||
size_t len, olen;
|
||||
XRectangle r = { x, y, w, h };
|
||||
XRenderColor xrcolor;
|
||||
XftColor xftcolor;
|
||||
XftDraw *xftdrawable;
|
||||
|
||||
XSetForeground(disp, gc, color[ColBG].pixel);
|
||||
XFillRectangles(disp, drawable, gc, &r, 1);
|
||||
drawrectangle(disp, screen, x, y, w, h, drawable, dw, dh, True, color[ColBG]);
|
||||
if(!text)
|
||||
return;
|
||||
olen = len = a_strlen(text);
|
||||
|
@ -81,14 +80,14 @@ drawrectangle(Display *disp, int screen, int x, int y, int w, int h, Drawable dr
|
|||
|
||||
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
cairo_set_source_rgb(cr, color.red, color.green, color.blue);
|
||||
cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
|
||||
if(filled)
|
||||
{
|
||||
cairo_rectangle(cr, x + 1, y + 1, w + 1, h + 1);
|
||||
cairo_rectangle(cr, x, y, w + 1, h + 1);
|
||||
cairo_fill(cr);
|
||||
}
|
||||
else
|
||||
cairo_rectangle(cr, x + 1, y + 1, w, h);
|
||||
cairo_rectangle(cr, x + 1, y, w, h);
|
||||
cairo_stroke(cr);
|
||||
|
||||
cairo_destroy(cr);
|
||||
|
|
2
draw.h
2
draw.h
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
void drawtext(Display *, int, int, int, int, int, GC, Drawable, XftFont *, const char *, XColor []);
|
||||
void drawtext(Display *, int, int, int, int, int, Drawable, int, int, XftFont *, const char *, XColor []);
|
||||
void drawrectangle(Display *, int, int, int, int, int, Drawable, int, int, Bool, XColor);
|
||||
inline unsigned short textwidth(Display *, XftFont *, char *, ssize_t);
|
||||
#endif
|
||||
|
|
63
statusbar.c
63
statusbar.c
|
@ -51,11 +51,6 @@ void
|
|||
drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
||||
{
|
||||
int z, i, x = 0, y = 0, w;
|
||||
ScreenInfo *si = get_screen_info(disp, awesomeconf->screen, NULL);
|
||||
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++)
|
||||
{
|
||||
|
@ -66,8 +61,11 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
|||
{
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, w,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.width,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->font,
|
||||
awesomeconf->tags[i].name, awesomeconf->colors_selected);
|
||||
if(isoccupied(i, awesomeconf->screen))
|
||||
drawrectangle(disp, awesomeconf->phys_screen,
|
||||
|
@ -84,8 +82,11 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
|||
{
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, w,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.width,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->font,
|
||||
awesomeconf->tags[i].name, awesomeconf->colors_normal);
|
||||
if(isoccupied(i, awesomeconf->screen))
|
||||
drawrectangle(disp, awesomeconf->phys_screen,
|
||||
|
@ -102,22 +103,28 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
|||
}
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, awesomeconf->statusbar.txtlayoutwidth,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.width,
|
||||
awesomeconf->statusbar.height,
|
||||
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;
|
||||
x = si[awesomeconf->screen].width - w;
|
||||
x = awesomeconf->statusbar.width - w;
|
||||
if(x < z)
|
||||
{
|
||||
x = z;
|
||||
w = si[awesomeconf->screen].width - z;
|
||||
w = awesomeconf->statusbar.width - z;
|
||||
}
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, w,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.width,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->font,
|
||||
awesomeconf->statustext, awesomeconf->colors_normal);
|
||||
if((w = x - z) > awesomeconf->statusbar.height)
|
||||
{
|
||||
|
@ -126,8 +133,11 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
|||
{
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, w,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.width,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->font,
|
||||
sel->name, awesomeconf->colors_selected);
|
||||
if(sel->isfloating)
|
||||
drawrectangle(disp, awesomeconf->phys_screen,
|
||||
|
@ -146,21 +156,26 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
|||
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,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.width,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->font,
|
||||
buf, awesomeconf->colors_normal);
|
||||
}
|
||||
else
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, w,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
awesomeconf->statusbar.height,
|
||||
awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.width,
|
||||
awesomeconf->statusbar.height,
|
||||
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);
|
||||
XFreeGC(awesomeconf->display, gc);
|
||||
awesomeconf->statusbar.window, DefaultGC(disp, awesomeconf->phys_screen), 0, 0,
|
||||
awesomeconf->statusbar.width, awesomeconf->statusbar.height, 0, 0);
|
||||
XSync(disp, False);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue