[gtk/wip/otte/inspector: 6/6] inspector: Add an initial clipboard page
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/inspector: 6/6] inspector: Add an initial clipboard page
- Date: Fri, 20 Aug 2021 04:30:07 +0000 (UTC)
commit 7ce22f900dada93ddfb4bb8d1398dc237860feef
Author: Benjamin Otte <otte redhat com>
Date: Thu Aug 19 18:38:27 2021 +0200
inspector: Add an initial clipboard page
gtk/inspector/clipboard.c | 270 +++++++++++++++++++++++++++++++++++++++++++++
gtk/inspector/clipboard.h | 38 +++++++
gtk/inspector/clipboard.ui | 98 ++++++++++++++++
gtk/inspector/init.c | 2 +
gtk/inspector/meson.build | 1 +
gtk/inspector/window.c | 3 +
gtk/inspector/window.h | 1 +
gtk/inspector/window.ui | 18 +++
8 files changed, 431 insertions(+)
---
diff --git a/gtk/inspector/clipboard.c b/gtk/inspector/clipboard.c
new file mode 100644
index 0000000000..794bc6c80d
--- /dev/null
+++ b/gtk/inspector/clipboard.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2021 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#include "clipboard.h"
+#include "window.h"
+
+#include "gtkbutton.h"
+#include "gtkdebug.h"
+#include "gtklabel.h"
+#include "gtkscale.h"
+#include "gtkswitch.h"
+#include "gtklistbox.h"
+#include "gtkprivate.h"
+#include "gtksizegroup.h"
+#include "gtkimage.h"
+#include "gtkadjustment.h"
+#include "gtkbox.h"
+#include "gtkbinlayout.h"
+#include "gtkmediafileprivate.h"
+
+struct _GtkInspectorClipboard
+{
+ GtkWidget parent;
+
+ GdkDisplay *display;
+
+ GtkWidget *swin;
+
+ GtkWidget *clipboard_formats;
+ GtkWidget *clipboard_info;
+
+ GtkWidget *primary_formats;
+ GtkWidget *primary_info;
+};
+
+typedef struct _GtkInspectorClipboardClass
+{
+ GtkWidgetClass parent_class;
+} GtkInspectorClipboardClass;
+
+G_DEFINE_TYPE (GtkInspectorClipboard, gtk_inspector_clipboard, GTK_TYPE_WIDGET)
+
+static gboolean
+is_gtype_supported (GType type)
+{
+ return g_type_is_a (type, G_TYPE_STRING);
+}
+
+static void
+add_gtype_row (GtkInspectorClipboard *self,
+ GtkListBox *list,
+ GType gtype)
+{
+ GtkWidget *row, *box, *label, *button;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 40);
+
+ label = gtk_label_new (g_type_name (gtype));
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_box_append (GTK_BOX (box), label);
+
+ if (is_gtype_supported (gtype))
+ {
+ button = gtk_button_new_with_label (_("Show"));
+ //g_signal_connect (button, "clicked", show_contents, clipboard);
+ gtk_widget_set_halign (button, GTK_ALIGN_END);
+ gtk_widget_set_valign (button, GTK_ALIGN_BASELINE);
+ gtk_box_append (GTK_BOX (box), button);
+ }
+
+ row = gtk_list_box_row_new ();
+ gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box);
+ gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
+
+ gtk_widget_set_hexpand (box, FALSE);
+ gtk_list_box_insert (list, row, -1);
+}
+
+static void
+add_mime_type_row (GtkInspectorClipboard *self,
+ GtkListBox *list,
+ const char *mime_type)
+{
+ GtkWidget *row, *box, *label;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 40);
+
+ label = gtk_label_new (mime_type);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_box_append (GTK_BOX (box), label);
+
+ row = gtk_list_box_row_new ();
+ gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box);
+ gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
+
+ gtk_widget_set_hexpand (box, FALSE);
+ gtk_list_box_insert (list, row, -1);
+}
+
+static void
+init_formats (GtkInspectorClipboard *self,
+ GtkListBox *list,
+ GdkClipboard *clipboard)
+{
+ GtkListBoxRow *row;
+ GdkContentFormats *formats;
+ const char * const *mime_types;
+ const GType *gtypes;
+ gsize i, n;
+
+ while ((row = gtk_list_box_get_row_at_index (list, 1)))
+ gtk_list_box_remove (list, GTK_WIDGET (row));
+
+ formats = gdk_clipboard_get_formats (clipboard);
+
+ gtypes = gdk_content_formats_get_gtypes (formats, &n);
+ for (i = 0; i < n; i++)
+ add_gtype_row (self, list, gtypes[i]);
+
+ mime_types = gdk_content_formats_get_mime_types (formats, &n);
+ for (i = 0; i < n; i++)
+ add_mime_type_row (self, list, mime_types[i]);
+}
+
+static void
+init_info (GtkInspectorClipboard *self,
+ GtkLabel *label,
+ GdkClipboard *clipboard)
+{
+ GdkContentFormats *formats;
+
+ formats = gdk_clipboard_get_formats (clipboard);
+ if (gdk_content_formats_get_gtypes (formats, NULL) == NULL &&
+ gdk_content_formats_get_mime_types (formats, NULL) == NULL)
+ {
+ gtk_label_set_text (label, C_("clipboard", "empty"));
+ return;
+ }
+
+ if (gdk_clipboard_is_local (clipboard))
+ gtk_label_set_text (label, C_("clipboard", "local"));
+ else
+ gtk_label_set_text (label, C_("clipboard", "remote"));
+}
+
+static void
+clipboard_notify (GdkClipboard *clipboard,
+ GParamSpec *pspec,
+ GtkInspectorClipboard *self)
+{
+ if (g_str_equal (pspec->name, "formats"))
+ {
+ init_formats (self, GTK_LIST_BOX (self->clipboard_formats), clipboard);
+ }
+
+ init_info (self, GTK_LABEL (self->clipboard_info), clipboard);
+}
+
+static void
+primary_notify (GdkClipboard *clipboard,
+ GParamSpec *pspec,
+ GtkInspectorClipboard *self)
+{
+ if (g_str_equal (pspec->name, "formats"))
+ {
+ init_formats (self, GTK_LIST_BOX (self->primary_formats), clipboard);
+ }
+
+ g_print ("%s: %s\n", pspec->name, gdk_content_formats_to_string (gdk_clipboard_get_formats (clipboard)));
+ init_info (self, GTK_LABEL (self->primary_info), clipboard);
+}
+
+static void
+gtk_inspector_clipboard_unset_display (GtkInspectorClipboard *self)
+{
+ GdkClipboard *clipboard;
+
+ if (self->display == NULL)
+ return;
+
+ clipboard = gdk_display_get_clipboard (self->display);
+ g_signal_handlers_disconnect_by_func (clipboard, clipboard_notify, self);
+
+ clipboard = gdk_display_get_primary_clipboard (self->display);
+ g_signal_handlers_disconnect_by_func (clipboard, primary_notify, self);
+}
+
+static void
+gtk_inspector_clipboard_init (GtkInspectorClipboard *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+gtk_inspector_clipboard_dispose (GObject *object)
+{
+ GtkInspectorClipboard *self = GTK_INSPECTOR_CLIPBOARD (object);
+
+ gtk_inspector_clipboard_unset_display (self);
+
+ g_clear_pointer (&self->swin, gtk_widget_unparent);
+
+ G_OBJECT_CLASS (gtk_inspector_clipboard_parent_class)->dispose (object);
+}
+
+static void
+gtk_inspector_clipboard_class_init (GtkInspectorClipboardClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->dispose = gtk_inspector_clipboard_dispose;
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/clipboard.ui");
+ gtk_widget_class_bind_template_child (widget_class, GtkInspectorClipboard, swin);
+ gtk_widget_class_bind_template_child (widget_class, GtkInspectorClipboard, clipboard_formats);
+ gtk_widget_class_bind_template_child (widget_class, GtkInspectorClipboard, clipboard_info);
+ gtk_widget_class_bind_template_child (widget_class, GtkInspectorClipboard, primary_formats);
+ gtk_widget_class_bind_template_child (widget_class, GtkInspectorClipboard, primary_info);
+
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+}
+
+void
+gtk_inspector_clipboard_set_display (GtkInspectorClipboard *self,
+ GdkDisplay *display)
+{
+ GdkClipboard *clipboard;
+
+ gtk_inspector_clipboard_unset_display (self);
+
+ self->display = display;
+
+ if (display == NULL)
+ return;
+
+ clipboard = gdk_display_get_clipboard (display);
+ g_signal_connect (clipboard, "notify", G_CALLBACK (clipboard_notify), self);
+ init_formats (self, GTK_LIST_BOX (self->clipboard_formats), clipboard);
+ init_info (self, GTK_LABEL (self->clipboard_info), clipboard);
+
+ clipboard = gdk_display_get_primary_clipboard (display);
+ g_signal_connect (clipboard, "notify", G_CALLBACK (primary_notify), self);
+ init_formats (self, GTK_LIST_BOX (self->primary_formats), clipboard);
+ init_info (self, GTK_LABEL (self->primary_info), clipboard);
+}
+
diff --git a/gtk/inspector/clipboard.h b/gtk/inspector/clipboard.h
new file mode 100644
index 0000000000..6bc7ee9619
--- /dev/null
+++ b/gtk/inspector/clipboard.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GTK_INSPECTOR_CLIPBOARD_H_
+#define _GTK_INSPECTOR_CLIPBOARD_H_
+
+#include <gtk/gtkwidget.h>
+
+#define GTK_TYPE_INSPECTOR_CLIPBOARD (gtk_inspector_clipboard_get_type())
+#define GTK_INSPECTOR_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),
GTK_TYPE_INSPECTOR_CLIPBOARD, GtkInspectorClipboard))
+#define GTK_INSPECTOR_IS_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),
GTK_TYPE_INSPECTOR_CLIPBOARD))
+
+typedef struct _GtkInspectorClipboard GtkInspectorClipboard;
+
+G_BEGIN_DECLS
+
+GType gtk_inspector_clipboard_get_type (void);
+
+void gtk_inspector_clipboard_set_display (GtkInspectorClipboard *self,
+ GdkDisplay *display);
+
+G_END_DECLS
+
+#endif // _GTK_INSPECTOR_CLIPBOARD_H_
diff --git a/gtk/inspector/clipboard.ui b/gtk/inspector/clipboard.ui
new file mode 100644
index 0000000000..ef83f037e9
--- /dev/null
+++ b/gtk/inspector/clipboard.ui
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk40">
+ <template class="GtkInspectorClipboard" parent="GtkWidget">
+ <child>
+ <object class="GtkScrolledWindow" id="swin">
+ <property name="hscrollbar-policy">never</property>
+ <child>
+ <object class="GtkBox" id="box">
+ <property name="orientation">vertical</property>
+ <property name="margin-start">60</property>
+ <property name="margin-end">60</property>
+ <property name="margin-top">60</property>
+ <property name="margin-bottom">60</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkFrame">
+ <child>
+ <object class="GtkListBox" id="clipboard_formats">
+ <property name="selection-mode">none</property>
+ <style>
+ <class name="rich-list"/>
+ </style>
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="activatable">0</property>
+ <child>
+ <object class="GtkBox">
+ <property name="spacing">40</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">Clipboard</property>
+ <property name="halign">start</property>
+ <property name="valign">baseline</property>
+ <property name="xalign">0.0</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="clipboard_info">
+ <property name="selectable">1</property>
+ <property name="halign">end</property>
+ <property name="valign">baseline</property>
+ <property name="ellipsize">end</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkFrame">
+ <child>
+ <object class="GtkListBox" id="primary_formats">
+ <property name="selection-mode">none</property>
+ <style>
+ <class name="rich-list"/>
+ </style>
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="activatable">0</property>
+ <child>
+ <object class="GtkBox">
+ <property name="spacing">40</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">Primary</property>
+ <property name="halign">start</property>
+ <property name="valign">baseline</property>
+ <property name="xalign">0.0</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="primary_info">
+ <property name="selectable">1</property>
+ <property name="halign">end</property>
+ <property name="valign">baseline</property>
+ <property name="ellipsize">end</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c
index ed489baee3..0e0691a16d 100644
--- a/gtk/inspector/init.c
+++ b/gtk/inspector/init.c
@@ -27,6 +27,7 @@
#include "a11y.h"
#include "actions.h"
#include "cellrenderergraph.h"
+#include "clipboard.h"
#include "controllers.h"
#include "css-editor.h"
#include "css-node-tree.h"
@@ -64,6 +65,7 @@ gtk_inspector_init (void)
g_type_ensure (GTK_TYPE_GRAPH_DATA);
g_type_ensure (GTK_TYPE_INSPECTOR_A11Y);
g_type_ensure (GTK_TYPE_INSPECTOR_ACTIONS);
+ g_type_ensure (GTK_TYPE_INSPECTOR_CLIPBOARD);
g_type_ensure (GTK_TYPE_INSPECTOR_CONTROLLERS);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_NODE_TREE);
diff --git a/gtk/inspector/meson.build b/gtk/inspector/meson.build
index 0ae9927011..048a0598bb 100644
--- a/gtk/inspector/meson.build
+++ b/gtk/inspector/meson.build
@@ -5,6 +5,7 @@ inspector_sources = files(
'actions.c',
'baselineoverlay.c',
'cellrenderergraph.c',
+ 'clipboard.c',
'controllers.c',
'css-editor.c',
'css-node-tree.c',
diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c
index 02b108d882..c2f6c432d0 100644
--- a/gtk/inspector/window.c
+++ b/gtk/inspector/window.c
@@ -30,6 +30,7 @@
#include "init.h"
#include "window.h"
#include "prop-list.h"
+#include "clipboard.h"
#include "controllers.h"
#include "css-editor.h"
#include "css-node-tree.h"
@@ -291,6 +292,7 @@ gtk_inspector_window_constructed (GObject *object)
gtk_inspector_css_editor_set_display (GTK_INSPECTOR_CSS_EDITOR (iw->css_editor), iw->inspected_display);
gtk_inspector_visual_set_display (GTK_INSPECTOR_VISUAL (iw->visual), iw->inspected_display);
gtk_inspector_general_set_display (GTK_INSPECTOR_GENERAL (iw->general), iw->inspected_display);
+ gtk_inspector_clipboard_set_display (GTK_INSPECTOR_CLIPBOARD (iw->clipboard), iw->inspected_display);
gtk_inspector_logs_set_display (GTK_INSPECTOR_LOGS (iw->logs), iw->inspected_display);
gtk_inspector_css_node_tree_set_display (GTK_INSPECTOR_CSS_NODE_TREE (iw->widget_css_node_tree),
iw->inspected_display);
}
@@ -645,6 +647,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, css_editor);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, visual);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, general);
+ gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, clipboard);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, logs);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, go_up_button);
diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h
index 90841a8ae4..efaec419a5 100644
--- a/gtk/inspector/window.h
+++ b/gtk/inspector/window.h
@@ -76,6 +76,7 @@ typedef struct
GtkWidget *sidebar_revealer;
GtkWidget *css_editor;
GtkWidget *visual;
+ GtkWidget *clipboard;
GtkWidget *general;
GtkWidget *logs;
diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui
index c76af022c6..7ecb543841 100644
--- a/gtk/inspector/window.ui
+++ b/gtk/inspector/window.ui
@@ -130,6 +130,14 @@
</property>
</object>
</child>
+ <child>
+ <object class="GtkStackPage">
+ <property name="name">clipboard</property>
+ <property name="child">
+ <object class="GtkBox"/>
+ </property>
+ </object>
+ </child>
<child>
<object class="GtkStackPage">
<property name="name">statistics</property>
@@ -587,6 +595,16 @@
</property>
</object>
</child>
+ <child>
+ <object class="GtkStackPage">
+ <property name="name">clipboard</property>
+ <property name="title" translatable="yes">Clipboard</property>
+ <property name="child">
+ <object class="GtkInspectorClipboard" id="clipboard">
+ </object>
+ </property>
+ </object>
+ </child>
<child>
<object class="GtkStackPage">
<property name="name">statistics</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]