Simplify cursor handling
This commit is contained in:
parent
e310136e02
commit
b8fd923e74
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
VERSION := git-20171004
|
VERSION := git-20171005
|
||||||
|
|
||||||
all: sxiv
|
all: sxiv
|
||||||
|
|
||||||
|
|
6
types.h
6
types.h
|
@ -65,9 +65,11 @@ typedef enum {
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CURSOR_ARROW,
|
CURSOR_ARROW,
|
||||||
CURSOR_NONE,
|
|
||||||
CURSOR_DRAG,
|
CURSOR_DRAG,
|
||||||
CURSOR_WATCH
|
CURSOR_WATCH,
|
||||||
|
CURSOR_NONE,
|
||||||
|
|
||||||
|
CURSOR_COUNT
|
||||||
} cursor_t;
|
} cursor_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
49
window.c
49
window.c
|
@ -35,10 +35,13 @@ enum {
|
||||||
V_TEXT_PAD = 1
|
V_TEXT_PAD = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
static Cursor carrow;
|
static struct {
|
||||||
static Cursor cnone;
|
int name;
|
||||||
static Cursor cdrag;
|
Cursor icon;
|
||||||
static Cursor cwatch;
|
} cursors[CURSOR_COUNT] = {
|
||||||
|
{ XC_left_ptr }, { XC_dotbox }, { XC_watch }
|
||||||
|
};
|
||||||
|
|
||||||
static GC gc;
|
static GC gc;
|
||||||
|
|
||||||
static XftFont *font;
|
static XftFont *font;
|
||||||
|
@ -153,6 +156,7 @@ void win_open(win_t *win)
|
||||||
XClassHint classhint;
|
XClassHint classhint;
|
||||||
unsigned long *icon_data;
|
unsigned long *icon_data;
|
||||||
XColor col;
|
XColor col;
|
||||||
|
Cursor *cnone = &cursors[CURSOR_NONE].icon;
|
||||||
char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
Pixmap none;
|
Pixmap none;
|
||||||
int gmask;
|
int gmask;
|
||||||
|
@ -209,17 +213,17 @@ void win_open(win_t *win)
|
||||||
ButtonReleaseMask | ButtonPressMask | KeyPressMask |
|
ButtonReleaseMask | ButtonPressMask | KeyPressMask |
|
||||||
PointerMotionMask | StructureNotifyMask);
|
PointerMotionMask | StructureNotifyMask);
|
||||||
|
|
||||||
carrow = XCreateFontCursor(e->dpy, XC_left_ptr);
|
for (i = 0; i < ARRLEN(cursors); i++) {
|
||||||
cdrag = XCreateFontCursor(e->dpy, XC_dotbox);
|
if (i != CURSOR_NONE)
|
||||||
cwatch = XCreateFontCursor(e->dpy, XC_watch);
|
cursors[i].icon = XCreateFontCursor(e->dpy, cursors[i].name);
|
||||||
|
}
|
||||||
if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black",
|
if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black",
|
||||||
&col, &col) == 0)
|
&col, &col) == 0)
|
||||||
{
|
{
|
||||||
error(EXIT_FAILURE, 0, "Error allocating color 'black'");
|
error(EXIT_FAILURE, 0, "Error allocating color 'black'");
|
||||||
}
|
}
|
||||||
none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8);
|
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);
|
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)
|
CLEANUP void win_close(win_t *win)
|
||||||
{
|
{
|
||||||
XFreeCursor(win->env.dpy, carrow);
|
int i;
|
||||||
XFreeCursor(win->env.dpy, cnone);
|
|
||||||
XFreeCursor(win->env.dpy, cdrag);
|
for (i = 0; i < ARRLEN(cursors); i++)
|
||||||
XFreeCursor(win->env.dpy, cwatch);
|
XFreeCursor(win->env.dpy, cursors[i].icon);
|
||||||
|
|
||||||
XFreeGC(win->env.dpy, gc);
|
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)
|
void win_set_cursor(win_t *win, cursor_t cursor)
|
||||||
{
|
{
|
||||||
switch (cursor) {
|
if (cursor >= 0 && cursor < ARRLEN(cursors)) {
|
||||||
case CURSOR_NONE:
|
XDefineCursor(win->env.dpy, win->xwin, cursors[cursor].icon);
|
||||||
XDefineCursor(win->env.dpy, win->xwin, cnone);
|
XFlush(win->env.dpy);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XFlush(win->env.dpy);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue