[gnome-control-center/gbsneto/gtk4: 11/38] info-overview: Port to GTK4
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gbsneto/gtk4: 11/38] info-overview: Port to GTK4
- Date: Thu, 18 Nov 2021 15:53:08 +0000 (UTC)
commit 5b6c0384841b17a5b50d6d619406ea58748ff614
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Oct 19 23:07:53 2021 -0300
info-overview: Port to GTK4
- Remove visible=True properties from the UI file
- Use GtkPicture for the OS logo
- Drop gtk_dialog_run()
- Port gnome-control-center-print-renderer to GTK4
by using GdkSurface to create the GL context
panels/info-overview/cc-info-overview-panel.c | 71 ++++++++++++----------
panels/info-overview/cc-info-overview-panel.ui | 45 +++-----------
.../gnome-control-center-print-renderer.c | 10 ++-
panels/info-overview/meson.build | 2 +-
panels/meson.build | 2 +-
shell/cc-panel-loader.c | 4 +-
6 files changed, 58 insertions(+), 76 deletions(-)
---
diff --git a/panels/info-overview/cc-info-overview-panel.c b/panels/info-overview/cc-info-overview-panel.c
index 6e832eb35..72425247d 100644
--- a/panels/info-overview/cc-info-overview-panel.c
+++ b/panels/info-overview/cc-info-overview-panel.c
@@ -42,14 +42,13 @@
#include <gdk/gdk.h>
#ifdef GDK_WINDOWING_WAYLAND
-#include <gdk/gdkwayland.h>
+#include <gdk/wayland/gdkwayland.h>
#endif
#ifdef GDK_WINDOWING_X11
-#include <gdk/gdkx.h>
+#include <gdk/x11/gdkx.h>
#endif
#include "cc-list-row.h"
-#include "list-box-helper.h"
#include "cc-info-overview-panel.h"
struct _CcInfoOverviewPanel
@@ -68,7 +67,7 @@ struct _CcInfoOverviewPanel
CcListRow *hostname_row;
CcListRow *memory_row;
GtkListBox *os_box;
- GtkImage *os_logo;
+ GtkPicture *os_logo;
CcListRow *os_name_row;
CcListRow *os_type_row;
CcListRow *processor_row;
@@ -830,19 +829,37 @@ on_device_name_entry_changed (CcInfoOverviewPanel *self)
{
const gchar *current_hostname, *new_hostname;
- current_hostname = gtk_entry_get_text (GTK_ENTRY (self->hostname_entry));
- new_hostname = gtk_entry_get_text (GTK_ENTRY (self->device_name_entry));
+ current_hostname = gtk_editable_get_text (GTK_EDITABLE (self->hostname_entry));
+ new_hostname = gtk_editable_get_text (GTK_EDITABLE (self->device_name_entry));
gtk_widget_set_sensitive (self->rename_button,
g_strcmp0 (current_hostname, new_hostname) != 0);
}
+static void
+on_hostname_editor_dialog_response_cb (GtkDialog *dialog,
+ gint response,
+ CcInfoOverviewPanel *self)
+{
+ if (response == GTK_RESPONSE_APPLY)
+ {
+ const gchar *hostname;
+
+ /* We simply change the CcHostnameEntry text. CcHostnameEntry
+ * listens to changes and updates hostname on change.
+ */
+ hostname = gtk_editable_get_text (GTK_EDITABLE (self->device_name_entry));
+ gtk_editable_set_text (GTK_EDITABLE (self->hostname_entry), hostname);
+ }
+
+ gtk_window_close (GTK_WINDOW (dialog));
+}
+
static void
open_hostname_edit_dialog (CcInfoOverviewPanel *self)
{
GtkWindow *toplevel;
CcShell *shell;
const gchar *hostname;
- gint response;
g_assert (CC_IS_INFO_OVERVIEW_PANEL (self));
@@ -850,21 +867,12 @@ open_hostname_edit_dialog (CcInfoOverviewPanel *self)
toplevel = GTK_WINDOW (cc_shell_get_toplevel (shell));
gtk_window_set_transient_for (GTK_WINDOW (self->hostname_editor), toplevel);
- hostname = gtk_entry_get_text (GTK_ENTRY (self->hostname_entry));
- gtk_entry_set_text (self->device_name_entry, hostname);
+ hostname = gtk_editable_get_text (GTK_EDITABLE (self->hostname_entry));
+ gtk_editable_set_text (GTK_EDITABLE (self->device_name_entry), hostname);
gtk_widget_grab_focus (GTK_WIDGET (self->device_name_entry));
- response = gtk_dialog_run (self->hostname_editor);
- gtk_widget_hide (GTK_WIDGET (self->hostname_editor));
-
- if (response != GTK_RESPONSE_APPLY)
- return;
+ gtk_window_present (GTK_WINDOW (self->hostname_editor));
- /* We simply change the CcHostnameEntry text. CcHostnameEntry
- * listens to changes and updates hostname on change.
- */
- hostname = gtk_entry_get_text (self->device_name_entry);
- gtk_entry_set_text (GTK_ENTRY (self->hostname_entry), hostname);
}
static void
@@ -883,25 +891,17 @@ cc_info_panel_row_activated_cb (CcInfoOverviewPanel *self,
static gboolean
use_dark_theme (CcInfoOverviewPanel *panel)
{
- GdkScreen *screen;
- GtkSettings *settings;
- g_autofree char *theme_name = NULL;
-
- theme_name = g_strdup (g_getenv ("GTK_THEME"));
- if (theme_name != NULL)
- return g_str_has_suffix (theme_name, "dark") ? TRUE : FALSE;
-
- screen = gtk_widget_get_screen (GTK_WIDGET (panel));
- settings = gtk_settings_get_for_screen (screen);
+ AdwStyleManager *style_manager = adw_style_manager_get_default ();
- g_object_get (settings, "gtk-theme-name", &theme_name, NULL);
- return (theme_name != NULL && g_str_has_suffix (theme_name, "dark")) ? TRUE : FALSE;
+ return adw_style_manager_get_dark (style_manager);
}
static void
setup_os_logo (CcInfoOverviewPanel *panel)
{
+ GtkIconTheme *icon_theme;
g_autofree char *logo_name = g_get_os_info ("LOGO");
+ g_autoptr(GtkIconPaintable) icon_paintable = NULL;
g_autoptr(GPtrArray) array = NULL;
g_autoptr(GIcon) icon = NULL;
gboolean dark;
@@ -919,7 +919,13 @@ setup_os_logo (CcInfoOverviewPanel *panel)
g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s", logo_name));
icon = g_themed_icon_new_from_names ((char **) array->pdata, array->len);
- gtk_image_set_from_gicon (panel->os_logo, icon, GTK_ICON_SIZE_INVALID);
+ icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
+ icon_paintable = gtk_icon_theme_lookup_by_gicon (icon_theme, icon,
+ 192,
+ gtk_widget_get_scale_factor (GTK_WIDGET (panel)),
+ gtk_widget_get_direction (GTK_WIDGET (panel)),
+ 0);
+ gtk_picture_set_paintable (panel->os_logo, GDK_PAINTABLE (icon_paintable));
}
static void
@@ -951,6 +957,7 @@ cc_info_overview_panel_class_init (CcInfoOverviewPanelClass *klass)
gtk_widget_class_bind_template_callback (widget_class, cc_info_panel_row_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, on_device_name_entry_changed);
+ gtk_widget_class_bind_template_callback (widget_class, on_hostname_editor_dialog_response_cb);
g_type_ensure (CC_TYPE_LIST_ROW);
g_type_ensure (CC_TYPE_HOSTNAME_ENTRY);
diff --git a/panels/info-overview/cc-info-overview-panel.ui b/panels/info-overview/cc-info-overview-panel.ui
index 95afe867c..18669acb5 100644
--- a/panels/info-overview/cc-info-overview-panel.ui
+++ b/panels/info-overview/cc-info-overview-panel.ui
@@ -2,43 +2,30 @@
<interface>
<!-- interface-requires gtk+ 3.0 -->
<template class="CcInfoOverviewPanel" parent="CcPanel">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
<child>
<object class="GtkScrolledWindow">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
<property name="min-content-height">480</property>
<property name="hscrollbar-policy">never</property>
<child>
- <object class="HdyClamp">
- <property name="visible">True</property>
+ <object class="AdwClamp">
<property name="margin_top">32</property>
<property name="margin_bottom">32</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<child>
<object class="GtkBox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="valign">center</property>
<property name="spacing">30</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkImage" id="os_logo">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="use_fallback">True</property>
+ <object class="GtkPicture" id="os_logo">
+ <property name="can-shrink">False</property>
+ <property name="alternative-text" translatable="yes">System Logo</property>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
</child>
<child>
<object class="GtkListBox">
- <property name="visible">True</property>
<property name="selection-mode">none</property>
<signal name="row-activated" handler="cc_info_panel_row_activated_cb" swapped="yes"/>
<style>
@@ -48,7 +35,6 @@
<!-- Device name -->
<child>
<object class="CcListRow" id="hostname_row">
- <property name="visible">True</property>
<property name="title" translatable="yes">Device Name</property>
<property name="secondary-label" bind-source="hostname_entry" bind-property="text"
bind-flags="sync-create" />
<property name="icon-name">go-next-symbolic</property>
@@ -60,7 +46,6 @@
<child>
<object class="GtkListBox" id="hardware_box">
- <property name="visible">True</property>
<property name="selection-mode">none</property>
<style>
<class name="content" />
@@ -78,7 +63,6 @@
<!-- Memory -->
<child>
<object class="CcListRow" id="memory_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes">Memory</property>
</object>
@@ -87,7 +71,6 @@
<!-- Processor -->
<child>
<object class="CcListRow" id="processor_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes">Processor</property>
</object>
@@ -96,7 +79,6 @@
<!-- Graphics -->
<child>
<object class="CcListRow" id="graphics_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes">Graphics</property>
</object>
@@ -105,7 +87,6 @@
<!-- Disk Capacity -->
<child>
<object class="CcListRow" id="disk_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes">Disk Capacity</property>
<property name="secondary-label" translatable="yes">Calculating…</property>
@@ -117,7 +98,6 @@
<child>
<object class="GtkListBox" id="os_box">
- <property name="visible">True</property>
<property name="selection-mode">none</property>
<signal name="row-activated" handler="cc_info_panel_row_activated_cb" swapped="yes"/>
<style>
@@ -127,7 +107,6 @@
<!-- OS Name -->
<child>
<object class="CcListRow" id="os_name_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes"
comments="translators: this field contains the distro name and version">OS
Name</property>
@@ -137,7 +116,6 @@
<!-- OS Type -->
<child>
<object class="CcListRow" id="os_type_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes">OS Type</property>
</object>
@@ -146,7 +124,6 @@
<!-- GNOME Version -->
<child>
<object class="CcListRow" id="gnome_version_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes">GNOME Version</property>
<property name="secondary-label">3.0</property>
@@ -156,7 +133,6 @@
<!-- Windowing System -->
<child>
<object class="CcListRow" id="windowing_system_row">
- <property name="visible">True</property>
<property name="activatable">False</property>
<property name="title" translatable="yes">Windowing System</property>
</object>
@@ -174,7 +150,6 @@
<!-- Software Updates -->
<child>
<object class="CcListRow" id="software_updates_row">
- <property name="visible">True</property>
<property name="title" translatable="yes">Software Updates</property>
<property name="icon-name">go-next-symbolic</property>
</object>
@@ -196,19 +171,19 @@
<property name="modal">True</property>
<property name="use-header-bar">1</property>
<property name="default-height">24</property>
+ <property name="hide-on-close">True</property>
<property name="title" translatable="yes">Rename Device</property>
- <signal name="delete-event" handler="gtk_widget_hide_on_delete"/>
+ <signal name="response" handler="on_hostname_editor_dialog_response_cb" object="CcInfoOverviewPanel"
swapped="no" />
- <child internal-child="vbox">
+ <child>
<object class="GtkBox">
- <property name="border-width">0</property>
<property name="margin-top">18</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="margin-bottom">18</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
- <property name="visible">True</property>
<property name="margin-bottom">18</property>
<property name="wrap">True</property>
<property name="max-width-chars">35</property>
@@ -218,7 +193,6 @@
</child>
<child>
<object class="GtkEntry" id="device_name_entry">
- <property name="visible">True</property>
<signal name="changed" handler="on_device_name_entry_changed" swapped="yes"/>
</object>
</child>
@@ -228,8 +202,6 @@
<!-- Rename button -->
<child type="action">
<object class="GtkButton" id="rename_button">
- <property name="visible">True</property>
- <property name="can-default">True</property>
<property name="use-underline">True</property>
<property name="label" translatable="yes">_Rename</property>
</object>
@@ -238,7 +210,6 @@
<!-- Cancel button -->
<child type="action">
<object class="GtkButton" id="cancel_button">
- <property name="visible">True</property>
<property name="use-underline">True</property>
<property name="label" translatable="yes">_Cancel</property>
</object>
diff --git a/panels/info-overview/gnome-control-center-print-renderer.c
b/panels/info-overview/gnome-control-center-print-renderer.c
index 3e83703c3..e84a11a81 100644
--- a/panels/info-overview/gnome-control-center-print-renderer.c
+++ b/panels/info-overview/gnome-control-center-print-renderer.c
@@ -28,13 +28,17 @@
static char *
get_gtk_gles_renderer (void)
{
+ GdkSurface *surface;
+ GtkNative *native;
GtkWidget *win;
GdkGLContext *context;
char *renderer = NULL;
- win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ win = gtk_window_new ();
gtk_widget_realize (win);
- context = gdk_window_create_gl_context (gtk_widget_get_window (win), NULL);
+ native = gtk_widget_get_native (win);
+ surface = gtk_native_get_surface (native);
+ context = gdk_surface_create_gl_context (surface, NULL);
if (!context)
return NULL;
gdk_gl_context_make_current (context);
@@ -50,7 +54,7 @@ main (int argc, char **argv)
{
g_autofree char *renderer_string = NULL;
- gtk_init (NULL, NULL);
+ gtk_init ();
renderer_string = get_gtk_gles_renderer ();
if (renderer_string) {
diff --git a/panels/info-overview/meson.build b/panels/info-overview/meson.build
index 2fe10b32c..b941f0833 100644
--- a/panels/info-overview/meson.build
+++ b/panels/info-overview/meson.build
@@ -54,7 +54,7 @@ info_panel_lib = static_library(
panels_libs += info_panel_lib
print_renderer_deps = [
- dependency('gtk+-3.0'),
+ dependency('gtk4'),
epoxy_dep
]
diff --git a/panels/meson.build b/panels/meson.build
index beeb0587d..029f5aa4d 100644
--- a/panels/meson.build
+++ b/panels/meson.build
@@ -9,7 +9,7 @@ panels = [
# 'default-apps',
# 'diagnostics',
# 'display',
-# 'info-overview',
+ 'info-overview',
# 'keyboard',
# 'location',
# 'lock',
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c
index a6ead7e90..fefabca7e 100644
--- a/shell/cc-panel-loader.c
+++ b/shell/cc-panel-loader.c
@@ -40,7 +40,7 @@
//extern GType cc_date_time_panel_get_type (void);
//extern GType cc_default_apps_panel_get_type (void);
//extern GType cc_display_panel_get_type (void);
-//extern GType cc_info_overview_panel_get_type (void);
+extern GType cc_info_overview_panel_get_type (void);
//extern GType cc_keyboard_panel_get_type (void);
//extern GType cc_mouse_panel_get_type (void);
//extern GType cc_multitasking_panel_get_type (void);
@@ -108,7 +108,7 @@ static CcPanelLoaderVtable default_panels[] =
//PANEL_TYPE("default-apps", cc_default_apps_panel_get_type, NULL),
//PANEL_TYPE("diagnostics", cc_diagnostics_panel_get_type,
cc_diagnostics_panel_static_init_func),
//PANEL_TYPE("display", cc_display_panel_get_type, NULL),
- //PANEL_TYPE("info-overview", cc_info_overview_panel_get_type, NULL),
+ PANEL_TYPE("info-overview", cc_info_overview_panel_get_type, NULL),
//PANEL_TYPE("keyboard", cc_keyboard_panel_get_type, NULL),
//PANEL_TYPE("location", cc_location_panel_get_type, NULL),
//PANEL_TYPE("lock", cc_lock_panel_get_type, NULL),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]