use Cairo for rendering square instead of Xlib
This commit is contained in:
parent
503e2050c5
commit
445479cf8b
4
config.c
4
config.c
|
@ -342,8 +342,8 @@ parse_config(Display * disp, int scr,const char *confpatharg, awesome_config *aw
|
|||
}
|
||||
awesomeconf->layouts[i].symbol = a_strdup(cfg_getstr(cfgsectmp, "symbol"));
|
||||
txtlen = awesomeconf->font->height + textwidth(disp, awesomeconf->font, awesomeconf->layouts[i].symbol, a_strlen(awesomeconf->layouts[i].symbol));
|
||||
if(txtlen > awesomeconf->statusbar.width)
|
||||
awesomeconf->statusbar.width = txtlen;
|
||||
if(txtlen > awesomeconf->statusbar.txtlayoutwidth)
|
||||
awesomeconf->statusbar.txtlayoutwidth = txtlen;
|
||||
}
|
||||
|
||||
awesomeconf->mwfact = cfg_getfloat(cfg_layouts, "mwfact");
|
||||
|
|
2
config.h
2
config.h
|
@ -67,6 +67,8 @@ typedef struct
|
|||
int width;
|
||||
/** Bar height */
|
||||
int height;
|
||||
/** Layout txt width */
|
||||
int txtlayoutwidth;
|
||||
/** Bar position */
|
||||
int position;
|
||||
/** Window */
|
||||
|
|
|
@ -14,8 +14,8 @@ X11INC = /usr/include/X11
|
|||
X11LIB = /usr/lib/X11
|
||||
|
||||
# includes and libs
|
||||
INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags libconfuse xft`
|
||||
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfuse xft` -lXext -lXrandr -lXinerama
|
||||
INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags libconfuse xft cairo`
|
||||
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfuse xft cairo` -lXext -lXrandr -lXinerama
|
||||
|
||||
# flags
|
||||
CFLAGS = -fgnu89-inline -std=gnu99 -ggdb3 -pipe -Wall -Wextra -W -Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wsign-compare -Wunused -Wuninitialized -Winit-self -Wpointer-arith -Wredundant-decls -Wno-format-zero-length -Wmissing-prototypes -Wmissing-format-attribute -Wmissing-noreturn -O3 ${INCS} -DVERSION=\"${VERSION}\"
|
||||
|
|
26
draw.c
26
draw.c
|
@ -19,6 +19,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <cairo.h>
|
||||
#include <cairo-xlib.h>
|
||||
#include "layout.h"
|
||||
#include "util.h"
|
||||
#include "draw.h"
|
||||
|
@ -69,20 +71,28 @@ drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable
|
|||
}
|
||||
|
||||
void
|
||||
drawsquare(Display *disp, int x, int y, int h, GC gc, Drawable drawable, Bool filled, XColor color)
|
||||
drawsquare(Display *disp, int screen, int x, int y, int h, Drawable drawable, int dw, int dh, Bool filled, XColor color)
|
||||
{
|
||||
XGCValues gcv;
|
||||
XRectangle r = { x, y, h, h };
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
|
||||
gcv.foreground = color.pixel;
|
||||
XChangeGC(disp, gc, GCForeground, &gcv);
|
||||
surface = cairo_xlib_surface_create(disp, drawable, DefaultVisual(disp, screen), dw, dh);
|
||||
cr = cairo_create (surface);
|
||||
|
||||
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);
|
||||
if(filled)
|
||||
{
|
||||
r.width++; r.height++;
|
||||
XFillRectangles(disp, drawable, gc, &r, 1);
|
||||
cairo_rectangle(cr, x + 1, y + 1, h + 1, h + 1);
|
||||
cairo_fill(cr);
|
||||
}
|
||||
else
|
||||
XDrawRectangles(disp, drawable, gc, &r, 1);
|
||||
cairo_rectangle(cr, x + 1, y + 1, h, h);
|
||||
cairo_stroke(cr);
|
||||
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
|
||||
|
||||
|
|
2
draw.h
2
draw.h
|
@ -25,6 +25,6 @@
|
|||
#include "config.h"
|
||||
|
||||
void drawtext(Display *, int, int, int, int, int, GC, Drawable, XftFont *, const char *, XColor []);
|
||||
void drawsquare(Display *, int, int, int, GC, Drawable, Bool, XColor);
|
||||
void drawsquare(Display *, int, int, int, int, Drawable, int, int, Bool, XColor);
|
||||
inline unsigned short textwidth(Display *, XftFont *, char *, ssize_t);
|
||||
#endif
|
||||
|
|
81
statusbar.c
81
statusbar.c
|
@ -59,51 +59,101 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
|||
|
||||
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;
|
||||
w = textwidth(disp, awesomeconf->font,
|
||||
awesomeconf->tags[i].name, a_strlen(awesomeconf->tags[i].name))
|
||||
+ awesomeconf->font->height;
|
||||
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);
|
||||
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, x, y, (awesomeconf->font->height + 2) / 4, gc, awesomeconf->statusbar.drawable, sel && sel->tags[i], awesomeconf->colors_selected[ColFG]);
|
||||
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);
|
||||
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, x, y, (awesomeconf->font->height + 2) / 4, gc, awesomeconf->statusbar.drawable, sel && sel->tags[i], awesomeconf->colors_normal[ColFG]);
|
||||
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]);
|
||||
}
|
||||
x += w;
|
||||
}
|
||||
w = awesomeconf->statusbar.width;
|
||||
drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, gc, awesomeconf->statusbar.drawable, awesomeconf->font, awesomeconf->current_layout->symbol, awesomeconf->colors_normal);
|
||||
z = x + w;
|
||||
w = textwidth(disp, awesomeconf->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext)) + awesomeconf->font->height;
|
||||
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;
|
||||
x = si[awesomeconf->screen].width - w;
|
||||
if(x < z)
|
||||
{
|
||||
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);
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, w,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
awesomeconf->statustext, awesomeconf->colors_normal);
|
||||
if((w = x - z) > awesomeconf->statusbar.height)
|
||||
{
|
||||
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);
|
||||
drawtext(disp, awesomeconf->phys_screen,
|
||||
x, y, w,
|
||||
awesomeconf->statusbar.height, gc,
|
||||
awesomeconf->statusbar.drawable, awesomeconf->font,
|
||||
sel->name, awesomeconf->colors_selected);
|
||||
if(sel->isfloating)
|
||||
drawsquare(disp, x, y, (awesomeconf->font->height + 2) / 4, gc, awesomeconf->statusbar.drawable, sel->ismax, awesomeconf->colors_selected[ColFG]);
|
||||
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(layout_tile) || IS_ARRANGE(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);
|
||||
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);
|
||||
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);
|
||||
XCopyArea(disp, awesomeconf->statusbar.drawable,
|
||||
awesomeconf->statusbar.window, gc, 0, 0,
|
||||
si[awesomeconf->screen].width, awesomeconf->statusbar.height, 0, 0);
|
||||
XFreeGC(awesomeconf->display, gc);
|
||||
XSync(disp, False);
|
||||
}
|
||||
|
@ -138,6 +188,7 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor)
|
|||
si[screen].width,
|
||||
statusbar->height,
|
||||
DefaultDepth(disp, phys_screen));
|
||||
statusbar->width = si[screen].width;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue