[gnome-builder/wip/gtk4-port] libide/gtk: move ide-gui-global helpers to libide-gtk



commit 16a0ff9728f7228e9f3c6b73e90df448e1527126
Author: Christian Hergert <chergert redhat com>
Date:   Mon Mar 28 14:11:21 2022 -0700

    libide/gtk: move ide-gui-global helpers to libide-gtk

 src/libide/gtk/ide-gtk.c        | 94 +++++++++++++++++++++++++++++++++++++++++
 src/libide/gtk/ide-gtk.h        | 41 ++++++++++++++++++
 src/libide/gtk/meson.build      |  2 +
 src/libide/gui/ide-gui-global.c | 68 -----------------------------
 4 files changed, 137 insertions(+), 68 deletions(-)
---
diff --git a/src/libide/gtk/ide-gtk.c b/src/libide/gtk/ide-gtk.c
new file mode 100644
index 000000000..9ac1f74ee
--- /dev/null
+++ b/src/libide/gtk/ide-gtk.c
@@ -0,0 +1,94 @@
+/* ide-gtk.c
+ *
+ * Copyright 2015-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-gtk"
+
+#include "config.h"
+
+#include <libide-threading.h>
+
+#include "ide-gtk.h"
+
+void
+ide_gtk_window_present (GtkWindow *window)
+{
+  /* TODO: We need the last event time to do this properly. Until then,
+   * we'll just fake some timing info to workaround wayland issues.
+   */
+  gtk_window_present_with_time (window, g_get_monotonic_time () / 1000L);
+}
+
+static void
+ide_gtk_show_uri_on_window_cb (GObject      *object,
+                               GAsyncResult *result,
+                               gpointer      user_data)
+{
+  IdeSubprocess *subprocess = (IdeSubprocess *)object;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_SUBPROCESS (subprocess));
+  g_assert (G_IS_ASYNC_RESULT (result));
+
+  if (!ide_subprocess_wait_finish (subprocess, result, &error))
+    g_warning ("Subprocess failed: %s", error->message);
+}
+
+gboolean
+ide_gtk_show_uri_on_window (GtkWindow    *window,
+                            const gchar  *uri,
+                            gint64        timestamp,
+                            GError      **error)
+{
+  g_return_val_if_fail (!window || GTK_IS_WINDOW (window), FALSE);
+  g_return_val_if_fail (uri != NULL, FALSE);
+
+  if (ide_is_flatpak ())
+    {
+      g_autoptr(IdeSubprocessLauncher) launcher = NULL;
+      g_autoptr(IdeSubprocess) subprocess = NULL;
+
+      /* We can't currently trust gtk_show_uri_on_window() because it tries
+       * to open our HTML page with Builder inside our current flatpak
+       * environment! We need to ensure this is fixed upstream, but it's
+       * currently unclear how to do so since we register handles for html.
+       */
+
+      launcher = ide_subprocess_launcher_new (0);
+      ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
+      ide_subprocess_launcher_set_clear_env (launcher, FALSE);
+      ide_subprocess_launcher_push_argv (launcher, "xdg-open");
+      ide_subprocess_launcher_push_argv (launcher, uri);
+
+      if (!(subprocess = ide_subprocess_launcher_spawn (launcher, NULL, error)))
+        return FALSE;
+
+      ide_subprocess_wait_async (subprocess,
+                                 NULL,
+                                 ide_gtk_show_uri_on_window_cb,
+                                 NULL);
+    }
+  else
+    {
+      /* XXX: Workaround for wayland timestamp issue */
+      gtk_show_uri (window, uri, timestamp / 1000L);
+    }
+
+  return TRUE;
+}
diff --git a/src/libide/gtk/ide-gtk.h b/src/libide/gtk/ide-gtk.h
new file mode 100644
index 000000000..cbfa1eb57
--- /dev/null
+++ b/src/libide/gtk/ide-gtk.h
@@ -0,0 +1,41 @@
+/* ide-gtk.h
+ *
+ * Copyright 2015-2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_GTK_INSIDE) && !defined (IDE_GTK_COMPILATION)
+# error "Only <libide-gtk.h> can be included directly."
+#endif
+
+#include <libide-core.h>
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+IDE_AVAILABLE_IN_ALL
+gboolean      ide_gtk_show_uri_on_window     (GtkWindow                *window,
+                                              const gchar              *uri,
+                                              gint64                    timestamp,
+                                              GError                  **error);
+IDE_AVAILABLE_IN_ALL
+void          ide_gtk_window_present         (GtkWindow                *window);
+
+G_END_DECLS
diff --git a/src/libide/gtk/meson.build b/src/libide/gtk/meson.build
index f46d30060..9218f0918 100644
--- a/src/libide/gtk/meson.build
+++ b/src/libide/gtk/meson.build
@@ -10,6 +10,7 @@ libide_gtk_public_headers = [
   'ide-animation.h',
   'ide-cell-renderer-fancy.h',
   'ide-fancy-tree-view.h',
+  'ide-gtk.h',
   'ide-menu-manager.h',
   'ide-search-entry.h',
   'libide-gtk.h',
@@ -29,6 +30,7 @@ libide_gtk_public_sources = [
   'ide-animation.c',
   'ide-cell-renderer-fancy.c',
   'ide-fancy-tree-view.c',
+  'ide-gtk.c',
   'ide-menu-manager.c',
   'ide-search-entry.c',
 ]
diff --git a/src/libide/gui/ide-gui-global.c b/src/libide/gui/ide-gui-global.c
index 7bf6283e7..dd6010af6 100644
--- a/src/libide/gui/ide-gui-global.c
+++ b/src/libide/gui/ide-gui-global.c
@@ -275,65 +275,6 @@ _ide_gtk_progress_bar_start_pulsing (GtkProgressBar *progress)
   ide_gtk_progress_bar_tick_cb (progress);
 }
 
-static void
-ide_gtk_show_uri_on_window_cb (GObject      *object,
-                               GAsyncResult *result,
-                               gpointer      user_data)
-{
-  IdeSubprocess *subprocess = (IdeSubprocess *)object;
-  g_autoptr(GError) error = NULL;
-
-  g_assert (IDE_IS_SUBPROCESS (subprocess));
-  g_assert (G_IS_ASYNC_RESULT (result));
-
-  if (!ide_subprocess_wait_finish (subprocess, result, &error))
-    g_warning ("Subprocess failed: %s", error->message);
-}
-
-gboolean
-ide_gtk_show_uri_on_window (GtkWindow    *window,
-                            const gchar  *uri,
-                            gint64        timestamp,
-                            GError      **error)
-{
-  g_return_val_if_fail (!window || GTK_IS_WINDOW (window), FALSE);
-  g_return_val_if_fail (uri != NULL, FALSE);
-
-  if (ide_is_flatpak ())
-    {
-      g_autoptr(IdeSubprocessLauncher) launcher = NULL;
-      g_autoptr(IdeSubprocess) subprocess = NULL;
-
-      /* We can't currently trust gtk_show_uri_on_window() because it tries
-       * to open our HTML page with Builder inside our current flatpak
-       * environment! We need to ensure this is fixed upstream, but it's
-       * currently unclear how to do so since we register handles for html.
-       */
-
-      launcher = ide_subprocess_launcher_new (0);
-      ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
-      ide_subprocess_launcher_set_clear_env (launcher, FALSE);
-      ide_subprocess_launcher_push_argv (launcher, "xdg-open");
-      ide_subprocess_launcher_push_argv (launcher, uri);
-
-      if (!(subprocess = ide_subprocess_launcher_spawn (launcher, NULL, error)))
-        return FALSE;
-
-      ide_subprocess_wait_async (subprocess,
-                                 NULL,
-                                 ide_gtk_show_uri_on_window_cb,
-                                 NULL);
-    }
-  else
-    {
-      /* XXX: Workaround for wayland timestamp issue */
-      if (!gtk_show_uri_on_window (window, uri, timestamp / 1000L, error))
-        return FALSE;
-    }
-
-  return TRUE;
-}
-
 static void
 show_parents (GtkWidget *widget)
 {
@@ -367,15 +308,6 @@ ide_widget_reveal_and_grab (GtkWidget *widget)
   gtk_widget_grab_focus (widget);
 }
 
-void
-ide_gtk_window_present (GtkWindow *window)
-{
-  /* TODO: We need the last event time to do this properly. Until then,
-   * we'll just fake some timing info to workaround wayland issues.
-   */
-  gtk_window_present_with_time (window, g_get_monotonic_time () / 1000L);
-}
-
 static void
 split_action_name (const gchar  *action_name,
                    gchar       **prefix,


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