[wing/track-clipboard] eventwindow: add property to track the clipboard messages



commit 4e756d85bbab5d91d51821539232895e16dd53d9
Author: Ignacio Casal Quinteiro <qignacio amazon com>
Date:   Wed Apr 22 14:38:48 2020 +0200

    eventwindow: add property to track the clipboard messages

 wing/wingeventwindow.c | 32 ++++++++++++++++++++++++++++++++
 wing/wingeventwindow.h |  1 +
 2 files changed, 33 insertions(+)
---
diff --git a/wing/wingeventwindow.c b/wing/wingeventwindow.c
index d073c7e..6223909 100644
--- a/wing/wingeventwindow.c
+++ b/wing/wingeventwindow.c
@@ -40,6 +40,7 @@ struct _WingEventWindow
 
   gchar *name;
   wchar_t *namew;
+  gboolean track_clipboard;
   HWND hwnd;
   guint watch_id;
   GIOChannel *channel;
@@ -50,6 +51,7 @@ enum
 {
     PROP_0,
     PROP_NAME,
+    PROP_TRACK_CLIPBOARD,
     LAST_PROP
 };
 
@@ -130,6 +132,9 @@ wing_event_window_get_property (GObject    *object,
     case PROP_NAME:
       g_value_set_string (value, window->name);
       break;
+    case PROP_TRACK_CLIPBOARD:
+      g_value_set_boolean (value, window->track_clipboard);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -151,6 +156,9 @@ wing_event_window_set_property (GObject      *object,
       if (window->name != NULL)
         window->namew = g_utf8_to_utf16 (window->name, -1, NULL, NULL, NULL);
       break;
+    case PROP_TRACK_CLIPBOARD:
+      window->track_clipboard = g_value_get_boolean (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -257,6 +265,14 @@ wing_event_window_class_init (WingEventWindowClass *klass)
                          G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT_ONLY);
 
+  props[PROP_TRACK_CLIPBOARD] =
+    g_param_spec_boolean ("track-clipboard",
+                          "Track clipboard",
+                          "Track clipboard",
+                          FALSE,
+                          G_PARAM_READWRITE |
+                          G_PARAM_CONSTRUCT_ONLY);
+
   g_object_class_install_properties (object_class, LAST_PROP, props);
 }
 
@@ -304,6 +320,20 @@ wing_event_window_initable_init (GInitable     *initable,
       return FALSE;
     }
 
+  if (window->track_clipboard &&
+      !AddClipboardFormatListener (window->hwnd))
+    {
+      gchar *err_msg;
+
+      err_msg = g_win32_error_message (GetLastError ());
+
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Could not add clipboard format listener: %s",
+                   err_msg);
+      g_free (err_msg);
+      return FALSE;
+    }
+
   /* Special style to remove the application from the Windows taskbar */
   ShowWindow (window->hwnd, SW_HIDE);
   style = GetWindowLong (window->hwnd, GWL_EXSTYLE);
@@ -327,11 +357,13 @@ wing_event_window_initable_iface_init (GInitableIface *iface)
 
 WingEventWindow *
 wing_event_window_new (const gchar  *name,
+                       gboolean      track_clipboard,
                        GError      **error)
 {
   return g_initable_new (WING_TYPE_EVENT_WINDOW,
                          NULL, error,
                          "name", name,
+                         "track-clipboard", track_clipboard,
                          NULL);
 }
 
diff --git a/wing/wingeventwindow.h b/wing/wingeventwindow.h
index 5b09bf6..dcfc858 100644
--- a/wing/wingeventwindow.h
+++ b/wing/wingeventwindow.h
@@ -39,6 +39,7 @@ typedef gboolean (* WingEventCallback)    (WingEventWindow *window,
 
 WING_AVAILABLE_IN_ALL
 WingEventWindow         *wing_event_window_new             (const gchar       *name,
+                                                            gboolean           track_clipboard,
                                                             GError           **error);
 
 WING_AVAILABLE_IN_ALL


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