[Xfce4-commits] [panel-plugins/xfce4-clipman-plugin] 01/03: Speed up shutdown and paste

noreply at xfce.org noreply at xfce.org
Sun Apr 5 23:45:28 CEST 2020


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-clipman-plugin.

commit 074e25a466fb889c44b3b68c4d3d88b3bb326cb1
Author: Florian Schüller <florian.schueller at tttech.com>
Date:   Wed Apr 1 11:54:26 2020 +0200

    Speed up shutdown and paste
    
    Moving "copying clipboard" and storing it to the end of the
    shutdown process is faster and is a good workaround for
    gtk_clipboard_store() blocking for 10 seconds on some systems.
---
 panel-plugin/xfce4-clipman-history.c | 75 ++++++++++++++++++++++++------------
 1 file changed, 50 insertions(+), 25 deletions(-)

diff --git a/panel-plugin/xfce4-clipman-history.c b/panel-plugin/xfce4-clipman-history.c
index 4013150..dac8837 100644
--- a/panel-plugin/xfce4-clipman-history.c
+++ b/panel-plugin/xfce4-clipman-history.c
@@ -52,6 +52,17 @@ GtkWidget   *clipman_history_treeview_init             (MyPlugin  *plugin);
 static void  clipman_history_copy_or_paste_on_activate (MyPlugin  *plugin,
                                                         guint      paste_on_activate);
 
+typedef struct _ClipmanHistoryShutdownData ClipmanHistoryShutdownData;
+
+struct _ClipmanHistoryShutdownData
+{
+  gchar *text;
+  gboolean add_primary_clipboard;
+  gboolean do_copy;
+};
+
+ClipmanHistoryShutdownData shutdown_data = { NULL, FALSE, FALSE };
+
 
 static void
 clipman_history_row_activated (GtkTreeView       *treeview,
@@ -61,7 +72,6 @@ clipman_history_row_activated (GtkTreeView       *treeview,
 {
   gboolean add_primary_clipboard;
   GtkWidget *window;
-  GtkClipboard *clipboard;
   GtkTreeSelection *selection;
   GtkTreeModel *model;
   GtkTreeIter iter;
@@ -80,19 +90,16 @@ clipman_history_row_activated (GtkTreeView       *treeview,
                       COLUMN_TEXT, &text,
                       -1);
 
-  clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
-  gtk_clipboard_set_text (clipboard, text, -1);
-
   /* Only update the primary clipboard if the setting "Sync mouse selections" is enabled */
   g_object_get (G_OBJECT (plugin->collector), "add-primary-clipboard", &add_primary_clipboard, NULL);
-  if (add_primary_clipboard)
-    {
-      clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
-      gtk_clipboard_set_text (clipboard, text, -1);
-    }
+
+  shutdown_data.do_copy = TRUE;
+  shutdown_data.text = g_strdup (text);
+  shutdown_data.add_primary_clipboard = add_primary_clipboard;
 
   window = gtk_widget_get_toplevel (GTK_WIDGET (treeview));
 
+
   if (GTK_IS_WINDOW (window))
     gtk_dialog_response (GTK_DIALOG (window), GTK_RESPONSE_CLOSE);
 }
@@ -361,16 +368,6 @@ clipman_history_treeview_init (MyPlugin *plugin)
   return box;
 }
 
-static gboolean
-clipman_history_paste_on_activate (gpointer user_data)
-{
-  guint paste_on_activate = GPOINTER_TO_UINT (user_data);
-
-  cb_paste_on_activate (paste_on_activate);
-
-  return FALSE;
-}
-
 static void
 clipman_history_dialog_finalize (MyPlugin  *plugin,
                                  GtkWidget *window)
@@ -383,12 +380,6 @@ clipman_history_dialog_finalize (MyPlugin  *plugin,
   g_object_unref (plugin->history);
   gtk_widget_destroy (plugin->dialog);
 
-  /* Should be after gtk_widget_destroy() to assure focus being in the (previous) "target" window */
-  if (internal_paste_on_activate != PASTE_INACTIVE)
-    {
-      g_timeout_add (10, (GSourceFunc) clipman_history_paste_on_activate, GUINT_TO_POINTER (internal_paste_on_activate));
-    }
-
   g_slice_free (MyPlugin, plugin);
   xfconf_shutdown ();
 }
@@ -547,6 +538,7 @@ main (gint argc, gchar *argv[])
 {
   GtkApplication *app;
   int status;
+  GtkClipboard *clipboard;
 
   if (!clipman_history_clipman_daemon_running ())
     {
@@ -563,5 +555,38 @@ main (gint argc, gchar *argv[])
   g_signal_connect (app, "activate", G_CALLBACK (clipman_history_activate), NULL);
   status = g_application_run (G_APPLICATION (app), argc, argv);
 
+  /* doing copy and paste outside of g_main to assure window being already gone and
+   * as in some occasions the implicit gtk_clipboard_store() lags for 10 seconds
+   */
+  if (shutdown_data.do_copy)
+    {
+      clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+      gtk_clipboard_set_text (clipboard, shutdown_data.text, -1);
+
+      if (shutdown_data.add_primary_clipboard)
+        {
+          clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+          gtk_clipboard_set_text (clipboard, shutdown_data.text, -1);
+        }
+      g_free (shutdown_data.text);
+
+      /* Should be after gtk_widget_destroy() to assure focus being in the (previous) "target" window */
+      if (internal_paste_on_activate != PASTE_INACTIVE)
+        {
+          cb_paste_on_activate (internal_paste_on_activate);
+        }
+
+      clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+      /* we are out of the g_main - so we have store() on our own */
+      gtk_clipboard_store (clipboard);
+
+      if (shutdown_data.add_primary_clipboard)
+        {
+          clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+          /* we are out of the g_main - so we have store() on our own */
+          gtk_clipboard_store (clipboard);
+        }
+    }
+
   return status;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list