Re: [AD] Default cursor behavior in windowed mode

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sat, 2005-04-02 at 18:48 -0500, Ryan Patterson wrote:
> Is there any reason that it isn't possible to make it so that the
> default behavior in windowed graphics mode is to allow the OS to draw
> the mouse cursor? Now that Allegro has this functionality, I think it
> would be good to get rid of that nuisance: That if one doesn't use a
> mouse in his program, no mouse will be drawn over his program's
> window.
> 
> And when I say "Default behavior", I mean "behavior when install_mouse
> has not been called".

Makes sense to me. The attached patch does it for the X11 port. I based
it on the configuration variable "[mouse]keep_os_cursor" though (which
by default would be on), so the hiding behavior can easily be restored
by setting it to off (not that it should ever be useful to do so).
Simply calling install_mouse will hide the cursor. Calling
show_os_cursor will show the cursor again.

An alternative would be to allow show_os_cursor before install_mouse.. I
don't feel like implementing that right now though. It should be the way
it works for 4.3.x though.. decide beforehand (probably with the config
system) if the window should have a mouse or not, and then the user
won't have to call any other mouse related functions, even install_mouse
could go.

-- 
Elias Pschernig
Index: include/xalleg.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/xalleg.h,v
retrieving revision 1.22
diff -u -p -r1.22 xalleg.h
--- include/xalleg.h	2 Dec 2004 00:07:16 -0000	1.22
+++ include/xalleg.h	3 Apr 2005 09:58:36 -0000
@@ -70,6 +70,7 @@ extern struct _xwin_type
    Cursor cursor;
    int cursor_shape;
    int hw_cursor_ok;
+   int kept_os_cursor;
 
    void (*screen_to_buffer)(int sx, int sy, int sw, int sh);
    void (*set_colors)(AL_CONST PALETTE p, int from, int to);
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.88
diff -u -p -r1.88 xwin.c
--- src/x/xwin.c	28 Mar 2005 12:36:36 -0000	1.88
+++ src/x/xwin.c	3 Apr 2005 09:58:38 -0000
@@ -74,6 +74,7 @@ struct _xwin_type _xwin =
    None,        /* cursor */
    XC_heart,    /* cursor_shape */
    1,           /* hw_cursor_ok */
+   0,           /* kept_os_cursor */
 
    0,           /* screen_to_buffer */
    0,           /* set_colors */
@@ -430,7 +431,9 @@ static int _xwin_private_create_window(v
    _xwin.gc = XCreateGC(_xwin.display, _xwin.window, gcmask, &gcvalues);
 
    /* Create invisible X cursor.  */
-   _xwin_hide_x_mouse();
+   _xwin.kept_os_cursor = get_config_int("mouse", "keep_os_cursor", 1);
+   if (!_xwin.kept_os_cursor)
+      _xwin_hide_x_mouse();
 
 #ifdef ALLEGRO_XWINDOWS_WITH_XCURSOR
    /* Detect if ARGB cursors are supported */
@@ -752,7 +755,8 @@ static BITMAP *_xwin_private_create_scre
 	 XWarpPointer(_xwin.display, None, _xwin.window, 0, 0, 0, 0, w - 1, h - 1);
       }
 
-      XWarpPointer(_xwin.display, None, _xwin.window, 0, 0, 0, 0, w / 2, h / 2);
+      if (!_xwin.kept_os_cursor)
+         XWarpPointer(_xwin.display, None, _xwin.window, 0, 0, 0, 0, w / 2, h / 2);
       XSync(_xwin.display, False);
 
       /* Grab the keyboard and mouse.  */
@@ -1688,10 +1692,11 @@ int _xwin_show_mouse(struct BITMAP *bmp,
  */
 void _xwin_hide_mouse(void)
 {
-   if (_xwin.support_argb_cursor) {
+   if (_xwin.support_argb_cursor || _xwin.kept_os_cursor) {
       XLOCK();
       _xwin_hide_x_mouse();
       XUNLOCK();
+      _xwin.kept_os_cursor = 0;
    }
    return;
 }
Index: src/x/xmouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xmouse.c,v
retrieving revision 1.9
diff -u -p -r1.9 xmouse.c
--- src/x/xmouse.c	15 Mar 2005 18:37:18 -0000	1.9
+++ src/x/xmouse.c	3 Apr 2005 09:58:38 -0000
@@ -118,6 +118,7 @@ static int _xwin_mousedrv_init(void)
 
    XLOCK();
 
+   _xwin_hide_mouse();
    _xwin_mouse_interrupt = _xwin_mousedrv_handler;
 
    XUNLOCK();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/