diff options
| author | Quentin Carbonneaux | 2014-08-25 12:31:49 -0400 |
|---|---|---|
| committer | Quentin Carbonneaux | 2014-08-25 12:31:49 -0400 |
| commit | d06b27f1e96ff2f2576f2972d59ea5115c0457bb (patch) | |
| tree | f9448b6207fde4fc0e5e66f1c38a33dd07c668cd | |
| parent | fad898d3866ed1f9879284dba53cd30e80c5d00d (diff) | |
first stab at the cursor support api
| -rw-r--r-- | gui.h | 16 | ||||
| -rw-r--r-- | x11.c | 30 |
2 files changed, 39 insertions, 7 deletions
@@ -4,10 +4,16 @@ #include "unicode.h" -typedef struct gcolor GColor; -typedef struct gfont GFont; -typedef struct grect GRect; -typedef struct gevent GEvent; +typedef struct gcolor GColor; +typedef struct gfont GFont; +typedef struct grect GRect; +typedef struct gevent GEvent; +typedef enum gpointer GPointer; + +enum gpointer { + GPNormal, + GPResize, +}; struct gcolor { unsigned char red; @@ -100,6 +106,8 @@ struct gui { void (*drawtext)(GRect *clip, Rune *str, int len, int x, int y, GColor color); void (*drawrect)(GRect *clip, int x, int y, int w, int h, GColor c); + int (*ptincontrol)(GRect *clip, int x, int y); + void (*setpointer)(GPointer pt); int (*textwidth)(Rune *str, int len); int (*nextevent)(GEvent *eret); int hmargin; @@ -5,6 +5,7 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xft/Xft.h> +#include <X11/cursorfont.h> #include "gui.h" @@ -169,6 +170,27 @@ decorate(GRect *clip, int dirty, GColor c) } static int +ptincontrol(GRect *clip, int x, int y) +{ + return + (x -= clip->x) >= 0 && x < HMargin-3 && + (y -= clip->y) >= 0 && y < VMargin + font->height; +} + +static void +setpointer(GPointer pt) +{ + static unsigned int map[] = { + [GPNormal] = XC_left_ptr, + [GPResize] = XC_center_ptr, + }; + Cursor c; + + c = XCreateFontCursor(d, map[pt]); + XDefineCursor(d, win, c); +} + +static int textwidth(Rune *str, int len) { XGlyphInfo gi; @@ -323,12 +345,14 @@ struct gui gui_x11 = { .init = init, .fini = fini, .sync = sync, - .getfont = getfont, .decorate = decorate, - .drawtext = drawtext, .drawrect = drawrect, - .textwidth = textwidth, + .drawtext = drawtext, + .getfont = getfont, .nextevent = nextevent, + .ptincontrol = ptincontrol, + .setpointer = setpointer, + .textwidth = textwidth, .hmargin = HMargin, .vmargin = VMargin, .border = Border, |
