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"));
|
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));
|
txtlen = awesomeconf->font->height + textwidth(disp, awesomeconf->font, awesomeconf->layouts[i].symbol, a_strlen(awesomeconf->layouts[i].symbol));
|
||||||
if(txtlen > awesomeconf->statusbar.width)
|
if(txtlen > awesomeconf->statusbar.txtlayoutwidth)
|
||||||
awesomeconf->statusbar.width = txtlen;
|
awesomeconf->statusbar.txtlayoutwidth = txtlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
awesomeconf->mwfact = cfg_getfloat(cfg_layouts, "mwfact");
|
awesomeconf->mwfact = cfg_getfloat(cfg_layouts, "mwfact");
|
||||||
|
|
2
config.h
2
config.h
|
@ -67,6 +67,8 @@ typedef struct
|
||||||
int width;
|
int width;
|
||||||
/** Bar height */
|
/** Bar height */
|
||||||
int height;
|
int height;
|
||||||
|
/** Layout txt width */
|
||||||
|
int txtlayoutwidth;
|
||||||
/** Bar position */
|
/** Bar position */
|
||||||
int position;
|
int position;
|
||||||
/** Window */
|
/** Window */
|
||||||
|
|
|
@ -14,8 +14,8 @@ X11INC = /usr/include/X11
|
||||||
X11LIB = /usr/lib/X11
|
X11LIB = /usr/lib/X11
|
||||||
|
|
||||||
# includes and libs
|
# includes and libs
|
||||||
INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags libconfuse xft`
|
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` -lXext -lXrandr -lXinerama
|
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfuse xft cairo` -lXext -lXrandr -lXinerama
|
||||||
|
|
||||||
# flags
|
# 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}\"
|
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 "layout.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "draw.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
|
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;
|
cairo_surface_t *surface;
|
||||||
XRectangle r = { x, y, h, h };
|
cairo_t *cr;
|
||||||
|
|
||||||
gcv.foreground = color.pixel;
|
surface = cairo_xlib_surface_create(disp, drawable, DefaultVisual(disp, screen), dw, dh);
|
||||||
XChangeGC(disp, gc, GCForeground, &gcv);
|
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)
|
if(filled)
|
||||||
{
|
{
|
||||||
r.width++; r.height++;
|
cairo_rectangle(cr, x + 1, y + 1, h + 1, h + 1);
|
||||||
XFillRectangles(disp, drawable, gc, &r, 1);
|
cairo_fill(cr);
|
||||||
}
|
}
|
||||||
else
|
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"
|
#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, 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);
|
inline unsigned short textwidth(Display *, XftFont *, char *, ssize_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
81
statusbar.c
81
statusbar.c
|
@ -59,51 +59,101 @@ drawstatusbar(Display *disp, awesome_config * awesomeconf)
|
||||||
|
|
||||||
for(i = 0; i < awesomeconf->ntags; i++)
|
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)
|
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))
|
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
|
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))
|
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;
|
x += w;
|
||||||
}
|
}
|
||||||
w = awesomeconf->statusbar.width;
|
drawtext(disp, awesomeconf->phys_screen,
|
||||||
drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, gc, awesomeconf->statusbar.drawable, awesomeconf->font, awesomeconf->current_layout->symbol, awesomeconf->colors_normal);
|
x, y, awesomeconf->statusbar.txtlayoutwidth,
|
||||||
z = x + w;
|
awesomeconf->statusbar.height, gc,
|
||||||
w = textwidth(disp, awesomeconf->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext)) + awesomeconf->font->height;
|
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;
|
x = si[awesomeconf->screen].width - w;
|
||||||
if(x < z)
|
if(x < z)
|
||||||
{
|
{
|
||||||
x = z;
|
x = z;
|
||||||
w = si[awesomeconf->screen].width - 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)
|
if((w = x - z) > awesomeconf->statusbar.height)
|
||||||
{
|
{
|
||||||
x = z;
|
x = z;
|
||||||
if(sel)
|
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)
|
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))
|
else if(IS_ARRANGE(layout_tile) || IS_ARRANGE(layout_tileleft))
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
snprintf(buf, sizeof(buf), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncol, awesomeconf->mwfact);
|
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
|
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);
|
XFreeGC(awesomeconf->display, gc);
|
||||||
XSync(disp, False);
|
XSync(disp, False);
|
||||||
}
|
}
|
||||||
|
@ -138,6 +188,7 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor)
|
||||||
si[screen].width,
|
si[screen].width,
|
||||||
statusbar->height,
|
statusbar->height,
|
||||||
DefaultDepth(disp, phys_screen));
|
DefaultDepth(disp, phys_screen));
|
||||||
|
statusbar->width = si[screen].width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue