gl/window/win32: Handle mouse and key events
authorSeungha Yang <seungha.yang@navercorp.com>
Thu, 13 Feb 2020 12:33:11 +0000 (21:33 +0900)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 17 Feb 2020 02:42:41 +0000 (02:42 +0000)
This is at least useful for the gst-play-1.0 use case.

gst-libs/gst/gl/win32/gstglwindow_win32.c

index 86667b2..2c67486 100644 (file)
@@ -407,6 +407,72 @@ gst_gl_window_win32_draw (GstGLWindow * window)
       RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE);
 }
 
+static void
+gst_gl_window_win32_handle_key_event (GstGLWindow * window, UINT uMsg,
+    LPARAM lParam)
+{
+  gunichar2 wcrep[128];
+  const gchar *event;
+
+  if (GetKeyNameTextW (lParam, (LPWSTR) wcrep, 128)) {
+    gchar *utfrep = g_utf16_to_utf8 (wcrep, 128, NULL, NULL, NULL);
+    if (utfrep) {
+      if (uMsg == WM_KEYDOWN)
+        event = "key-press";
+      else
+        event = "key-release";
+
+      gst_gl_window_send_key_event (window, event, utfrep);
+      g_free (utfrep);
+    }
+  }
+}
+
+static void
+gst_gl_window_win32_handle_mouse_event (GstGLWindow * window, UINT uMsg,
+    LPARAM lParam)
+{
+  gint button;
+  const gchar *event = NULL;
+
+  switch (uMsg) {
+    case WM_MOUSEMOVE:
+      button = 0;
+      event = "mouse-move";
+      break;
+    case WM_LBUTTONDOWN:
+      button = 1;
+      event = "mouse-button-press";
+      break;
+    case WM_LBUTTONUP:
+      button = 1;
+      event = "mouse-button-release";
+      break;
+    case WM_RBUTTONDOWN:
+      button = 2;
+      event = "mouse-button-press";
+      break;
+    case WM_RBUTTONUP:
+      button = 2;
+      event = "mouse-button-release";
+      break;
+    case WM_MBUTTONDOWN:
+      button = 3;
+      event = "mouse-button-press";
+      break;
+    case WM_MBUTTONUP:
+      button = 3;
+      event = "mouse-button-release";
+      break;
+    default:
+      break;
+  }
+
+  if (event)
+    gst_gl_window_send_mouse_event (window, event, button,
+        (double) LOWORD (lParam), (double) HIWORD (lParam));
+}
+
 /* PRIVATE */
 
 LRESULT CALLBACK
@@ -487,6 +553,21 @@ window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
         ret = TRUE;
         break;
       }
+      case WM_KEYDOWN:
+      case WM_KEYUP:
+        gst_gl_window_win32_handle_key_event (window, uMsg, lParam);
+        ret = DefWindowProc (hWnd, uMsg, wParam, lParam);
+        break;
+      case WM_LBUTTONDOWN:
+      case WM_LBUTTONUP:
+      case WM_RBUTTONDOWN:
+      case WM_RBUTTONUP:
+      case WM_MBUTTONDOWN:
+      case WM_MBUTTONUP:
+      case WM_MOUSEMOVE:
+        gst_gl_window_win32_handle_mouse_event (window, uMsg, lParam);
+        ret = DefWindowProc (hWnd, uMsg, wParam, lParam);
+        break;
       default:
       {
         ret = DefWindowProc (hWnd, uMsg, wParam, lParam);