[gtk+] W32: Implement composition check for GDK



commit 7ae5a56948e5124eabd558438ff29187f5721819
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date:   Thu Apr 10 08:48:13 2014 +0000

    W32: Implement composition check for GDK
    
    Also move DWM function grabbing and make those functions available to all of GDK-Win32.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727316

 gdk/win32/gdkmain-win32.c    |   29 +++++++++++++++++++++++++++++
 gdk/win32/gdkprivate-win32.h |   10 ++++++++++
 gdk/win32/gdkscreen-win32.c  |   17 +++++++++++++++++
 gtk/gtkwindow.c              |    3 +++
 4 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/gdk/win32/gdkmain-win32.c b/gdk/win32/gdkmain-win32.c
index 905c729..5011817 100644
--- a/gdk/win32/gdkmain-win32.c
+++ b/gdk/win32/gdkmain-win32.c
@@ -48,6 +48,12 @@ static gboolean gdk_synchronize = FALSE;
 
 static gboolean dummy;
 
+#ifdef HAVE_W32_DWM
+static HMODULE dwmdll = NULL;
+PFN_DwmEnableBlurBehindWindow dwmEnableBlurBehindWindow = NULL;
+PFN_DwmIsCompositionEnabled dwmIsCompositionEnabled = NULL;
+#endif
+
 const GOptionEntry _gdk_windowing_args[] = {
   { "sync", 0, 0, G_OPTION_ARG_NONE, &gdk_synchronize, 
     /* Description of --sync in --help output */              N_("Don't batch GDI requests"), NULL },
@@ -132,6 +138,29 @@ _gdk_win32_windowing_init (void)
   _cf_text_html = RegisterClipboardFormat ("text/html");
 
   _gdk_win32_selection_init ();
+
+/* HAVE_W32_DWM means that we have necessary declarations at compile-time,
+ * but we'd still like to be able to run on XP, so we'll load the functions
+ * we need at runtime.
+ */
+#ifdef HAVE_W32_DWM
+  if (dwmdll == NULL)
+    {
+      dwmdll = LoadLibraryA ("dwmapi.dll");
+      if (dwmdll == NULL)
+        {
+          /* This will make sure that we only try this once */
+          dwmdll = INVALID_HANDLE_VALUE;
+        }
+      else
+        {
+          dwmEnableBlurBehindWindow = (PFN_DwmEnableBlurBehindWindow)
+              GetProcAddress (dwmdll, "DwmEnableBlurBehindWindow");
+          dwmIsCompositionEnabled = (PFN_DwmIsCompositionEnabled)
+              GetProcAddress (dwmdll, "DwmIsCompositionEnabled");
+        }
+    }
+#endif
 }
 
 void
diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h
index acc3fca..2482c5d 100644
--- a/gdk/win32/gdkprivate-win32.h
+++ b/gdk/win32/gdkprivate-win32.h
@@ -41,6 +41,15 @@
 
 #include "config.h"
 
+#ifdef HAVE_W32_DWM
+#include <dwmapi.h>
+typedef HRESULT (WINAPI *PFN_DwmEnableBlurBehindWindow)(HWND,
+    const DWM_BLURBEHIND *);
+typedef HRESULT (WINAPI *PFN_DwmIsCompositionEnabled)(BOOL *pfEnabled);
+extern PFN_DwmEnableBlurBehindWindow dwmEnableBlurBehindWindow;
+extern PFN_DwmIsCompositionEnabled dwmIsCompositionEnabled;
+#endif
+
 /* Make up for some minor w32api or MSVC6 header lossage */
 
 #ifndef PS_JOIN_MASK
@@ -496,6 +505,7 @@ gchar *_gdk_win32_display_manager_get_atom_name (GdkDisplayManager *manager,
                                                 GdkAtom            atom);
 void _gdk_win32_append_event (GdkEvent *event);
 void _gdk_win32_emit_configure_event (GdkWindow *window);
+gboolean _gdk_win32_is_desktop_composition_enabled ();
 
 /* Initialization */
 void _gdk_win32_windowing_init (void);
diff --git a/gdk/win32/gdkscreen-win32.c b/gdk/win32/gdkscreen-win32.c
index d2c2dea..2ab8801 100644
--- a/gdk/win32/gdkscreen-win32.c
+++ b/gdk/win32/gdkscreen-win32.c
@@ -174,6 +174,23 @@ gdk_win32_screen_is_composited (GdkScreen *screen)
 {
   g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
 
+  return _gdk_win32_is_desktop_composition_enabled ();
+}
+
+gboolean
+_gdk_win32_is_desktop_composition_enabled ()
+{
+  BOOL b;
+  DWORD sysver, major, minor;
+  sysver = GetVersion ();
+  major = (DWORD)(LOBYTE (LOWORD (sysver)));
+  minor = (DWORD)(HIBYTE (LOWORD (sysver)));
+  /* Composition is always enabled in W8 */
+  if (major >= 6 && minor >= 2)
+    return TRUE;
+
+  if (dwmIsCompositionEnabled && (S_OK == dwmIsCompositionEnabled (&b)))
+    return b;
   return FALSE;
 }
 
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index d791186..9104fed 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -3630,6 +3630,9 @@ gdk_window_supports_csd (GtkWindow *window)
 
       screen = gtk_widget_get_screen (widget);
 
+      if (!gdk_screen_is_composited (screen))
+        return FALSE;
+
       /* We need a visual with alpha */
       visual = gdk_screen_get_rgba_visual (screen);
       if (!visual)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]