WinHost: Add SimplePointer support
authorMarvin Haeuser <mhaeuser@outlook.de>
Tue, 24 Sep 2019 12:46:14 +0000 (20:46 +0800)
committerRay Ni <ray.ni@intel.com>
Mon, 21 Oct 2019 02:08:09 +0000 (10:08 +0800)
Catch WM mouse events and expose them via the SimplePointer protocol.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Andrew Fish <afish@apple.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Signed-off-by: Marvin Haeuser <mhaeuser@outlook.de>
EmulatorPkg/Win/Host/WinGop.h
EmulatorPkg/Win/Host/WinGopInput.c
EmulatorPkg/Win/Host/WinGopScreen.c
EmulatorPkg/Win/Host/WinInclude.h

index aa41db6..5943ca9 100644 (file)
@@ -22,6 +22,7 @@ Abstract:
 \r
 #include <Protocol/EmuIoThunk.h>\r
 #include <Protocol/EmuGraphicsWindow.h>\r
+#include <Protocol/SimplePointer.h>\r
 #include <Protocol/SimpleTextIn.h>\r
 #include <Protocol/SimpleTextInEx.h>\r
 #include <Protocol/GraphicsOutput.h>\r
@@ -109,6 +110,10 @@ typedef struct {
   BOOLEAN                           ScrollLock;\r
   BOOLEAN                           CapsLock;\r
   BOOLEAN                           IsPartialKeySupport;\r
+  INT32                             PointerPreviousX;\r
+  INT32                             PointerPreviousY;\r
+  BOOLEAN                           PointerStateChanged;\r
+  EFI_SIMPLE_POINTER_STATE          PointerState;\r
 } GRAPHICS_PRIVATE_DATA;\r
 #define GRAPHICS_PRIVATE_DATA_SIGNATURE  SIGNATURE_32 ('g', 'f', 'x', 'd')\r
 #define GRAPHICS_PRIVATE_DATA_FROM_THIS(a)  \\r
index 0e8d11f..312a549 100644 (file)
@@ -409,9 +409,12 @@ WinNtWndCheckPointer (
 \r
   Private = GRAPHICS_PRIVATE_DATA_FROM_THIS (GraphicsIo);\r
 \r
-  return EFI_NOT_READY;\r
-}\r
+  if (!Private->PointerStateChanged) {\r
+    return EFI_NOT_READY;\r
+  }\r
 \r
+  return EFI_SUCCESS;\r
+}\r
 \r
 EFI_STATUS\r
 EFIAPI\r
@@ -424,5 +427,21 @@ WinNtWndGetPointerState (
 \r
   Private = GRAPHICS_PRIVATE_DATA_FROM_THIS (GraphicsIo);\r
 \r
-  return EFI_NOT_READY;\r
+  if (!Private->PointerStateChanged) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  State->RelativeMovementX = Private->PointerState.RelativeMovementX;\r
+  State->RelativeMovementY = Private->PointerState.RelativeMovementY;\r
+  State->RelativeMovementZ = Private->PointerState.RelativeMovementZ;\r
+  State->LeftButton        = Private->PointerState.LeftButton;\r
+  State->RightButton       = Private->PointerState.RightButton;\r
+\r
+  Private->PointerState.RelativeMovementX = 0;\r
+  Private->PointerState.RelativeMovementY = 0;\r
+  Private->PointerState.RelativeMovementZ = 0;\r
+\r
+  Private->PointerStateChanged = FALSE;\r
+\r
+  return EFI_SUCCESS;\r
 }\r
index 8f42606..fa34596 100644 (file)
@@ -399,6 +399,8 @@ WinNtGopThreadWindowProc (
   LPARAM                Index;\r
   EFI_INPUT_KEY         Key;\r
   BOOLEAN               AltIsPress;\r
+  INT32                 PosX;\r
+  INT32                 PosY;\r
 \r
   //\r
   // Use mTlsIndex global to get a Thread Local Storage version of Private.\r
@@ -527,6 +529,45 @@ WinNtGopThreadWindowProc (
     WinNtGopConvertParamToEfiKeyShiftState (Private, &wParam, &lParam, FALSE);\r
     return 0;\r
 \r
+  case WM_MOUSEMOVE:\r
+    PosX = GET_X_LPARAM (lParam);\r
+    PosY = GET_Y_LPARAM (lParam);\r
+\r
+    if (Private->PointerPreviousX != PosX) {\r
+      Private->PointerState.RelativeMovementX += (PosX - Private->PointerPreviousX);\r
+      Private->PointerPreviousX                = PosX;\r
+      Private->PointerStateChanged             = TRUE;\r
+    }\r
+\r
+    if (Private->PointerPreviousY != PosY) {\r
+      Private->PointerState.RelativeMovementY += (PosY - Private->PointerPreviousY);\r
+      Private->PointerPreviousY                = PosY;\r
+      Private->PointerStateChanged             = TRUE;\r
+    }\r
+\r
+    Private->PointerState.RelativeMovementZ  = 0;\r
+    return 0;\r
+\r
+  case WM_LBUTTONDOWN:\r
+    Private->PointerState.LeftButton = TRUE;\r
+    Private->PointerStateChanged     = TRUE;\r
+    return 0;\r
+\r
+  case WM_LBUTTONUP:\r
+    Private->PointerState.LeftButton = FALSE;\r
+    Private->PointerStateChanged     = TRUE;\r
+    return 0;\r
+\r
+  case WM_RBUTTONDOWN:\r
+    Private->PointerState.RightButton = TRUE;\r
+    Private->PointerStateChanged      = TRUE;\r
+    return 0;\r
+\r
+  case WM_RBUTTONUP:\r
+    Private->PointerState.RightButton = FALSE;\r
+    Private->PointerStateChanged      = TRUE;\r
+    return 0;\r
+\r
   case WM_CLOSE:\r
     //\r
     // This close message is issued by user, core is not aware of this,\r
index ae02770..8a9ae7d 100644 (file)
@@ -40,6 +40,7 @@ typedef UINT32 size_t ;
 #endif\r
 \r
 #include "windows.h"\r
+#include "windowsx.h"\r
 \r
 #undef GUID\r
 #undef _LIST_ENTRY\r