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

Ben Byer bbyer at kemper.freedesktop.org
Tue Apr 29 23:38:39 PDT 2008


 hw/xquartz/X11Application.m |   37 +++++++++++++++++++----------
 hw/xquartz/darwin.c         |   51 +++++++++++++++++++++++++++++++---------
 hw/xquartz/darwin.h         |    1 
 hw/xquartz/darwinEvents.c   |   56 ++++++++++++++++++++++----------------------
 hw/xquartz/darwinEvents.h   |    5 +--
 5 files changed, 96 insertions(+), 54 deletions(-)

New commits:
commit 50641bce730ee03738fa0c4beb8125b34fda556f
Author: Ben Byer <bbyer at bushing.apple.com>
Date:   Tue Apr 29 23:37:58 2008 -0700

    xquartz: created darwinTablet, to represent tablet events

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 508e3e5..9f6923c 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -1,10 +1,9 @@
 /**************************************************************
  *
- * Shared code for the Darwin X Server
- * running with Quartz or IOKit display mode
+ * Xquartz initialization code
  *
+ * Copyright (c) 2007-2008 Apple Inc.
  * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
- * Copyright (c) 2007 Apple Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -112,6 +111,7 @@ int                     darwinFakeMouse3Mask = NX_COMMANDMASK;
 
 // devices
 DeviceIntPtr            darwinPointer = NULL;
+DeviceIntPtr            darwinTablet = NULL;
 DeviceIntPtr            darwinKeyboard = NULL;
 
 // Common pixmap formats
@@ -332,14 +332,13 @@ static void DarwinChangePointerControl(
 #endif
 
 /*
- * DarwinMouseProc
- *  Handle the initialization, etc. of a mouse
+ * DarwinMouseProc: Handle the initialization, etc. of a mouse
  */
 static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
+	// 7 buttons: left, right, middle, then four scroll wheel "buttons"
     CARD8 map[8] = {0, 1, 2, 3, 4, 5, 6, 7};
     
     switch (what) {
-            
         case DEVICE_INIT:
             pPointer->public.on = FALSE;
             
@@ -347,15 +346,13 @@ static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
             InitPointerDeviceStruct((DevicePtr)pPointer, map, 7,
                                     GetMotionHistory,
                                     (PtrCtrlProcPtr)NoopDDA,
-                                    GetMotionHistorySize(), 7);
-            InitProximityClassDeviceStruct(pPointer);
+                                    GetMotionHistorySize(), 2);
+								pPointer->name = strdup("Quartz Pointing Device");
             break;
-            
         case DEVICE_ON:
             pPointer->public.on = TRUE;
             AddEnabledDevice( darwinEventReadFD );
             return Success;
-            
         case DEVICE_CLOSE:
         case DEVICE_OFF:
             pPointer->public.on = FALSE;
@@ -366,6 +363,34 @@ static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
     return Success;
 }
 
+static int DarwinTabletProc(DeviceIntPtr pPointer, int what) {
+    CARD8 map[4] = {0, 1, 2, 3};
+    
+    switch (what) {
+        case DEVICE_INIT:
+            pPointer->public.on = FALSE;
+            
+            // Set button map.
+            InitPointerDeviceStruct((DevicePtr)pPointer, map, 3,
+                                    GetMotionHistory,
+                                    (PtrCtrlProcPtr)NoopDDA,
+                                    GetMotionHistorySize(), 7);
+            InitProximityClassDeviceStruct(pPointer);
+//			InitAbsoluteClassDeviceStruct(pPointer);
+			pPointer->name = strdup("pen");			
+            break;
+        case DEVICE_ON:
+            pPointer->public.on = TRUE;
+            AddEnabledDevice( darwinEventReadFD );
+            return Success;
+        case DEVICE_CLOSE:
+        case DEVICE_OFF:
+            pPointer->public.on = FALSE;
+            RemoveEnabledDevice(darwinEventReadFD);
+            return Success;
+    }
+    return Success;
+}
 
 /*
  * DarwinKeybdProc
@@ -376,6 +401,7 @@ static int DarwinKeybdProc( DeviceIntPtr pDev, int onoff )
     switch ( onoff ) {
         case DEVICE_INIT:
             DarwinKeyboardInit( pDev );
+			pDev->name = strdup("Quartz Keyboard");
             break;
         case DEVICE_ON:
             pDev->public.on = TRUE;
@@ -499,9 +525,11 @@ int DarwinParseModifierList(
 void InitInput( int argc, char **argv )
 {
     darwinPointer = AddInputDevice(DarwinMouseProc, TRUE);
-	darwinPointer->name = strdup("tablet");
     RegisterPointerDevice( darwinPointer );
 
+    darwinTablet = AddInputDevice(DarwinTabletProc, TRUE);
+    RegisterPointerDevice( darwinTablet );
+
     darwinKeyboard = AddInputDevice(DarwinKeybdProc, TRUE);
     RegisterKeyboardDevice( darwinKeyboard );
 
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index bc0b8df..088880f 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -71,6 +71,7 @@ extern io_connect_t     darwinParamConnect;
 extern int              darwinEventReadFD;
 extern int              darwinEventWriteFD;
 extern DeviceIntPtr     darwinPointer;
+extern DeviceIntPtr     darwinTablet;
 extern DeviceIntPtr     darwinKeyboard;
 
 // User preferences
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index e25ae84..7b3091d 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -365,7 +365,8 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	static int darwinFakeMouseButtonDown = 0;
 	static int darwinFakeMouseButtonMask = 0;
 	int i, num_events;
-
+	DeviceIntPtr dev;
+	
 //    DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     
 	if(!darwinEvents) {
@@ -376,7 +377,10 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	int valuators[5] = {pointer_x, pointer_y, pressure * SCALEFACTOR_PRESSURE, 
 		      tilt_x * SCALEFACTOR_TILT, tilt_y * SCALEFACTOR_TILT};
 	
-		DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", 
+	if (pressure == 0 && tilt_x == 0 && tilt_y == 0) dev = darwinPointer;
+	else dev = darwinTablet;
+
+	DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", 
 			valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
 	if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
 		// Mimic multi-button mouse with modifier-clicks
@@ -410,9 +414,9 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	} 
 
     mieqEnqueue_lock(); {
-        num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
-                                      POINTER_ABSOLUTE, 0, 5, valuators);
-        for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+        num_events = GetPointerEvents(darwinEvents, dev, ev_type, ev_button, 
+                                      POINTER_ABSOLUTE, 0, dev==darwinTablet?5:2, valuators);
+        for(i=0; i<num_events; i++) mieqEnqueue (dev,&darwinEvents[i]);
         DarwinPokeEQ();
 
     } mieqEnqueue_unlock();
@@ -460,9 +464,9 @@ void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y) {
 	}
 
     mieqEnqueue_lock(); {
-        num_events = GetProximityEvents(darwinEvents, darwinPointer, ev_type,
+        num_events = GetProximityEvents(darwinEvents, darwinTablet, ev_type,
                                         0, 5, valuators);
-        for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+        for(i=0; i<num_events; i++) mieqEnqueue (darwinTablet,&darwinEvents[i]);
         DarwinPokeEQ();
     } mieqEnqueue_unlock();
 }
commit 299a056737168ca1faefd675dce6d6ab13176be9
Author: Ben Byer <bbyer at bushing.apple.com>
Date:   Tue Apr 29 23:00:09 2008 -0700

    xquartz: remove unused params from DarwinEQInit

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 48830ef..508e3e5 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -499,12 +499,13 @@ int DarwinParseModifierList(
 void InitInput( int argc, char **argv )
 {
     darwinPointer = AddInputDevice(DarwinMouseProc, TRUE);
+	darwinPointer->name = strdup("tablet");
     RegisterPointerDevice( darwinPointer );
 
     darwinKeyboard = AddInputDevice(DarwinKeybdProc, TRUE);
     RegisterKeyboardDevice( darwinKeyboard );
 
-    DarwinEQInit( (DevicePtr)darwinKeyboard, (DevicePtr)darwinPointer );
+    DarwinEQInit();
 
     QuartzInitInput(argc, argv);
 }
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index cd2b49a..e25ae84 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -307,7 +307,7 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
     }
 }
 
-Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) { 
+Bool DarwinEQInit(void) { 
     if (!darwinEvents)
         darwinEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
     if (!darwinEvents)
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 4a619c9..ef8bf39 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -28,7 +28,7 @@
 #ifndef _DARWIN_EVENTS_H
 #define _DARWIN_EVENTS_H
 
-Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr);
+Bool DarwinEQInit(void);
 void DarwinEQEnqueue(const xEventPtr e);
 void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
commit 588683cecca2cfc65a28de035cd6ee3d64ff59d2
Author: Ben Byer <bbyer at bushing.apple.com>
Date:   Tue Apr 29 22:35:34 2008 -0700

    XQuartz: Fix to tablet-event handling code; we now scale
    more conservatively (to match Linux's Wacom driver) and
    we now receive all tablet-related events.

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 7a43bfc..0dce4ca 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -53,6 +53,9 @@
 #define XSERVER_VERSION "?"
 #endif
 
+#define ProximityIn    0
+#define ProximityOut   1
+
 int X11EnableKeyEquivalents = TRUE;
 int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
 
@@ -859,27 +862,37 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
 	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 NSLeftMouseDown:    ev_button=1; ev_type=ButtonPress; goto check_subtype;
+		case NSOtherMouseDown:   ev_button=2; ev_type=ButtonPress; goto check_subtype;
+		case NSRightMouseDown:   ev_button=3; ev_type=ButtonPress; goto check_subtype;
+		case NSLeftMouseUp:      ev_button=1; ev_type=ButtonRelease; goto check_subtype;
+		case NSOtherMouseUp:     ev_button=2; ev_type=ButtonRelease; goto check_subtype;
+		case NSRightMouseUp:     ev_button=3; ev_type=ButtonRelease; goto check_subtype;
+		case NSLeftMouseDragged:  ev_button=1; ev_type=MotionNotify; goto check_subtype;
+		case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto check_subtype;
+		case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto check_subtype;
+		
+check_subtype:
+			if ([e subtype] != NSTabletPointEventSubtype) goto handle_mouse;
+			// fall through to get tablet data
 		case NSTabletPoint:
 			pressure = [e pressure];
 			tilt_x = [e tilt].x;
-			tilt_y = [e tilt].y; // fall through
+			tilt_y = [e tilt].y; 
+			// fall through to normal mouse handling
+
 		case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
-		handle_mouse:
 
-//      if ([e subtype] == NSTabletPointEventSubtype) pressure = [e pressure];
+handle_mouse:
 		DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y,
 			pressure, tilt_x, tilt_y);
 		break;
 
+		case NSTabletProximity:
+			DarwinSendProximityEvents([e isEnteringProximity]?ProximityIn:ProximityOut,
+				pointer_x, pointer_y);
+		break;
+
 		case NSScrollWheel:
 			DarwinSendScrollEvents([e deltaX], [e deltaY], pointer_x, pointer_y,
 				pressure, tilt_x, tilt_y);
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 86e7704..cd2b49a 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -65,6 +65,10 @@ in this Software without prior written authorization from The Open Group.
 #define SCROLLWHEELLEFTFAKE  6
 #define SCROLLWHEELRIGHTFAKE 7
 
+/* These values were chosen to match the output of xinput under Linux */
+#define SCALEFACTOR_TILT        64.0
+#define SCALEFACTOR_PRESSURE    1000.0
+
 #define _APPLEWM_SERVER_
 #include "applewmExt.h"
 #include <X11/extensions/applewm.h>
@@ -362,26 +366,18 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	static int darwinFakeMouseButtonMask = 0;
 	int i, num_events;
 
-    //DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
+//    DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     
 	if(!darwinEvents) {
 		ErrorF("DarwinSendPointerEvents called before darwinEvents was initialized\n");
 		return;
 	}
-	/* I can't find a spec for this, but at least GTK expects that tablets are
-     just like mice, except they have either one or three extra valuators, in this
-     order:
-     
-     X coord, Y coord, pressure, X tilt, Y tilt
-     Pressure and tilt should be represented natively as floats; unfortunately,
-     we can't do that.  Again, GTK seems to record the min/max of each valuator,
-     and then perform scaling back to float itself using that info. Soo.... */
-
-	int valuators[5] = {pointer_x, pointer_y, 
-		      pressure * INT32_MAX * 1.0f, 
-		      tilt_x * INT32_MAX * 1.0f, 
-		      tilt_y * INT32_MAX * 1.0f};
 
+	int valuators[5] = {pointer_x, pointer_y, pressure * SCALEFACTOR_PRESSURE, 
+		      tilt_x * SCALEFACTOR_TILT, tilt_y * SCALEFACTOR_TILT};
+	
+		DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", 
+			valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
 	if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
 		// Mimic multi-button mouse with modifier-clicks
 		// If both sets of modifiers are pressed,
@@ -450,16 +446,16 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
     } mieqEnqueue_unlock();
 }
 
-void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y, 
-			       float pressure, float tilt_x, float tilt_y) {
+void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y) {
 	int i, num_events;
-	int valuators[5] = {pointer_x, pointer_y, 
-		      pressure * INT32_MAX * 1.0f, 
-		      tilt_x * INT32_MAX * 1.0f, 
-		      tilt_y * INT32_MAX * 1.0f};
 
+	// tilt and pressure have no meaning for a Prox event
+	int valuators[5] = {pointer_x, pointer_y, 0, 0, 0};  
+
+	DEBUG_LOG("DarwinSendProximityEvents(%d, %d, %d)\n", ev_type, pointer_x, pointer_y);
+	
 	if(!darwinEvents) {
-		ErrorF("DarwinSendProximityvents called before darwinEvents was initialized\n");
+		ErrorF("DarwinSendProximityEvents called before darwinEvents was initialized\n");
 		return;
 	}
 
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index dd3f81c..4a619c9 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -34,8 +34,7 @@ void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
 void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y,
 			     float pressure, float tilt_x, float tilt_y);
-void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y, 
-			       float pressure, float tilt_x, float tilt_y);
+void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y);
 void DarwinSendKeyboardEvents(int ev_type, int keycode);
 void DarwinSendScrollEvents(float count_x, float count_y, int pointer_x, int pointer_y,
 			    float pressure, float tilt_x, float tilt_y);


More information about the xorg-commit mailing list