diff --git a/caca/caca.h b/caca/caca.h index 4beeab2..1bcb7af 100644 --- a/caca/caca.h +++ b/caca/caca.h @@ -244,8 +244,7 @@ int caca_get_event(caca_t *kk, unsigned int, struct caca_event *); int caca_wait_event(caca_t *kk, unsigned int, struct caca_event *); unsigned int caca_get_mouse_x(caca_t *kk); unsigned int caca_get_mouse_y(caca_t *kk); -void caca_hide_cursor(caca_t *kk); -void caca_show_cursor(caca_t *kk); +void caca_set_mouse(caca_t *kk, int); /* @} */ #ifdef __cplusplus diff --git a/caca/caca_internals.h b/caca/caca_internals.h index 16d16e8..125ff71 100644 --- a/caca/caca_internals.h +++ b/caca/caca_internals.h @@ -117,8 +117,7 @@ struct caca_context void (* display) (caca_t *); void (* handle_resize) (caca_t *); int (* get_event) (caca_t *, struct caca_event *); - void (* show_cursor) (caca_t *); - void (* hide_cursor) (caca_t *); + void (* set_mouse) (caca_t *, int); } drv; /* Mouse position */ diff --git a/caca/driver_conio.c b/caca/driver_conio.c index 6b55965..1bfe3fa 100644 --- a/caca/driver_conio.c +++ b/caca/driver_conio.c @@ -163,8 +163,7 @@ int conio_install(caca_t *kk) kk->drv.display = conio_display; kk->drv.handle_resize = conio_handle_resize; kk->drv.get_event = conio_get_event; - kk->drv.show_cursor = NULL; - kk->drv.hide_cursor = NULL; + kk->drv.set_mouse = NULL; return 0; } diff --git a/caca/driver_gl.c b/caca/driver_gl.c index 9bf286a..448f48c 100644 --- a/caca/driver_gl.c +++ b/caca/driver_gl.c @@ -387,18 +387,14 @@ static int gl_get_event(caca_t *kk, struct caca_event *ev) } -static void gl_show_cursor(caca_t *kk) +static void gl_set_mouse(caca_t *kk, int flag) { - glutSetCursor(GLUT_CURSOR_RIGHT_ARROW); -} - -static void gl_hide_cursor(caca_t *kk) -{ - glutSetCursor(GLUT_CURSOR_NONE); + if(flag) + glutSetCursor(GLUT_CURSOR_RIGHT_ARROW); + else + glutSetCursor(GLUT_CURSOR_NONE); } - - /* * XXX: following functions are local */ @@ -477,8 +473,8 @@ int gl_install(caca_t *kk) kk->drv.display = gl_display; kk->drv.handle_resize = gl_handle_resize; kk->drv.get_event = gl_get_event; - kk->drv.show_cursor = gl_show_cursor; - kk->drv.hide_cursor = gl_hide_cursor; + kk->drv.set_mouse = gl_set_mouse; + return 0; } diff --git a/caca/driver_ncurses.c b/caca/driver_ncurses.c index 44c30bd..9f2bf15 100644 --- a/caca/driver_ncurses.c +++ b/caca/driver_ncurses.c @@ -542,8 +542,8 @@ int ncurses_install(caca_t *kk) kk->drv.display = ncurses_display; kk->drv.handle_resize = ncurses_handle_resize; kk->drv.get_event = ncurses_get_event; - kk->drv.show_cursor = NULL; - kk->drv.hide_cursor = NULL; + kk->drv.set_mouse = NULL; + return 0; } diff --git a/caca/driver_network.c b/caca/driver_network.c index 726badd..3273fac 100644 --- a/caca/driver_network.c +++ b/caca/driver_network.c @@ -562,12 +562,10 @@ int network_install(caca_t *kk) kk->drv.display = network_display; kk->drv.handle_resize = network_handle_resize; kk->drv.get_event = network_get_event; - kk->drv.show_cursor = NULL; - kk->drv.hide_cursor = NULL; + kk->drv.set_mouse = NULL; return 0; } - #endif /* USE_NETWORK */ diff --git a/caca/driver_slang.c b/caca/driver_slang.c index a72de12..a10a17c 100644 --- a/caca/driver_slang.c +++ b/caca/driver_slang.c @@ -480,8 +480,7 @@ int slang_install(caca_t *kk) kk->drv.display = slang_display; kk->drv.handle_resize = slang_handle_resize; kk->drv.get_event = slang_get_event; - kk->drv.show_cursor = NULL; - kk->drv.hide_cursor = NULL; + kk->drv.set_mouse = NULL; return 0; } diff --git a/caca/driver_vga.c b/caca/driver_vga.c index a6d4335..769eeb9 100644 --- a/caca/driver_vga.c +++ b/caca/driver_vga.c @@ -157,8 +157,7 @@ int vga_install(caca_t *kk) kk->drv.display = vga_display; kk->drv.handle_resize = vga_handle_resize; kk->drv.get_event = vga_get_event; - kk->drv.show_cursor = NULL; - kk->drv.hide_cursor = NULL; + kk->drv.set_mouse = NULL; return 0; } diff --git a/caca/driver_win32.c b/caca/driver_win32.c index d141e1c..e9f3b4d 100644 --- a/caca/driver_win32.c +++ b/caca/driver_win32.c @@ -345,8 +345,7 @@ int win32_install(caca_t *kk) kk->drv.display = win32_display; kk->drv.handle_resize = win32_handle_resize; kk->drv.get_event = win32_get_event; - kk->drv.show_cursor = NULL; - kk->drv.hide_cursor = NULL; + kk->drv.set_mouse = NULL; return 0; } diff --git a/caca/driver_x11.c b/caca/driver_x11.c index 2e016a2..d0575a4 100644 --- a/caca/driver_x11.c +++ b/caca/driver_x11.c @@ -209,8 +209,6 @@ static int x11_init_graphics(caca_t *kk) kk->qq->height * kk->drv.p->font_height, DefaultDepth(kk->drv.p->dpy, DefaultScreen(kk->drv.p->dpy))); - - kk->drv.p->pointer = None; return 0; @@ -537,37 +535,38 @@ static int x11_get_event(caca_t *kk, struct caca_event *ev) return 0; } -static void x11_show_cursor(caca_t *kk) -{ - XDefineCursor(kk->drv.p->dpy,kk->drv.p->window, 0); -} - -static void x11_hide_cursor(caca_t *kk) +static void x11_set_mouse(caca_t *kk, int flags) { Cursor no_ptr; Pixmap bm_no; XColor black, dummy; Colormap colormap; - static char empty[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + static char const empty[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + + if(flags) + { + XDefineCursor(kk->drv.p->dpy,kk->drv.p->window, 0); + return; + } colormap = DefaultColormap(kk->drv.p->dpy, DefaultScreen(kk->drv.p->dpy)); - if ( !XAllocNamedColor(kk->drv.p->dpy, colormap, "black", &black, &dummy) ) + if(!XAllocNamedColor(kk->drv.p->dpy, colormap, "black", &black, &dummy)) { - return; + return; } - bm_no = XCreateBitmapFromData(kk->drv.p->dpy, kk->drv.p->window, empty, 8, 8); - no_ptr = XCreatePixmapCursor(kk->drv.p->dpy, bm_no, bm_no, &black, &black, 0, 0); - XDefineCursor(kk->drv.p->dpy, kk->drv.p->window, no_ptr); + bm_no = XCreateBitmapFromData(kk->drv.p->dpy, kk->drv.p->window, + empty, 8, 8); + no_ptr = XCreatePixmapCursor(kk->drv.p->dpy, bm_no, bm_no, + &black, &black, 0, 0); + XDefineCursor(kk->drv.p->dpy, kk->drv.p->window, no_ptr); XFreeCursor(kk->drv.p->dpy, no_ptr); - if (bm_no != None) + if(bm_no != None) XFreePixmap(kk->drv.p->dpy, bm_no); - XFreeColors(kk->drv.p->dpy,colormap,&black.pixel,1,0); + XFreeColors(kk->drv.p->dpy, colormap, &black.pixel, 1, 0); XSync(kk->drv.p->dpy, False); - } - /* * XXX: following functions are local */ @@ -599,8 +598,7 @@ int x11_install(caca_t *kk) kk->drv.display = x11_display; kk->drv.handle_resize = x11_handle_resize; kk->drv.get_event = x11_get_event; - kk->drv.show_cursor = x11_show_cursor; - kk->drv.hide_cursor = x11_hide_cursor; + kk->drv.set_mouse = x11_set_mouse; return 0; } diff --git a/caca/graphics.c b/caca/graphics.c index aded996..ee3933b 100644 --- a/caca/graphics.c +++ b/caca/graphics.c @@ -143,29 +143,20 @@ void caca_display(caca_t *kk) kk->lastticks = 0; } -/** \brief Show cursor on capable drivers +/** \brief Show or hide the mouse pointer. * - * This function shows the cursor on drivers permitting it. + * This function shows or hides the mouse pointer, for devices that + * support it. * + * \param flag 0 hides the pointer, 1 shows the system's default pointer + * (usually an arrow). Other values are reserved for future use. */ -void caca_show_cursor(caca_t *kk) +void caca_set_mouse(caca_t *kk, int flag) { - if(kk->drv.show_cursor) - kk->drv.show_cursor(kk); + if(kk->drv.set_mouse) + kk->drv.set_mouse(kk, flag); } -/** \brief Hide cursor on capable drivers - * - * This function hides the cursor on drivers permitting it. - * - */ -void caca_hide_cursor(caca_t *kk) -{ - if(kk->drv.hide_cursor) - kk->drv.hide_cursor(kk); -} - - /* * XXX: following functions are local */ diff --git a/test/demo.c b/test/demo.c index 0a5a0da..0195141 100644 --- a/test/demo.c +++ b/test/demo.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) sprite = cucul_load_sprite(qq, "examples/caca.txt"); /* Disable cursor */ - caca_hide_cursor(kk); + caca_set_mouse(kk, 0); /* Main menu */ display_menu();