| @@ -35,10 +35,13 @@ enum { |
| 35 | 35 | | V_TEXT_PAD = 1 |
| 36 | 36 | | }; |
| 37 | 37 | | |
| 38 | | − | static Cursor carrow; |
| 39 | | − | static Cursor cnone; |
| 40 | | − | static Cursor cdrag; |
| 41 | | − | static Cursor cwatch; |
| 38 | + | static struct { |
| 39 | + | int name; |
| 40 | + | Cursor icon; |
| 41 | + | } cursors[CURSOR_COUNT] = { |
| 42 | + | { XC_left_ptr }, { XC_dotbox }, { XC_watch } |
| 43 | + | }; |
| 44 | + | |
| 42 | 45 | | static GC gc; |
| 43 | 46 | | |
| 44 | 47 | | static XftFont *font; |
| @@ -153,6 +156,7 @@ void win_open(win_t *win) |
| 153 | 156 | | XClassHint classhint; |
| 154 | 157 | | unsigned long *icon_data; |
| 155 | 158 | | XColor col; |
| 159 | + | Cursor *cnone = &cursors[CURSOR_NONE].icon; |
| 156 | 160 | | char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 157 | 161 | | Pixmap none; |
| 158 | 162 | | int gmask; |
| @@ -209,17 +213,17 @@ void win_open(win_t *win) |
| 209 | 213 | | ButtonReleaseMask | ButtonPressMask | KeyPressMask | |
| 210 | 214 | | PointerMotionMask | StructureNotifyMask); |
| 211 | 215 | | |
| 212 | | − | carrow = XCreateFontCursor(e->dpy, XC_left_ptr); |
| 213 | | − | cdrag = XCreateFontCursor(e->dpy, XC_dotbox); |
| 214 | | − | cwatch = XCreateFontCursor(e->dpy, XC_watch); |
| 215 | | − | |
| 216 | + | for (i = 0; i < ARRLEN(cursors); i++) { |
| 217 | + | if (i != CURSOR_NONE) |
| 218 | + | cursors[i].icon = XCreateFontCursor(e->dpy, cursors[i].name); |
| 219 | + | } |
| 216 | 220 | | if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black", |
| 217 | 221 | | &col, &col) == 0) |
| 218 | 222 | | { |
| 219 | 223 | | error(EXIT_FAILURE, 0, "Error allocating color 'black'"); |
| 220 | 224 | | } |
| 221 | 225 | | none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); |
| 222 | | − | cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); |
| 226 | + | *cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); |
| 223 | 227 | | |
| 224 | 228 | | gc = XCreateGC(e->dpy, win->xwin, 0, None); |
| 225 | 229 | | |
| @@ -275,10 +279,10 @@ void win_open(win_t *win) |
| 275 | 279 | | |
| 276 | 280 | | CLEANUP void win_close(win_t *win) |
| 277 | 281 | | { |
| 278 | | − | XFreeCursor(win->env.dpy, carrow); |
| 279 | | − | XFreeCursor(win->env.dpy, cnone); |
| 280 | | − | XFreeCursor(win->env.dpy, cdrag); |
| 281 | | − | XFreeCursor(win->env.dpy, cwatch); |
| 282 | + | int i; |
| 283 | + | |
| 284 | + | for (i = 0; i < ARRLEN(cursors); i++) |
| 285 | + | XFreeCursor(win->env.dpy, cursors[i].icon); |
| 282 | 286 | | |
| 283 | 287 | | XFreeGC(win->env.dpy, gc); |
| 284 | 288 | | |
| @@ -461,21 +465,8 @@ void win_set_title(win_t *win, const char *title) |
| 461 | 465 | | |
| 462 | 466 | | void win_set_cursor(win_t *win, cursor_t cursor) |
| 463 | 467 | | { |
| 464 | | − | switch (cursor) { |
| 465 | | − | case CURSOR_NONE: |
| 466 | | − | XDefineCursor(win->env.dpy, win->xwin, cnone); |
| 467 | | − | break; |
| 468 | | − | case CURSOR_DRAG: |
| 469 | | − | XDefineCursor(win->env.dpy, win->xwin, cdrag); |
| 470 | | − | break; |
| 471 | | − | case CURSOR_WATCH: |
| 472 | | − | XDefineCursor(win->env.dpy, win->xwin, cwatch); |
| 473 | | − | break; |
| 474 | | − | case CURSOR_ARROW: |
| 475 | | − | default: |
| 476 | | − | XDefineCursor(win->env.dpy, win->xwin, carrow); |
| 477 | | − | break; |
| 468 | + | if (cursor >= 0 && cursor < ARRLEN(cursors)) { |
| 469 | + | XDefineCursor(win->env.dpy, win->xwin, cursors[cursor].icon); |
| 470 | + | XFlush(win->env.dpy); |
| 478 | 471 | | } |
| 479 | | − | |
| 480 | | − | XFlush(win->env.dpy); |
| 481 | 472 | | } |