[console/zbrown/term-intent-2: 8/8] gtk4 fixups
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [console/zbrown/term-intent-2: 8/8] gtk4 fixups
- Date: Thu, 28 Jul 2022 01:11:23 +0000 (UTC)
commit 54eee87cab644e1cc484c06869737d5be9c9dcc2
Author: Zander Brown <zbrown gnome org>
Date: Thu Jul 28 02:10:56 2022 +0100
gtk4 fixups
.editorconfig | 4 +-
src/kgx-application.c | 11 +++-
src/kgx-term-app-window.c | 139 ++++++++++++++++++++++++++++++++++------------
src/kgx-term-app-window.h | 1 -
src/kgx-terminal.c | 2 +-
src/kgx-window.c | 2 +-
6 files changed, 118 insertions(+), 41 deletions(-)
---
diff --git a/.editorconfig b/.editorconfig
index 3bc0d4a..1066c04 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,3 +1,5 @@
[*.{c,h}]
indent_size = 2
-indent_style = space
\ No newline at end of file
+indent_style = space
+trim_trailing_whitespace = true
+insert_final_newline = true
diff --git a/src/kgx-application.c b/src/kgx-application.c
index 2070373..6496a0d 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -332,8 +332,6 @@ kgx_application_startup (GApplication *app)
const char *const zoom_out_accels[] = { "<primary>minus", NULL };
const char *const zoom_normal_accels[] = { "<primary>0", NULL };
- g_set_prgname (g_application_get_application_id (app));
-
g_resources_register (kgx_get_resource ());
g_type_ensure (KGX_TYPE_TERMINAL);
@@ -407,6 +405,8 @@ handle_launch (XdgTerminal1 *xdg_term,
KgxWindow *window = NULL;
guint32 timezone = GDK_CURRENT_TIME;
+ g_debug ("Got launch");
+
if (working_directory) {
working = g_file_new_for_path (working_directory);
}
@@ -432,12 +432,17 @@ handle_launch (XdgTerminal1 *xdg_term,
"can-have-tabs", FALSE,
NULL);
+ // TODO: Maybe discount things like sh, python?
title = g_path_get_basename (exec[0]);
}
kgx_application_add_terminal (self, window, timezone, working, (GStrv) exec, title);
- xdg_terminal1_complete_launch_command (xdg_term, invocation);
+ g_debug ("…complete launch");
+
+ xdg_terminal1_complete_launch_command (xdg_term, g_object_ref (invocation));
+
+ g_debug ("done");
}
diff --git a/src/kgx-term-app-window.c b/src/kgx-term-app-window.c
index ca7e608..a2555d3 100644
--- a/src/kgx-term-app-window.c
+++ b/src/kgx-term-app-window.c
@@ -27,7 +27,7 @@
#include <glib/gi18n.h>
#include <gdk/gdk.h>
#ifdef GDK_WINDOWING_WAYLAND
-#include <gdk/gdkwayland.h>
+#include <gdk/wayland/gdkwayland.h>
#endif
#include "kgx-term-app-window.h"
@@ -49,12 +49,7 @@ kgx_term_app_window_dispose (GObject *object)
{
KgxTermAppWindow *self = KGX_TERM_APP_WINDOW (object);
- if (self->cancellable && G_IS_CANCELLABLE (self->cancellable)) {
- g_cancellable_cancel (self->cancellable);
- }
-
g_clear_object (&self->entry);
- g_clear_object (&self->cancellable);
G_OBJECT_CLASS (kgx_term_app_window_parent_class)->dispose (object);
}
@@ -99,57 +94,130 @@ kgx_term_app_window_set_property (GObject *object,
}
-static void
-icon_loaded (GObject *src, GAsyncResult *res, gpointer data)
+static GdkTexture *
+load_icon_texture (KgxTermAppWindow *self,
+ GtkIconTheme *theme,
+ GIcon *icon,
+ int scale_factor,
+ GtkDirectionType dir)
{
- g_autoptr (GdkPixbuf) pixbuf = NULL;
+ g_autoptr (GtkIconPaintable) paintable = NULL;
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GdkTexture) texture = NULL;
g_autoptr (GError) error = NULL;
- pixbuf = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (src), res, &error);
+ paintable = gtk_icon_theme_lookup_by_gicon (theme,
+ icon,
+ 64,
+ scale_factor,
+ dir,
+ 0);
+ file = gtk_icon_paintable_get_file (paintable);
+ if (!file) {
+ return NULL;
+ }
+ texture = gdk_texture_new_from_file (file, &error);
if (error) {
- g_warning ("Unable to set icon: %s", error->message);
-
- return;
+ g_debug ("Unable to load icon (%s): %s",
+ g_file_get_uri (file),
+ error->message);
+ return NULL;
}
- gtk_window_set_icon (GTK_WINDOW (data), pixbuf);
+ return g_steal_pointer (&texture);
}
static void
-kgx_term_app_window_map (GtkWidget *widget)
+setup_icon (KgxTermAppWindow *self)
{
- KgxTermAppWindow *self = KGX_TERM_APP_WINDOW (widget);
- g_autofree char *basename = NULL;
- g_autoptr (GtkIconInfo) info = NULL;
- g_auto (GStrv) parts = NULL;
+ g_autolist (GdkTexture) list = NULL;
+ g_autoptr (GdkTexture) texture = NULL;
+ g_autoptr (GIcon) fallback = NULL;
+ GtkIconTheme *theme;
+ GdkDisplay *display;
GIcon *icon;
- GdkWindow *window;
+ int scale_factor;
+ GtkDirectionType dir;
+ GtkNative *native;
+ GdkSurface *surface;
- GTK_WIDGET_CLASS (kgx_term_app_window_parent_class)->map (widget);
+ display = gtk_widget_get_display (GTK_WIDGET (self));
- window = gtk_widget_get_window (widget);
+ theme = gtk_icon_theme_get_for_display (display);
+ icon = g_app_info_get_icon (G_APP_INFO (self->entry));
+ scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
+ dir = gtk_widget_get_direction (GTK_WIDGET (self));
- if (!window) {
- g_debug ("Apparently no window?");
- return;
+ texture = load_icon_texture (self, theme, icon, scale_factor, dir);
+ if (texture) {
+ list = g_list_append (list, g_steal_pointer (&texture));
}
- icon = g_app_info_get_icon (G_APP_INFO (self->entry));
+ fallback = g_themed_icon_new ("text-x-script");
+ texture = load_icon_texture (self, theme, fallback, scale_factor, dir);
+
+ if (texture) {
+ list = g_list_append (list, g_steal_pointer (&texture));
+ }
+
+ native = gtk_widget_get_native (GTK_WIDGET (self));
+ surface = gtk_native_get_surface (native);
+
+ gdk_toplevel_set_icon_list (GDK_TOPLEVEL (surface), list);
+}
- info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon, 64, 0);
- gtk_icon_info_load_icon_async (info, self->cancellable, icon_loaded, self);
#ifdef GDK_WINDOWING_WAYLAND
- basename = g_path_get_basename (g_desktop_app_info_get_filename (self->entry));
+static void
+setup_appid (KgxTermAppWindow *self)
+{
+ g_autofree char *app_id = NULL;
+ GtkNative *native;
+ GdkSurface *surface;
- parts = g_strsplit (basename, ".", 2);
+ native = gtk_widget_get_native (GTK_WIDGET (self));
+ surface = gtk_native_get_surface (native);
- if (GDK_IS_WAYLAND_WINDOW (window) && parts[1] && g_strcmp0 (parts[1], "desktop") == 0) {
- g_print ("Hey: %p\n", self->entry);
- gdk_wayland_window_set_application_id (GDK_WAYLAND_WINDOW (window), parts[0]);
+ if (!GDK_IS_WAYLAND_SURFACE (surface)) {
+ return;
}
+
+ app_id = g_strdup (g_app_info_get_id (G_APP_INFO (self->entry)));
+
+ if (G_UNLIKELY (!app_id)) {
+ return;
+ }
+
+ if (G_LIKELY (g_str_has_suffix (app_id, ".desktop"))) {
+ size_t len = strlen (app_id);
+
+ for (size_t i = len - 1; i > 0; i--) {
+ if (app_id[i] == '.') {
+ app_id[i] = '\0';
+ break;
+ }
+ }
+ }
+
+ g_debug ("Adopting app-id ‘%s’ for surface %p", app_id, surface);
+
+ gdk_wayland_toplevel_set_application_id (GDK_TOPLEVEL (surface), app_id);
+}
+#endif
+
+
+static void
+kgx_term_app_window_map (GtkWidget *widget)
+{
+ KgxTermAppWindow *self = KGX_TERM_APP_WINDOW (widget);
+
+ GTK_WIDGET_CLASS (kgx_term_app_window_parent_class)->map (widget);
+
+ setup_icon (self);
+#ifdef GDK_WINDOWING_WAYLAND
+ setup_appid (self);
#endif
}
@@ -183,5 +251,8 @@ kgx_term_app_window_class_init (KgxTermAppWindowClass *klass)
static void
kgx_term_app_window_init (KgxTermAppWindow *self)
{
- self->cancellable = g_cancellable_new ();
+ g_object_connect (self,
+ "swapped-signal::notify::scale-factor", G_CALLBACK (setup_icon), self,
+ "swapped-signal::direction-changed", G_CALLBACK (setup_icon), self,
+ NULL);
}
diff --git a/src/kgx-term-app-window.h b/src/kgx-term-app-window.h
index 8bb19e4..71322c1 100644
--- a/src/kgx-term-app-window.h
+++ b/src/kgx-term-app-window.h
@@ -40,7 +40,6 @@ struct _KgxTermAppWindow {
/*< public >*/
GDesktopAppInfo *entry;
- GCancellable *cancellable;
};
G_DECLARE_FINAL_TYPE (KgxTermAppWindow, kgx_term_app_window, KGX, TERM_APP_WINDOW, KgxWindow)
diff --git a/src/kgx-terminal.c b/src/kgx-terminal.c
index 87844d1..e6d4431 100644
--- a/src/kgx-terminal.c
+++ b/src/kgx-terminal.c
@@ -517,7 +517,7 @@ clear_paste_data (gpointer data)
g_clear_weak_pointer (&self->dest);
g_free (self->text);
g_free (self);
-}
+}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PasteData, clear_paste_data)
diff --git a/src/kgx-window.c b/src/kgx-window.c
index 263415b..290f7dd 100644
--- a/src/kgx-window.c
+++ b/src/kgx-window.c
@@ -467,7 +467,7 @@ kgx_window_class_init (KgxWindowClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, pages);
gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, primary_menu);
gtk_widget_class_bind_template_child_private (widget_class, KgxWindow, new_tab);
-
+
gtk_widget_class_bind_template_callback (widget_class, active_changed);
gtk_widget_class_bind_template_callback (widget_class, zoom);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]