[AD] X hardware cursors fix |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Without the attached patch, the if the first cursor shown was:
- MOUSE_CURSOR_ALLEGRO: then choose a system cursor later would do nothing
- something else: then MOUSE_CURSOR_ALLEGRO would not be hardware
accelerated
Also attached is the start of an example program, which demonstrates the
bug.
Peter
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.87
diff -u -p -r1.87 xwin.c
--- src/x/xwin.c 19 Mar 2005 11:15:07 -0000 1.87
+++ src/x/xwin.c 19 Mar 2005 13:35:09 -0000
@@ -331,6 +331,18 @@ static void _xwin_hide_x_mouse(void)
XGCValues gcvalues;
Pixmap pixmap;
+ XUndefineCursor(_xwin.display, _xwin.window);
+
+ if (_xwin.cursor != None) {
+ XFreeCursor(_xwin.display, _xwin.cursor);
+ _xwin.cursor = None;
+ }
+
+ if (_xwin.xcursor_image != None) {
+ XcursorImageDestroy(_xwin.xcursor_image);
+ _xwin.xcursor_image = None;
+ }
+
pixmap = XCreatePixmap(_xwin.display, _xwin.window, 1, 1, 1);
if (pixmap != None) {
GC temp_gc;
/*
* Test program for hardware cursors.
*/
#include <stdio.h>
#include <allegro.h>
static void handle_key(int *quit);
static void do_select_cursor(int cursor);
int main(void)
{
int quit;
allegro_init();
install_timer();
install_mouse();
install_keyboard();
if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Error setting video mode: %s\n", allegro_error);
return 1;
}
else {
printf("gfx_driver: %s\n", gfx_driver->name);
fflush(stdout);
}
enable_hardware_cursor();
// first cursor shown
do_select_cursor(MOUSE_CURSOR_ALLEGRO);
quit = FALSE;
while (!quit) {
handle_key(&quit);
rest(1);
}
return 0;
}
END_OF_MAIN()
static void handle_key(int *quit)
{
int k;
if (!keypressed())
return;
k = readkey() & 0xff;
switch (k) {
case 27:
case 'q':
case 'Q':
(*quit) = TRUE;
break;
case '1':
do_select_cursor(MOUSE_CURSOR_ALLEGRO);
break;
case '2':
do_select_cursor(MOUSE_CURSOR_ARROW);
break;
case '3':
do_select_cursor(MOUSE_CURSOR_BUSY);
break;
case '4':
do_select_cursor(MOUSE_CURSOR_QUESTION);
break;
case '5':
do_select_cursor(MOUSE_CURSOR_EDIT);
break;
default:
break;
}
}
static void do_select_cursor(int cursor)
{
printf("----\n");
printf("before: %s, %s\n",
(gfx_capabilities & GFX_HW_CURSOR) ? "HW_CURSOR" : "no HW_CURSOR",
(gfx_capabilities & GFX_SYSTEM_CURSOR) ? "SYSTEM_CURSOR" : "no SYSTEM_CURSOR");
select_mouse_cursor(cursor);
show_mouse(screen);
printf("after: %s, %s\n",
(gfx_capabilities & GFX_HW_CURSOR) ? "HW_CURSOR" : "no HW_CURSOR",
(gfx_capabilities & GFX_SYSTEM_CURSOR) ? "SYSTEM_CURSOR" : "no SYSTEM_CURSOR");
fflush(stdout);
}