aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2017-10-05 12:30:31 +0200
committerBert Münnich <ber.t@posteo.de>2017-10-05 12:30:31 +0200
commitb8fd923e740bcbaebe523c48ca67c3725c1b3863 (patch)
tree5390e7af412714ed3e4c5f9e6ff36d2190ee17a5
parente310136e02ada4862c250280034d36fbfa24fc61 (diff)
Simplify cursor handling
-rw-r--r--Makefile2
-rw-r--r--types.h6
-rw-r--r--window.c49
3 files changed, 25 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index cc447de..2c5b701 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION := git-20171004
+VERSION := git-20171005
all: sxiv
diff --git a/types.h b/types.h
index 57402e0..eacbd62 100644
--- a/types.h
+++ b/types.h
@@ -65,9 +65,11 @@ typedef enum {
typedef enum {
CURSOR_ARROW,
- CURSOR_NONE,
CURSOR_DRAG,
- CURSOR_WATCH
+ CURSOR_WATCH,
+ CURSOR_NONE,
+
+ CURSOR_COUNT
} cursor_t;
typedef enum {
diff --git a/window.c b/window.c
index 6ed4bfc..72b94b2 100644
--- a/window.c
+++ b/window.c
@@ -35,10 +35,13 @@ enum {
V_TEXT_PAD = 1
};
-static Cursor carrow;
-static Cursor cnone;
-static Cursor cdrag;
-static Cursor cwatch;
+static struct {
+ int name;
+ Cursor icon;
+} cursors[CURSOR_COUNT] = {
+ { XC_left_ptr }, { XC_dotbox }, { XC_watch }
+};
+
static GC gc;
static XftFont *font;
@@ -153,6 +156,7 @@ void win_open(win_t *win)
XClassHint classhint;
unsigned long *icon_data;
XColor col;
+ Cursor *cnone = &cursors[CURSOR_NONE].icon;
char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
Pixmap none;
int gmask;
@@ -209,17 +213,17 @@ void win_open(win_t *win)
ButtonReleaseMask | ButtonPressMask | KeyPressMask |
PointerMotionMask | StructureNotifyMask);
- carrow = XCreateFontCursor(e->dpy, XC_left_ptr);
- cdrag = XCreateFontCursor(e->dpy, XC_dotbox);
- cwatch = XCreateFontCursor(e->dpy, XC_watch);
-
+ for (i = 0; i < ARRLEN(cursors); i++) {
+ if (i != CURSOR_NONE)
+ cursors[i].icon = XCreateFontCursor(e->dpy, cursors[i].name);
+ }
if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black",
&col, &col) == 0)
{
error(EXIT_FAILURE, 0, "Error allocating color 'black'");
}
none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8);
- cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0);
+ *cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0);
gc = XCreateGC(e->dpy, win->xwin, 0, None);
@@ -275,10 +279,10 @@ void win_open(win_t *win)
CLEANUP void win_close(win_t *win)
{
- XFreeCursor(win->env.dpy, carrow);
- XFreeCursor(win->env.dpy, cnone);
- XFreeCursor(win->env.dpy, cdrag);
- XFreeCursor(win->env.dpy, cwatch);
+ int i;
+
+ for (i = 0; i < ARRLEN(cursors); i++)
+ XFreeCursor(win->env.dpy, cursors[i].icon);
XFreeGC(win->env.dpy, gc);
@@ -461,21 +465,8 @@ void win_set_title(win_t *win, const char *title)
void win_set_cursor(win_t *win, cursor_t cursor)
{
- switch (cursor) {
- case CURSOR_NONE:
- XDefineCursor(win->env.dpy, win->xwin, cnone);
- break;
- case CURSOR_DRAG:
- XDefineCursor(win->env.dpy, win->xwin, cdrag);
- break;
- case CURSOR_WATCH:
- XDefineCursor(win->env.dpy, win->xwin, cwatch);
- break;
- case CURSOR_ARROW:
- default:
- XDefineCursor(win->env.dpy, win->xwin, carrow);
- break;
+ if (cursor >= 0 && cursor < ARRLEN(cursors)) {
+ XDefineCursor(win->env.dpy, win->xwin, cursors[cursor].icon);
+ XFlush(win->env.dpy);
}
-
- XFlush(win->env.dpy);
}