xserver: Branch 'xorg-server-1.4-apple' - 3 commits

Ben Byer bbyer at kemper.freedesktop.org
Tue Apr 1 00:41:48 PDT 2008


 hw/xquartz/X11Application.m |  505 +++++++++++++++++++++-----------------------
 hw/xquartz/X11Controller.m  |   32 +-
 hw/xquartz/darwin.h         |   10 
 hw/xquartz/darwinEvents.c   |   35 ++-
 hw/xquartz/darwinEvents.h   |    2 
 hw/xquartz/darwinKeyboard.c |   12 -
 hw/xquartz/darwinKeyboard.h |    2 
 hw/xquartz/quartz.c         |   31 --
 hw/xquartz/quartzKeyboard.h |    1 
 hw/xquartz/xpr/xprScreen.c  |    8 
 10 files changed, 309 insertions(+), 329 deletions(-)

New commits:
commit 7e653f806ff5508aace059312156f319a9ed4479
Author: Ben Byer <bbyer at apple.com>
Date:   Tue Apr 1 00:40:46 2008 -0700

    The AppKit thread should not be calling directly into the X server
    functions to change state when the keyboard is reloaded; instead,
    pass it as an event.

diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index a8ac9ff..f672047 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -91,13 +91,8 @@ extern int              darwinMainScreenY;
  * Special ddx events understood by the X server
  */
 enum {
-    kXquartzUpdateModifiers   // update all modifier keys
+    kXquartzReloadKeymap      // Reload system keymap
             = LASTEvent+1,    // (from X.h list of event names)
-    kXquartzUpdateButtons,    // update state of mouse buttons 2 and up
-    kXquartzScrollWheel,      // scroll wheel event
-    /*
-     * Quartz-specific events -- not used in IOKit mode
-     */
     kXquartzActivate,         // restore X drawing and cursor
     kXquartzDeactivate,       // clip X drawing and switch to Aqua cursor
     kXquartzSetRootClip,      // enable or disable drawing to the X screen
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index b6cd3f2..3afbaf8 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -289,6 +289,7 @@ Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) {
         FatalError("Couldn't allocate event buffer\n");
 
     mieqInit();
+    mieqSetHandler(kXquartzReloadKeymap, DarwinKeyboardReloadHandler);
     mieqSetHandler(kXquartzActivate, DarwinEventHandler);
     mieqSetHandler(kXquartzDeactivate, DarwinEventHandler);
     mieqSetHandler(kXquartzSetRootClip, DarwinEventHandler);
@@ -322,7 +323,7 @@ void ProcessInputEvents(void) {
     // Empty the signaling pipe
     int x = sizeof(xe);
     while (x == sizeof(xe)) {
-      DEBUG_LOG("draining pipe\n");
+//      DEBUG_LOG("draining pipe\n");
       x = read(darwinEventReadFD, &xe, sizeof(xe));
     }
 }
@@ -412,8 +413,8 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
 
     this_seed = QuartzSystemKeymapSeed();
     if (this_seed != last_seed) {
-      last_seed = this_seed;
-      DarwinKeyboardReload(darwinKeyboard);
+		last_seed = this_seed;
+		DarwinSendDDXEvent(kXquartzReloadKeymap, 0);
     }
   }
 
diff --git a/hw/xquartz/darwinKeyboard.c b/hw/xquartz/darwinKeyboard.c
index 472d80d..a9fbdfc 100644
--- a/hw/xquartz/darwinKeyboard.c
+++ b/hw/xquartz/darwinKeyboard.c
@@ -850,16 +850,18 @@ static Bool InitModMap(register KeyClassPtr keyc) {
 }
 
 
-void DarwinKeyboardReload(DeviceIntPtr pDev) {
+void DarwinKeyboardReloadHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) {
     KeySymsRec keySyms;
-
+	if (dev == NULL) dev = darwinKeyboard;
+	
+	DEBUG_LOG("DarwinKeyboardReloadHandler(%p)\n", dev);
     DarwinLoadKeyboardMapping(&keySyms);
 
-    if (SetKeySymsMap(&pDev->key->curKeySyms, &keySyms)) {
+    if (SetKeySymsMap(&dev->key->curKeySyms, &keySyms)) {
         /* now try to update modifiers. */
 
-        memmove(pDev->key->modifierMap, keyInfo.modMap, MAP_LENGTH);
-        InitModMap(pDev->key);
+        memmove(dev->key->modifierMap, keyInfo.modMap, MAP_LENGTH);
+        InitModMap(dev->key);
     } else DEBUG_LOG("SetKeySymsMap=0\n");
 
     SendMappingNotify(MappingKeyboard, MIN_KEYCODE, NUM_KEYCODES, 0);
diff --git a/hw/xquartz/darwinKeyboard.h b/hw/xquartz/darwinKeyboard.h
index 5cf64c7..762f659 100644
--- a/hw/xquartz/darwinKeyboard.h
+++ b/hw/xquartz/darwinKeyboard.h
@@ -31,7 +31,7 @@
 
 /* Provided for darwinEvents.c */
 extern darwinKeyboardInfo keyInfo;
-void DarwinKeyboardReload(DeviceIntPtr pDev);
+void DarwinKeyboardReloadHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents);
 void DarwinKeyboardInit(DeviceIntPtr pDev);
 int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide);
 int DarwinModifierNXKeyToNXKeycode(int key, int side);
diff --git a/hw/xquartz/quartzKeyboard.h b/hw/xquartz/quartzKeyboard.h
index 8131b56..4f495bb 100644
--- a/hw/xquartz/quartzKeyboard.h
+++ b/hw/xquartz/quartzKeyboard.h
@@ -46,7 +46,6 @@ typedef struct darwinKeyboardInfo_struct {
 } darwinKeyboardInfo;
 
 /* These functions need to be implemented by Xquartz, XDarwin, etc. */
-void DarwinKeyboardReload(DeviceIntPtr pDev);
 Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info);
 unsigned int QuartzSystemKeymapSeed(void);
 
commit eb083d3f68f459d90417558da1ed00729b749950
Author: Ben Byer <bbyer at apple.com>
Date:   Mon Mar 31 23:31:25 2008 -0700

    formatting cleanup for X11Application.m (no code changes)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 8ddc347..c185d37 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -170,171 +170,170 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
     static TSMDocumentID x11_document;
 	DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
     if (state) {
-      DarwinSendDDXEvent(kXquartzActivate, 0);
-      
-      if (!_x_active) {
-	if (x11_document == 0 && darwinKeymapFile == NULL) {
-	  OSType types[1];
-	  types[0] = kUnicodeDocument;
-	  NewTSMDocument (1, types, &x11_document, 0);
-	}
-	
-	if (x11_document != 0)	ActivateTSMDocument (x11_document);
-      }
+		DarwinSendDDXEvent(kXquartzActivate, 0);
+
+		if (!_x_active) {
+			if (x11_document == 0 && darwinKeymapFile == NULL) {
+				OSType types[1];
+				types[0] = kUnicodeDocument;
+				NewTSMDocument (1, types, &x11_document, 0);
+			}
+
+			if (x11_document != 0)	ActivateTSMDocument (x11_document);
+		}
     } else {
-      DarwinSendDDXEvent(kXquartzDeactivate, 0);
-      
-      if (_x_active && x11_document != 0)
-		DeactivateTSMDocument (x11_document);
-    }
-    
-    _x_active = state;
+		DarwinSendDDXEvent(kXquartzDeactivate, 0);
+
+		if (_x_active && x11_document != 0)
+			DeactivateTSMDocument (x11_document);
+	}
+
+	_x_active = state;
 }
 
 - (void) became_key:(NSWindow *)win {
-    [self activateX:NO];
+	[self activateX:NO];
 }
 
 - (void) sendEvent:(NSEvent *)e {
-  NSEventType type;
-  BOOL for_appkit, for_x;
-  
-  type = [e type];
-  
-  /* By default pass down the responder chain and to X. */
-  for_appkit = YES;
-  for_x = YES;
-  
-  switch (type) {
-  case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
-  case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
-    if ([e window] != nil) {
-      /* Pointer event has an (AppKit) window. Probably something for the kit. */
-      for_x = NO;
-      if (_x_active) [self activateX:NO];
-    } else if ([self modalWindow] == nil) {
-      /* Must be an X window. Tell appkit it doesn't have focus. */
-      WindowPtr pWin = xprGetXWindowFromAppKit([e windowNumber]);
-      if (pWin) RootlessReorderWindow(pWin);
-      for_appkit = NO;
-      
-      if ([self isActive]) {
-	[self deactivate];
-	
-	if (!_x_active && quartzProcs->IsX11Window([e window],
-						   [e windowNumber]))
-	  [self activateX:YES];
-      }
-    }
-    break;
-      
-  case NSKeyDown: case NSKeyUp:
-    if (_x_active) {
-      static int swallow_up;
-      
-      /* No kit window is focused, so send it to X. */
-      for_appkit = NO;
-      if (type == NSKeyDown) {
-	/* Before that though, see if there are any global
-	   shortcuts bound to it. */
-	
-	if (X11EnableKeyEquivalents
-	    && [[self mainMenu] performKeyEquivalent:e]) {
-	  swallow_up = [e keyCode];
-	  for_x = NO;
-	} else if (!quartzEnableRootless
-		   && ([e modifierFlags] & ALL_KEY_MASKS)
-		   == (NSCommandKeyMask | NSAlternateKeyMask)
-		   && ([e keyCode] == 0 /*a*/
-		    || [e keyCode] == 53 /*Esc*/)) {
-	  swallow_up = 0;
-	  for_x = NO;
+ 	NSEventType type;
+	BOOL for_appkit, for_x;
+
+	type = [e type];
+
+	/* By default pass down the responder chain and to X. */
+	for_appkit = YES;
+	for_x = YES;
+  
+	switch (type) {
+		case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
+		case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
+		if ([e window] != nil) {
+			/* Pointer event has an (AppKit) window. Probably something for the kit. */
+			for_x = NO;
+			if (_x_active) [self activateX:NO];
+		} else if ([self modalWindow] == nil) {
+			/* Must be an X window. Tell appkit it doesn't have focus. */
+			WindowPtr pWin = xprGetXWindowFromAppKit([e windowNumber]);
+			if (pWin) RootlessReorderWindow(pWin);
+			for_appkit = NO;
+
+			if ([self isActive]) {
+				[self deactivate];
+				if (!_x_active && quartzProcs->IsX11Window([e window],
+					[e windowNumber]))
+					[self activateX:YES];
+			}
+		}
+		break;
+
+		case NSKeyDown: case NSKeyUp:
+		if (_x_active) {
+			static int swallow_up;
+
+			/* No kit window is focused, so send it to X. */
+			for_appkit = NO;
+			if (type == NSKeyDown) {
+				/* Before that though, see if there are any global
+				shortcuts bound to it. */
+
+					if (X11EnableKeyEquivalents
+						&& [[self mainMenu] performKeyEquivalent:e]) {
+							swallow_up = [e keyCode];
+							for_x = NO;
+					} else if (!quartzEnableRootless
+						&& ([e modifierFlags] & ALL_KEY_MASKS)
+						== (NSCommandKeyMask | NSAlternateKeyMask)
+						&& ([e keyCode] == 0 /*a*/
+							|| [e keyCode] == 53 /*Esc*/)) {
+						swallow_up = 0;
+						for_x = NO;
 #ifdef DARWIN_DDX_MISSING
-	  DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
+						DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
 #endif
+					}
+			} else {
+			/* If we saw a key equivalent on the down, don't pass
+	   			the up through to X. */
+
+				if (swallow_up != 0 && [e keyCode] == swallow_up) {
+					swallow_up = 0;
+					for_x = NO;
+				}
+			}
+    		} else for_x = NO;
+    	break;
+
+		case NSFlagsChanged:
+			/* For the l33t X users who remap modifier keys to normal keysyms. */
+			if (!_x_active) for_x = NO;
+		break;
+
+		case NSAppKitDefined:
+		switch ([e subtype]) {
+			case NSApplicationActivatedEventType:
+      		for_x = NO;
+			if ([self modalWindow] == nil) {
+				for_appkit = NO;
+
+				/* FIXME: hack to avoid having to pass the event to appkit,
+	   			which would cause it to raise one of its windows. */
+				_appFlags._active = YES;
+
+				[self activateX:YES];
+				if ([e data2] & 0x10) X11ApplicationSetFrontProcess();
+			}
+			break;
+
+			case 18: /* ApplicationDidReactivate */
+				if (quartzHasRoot) for_appkit = NO;
+			break;
+
+			case NSApplicationDeactivatedEventType:
+				for_x = NO;
+				[self activateX:NO];
+			break;
+		}
+	break;
+ 
+	default: break; /* for gcc */
 	}
-      } else {
-	/* If we saw a key equivalent on the down, don't pass
-	   the up through to X. */
-	
-	if (swallow_up != 0 && [e keyCode] == swallow_up) {
-	  swallow_up = 0;
-	  for_x = NO;
-	}
-      }
-    } else for_x = NO;
-    break;
-    
-  case NSFlagsChanged:
-    /* For the l33t X users who remap modifier keys to normal keysyms. */
-    if (!_x_active) for_x = NO;
-    break;
-    
-  case NSAppKitDefined:
-    switch ([e subtype]) {
-    case NSApplicationActivatedEventType:
-      for_x = NO;
-      if ([self modalWindow] == nil) {
-		for_appkit = NO;
-	
-	/* FIXME: hack to avoid having to pass the event to appkit,
-	   which would cause it to raise one of its windows. */
-	_appFlags._active = YES;
-	
-	[self activateX:YES];
-	if ([e data2] & 0x10) X11ApplicationSetFrontProcess();
-      }
-      break;
-      
-    case 18: /* ApplicationDidReactivate */
-      if (quartzHasRoot) for_appkit = NO;
-      break;
-      
-    case NSApplicationDeactivatedEventType:
-      for_x = NO;
-      [self activateX:NO];
-      break;
-    }
-    break;
-    
-  default: break; /* for gcc */
-  }
-  
-  if (for_appkit) [super sendEvent:e];
-  
-  if (for_x) send_nsevent (type, e);
+
+	if (for_appkit) [super sendEvent:e];
+
+	if (for_x) send_nsevent (type, e);
 }
 
 - (void) set_window_menu:(NSArray *)list {
-    [_controller set_window_menu:list];
+	[_controller set_window_menu:list];
 }
 
 - (void) set_window_menu_check:(NSNumber *)n {
-    [_controller set_window_menu_check:n];
+	[_controller set_window_menu_check:n];
 }
 
 - (void) set_apps_menu:(NSArray *)list {
-    [_controller set_apps_menu:list];
+	[_controller set_apps_menu:list];
 }
 
 - (void) set_front_process:unused {
-    [NSApp activateIgnoringOtherApps:YES];
+	[NSApp activateIgnoringOtherApps:YES];
 
-    if ([self modalWindow] == nil)
-        [self activateX:YES];
+	if ([self modalWindow] == nil)
+		[self activateX:YES];
 }
 
 - (void) set_can_quit:(NSNumber *)state {
-    [_controller set_can_quit:[state boolValue]];
+	[_controller set_can_quit:[state boolValue]];
 }
 
 - (void) server_ready:unused {
-    [_controller server_ready];
+	[_controller server_ready];
 }
 
 - (void) show_hide_menubar:(NSNumber *)state {
-    if ([state boolValue]) ShowMenuBar ();
-    else HideMenuBar ();
+	if ([state boolValue]) ShowMenuBar ();
+	else HideMenuBar ();
 }
 
 
@@ -352,57 +351,57 @@ static void cfrelease (CFAllocatorRef a, const void *b) {
 }
 
 static CFMutableArrayRef nsarray_to_cfarray (NSArray *in) {
-    CFMutableArrayRef out;
-    CFArrayCallBacks cb;
-    NSObject *ns;
-    const CFTypeRef *cf;
-    int i, count;
-	
-    memset (&cb, 0, sizeof (cb));
-    cb.version = 0;
-    cb.retain = cfretain;
-    cb.release = cfrelease;
-	
-    count = [in count];
-    out = CFArrayCreateMutable (NULL, count, &cb);
-	
-    for (i = 0; i < count; i++) {
-      ns = [in objectAtIndex:i];
-      
-      if ([ns isKindOfClass:[NSArray class]])
-	cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns);
-      else
-	cf = CFRetain ((CFTypeRef) ns);
-      
-      CFArrayAppendValue (out, cf);
-      CFRelease (cf);
-    }
-    
-    return out;
+	CFMutableArrayRef out;
+	CFArrayCallBacks cb;
+	NSObject *ns;
+	const CFTypeRef *cf;
+	int i, count;
+
+	memset (&cb, 0, sizeof (cb));
+	cb.version = 0;
+	cb.retain = cfretain;
+	cb.release = cfrelease;
+
+	count = [in count];
+	out = CFArrayCreateMutable (NULL, count, &cb);
+
+	for (i = 0; i < count; i++) {
+		ns = [in objectAtIndex:i];
+
+		if ([ns isKindOfClass:[NSArray class]])
+			cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns);
+		else
+			cf = CFRetain ((CFTypeRef) ns);
+
+		CFArrayAppendValue (out, cf);
+		CFRelease (cf);
+	}
+
+	return out;
 }
 
 static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
-    NSMutableArray *out;
-    const CFTypeRef *cf;
-    NSObject *ns;
-    int i, count;
-	
-    count = CFArrayGetCount (in);
-    out = [[NSMutableArray alloc] initWithCapacity:count];
-	
-    for (i = 0; i < count; i++) {
-      cf = CFArrayGetValueAtIndex (in, i);
-		
-      if (CFGetTypeID (cf) == CFArrayGetTypeID ())
-	ns = cfarray_to_nsarray ((CFArrayRef) cf);
-      else
-	ns = [(id)cf retain];
-      
-      [out addObject:ns];
-      [ns release];
-    }
-    
-    return out;
+	NSMutableArray *out;
+	const CFTypeRef *cf;
+	NSObject *ns;
+	int i, count;
+
+	count = CFArrayGetCount (in);
+	out = [[NSMutableArray alloc] initWithCapacity:count];
+
+	for (i = 0; i < count; i++) {
+		cf = CFArrayGetValueAtIndex (in, i);
+
+		if (CFGetTypeID (cf) == CFArrayGetTypeID ())
+			ns = cfarray_to_nsarray ((CFArrayRef) cf);
+		else
+			ns = [(id)cf retain];
+
+		[out addObject:ns];
+		[ns release];
+	}
+
+	return out;
 }
 
 - (CFPropertyListRef) prefs_get:(NSString *)key {
@@ -859,86 +858,68 @@ convert_flags (unsigned int nsflags) {
     return xflags;
 }
 
-
-// This code should probably be merged with that in XDarwin's XServer.m - BB
 static void send_nsevent (NSEventType type, NSEvent *e) {
-  //    static unsigned int button_state = 0;
-    NSRect screen;
-    NSPoint location;
-    NSWindow *window;
-    int pointer_x, pointer_y, ev_button, ev_type;
-    float pressure, tilt_x, tilt_y;
-
-    //    int num_events=0, i=0, state;
-    // xEvent xe;
-	
-    /* convert location to global top-left coordinates */
-    location = [e locationInWindow];
-    window = [e window];
-    screen = [[[NSScreen screens] objectAtIndex:0] frame];
-		
+	NSRect screen;
+	NSPoint location;
+	NSWindow *window;
+	int pointer_x, pointer_y, ev_button, ev_type;
+	float pressure, tilt_x, tilt_y;
+
+	/* convert location to global top-left coordinates */
+	location = [e locationInWindow];
+	window = [e window];
+	screen = [[[NSScreen screens] objectAtIndex:0] frame];
+
     if (window != nil)	{
-      NSRect frame = [window frame];
-      pointer_x = location.x + frame.origin.x;
-      pointer_y = (((screen.origin.y + screen.size.height)
-		    - location.y) - frame.origin.y);
-    } else {
-      pointer_x = location.x;
-      pointer_y = (screen.origin.y + screen.size.height) - location.y;
-    }
-    
-    pointer_y -= aquaMenuBarHeight;
-    //    state = convert_flags ([e modifierFlags]);
-    
-    pressure = 0;  // for tablets
-    tilt_x = 0;
-    tilt_y = 0;
-
-    switch (type) {
-    case NSLeftMouseDown:    ev_button=1; ev_type=ButtonPress; goto handle_mouse;
-    case NSOtherMouseDown:   ev_button=2; ev_type=ButtonPress; goto handle_mouse;
-    case NSRightMouseDown:   ev_button=3; ev_type=ButtonPress; goto handle_mouse;
-    case NSLeftMouseUp:      ev_button=1; ev_type=ButtonRelease; goto handle_mouse;
-    case NSOtherMouseUp:     ev_button=2; ev_type=ButtonRelease; goto handle_mouse;
-    case NSRightMouseUp:     ev_button=3; ev_type=ButtonRelease; goto handle_mouse;
-    case NSLeftMouseDragged:  ev_button=1; ev_type=MotionNotify; goto handle_mouse;
-    case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse;
-    case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse;
-    case NSTabletPoint:
-      pressure = [e pressure];
-      tilt_x = [e tilt].x;
-      tilt_y = [e tilt].y; // fall through
-    case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
-    handle_mouse:
-      
-      /* I'm not sure the below code is necessary or useful (-bb)
-	if(ev_type==ButtonPress) {
-	if (!quartzProcs->IsX11Window([e window], [e windowNumber])) {
-	  fprintf(stderr, "Dropping event because it's not a window\n");
-	  break;
+		NSRect frame = [window frame];
+		pointer_x = location.x + frame.origin.x;
+		pointer_y = (((screen.origin.y + screen.size.height)
+			- location.y) - frame.origin.y);
+	} else {
+		pointer_x = location.x;
+		pointer_y = (screen.origin.y + screen.size.height) - location.y;
 	}
-	button_state |= (1 << ev_button);
-	DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y);
-      } else if (ev_type==ButtonRelease && (button_state & (1 << ev_button)) == 0) break;
-      */
-
-      //      if ([e subtype] == NSTabletPointEventSubtype) pressure = [e pressure];
-      DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y,
-			      pressure, tilt_x, tilt_y);
-      break;
-    case NSScrollWheel:
-      DarwinSendScrollEvents([e deltaY], pointer_x, pointer_y,
-			     pressure, tilt_x, tilt_y);
-      break;
-      
-    case NSKeyDown:  // do we need to translate these keyCodes?
-    case NSKeyUp:
-      DarwinSendKeyboardEvents((type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
-      break;
-
-    case NSFlagsChanged:
-      DarwinUpdateModKeys([e modifierFlags]);
-      break;
-    default: break; /* for gcc */
-    }	
+
+	pointer_y -= aquaMenuBarHeight;
+
+	pressure = 0;  // for tablets
+	tilt_x = 0;
+	tilt_y = 0;
+
+	switch (type) {
+		case NSLeftMouseDown:    ev_button=1; ev_type=ButtonPress; goto handle_mouse;
+		case NSOtherMouseDown:   ev_button=2; ev_type=ButtonPress; goto handle_mouse;
+		case NSRightMouseDown:   ev_button=3; ev_type=ButtonPress; goto handle_mouse;
+		case NSLeftMouseUp:      ev_button=1; ev_type=ButtonRelease; goto handle_mouse;
+		case NSOtherMouseUp:     ev_button=2; ev_type=ButtonRelease; goto handle_mouse;
+		case NSRightMouseUp:     ev_button=3; ev_type=ButtonRelease; goto handle_mouse;
+		case NSLeftMouseDragged:  ev_button=1; ev_type=MotionNotify; goto handle_mouse;
+		case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse;
+		case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse;
+		case NSTabletPoint:
+			pressure = [e pressure];
+			tilt_x = [e tilt].x;
+			tilt_y = [e tilt].y; // fall through
+		case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
+		handle_mouse:
+
+//      if ([e subtype] == NSTabletPointEventSubtype) pressure = [e pressure];
+		DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y,
+			pressure, tilt_x, tilt_y);
+		break;
+
+		case NSScrollWheel:
+			DarwinSendScrollEvents([e deltaY], pointer_x, pointer_y,
+				pressure, tilt_x, tilt_y);
+		break;
+
+		case NSKeyDown: case NSKeyUp:
+			DarwinSendKeyboardEvents((type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
+		break;
+
+		case NSFlagsChanged:
+			DarwinUpdateModKeys([e modifierFlags]);
+		break;
+		default: break; /* for gcc */
+	}	
 }
commit bee2b377efc930e25017636e5112093a3a6549c7
Author: Ben Byer <bbyer at apple.com>
Date:   Mon Mar 31 22:55:24 2008 -0700

    moved and renamed QuartzMessageServerThread to
    DarwinSendDDXEvent to make more clear what it actually does.

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 0bed917..8ddc347 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -1,6 +1,6 @@
 /* X11Application.m -- subclass of NSApplication to multiplex events
  
- Copyright (c) 2002-2007 Apple Inc.
+ Copyright (c) 2002-2008 Apple Inc.
  
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
@@ -170,7 +170,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
     static TSMDocumentID x11_document;
 	DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
     if (state) {
-      QuartzMessageServerThread (kXquartzActivate, 0);
+      DarwinSendDDXEvent(kXquartzActivate, 0);
       
       if (!_x_active) {
 	if (x11_document == 0 && darwinKeymapFile == NULL) {
@@ -182,10 +182,10 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 	if (x11_document != 0)	ActivateTSMDocument (x11_document);
       }
     } else {
-      QuartzMessageServerThread (kXquartzDeactivate, 0);
+      DarwinSendDDXEvent(kXquartzDeactivate, 0);
       
       if (_x_active && x11_document != 0)
-	DeactivateTSMDocument (x11_document);
+		DeactivateTSMDocument (x11_document);
     }
     
     _x_active = state;
@@ -250,7 +250,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 	  swallow_up = 0;
 	  for_x = NO;
 #ifdef DARWIN_DDX_MISSING
-	  QuartzMessageServerThread (kXquartzToggleFullscreen, 0);
+	  DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
 #endif
 	}
       } else {
@@ -275,7 +275,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
     case NSApplicationActivatedEventType:
       for_x = NO;
       if ([self modalWindow] == nil) {
-	for_appkit = NO;
+		for_appkit = NO;
 	
 	/* FIXME: hack to avoid having to pass the event to appkit,
 	   which would cause it to raise one of its windows. */
@@ -658,7 +658,7 @@ static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
 
 /* This will end up at the end of the responder chain. */
 - (void) copy:sender {
-  QuartzMessageServerThread (kXquartzPasteboardNotify, 1,
+  DarwinSendDDXEvent(kXquartzPasteboardNotify, 1,
 			     AppleWMCopyToPasteboard);
 }
 
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index aa9fa94..5bf4f4d 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -1,6 +1,6 @@
 /* X11Controller.m -- connect the IB ui, also the NSApp delegate
  
-   Copyright (c) 2002-2007 Apple Inc. All rights reserved.
+   Copyright (c) 2002-2008 Apple Inc. All rights reserved.
  
    Permission is hereby granted, free of charge, to any person
    obtaining a copy of this software and associated documentation files
@@ -103,7 +103,7 @@
 {
   [NSApp activateIgnoringOtherApps:YES];
 	
-  QuartzMessageServerThread (kXquartzControllerNotify, 2,
+  DarwinSendDDXEvent(kXquartzControllerNotify, 2,
 			     AppleWMWindowMenuItem, [sender tag]);
 }
 
@@ -254,7 +254,7 @@
   [self remove_window_menu];
   [self install_window_menu:list];
 	
-  QuartzMessageServerThread (kXquartzControllerNotify, 1,
+  DarwinSendDDXEvent(kXquartzControllerNotify, 1,
 			     AppleWMWindowMenuNotify);
 }
 
@@ -539,20 +539,20 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 - (void) hide_window:sender
 {
   if ([X11App x_active])
-    QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMHideWindow);
+    DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideWindow);
   else
     NSBeep ();			/* FIXME: something here */
 }
 
 - (IBAction)bring_to_front:sender
 {
-  QuartzMessageServerThread(kXquartzControllerNotify, 1, AppleWMBringAllToFront);
+  DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMBringAllToFront);
 }
 
 - (IBAction)close_window:sender
 {
   if ([X11App x_active])
-    QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMCloseWindow);
+    DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMCloseWindow);
   else
     [[NSApp keyWindow] performClose:sender];
 }
@@ -560,7 +560,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 - (IBAction)minimize_window:sender
 {
   if ([X11App x_active])
-    QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMMinimizeWindow);
+    DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMMinimizeWindow);
   else
     [[NSApp keyWindow] performMiniaturize:sender];
 }
@@ -568,19 +568,19 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 - (IBAction)zoom_window:sender
 {
   if ([X11App x_active])
-    QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMZoomWindow);
+    DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMZoomWindow);
   else
     [[NSApp keyWindow] performZoom:sender];
 }
 
 - (IBAction) next_window:sender
 {
-  QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMNextWindow);
+  DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMNextWindow);
 }
 
 - (IBAction) previous_window:sender
 {
-  QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMPreviousWindow);
+  DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMPreviousWindow);
 }
 
 - (IBAction) enable_fullscreen_changed:sender
@@ -588,7 +588,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
   int value = ![enable_fullscreen intValue];
 	
 #ifdef DARWIN_DDX_MISSING
-  QuartzMessageServerThread (kXquartzSetRootless, 1, value);
+  DarwinSendDDXEvent(kXquartzSetRootless, 1, value);
 #endif
 	
   [NSApp prefs_set_boolean:@PREFS_ROOTLESS value:value];
@@ -598,7 +598,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 - (IBAction) toggle_fullscreen:sender
 {
 #ifdef DARWIN_DDX_MISSING
-  QuartzMessageServerThread (kXquartzToggleFullscreen, 0);
+  DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
 #endif
 }
 
@@ -661,7 +661,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 
 - (IBAction) quit:sender
 {
-  QuartzMessageServerThread (kXquartzQuit, 0);
+  DarwinSendDDXEvent(kXquartzQuit, 0);
 }
 
 - (IBAction) x11_help:sender
@@ -684,12 +684,12 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 
 - (void) applicationDidHide:(NSNotification *)notify
 {
-  QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMHideAll);
+  DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideAll);
 }
 
 - (void) applicationDidUnhide:(NSNotification *)notify
 {
-  QuartzMessageServerThread (kXquartzControllerNotify, 1, AppleWMShowAll);
+  DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMShowAll);
 }
 
 - (NSApplicationTerminateReply) applicationShouldTerminate:sender
@@ -717,7 +717,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
   [X11App prefs_synchronize];
 	
   /* shutdown the X server, it will exit () for us. */
-  QuartzMessageServerThread (kXquartzQuit, 0);
+  DarwinSendDDXEvent(kXquartzQuit, 0);
 	
   /* In case it doesn't, exit anyway after a while. */
   while (sleep (10) != 0) ;
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index a71941d..a8ac9ff 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2008 Apple, Inc.
  * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -120,6 +121,8 @@ enum {
     kXquartzWindowMoved,      // window has moved on screen
 };
 
+void DarwinSendDDXEvent(int type, int argc, ...);
+
 #define ENABLE_DEBUG_LOG 1
 
 #ifdef ENABLE_DEBUG_LOG
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 28a712d..b6cd3f2 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -476,3 +476,31 @@ void DarwinUpdateModKeys(int flags) {
   DarwinUpdateModifiers(KeyPress, ~old_flags & flags);
   old_flags = flags;
 }
+
+
+/*
+ * DarwinSendDDXEvent
+ *  Send the X server thread a message by placing it on the event queue.
+ */
+void DarwinSendDDXEvent(int type, int argc, ...) {
+    xEvent xe;
+    INT32 *argv;
+    int i, max_args;
+    va_list args;
+
+    memset(&xe, 0, sizeof(xe));
+    xe.u.u.type = type;
+    xe.u.clientMessage.u.l.type = type;
+
+    argv = &xe.u.clientMessage.u.l.longs0;
+    max_args = 4;
+
+    if (argc > 0 && argc <= max_args) {
+        va_start (args, argc);
+        for (i = 0; i < argc; i++)
+            argv[i] = (int) va_arg (args, int);
+        va_end (args);
+    }
+
+    mieqEnqueue(NULL, &xe);
+}
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 1d8e92a..7c56be9 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2008 Apple, Inc.
  * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -43,4 +44,5 @@ void DarwinUpdateModKeys(int flags);
 
 void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, 
 			int nevents);
+
 #endif  /* _DARWIN_EVENTS_H */
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 7ab1e15..7f600ab 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -381,34 +381,3 @@ void QuartzSpaceChanged(uint32_t space_id) {
     /* Do something special here, so we don't depend on quartz-wm for spaces to work... */
     DEBUG_LOG("Space Changed (%u) ... do something interesting...\n", space_id);
 }
-
-/*
- * QuartzMessageServerThread
- *  Send the X server thread a message by placing it on the event queue.
- */
-void
-QuartzMessageServerThread(
-    int type,
-    int argc, ...)
-{
-    xEvent xe;
-    INT32 *argv;
-    int i, max_args;
-    va_list args;
-
-    memset(&xe, 0, sizeof(xe));
-    xe.u.u.type = type;
-    xe.u.clientMessage.u.l.type = type;
-
-    argv = &xe.u.clientMessage.u.l.longs0;
-    max_args = 4;
-
-    if (argc > 0 && argc <= max_args) {
-        va_start (args, argc);
-        for (i = 0; i < argc; i++)
-            argv[i] = (int) va_arg (args, int);
-        va_end (args);
-    }
-
-    mieqEnqueue(NULL, &xe);
-}
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index 4aa654a..2956956 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -68,7 +68,7 @@ static void eventHandler(unsigned int type, const void *arg,
     switch (type) {
         case XP_EVENT_DISPLAY_CHANGED:
             DEBUG_LOG("XP_EVENT_DISPLAY_CHANGED\n");
-            QuartzMessageServerThread(kXquartzDisplayChanged, 0);
+            DarwinSendDDXEvent(kXquartzDisplayChanged, 0);
             break;
             
         case XP_EVENT_WINDOW_STATE_CHANGED:
@@ -76,7 +76,7 @@ static void eventHandler(unsigned int type, const void *arg,
                 const xp_window_state_event *ws_arg = arg;
                 
                 DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: id=%d, state=%d\n", ws_arg->id, ws_arg->state);
-                QuartzMessageServerThread(kXquartzWindowState, 2,
+                DarwinSendDDXEvent(kXquartzWindowState, 2,
                                           ws_arg->id, ws_arg->state);
             } else {
                 DEBUG_LOG("XP_EVENT_WINDOW_STATE_CHANGED: ignored\n");
@@ -88,7 +88,7 @@ static void eventHandler(unsigned int type, const void *arg,
             if (arg_size == sizeof(xp_window_id))  {
                 xp_window_id id = * (xp_window_id *) arg;
                 WindowPtr pWin = xprGetXWindow(id);
-                QuartzMessageServerThread(kXquartzWindowMoved, 1, pWin);
+                DarwinSendDDXEvent(kXquartzWindowMoved, 1, pWin);
             }
             break;
             
@@ -112,7 +112,7 @@ static void eventHandler(unsigned int type, const void *arg,
             ErrorF("XP_EVENT_SPACE_CHANGED\n");
             if(arg_size == sizeof(uint32_t)) {
                 uint32_t space_id = *(uint32_t *)arg;
-                QuartzMessageServerThread(kXquartzSpaceChanged, 1, space_id);
+                DarwinSendDDXEvent(kXquartzSpaceChanged, 1, space_id);
             }
             break;
 #endif


More information about the xorg-commit mailing list