Re: [AD] X: sending input events down a different display connection

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


On Mon, Mar 19, 2001 at 11:25:58PM +0000, George Foot wrote:
> I'm attaching a patch which nearly does this.

But to this email, just to confuse you all.

-- 
Random project update:
22/06/2000: AllegroGL documentation:  http://allegrogl.sourceforge.net/
        See under `Documentation' for the AllegroGL Reference Manual in
        various formats.

Index: include/xalleg.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/xalleg.h,v
retrieving revision 1.6
diff -u -r1.6 xalleg.h
--- include/xalleg.h	2001/03/17 20:15:34	1.6
+++ include/xalleg.h	2001/03/19 23:13:13
@@ -55,6 +55,7 @@
 extern struct _xwin_type
 {
    Display *display;
+   Display *event_display;
    int screen;
    Window window;
    GC gc;
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.19
diff -u -r1.19 xwin.c
--- src/x/xwin.c	2001/03/17 20:15:34	1.19
+++ src/x/xwin.c	2001/03/19 23:13:24
@@ -52,6 +52,7 @@
 struct _xwin_type _xwin =
 {
    0,           /* display */
+   0,           /* event display */
    0,           /* screen */
    None,        /* window */
    None,        /* gc */
@@ -291,10 +292,18 @@
    if (_xwin.display != 0)
       return -1;
 
-   _xwin.display = XOpenDisplay(name);
-   _xwin.screen = ((_xwin.display == 0) ? 0 : XDefaultScreen(_xwin.display));
+   /* open main display connection */
+   if (!(_xwin.display = XOpenDisplay(name)))
+      return -1;
+
+   /* open second display connection for async event processing */
+   if (!(_xwin.event_display = XOpenDisplay(name))) {
+      XCloseDisplay (_xwin.display);
+      return -1;
+   }
 
-   return ((_xwin.display != 0) ? 0 : -1);
+   _xwin.screen = ((_xwin.display == 0) ? 0 : XDefaultScreen(_xwin.display));
+   return 0;
 }
 
 int _xwin_open_display(char *name)
@@ -319,6 +328,10 @@
       XCloseDisplay(_xwin.display);
       _xwin.display = 0;
    }
+   if (_xwin.event_display != 0) {
+      XCloseDisplay(_xwin.event_display);
+      _xwin.event_display = 0;
+   }
 }
 
 void _xwin_close_display(void)
@@ -348,16 +361,25 @@
 
    /* Create window.  */
    setattr.border_pixel = XBlackPixel(_xwin.display, _xwin.screen);
-   setattr.event_mask = (KeyPressMask | KeyReleaseMask 
+   setattr.event_mask = 0;/*(KeyPressMask | KeyReleaseMask 
 			 | EnterWindowMask | LeaveWindowMask
 			 | FocusChangeMask | ExposureMask | PropertyChangeMask
-			 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask
-			 /*| MappingNotifyMask (SubstructureRedirectMask?)*/);
+			 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);*/
+			 /*| MappingNotifyMask (SubstructureRedirectMask?)*/
    _xwin.window = XCreateWindow(_xwin.display, XDefaultRootWindow(_xwin.display),
 				0, 0, 320, 200, 0,
 				CopyFromParent, InputOutput, CopyFromParent,
 				CWBorderPixel | CWEventMask, &setattr);
 
+   /* It seems we need to sync before selecting input events... */
+   XSync(_xwin.display, False);
+   XSelectInput (_xwin.event_display, _xwin.window,
+		KeyPressMask | KeyReleaseMask |
+		EnterWindowMask | LeaveWindowMask |
+		FocusChangeMask | ExposureMask | PropertyChangeMask |
+		ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
+   XFlush(_xwin.event_display); /* and flush afterwards */
+
    /* Get associated visual and window depth (bits per pixel).  */
    XGetWindowAttributes(_xwin.display, _xwin.window, &getattr);
    _xwin.visual = getattr.visual;
@@ -1957,7 +1979,7 @@
 	       }
 	     	       
 	       /* Warp X-cursor to the center of the screen.  */
-	       XWarpPointer(_xwin.display, None, _xwin.window, 0, 0, 0, 0, 
+	       XWarpPointer(_xwin.event_display, None, _xwin.window, 0, 0, 0, 0, 
 			    _xwin.screen_width / 2, _xwin.screen_height / 2);
 	       mouse_was_warped = 1;
 	    }
@@ -1989,7 +2011,7 @@
 	       mouse_savedx = _xwin.window_width / 2;
 	       mouse_savedy = _xwin.window_height / 2;
 	       mouse_was_warped = 1;
-	       XWarpPointer(_xwin.display, _xwin.window, _xwin.window,
+	       XWarpPointer(_xwin.event_display, _xwin.window, _xwin.window,
 			    0, 0, _xwin.window_width, _xwin.window_height,
 			    mouse_savedx, mouse_savedy);
 	    }
@@ -2032,7 +2054,7 @@
 	 if (_xwin_mouse_interrupt)
 	    (*_xwin_mouse_interrupt)(0, 0, 0, mouse_buttons);
 	 break;
-      case Expose:
+      case Expose: /* FIXME: this uses _xwin.display */
 	 /* Request to redraw part of the window.  */
 	 (*_xwin_window_redrawer)(event->xexpose.x, event->xexpose.y,
 				     event->xexpose.width, event->xexpose.height);
@@ -2042,7 +2064,7 @@
 	 if (event->xmapping.request == MappingKeyboard)
 	    _xwin_private_init_keyboard_tables();
 	 break;
-      case ClientMessage:
+      case ClientMessage: /* FIXME: _xwin.event_display never gets this */
          /* Window close request */
          if (event->xclient.data.l[0] == wm_delete_window) {
             if (_xwin.window_close_hook)
@@ -2074,7 +2096,7 @@
       if (_xwin.mouse_warped && (_xwin.mouse_warped++ > MOUSE_WARP_DELAY)) {
 	 _xwin.mouse_warped = 0;
 	 /* Move X-cursor to Allegro cursor.  */
-	 XWarpPointer(_xwin.display, _xwin.window, _xwin.window,
+	 XWarpPointer(_xwin.event_display, _xwin.window, _xwin.window,
 		      0, 0, _xwin.window_width, _xwin.window_height,
 		      _mouse_x, _mouse_y);
       }
@@ -2083,10 +2105,11 @@
 #endif
 
    /* Flush X-buffers.  */
-   _xwin_private_flush_buffers();
+   _xwin_private_flush_buffers(); /* FIXME: this uses the primary display */
+   XSync (_xwin.event_display, False);
 
    /* How much events are available in the queue.  */
-   events = XEventsQueued(_xwin.display, QueuedAlready);
+   events = XEventsQueued(_xwin.event_display, QueuedAlready);
    if (events <= 0)
       return;
 
@@ -2096,7 +2119,7 @@
 
    /* Read pending events.  */
    for (i = 0; i < events; i++)
-      XNextEvent(_xwin.display, &event[i]);
+      XNextEvent(_xwin.event_display, &event[i]);
 
    /* Process all events.  */
    for (i = 0; i < events; i++)
@@ -2491,7 +2514,7 @@
    }
 
    /* Get the number of keycodes.  */
-   XDisplayKeycodes(_xwin.display, &min_keycode, &max_keycode);
+   XDisplayKeycodes(_xwin.event_display, &min_keycode, &max_keycode);
    if (min_keycode < 0)
       min_keycode = 0;
    if (max_keycode > 255)
@@ -2499,7 +2522,7 @@
 
    /* Setup initial X keycode to Allegro scancode mappings.  */
    for (i = min_keycode; i <= max_keycode; i++) {
-      keysym = XKeycodeToKeysym(_xwin.display, i, 0);
+      keysym = XKeycodeToKeysym(_xwin.event_display, i, 0);
       if (keysym != NoSymbol) {
 	 for (j = 0; _xwin_keysym_to_scancode[j].keysym != NoSymbol; j++) {
 	    if (_xwin_keysym_to_scancode[j].keysym == keysym) {


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