GDK W32: Use a dumb window class for decorative windows
authorРуслан Ижбулатов <lrn1986@gmail.com>
Tue, 15 Mar 2016 16:10:34 +0000 (16:10 +0000)
committerРуслан Ижбулатов <lrn1986@gmail.com>
Wed, 30 Mar 2016 09:04:46 +0000 (09:04 +0000)
Currently only one kind of decorative window is in use - the shape
indicator that is shown when snapping windows to the edge of the screen.

When normal toplevel class is used, its window procedure expects certain
motions from GDK (passing user data to CreateWindowEx(), registering
handle in a hash map etc), and might crash if that is not done.

Dumb window doesn't require anything, it can just be.

https://bugzilla.gnome.org/show_bug.cgi?id=763013

gdk/win32/gdkwindow-win32.c

index 50814cbf53089fc23f7b99ade2655ddbce919d12..e6601a85c52ebd63eba6d27c1c445f5928327a6a 100644 (file)
@@ -3546,6 +3546,47 @@ apply_snap (GdkWindow             *window,
     }
 }
 
+/* Registers a dumb window class. This window
+ * has DefWindowProc() for a window procedure and
+ * does not do anything that GdkWindow-bound HWNDs do.
+ */
+static ATOM
+RegisterGdkDumbClass ()
+{
+  static ATOM klassDUMB = 0;
+  static WNDCLASSEXW wcl;
+  ATOM klass = 0;
+
+  wcl.cbSize = sizeof (WNDCLASSEX);
+  wcl.style = 0; /* DON'T set CS_<H,V>REDRAW. It causes total redraw
+                  * on WM_SIZE and WM_MOVE. Flicker, Performance!
+                  */
+  wcl.lpfnWndProc = DefWindowProcW;
+  wcl.cbClsExtra = 0;
+  wcl.cbWndExtra = 0;
+  wcl.hInstance = _gdk_app_hmodule;
+  wcl.hIcon = 0;
+  wcl.hIconSm = 0;
+  wcl.lpszMenuName = NULL;
+  wcl.hbrBackground = NULL;
+  wcl.hCursor = LoadCursor (NULL, IDC_ARROW);
+  wcl.style |= CS_OWNDC;
+  wcl.lpszClassName = L"gdkWindowDumb";
+
+  if (klassDUMB == 0)
+    klassDUMB = RegisterClassExW (&wcl);
+
+  klass = klassDUMB;
+
+  if (klass == 0)
+    {
+      WIN32_API_FAILED ("RegisterClassExW");
+      g_error ("That is a fatal error");
+    }
+
+  return klass;
+}
+
 static gboolean
 ensure_snap_indicator_exists (GdkW32DragMoveResizeContext *context)
 {
@@ -3553,7 +3594,7 @@ ensure_snap_indicator_exists (GdkW32DragMoveResizeContext *context)
     {
       HWND handle;
       ATOM klass;
-      klass = RegisterGdkClass (GDK_WINDOW_TOPLEVEL, GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
+      klass = RegisterGdkDumbClass ();
 
       handle = CreateWindowExW (WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE,
                                 MAKEINTRESOURCEW (klass),