Skip to content

Commit

Permalink
Merge pull request #46 from ideasman42/xft-update
Browse files Browse the repository at this point in the history
Updated XFT support against master
  • Loading branch information
raboof committed Jun 19, 2017
2 parents 5720c41 + 9881adf commit 32784ef
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ matrix:
exclude:
- compiler: clang
env: C99_SOURCE=""
before_install: sudo apt-get install lua5.2 liblua5.2-dev gettext
before_install: sudo apt-get install lua5.2 liblua5.2-dev gettext libxft-dev
script:
- make
- make test
22 changes: 22 additions & 0 deletions de/brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ bool debrush_init(DEBrush *brush, Window win,

gr_stylespec_init(&brush->current_attr);

#ifdef HAVE_X11_XFT
brush->draw=NULL;
#endif /* HAVE_X11_XFT */
style->usecount++;

if(!grbrush_init(&(brush->grbrush))){
Expand Down Expand Up @@ -128,6 +131,10 @@ void debrush_deinit(DEBrush *brush)
{
destyle_unref(brush->d);
brush->d=NULL;
#ifdef HAVE_X11_XFT
if(brush->draw!=NULL)
XftDrawDestroy(brush->draw);
#endif /* HAVE_X11_XFT */
gr_stylespec_unalloc(&brush->current_attr);
grbrush_deinit(&(brush->grbrush));
}
Expand All @@ -139,6 +146,21 @@ void debrush_release(DEBrush *brush)
}


#ifdef HAVE_X11_XFT
XftDraw *debrush_get_draw(DEBrush *brush, Drawable d)
{
if(brush->draw==NULL)
brush->draw=XftDrawCreate(ioncore_g.dpy, d,
XftDEDefaultVisual(),
DefaultColormap(ioncore_g.dpy,
0));
else
XftDrawChange(brush->draw, d);

return brush->draw;
}
#endif

/*}}}*/


Expand Down
10 changes: 10 additions & 0 deletions de/brush.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <ioncore/gr.h>
#include <ioncore/rectangle.h>

#ifdef HAVE_X11_XFT
#include <X11/Xft/Xft.h>
#endif /* HAVE_X11_XFT */

INTRCLASS(DEBrush);

#include "style.h"
Expand All @@ -33,6 +37,9 @@ typedef void DEBrushExtrasFn(DEBrush *brush,
DECLCLASS(DEBrush){
GrBrush grbrush;
DEStyle *d;
#ifdef HAVE_X11_XFT
XftDraw *draw;
#endif
DEBrushExtrasFn *extras_fn;
int indicator_w;
Window win;
Expand Down Expand Up @@ -108,5 +115,8 @@ extern void debrush_enable_transparency(DEBrush *brush, GrTransparency mode);
extern void debrush_fill_area(DEBrush *brush, const WRectangle *geom);
extern void debrush_clear_area(DEBrush *brush, const WRectangle *geom);

#ifdef HAVE_X11_XFT
XftDraw *debrush_get_draw(DEBrush *brush, Drawable d);
#endif

#endif /* ION_DE_BRUSH_H */
32 changes: 32 additions & 0 deletions de/colour.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@

bool de_alloc_colour(WRootWin *rootwin, DEColour *ret, const char *name)
{
#ifdef HAVE_X11_XFT
if(name==NULL)
return FALSE;
return XftColorAllocName(
ioncore_g.dpy,
XftDEDefaultVisual(),
rootwin->default_cmap,
name,
ret);
#else /* HAVE_X11_XFT */
XColor c;
bool ok=FALSE;

Expand All @@ -25,11 +35,20 @@ bool de_alloc_colour(WRootWin *rootwin, DEColour *ret, const char *name)
}

return ok;
#endif /* HAVE_X11_XFT */
}


bool de_duplicate_colour(WRootWin *rootwin, DEColour in, DEColour *out)
{
#ifdef HAVE_X11_XFT
return XftColorAllocValue(
ioncore_g.dpy,
XftDEDefaultVisual(),
rootwin->default_cmap,
&(in.color),
out);
#else /* HAVE_X11_XFT */
XColor c;
c.pixel=in;
XQueryColor(ioncore_g.dpy, rootwin->default_cmap, &c);
Expand All @@ -38,11 +57,19 @@ bool de_duplicate_colour(WRootWin *rootwin, DEColour in, DEColour *out)
return TRUE;
}
return FALSE;
#endif /* HAVE_X11_XFT */
}


void de_free_colour_group(WRootWin *rootwin, DEColourGroup *cg)
{
#ifdef HAVE_X11_XFT
de_free_colour(rootwin, cg->bg);
de_free_colour(rootwin, cg->fg);
de_free_colour(rootwin, cg->hl);
de_free_colour(rootwin, cg->sh);
de_free_colour(rootwin, cg->pad);
#else /* HAVE_X11_XFT */
DEColour pixels[5];

pixels[0]=cg->bg;
Expand All @@ -54,15 +81,20 @@ void de_free_colour_group(WRootWin *rootwin, DEColourGroup *cg)
XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 5, 0);

gr_stylespec_unalloc(&cg->spec);
#endif /* HAVE_X11_XFT */
}


void de_free_colour(WRootWin *rootwin, DEColour col)
{
#ifdef HAVE_X11_XFT
XftColorFree(ioncore_g.dpy, XftDEDefaultVisual(), rootwin->default_cmap, &col);
#else /* HAVE_X11_XFT */
DEColour pixels[1];

pixels[0]=col;

XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 1, 0);
#endif /* HAVE_X11_XFT */
}

8 changes: 8 additions & 0 deletions de/colour.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
#include <ioncore/common.h>
#include <ioncore/global.h>
#include <ioncore/rootwin.h>
#ifdef HAVE_X11_XFT
#include <X11/Xft/Xft.h>
#endif /* HAVE_X11_XFT */


INTRSTRUCT(DEColourGroup);


#ifdef HAVE_X11_XFT
typedef XftColor DEColour;
#else /* HAVE_X11_XFT */
typedef unsigned long DEColour;
#endif /* HAVE_X11_XFT */


DECLSTRUCT(DEColourGroup){
Expand All @@ -34,5 +41,6 @@ bool de_alloc_colour(WRootWin *rootwin, DEColour *ret, const char *name);
bool de_duplicate_colour(WRootWin *rootwin, DEColour in, DEColour *out);
void de_free_colour_group(WRootWin *rootwin, DEColourGroup *cg);
void de_free_colour(WRootWin *rootwin, DEColour col);
#define XftDEDefaultVisual() DefaultVisual(ioncore_g.dpy, 0)

#endif /* ION_DE_COLOUR_H */
35 changes: 21 additions & 14 deletions de/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
#include <X11/extensions/shape.h>


#ifdef HAVE_X11_XFT
# define PIXEL(x) (x).pixel
#else /* HAVE_X11_XFT */
# define PIXEL(x) x
#endif /* HAVE_X11_XFT */


/*{{{ Colour group lookup */


Expand Down Expand Up @@ -84,7 +91,7 @@ static void do_draw_border(Window win, GC gc, int x, int y, int w, int h,
w--;
h--;

XSetForeground(ioncore_g.dpy, gc, tlc);
XSetForeground(ioncore_g.dpy, gc, PIXEL(tlc));


a=(br!=0);
Expand All @@ -104,7 +111,7 @@ static void do_draw_border(Window win, GC gc, int x, int y, int w, int h,
}


XSetForeground(ioncore_g.dpy, gc, brc);
XSetForeground(ioncore_g.dpy, gc, PIXEL(brc));

a=(tl!=0);
b=0;
Expand Down Expand Up @@ -141,23 +148,23 @@ static void draw_borderline(Window win, GC gc, WRectangle *geom,
GrBorderLine line)
{
if(line==GR_BORDERLINE_LEFT && geom->h>0 && tl>0){
XSetForeground(ioncore_g.dpy, gc, tlc);
XSetBackground(ioncore_g.dpy, gc, tlc);
XSetForeground(ioncore_g.dpy, gc, PIXEL(tlc));
XSetBackground(ioncore_g.dpy, gc, PIXEL(tlc));
XFillRectangle(ioncore_g.dpy, win, gc, geom->x, geom->y, tl, geom->h);
geom->x+=tl;
}else if(line==GR_BORDERLINE_TOP && geom->w>0 && tl>0){
XSetForeground(ioncore_g.dpy, gc, tlc);
XSetBackground(ioncore_g.dpy, gc, tlc);
XSetForeground(ioncore_g.dpy, gc, PIXEL(tlc));
XSetBackground(ioncore_g.dpy, gc, PIXEL(tlc));
XFillRectangle(ioncore_g.dpy, win, gc, geom->x, geom->y, geom->w, tl);
geom->y+=tl;
}else if(line==GR_BORDERLINE_RIGHT && geom->h>0 && br>0){
XSetForeground(ioncore_g.dpy, gc, brc);
XSetBackground(ioncore_g.dpy, gc, brc);
XSetForeground(ioncore_g.dpy, gc, PIXEL(brc));
XSetBackground(ioncore_g.dpy, gc, PIXEL(brc));
XFillRectangle(ioncore_g.dpy, win, gc, geom->x+geom->w-br, geom->y, br, geom->h);
geom->w-=br;
}else if(line==GR_BORDERLINE_BOTTOM && geom->w>0 && br>0){
XSetForeground(ioncore_g.dpy, gc, brc);
XSetBackground(ioncore_g.dpy, gc, brc);
XSetForeground(ioncore_g.dpy, gc, PIXEL(brc));
XSetBackground(ioncore_g.dpy, gc, PIXEL(brc));
XFillRectangle(ioncore_g.dpy, win, gc, geom->x, geom->y+geom->h-br, geom->w, br);
geom->h-=br;
}
Expand Down Expand Up @@ -388,7 +395,7 @@ void debrush_tab_extras(DEBrush *brush, const WRectangle *g,
}

if(ISSET(a2, GR_ATTR(tagged)) || ISSET(a1, GR_ATTR(tagged))){
XSetForeground(ioncore_g.dpy, d->copy_gc, cg->fg);
XSetForeground(ioncore_g.dpy, d->copy_gc, PIXEL(cg->fg));

copy_masked(brush, d->tag_pixmap, brush->win, 0, 0,
d->tag_pixmap_w, d->tag_pixmap_h,
Expand Down Expand Up @@ -437,7 +444,7 @@ void debrush_do_draw_box(DEBrush *brush, const WRectangle *geom,
GC gc=brush->d->normal_gc;

if(TRUE/*needfill*/){
XSetForeground(ioncore_g.dpy, gc, cg->bg);
XSetForeground(ioncore_g.dpy, gc, PIXEL(cg->bg));
XFillRectangle(ioncore_g.dpy, brush->win, gc, geom->x, geom->y,
geom->w, geom->h);
}
Expand Down Expand Up @@ -605,7 +612,7 @@ void debrush_enable_transparency(DEBrush *brush, GrTransparency mode)
attr.background_pixmap=ParentRelative;
}else{
attrflags=CWBackPixel;
attr.background_pixel=brush->d->cgrp.bg;
attr.background_pixel=PIXEL(brush->d->cgrp.bg);
}

XChangeWindowAttributes(ioncore_g.dpy, brush->win, attrflags, &attr);
Expand All @@ -621,7 +628,7 @@ void debrush_fill_area(DEBrush *brush, const WRectangle *geom)
if(cg==NULL)
return;

XSetForeground(ioncore_g.dpy, gc, cg->bg);
XSetForeground(ioncore_g.dpy, gc, PIXEL(cg->bg));
XFillRectangle(ioncore_g.dpy, brush->win, gc,
geom->x, geom->y, geom->w, geom->h);
}
Expand Down
Loading

0 comments on commit 32784ef

Please sign in to comment.