[gnome-control-center/gbsneto/gtk4: 15/53] common: Port to GTK4
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gbsneto/gtk4: 15/53] common: Port to GTK4
- Date: Wed, 15 Dec 2021 01:34:33 +0000 (UTC)
commit 59bdf8102806ed41697c05e75149b4b601f8c0e7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Oct 19 20:53:12 2021 -0300
common: Port to GTK4
This is only the bare minimum to make everything under panels/common
build. Since these widgets are used by the main window, port them
first.
CcTimeEntry was particularly hard to port. That's because GtkEntry
is a final class now. Overall, though, I'm happy with how it turned
out to be - much cleaner, less code, more obvious.
meson.build | 2 +-
panels/common/cc-hostname-entry.c | 8 +-
panels/common/cc-language-chooser.c | 34 ++--
panels/common/cc-language-chooser.ui | 20 +-
panels/common/cc-list-row.c | 3 +
panels/common/cc-list-row.ui | 5 +-
panels/common/cc-permission-infobar.c | 8 +-
panels/common/cc-permission-infobar.h | 4 +-
panels/common/cc-permission-infobar.ui | 94 ++++-----
panels/common/cc-time-editor.c | 29 +--
panels/common/cc-time-editor.h | 4 +-
panels/common/cc-time-editor.ui | 147 ++++++--------
panels/common/cc-time-entry.c | 347 ++++++++++++++++++---------------
panels/common/cc-time-entry.h | 3 +-
panels/common/gnome-settings-bus.h | 2 +-
panels/common/gsd-device-manager.c | 14 +-
panels/common/gsd-input-helper.c | 2 +-
panels/common/list-box-helper.c | 108 ----------
panels/common/list-box-helper.h | 33 ----
panels/common/meson.build | 1 -
20 files changed, 369 insertions(+), 499 deletions(-)
---
diff --git a/meson.build b/meson.build
index 6c95516cb..e9b33f718 100644
--- a/meson.build
+++ b/meson.build
@@ -113,7 +113,7 @@ colord_dep = dependency('colord', version: '>= 0.1.34')
gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.23.0')
gio_dep = dependency('gio-2.0')
glib_dep = dependency('glib-2.0', version: '>= 2.68.0')
-gnome_desktop_dep = dependency('gnome-desktop-3.0', version: '>= 3.33.4')
+gnome_desktop_dep = dependency('gnome-desktop-4')
gnome_settings_dep = dependency('gnome-settings-daemon', version: '>= 3.27.90')
goa_dep = dependency('goa-1.0', version: goa_req_version)
gsettings_desktop_dep = dependency('gsettings-desktop-schemas', version: '>= 40.alpha')
diff --git a/panels/common/cc-hostname-entry.c b/panels/common/cc-hostname-entry.c
index aff139c31..8a79b0323 100644
--- a/panels/common/cc-hostname-entry.c
+++ b/panels/common/cc-hostname-entry.c
@@ -19,6 +19,7 @@
*/
+#include "cc-common-resources.h"
#include "cc-hostname-entry.h"
#include "hostname-helper.h"
@@ -46,7 +47,7 @@ cc_hostname_entry_set_hostname (CcHostnameEntry *self)
g_autoptr(GError) static_error = NULL;
const gchar *text;
- text = gtk_entry_get_text (GTK_ENTRY (self));
+ text = gtk_editable_get_text (GTK_EDITABLE (self));
g_debug ("Setting PrettyHostname to '%s'", text);
pretty_result = g_dbus_proxy_call_sync (self->hostnamed_proxy,
@@ -229,9 +230,9 @@ cc_hostname_entry_constructed (GObject *object)
str = cc_hostname_entry_get_display_hostname (CC_HOSTNAME_ENTRY (self));
if (str != NULL)
- gtk_entry_set_text (GTK_ENTRY (self), str);
+ gtk_editable_set_text (GTK_EDITABLE (self), str);
else
- gtk_entry_set_text (GTK_ENTRY (self), "");
+ gtk_editable_set_text (GTK_EDITABLE (self), "");
g_signal_connect (self, "changed", G_CALLBACK (text_changed_cb), NULL);
}
@@ -248,6 +249,7 @@ cc_hostname_entry_class_init (CcHostnameEntryClass *klass)
static void
cc_hostname_entry_init (CcHostnameEntry *self)
{
+ g_resources_register (cc_common_get_resource ());
}
CcHostnameEntry *
diff --git a/panels/common/cc-language-chooser.c b/panels/common/cc-language-chooser.c
index aa342d506..1aa2ec480 100644
--- a/panels/common/cc-language-chooser.c
+++ b/panels/common/cc-language-chooser.c
@@ -30,7 +30,6 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
-#include "list-box-helper.h"
#include "cc-common-language.h"
#include "cc-util.h"
@@ -165,7 +164,7 @@ language_filter_entry_search_changed_cb (CcLanguageChooser *self)
g_clear_pointer (&self->filter_words, g_strfreev);
filter_contents =
- cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY
(self->language_filter_entry)));
+ cc_util_normalize_casefold_and_unaccent (gtk_editable_get_text (GTK_EDITABLE
(self->language_filter_entry)));
if (!filter_contents) {
gtk_list_box_invalidate_filter (self->language_listbox);
return;
@@ -179,7 +178,7 @@ show_more (CcLanguageChooser *self, gboolean visible)
{
gint width, height;
- gtk_window_get_size (GTK_WINDOW (self), &width, &height);
+ gtk_window_get_default_size (GTK_WINDOW (self), &width, &height);
gtk_widget_set_size_request (GTK_WIDGET (self), width, height);
gtk_search_bar_set_search_mode (self->search_bar, visible);
@@ -194,29 +193,30 @@ static void
set_locale_id (CcLanguageChooser *self,
const gchar *locale_id)
{
- g_autoptr(GList) children = NULL;
- GList *l;
+ GtkWidget *child;
gtk_widget_set_sensitive (GTK_WIDGET (self->select_button), FALSE);
- children = gtk_container_get_children (GTK_CONTAINER (self->language_listbox));
- for (l = children; l; l = l->next) {
- GtkListBoxRow *row = l->data;
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (self->language_listbox));
+ child;
+ child = gtk_widget_get_next_sibling (child)) {
+ CcLanguageRow *row;
- if (!CC_IS_LANGUAGE_ROW (row))
+ if (!CC_IS_LANGUAGE_ROW (child))
continue;
- if (g_strcmp0 (locale_id, cc_language_row_get_locale_id (CC_LANGUAGE_ROW (row))) == 0) {
- cc_language_row_set_checked (CC_LANGUAGE_ROW (row), TRUE);
+ row = CC_LANGUAGE_ROW (child);
+ if (g_strcmp0 (locale_id, cc_language_row_get_locale_id (row)) == 0) {
+ cc_language_row_set_checked (row, TRUE);
gtk_widget_set_sensitive (GTK_WIDGET (self->select_button), TRUE);
/* make sure the selected language is shown */
- if (!self->showing_extra && cc_language_row_get_is_extra (CC_LANGUAGE_ROW (row))) {
- cc_language_row_set_is_extra (CC_LANGUAGE_ROW (row), FALSE);
+ if (!self->showing_extra && cc_language_row_get_is_extra (row)) {
+ cc_language_row_set_is_extra (row, FALSE);
gtk_list_box_invalidate_filter (self->language_listbox);
}
} else {
- cc_language_row_set_checked (CC_LANGUAGE_ROW (row), FALSE);
+ cc_language_row_set_checked (row, FALSE);
}
}
@@ -274,10 +274,6 @@ cc_language_chooser_init (CcLanguageChooser *self)
sort_languages, self, NULL);
gtk_list_box_set_filter_func (self->language_listbox,
language_visible, self, NULL);
- gtk_list_box_set_selection_mode (self->language_listbox,
- GTK_SELECTION_NONE);
- gtk_list_box_set_header_func (self->language_listbox,
- cc_list_box_update_header_func, NULL, NULL);
add_all_languages (self);
gtk_list_box_invalidate_filter (self->language_listbox);
@@ -327,7 +323,7 @@ void
cc_language_chooser_clear_filter (CcLanguageChooser *self)
{
g_return_if_fail (CC_IS_LANGUAGE_CHOOSER (self));
- gtk_entry_set_text (GTK_ENTRY (self->language_filter_entry), "");
+ gtk_editable_set_text (GTK_EDITABLE (self->language_filter_entry), "");
show_more (self, FALSE);
}
diff --git a/panels/common/cc-language-chooser.ui b/panels/common/cc-language-chooser.ui
index 8f6fd53b1..cd8cd07d3 100644
--- a/panels/common/cc-language-chooser.ui
+++ b/panels/common/cc-language-chooser.ui
@@ -11,11 +11,7 @@
<child type="action">
<object class="GtkButton" id="select_button">
<property name="label" translatable="yes">_Select</property>
- <property name="visible">True</property>
<property name="sensitive">False</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
<property name="use_underline">True</property>
<property name="valign">center</property>
</object>
@@ -23,25 +19,19 @@
<child type="action">
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">_Cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
<property name="use_underline">True</property>
<property name="valign">center</property>
</object>
</child>
- <child internal-child="vbox">
+ <child>
<object class="GtkBox">
- <property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">0</property>
- <property name="border-width">0</property>
<child>
<object class="GtkSearchBar" id="search_bar">
- <property name="visible">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkSearchEntry" id="language_filter_entry">
- <property name="visible">True</property>
<property name="width_chars">30</property>
<signal name="search-changed" handler="language_filter_entry_search_changed_cb"
object="CcLanguageChooser" swapped="yes"/>
</object>
@@ -50,22 +40,21 @@
</child>
<child>
<object class="GtkScrolledWindow">
- <property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
<property name="propagate-natural-height">True</property>
<property name="min-content-height">200</property>
<child>
<object class="GtkListBox" id="language_listbox">
- <property name="visible">True</property>
<property name="can-focus">True</property>
<property name="vexpand">True</property>
<property name="halign">fill</property>
<property name="valign">fill</property>
+ <property name="selection-mode">none</property>
+ <property name="show-separators">True</property>
<signal name="row-activated" handler="language_listbox_row_activated_cb"
object="CcLanguageChooser" swapped="yes"/>
<child type="placeholder">
<object class="GtkLabel">
- <property name="visible">True</property>
<property name="label" translatable="yes">No languages found</property>
<property name="sensitive">False</property>
</object>
@@ -74,15 +63,12 @@
<!-- "More" row -->
<child>
<object class="GtkListBoxRow" id="more_row">
- <property name="visible">True</property>
<child>
<object class="GtkBox">
- <property name="visible">True</property>
<property name="spacing">10</property>
<property name="tooltip_markup" translatable="yes">More…</property>
<child>
<object class="GtkImage">
- <property name="visible">True</property>
<property name="hexpand">True</property>
<property name="halign">center</property>
<property name="icon-name">view-more-symbolic</property>
diff --git a/panels/common/cc-list-row.c b/panels/common/cc-list-row.c
index f58c99c5e..d5dfe8d3e 100644
--- a/panels/common/cc-list-row.c
+++ b/panels/common/cc-list-row.c
@@ -29,6 +29,7 @@
# include <config.h>
#endif
+#include "cc-common-resources.h"
#include "cc-list-row.h"
struct _CcListRow
@@ -302,6 +303,8 @@ cc_list_row_class_init (CcListRowClass *klass)
static void
cc_list_row_init (CcListRow *self)
{
+ g_resources_register (cc_common_get_resource ());
+
gtk_widget_init_template (GTK_WIDGET (self));
g_signal_connect_object (self, "notify::parent",
G_CALLBACK (cc_list_row_parent_changed_cb),
diff --git a/panels/common/cc-list-row.ui b/panels/common/cc-list-row.ui
index 730b8d91a..655fd050d 100644
--- a/panels/common/cc-list-row.ui
+++ b/panels/common/cc-list-row.ui
@@ -5,7 +5,10 @@
<child>
<object class="GtkBox" id="box">
<property name="visible">1</property>
- <property name="margin">12</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
<property name="spacing">12</property>
<child>
diff --git a/panels/common/cc-permission-infobar.c b/panels/common/cc-permission-infobar.c
index afe207bb1..78e2b0711 100644
--- a/panels/common/cc-permission-infobar.c
+++ b/panels/common/cc-permission-infobar.c
@@ -33,13 +33,14 @@
struct _CcPermissionInfobar
{
- GtkRevealer parent_instance;
+ AdwBin parent_instance;
+ GtkRevealer *revealer;
GtkLabel *title;
GtkLockButton *lock_button;
};
-G_DEFINE_TYPE (CcPermissionInfobar, cc_permission_infobar, GTK_TYPE_REVEALER)
+G_DEFINE_TYPE (CcPermissionInfobar, cc_permission_infobar, ADW_TYPE_BIN)
static void
on_permission_changed (CcPermissionInfobar *self)
@@ -50,7 +51,7 @@ on_permission_changed (CcPermissionInfobar *self)
permission = gtk_lock_button_get_permission (self->lock_button);
is_authorized = g_permission_get_allowed (permission);
- gtk_revealer_set_reveal_child (GTK_REVEALER (self), !is_authorized);
+ gtk_revealer_set_reveal_child (self->revealer, !is_authorized);
}
static void
@@ -62,6 +63,7 @@ cc_permission_infobar_class_init (CcPermissionInfobarClass *klass)
"/org/gnome/control-center/"
"common/cc-permission-infobar.ui");
+ gtk_widget_class_bind_template_child (widget_class, CcPermissionInfobar, revealer);
gtk_widget_class_bind_template_child (widget_class, CcPermissionInfobar, title);
gtk_widget_class_bind_template_child (widget_class, CcPermissionInfobar, lock_button);
}
diff --git a/panels/common/cc-permission-infobar.h b/panels/common/cc-permission-infobar.h
index 03b8ad988..4d7064d5a 100644
--- a/panels/common/cc-permission-infobar.h
+++ b/panels/common/cc-permission-infobar.h
@@ -21,12 +21,12 @@
*/
#pragma once
-#include <gtk/gtk.h>
+#include <adwaita.h>
G_BEGIN_DECLS
#define CC_TYPE_PERMISSION_INFOBAR (cc_permission_infobar_get_type())
-G_DECLARE_FINAL_TYPE (CcPermissionInfobar, cc_permission_infobar, CC, PERMISSION_INFOBAR, GtkRevealer)
+G_DECLARE_FINAL_TYPE (CcPermissionInfobar, cc_permission_infobar, CC, PERMISSION_INFOBAR, AdwBin)
void cc_permission_infobar_set_permission (CcPermissionInfobar *self,
GPermission *permission);
diff --git a/panels/common/cc-permission-infobar.ui b/panels/common/cc-permission-infobar.ui
index 770765e08..851fcd040 100644
--- a/panels/common/cc-permission-infobar.ui
+++ b/panels/common/cc-permission-infobar.ui
@@ -1,63 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="CcPermissionInfobar" parent="GtkRevealer">
- <property name="reveal-child">True</property>
+ <template class="CcPermissionInfobar" parent="AdwBin">
<property name="valign">start</property>
<child>
- <object class="GtkInfoBar">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <child internal-child="action_area">
- <object class="GtkButtonBox">
- <property name="can-focus">False</property>
- <property name="layout-style">end</property>
- <property name="border-width">10</property>
- <child>
- <object class="GtkLockButton" id="lock_button">
- <property name="visible">True</property>
- <property name="can-focus">True</property>
- <property name="receives-default">True</property>
- <property name="label" translatable="yes">Unlock…</property>
- </object>
- </child>
- </object>
- </child>
- <child internal-child="content_area">
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="border-width">10</property>
- <property name="spacing">10</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">system-lock-screen-symbolic</property>
- </object>
- </child>
+ <object class="GtkRevealer" id="revealer">
+ <property name="hexpand">True</property>
+ <property name="reveal-child">True</property>
+ <child>
+ <object class="GtkInfoBar">
<child>
<object class="GtkBox">
- <property name="visible">True</property>
- <property name="hexpand">True</property>
- <property name="orientation">vertical</property>
+ <property name="margin-top">10</property>
+ <property name="margin-bottom">10</property>
+ <property name="margin-start">10</property>
+ <property name="margin-end">10</property>
+ <property name="spacing">10</property>
<child>
- <object class="GtkLabel" id="title">
- <property name="visible">True</property>
- <property name="halign">start</property>
- <!-- Actual string set in code -->
- <property name="label"></property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
+ <object class="GtkImage">
+ <property name="icon-name">system-lock-screen-symbolic</property>
</object>
</child>
<child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="halign">start</property>
- <property name="label" translatable="yes">Some settings must be unlocked before they can
be changed.</property>
+ <object class="GtkBox">
+ <property name="hexpand">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="title">
+ <property name="halign">start</property>
+ <!-- Actual string set in code -->
+ <property name="label"></property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Some settings must be unlocked before they
can be changed.</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkCenterBox">
+ <property name="margin-top">10</property>
+ <property name="margin-bottom">10</property>
+ <property name="margin-start">10</property>
+ <property name="margin-end">10</property>
+ <child type="end">
+ <object class="GtkLockButton" id="lock_button">
+ <property name="receives-default">True</property>
+ <property name="label" translatable="yes">Unlock…</property>
</object>
</child>
</object>
</child>
+
</object>
</child>
</object>
diff --git a/panels/common/cc-time-editor.c b/panels/common/cc-time-editor.c
index 684a9cd12..a38ca0137 100644
--- a/panels/common/cc-time-editor.c
+++ b/panels/common/cc-time-editor.c
@@ -51,7 +51,7 @@
struct _CcTimeEditor
{
- GtkBin parent_instance;
+ AdwBin parent_instance;
GtkButton *am_pm_button;
GtkStack *am_pm_stack;
@@ -70,7 +70,7 @@ struct _CcTimeEditor
guint timer_id;
};
-G_DEFINE_TYPE (CcTimeEditor, cc_time_editor, GTK_TYPE_BIN)
+G_DEFINE_TYPE (CcTimeEditor, cc_time_editor, ADW_TYPE_BIN)
enum {
@@ -171,18 +171,24 @@ editor_change_time_cb (CcTimeEditor *self)
}
static gboolean
-editor_change_time_pressed_cb (CcTimeEditor *self,
- GdkEvent *event,
- GtkButton *button)
+editor_change_time_pressed_cb (CcTimeEditor *self,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ GtkGestureClick *click_gesture)
{
+ GtkWidget *button;
+
g_assert (CC_IS_TIME_EDITOR (self));
- self->clicked_button = button;
+ button = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (click_gesture));
+
+ self->clicked_button = GTK_BUTTON (button);
/* Keep changing time until the press is released */
self->timer_id = g_timeout_add (TIMEOUT_INITIAL,
(GSourceFunc)editor_change_time_cb,
self);
- editor_change_time_clicked_cb (self, button);
+ editor_change_time_clicked_cb (self, GTK_BUTTON (button));
return FALSE;
}
@@ -212,19 +218,16 @@ editor_am_pm_button_clicked_cb (CcTimeEditor *self)
static void
editor_am_pm_stack_changed_cb (CcTimeEditor *self)
{
- AtkObject *accessible;
GtkWidget *label;
const gchar *text;
g_assert (CC_IS_TIME_EDITOR (self));
- accessible = gtk_widget_get_accessible (GTK_WIDGET (self->am_pm_button));
- if (accessible == NULL)
- return;
-
label = gtk_stack_get_visible_child (self->am_pm_stack);
text = gtk_label_get_text (GTK_LABEL (label));
- atk_object_set_name (accessible, text);
+ gtk_accessible_update_property (GTK_ACCESSIBLE (self->am_pm_button),
+ GTK_ACCESSIBLE_PROPERTY_LABEL, text,
+ -1);
}
static void
diff --git a/panels/common/cc-time-editor.h b/panels/common/cc-time-editor.h
index 48c4534e2..f33b10a2d 100644
--- a/panels/common/cc-time-editor.h
+++ b/panels/common/cc-time-editor.h
@@ -24,13 +24,13 @@
#pragma once
-#include <gtk/gtk.h>
+#include <adwaita.h>
G_BEGIN_DECLS
#define CC_TYPE_TIME_EDITOR (cc_time_editor_get_type ())
-G_DECLARE_FINAL_TYPE (CcTimeEditor, cc_time_editor, CC, TIME_EDITOR, GtkBin)
+G_DECLARE_FINAL_TYPE (CcTimeEditor, cc_time_editor, CC, TIME_EDITOR, AdwBin)
CcTimeEditor *cc_time_editor_new (void);
void cc_time_editor_set_time (CcTimeEditor *self,
diff --git a/panels/common/cc-time-editor.ui b/panels/common/cc-time-editor.ui
index 1732fcd6f..155d83075 100644
--- a/panels/common/cc-time-editor.ui
+++ b/panels/common/cc-time-editor.ui
@@ -1,170 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="CcTimeEditor" parent="GtkBin">
- <property name="visible">True</property>
+ <template class="CcTimeEditor" parent="AdwBin">
<child>
<object class="GtkGrid">
- <property name="visible">True</property>
<property name="row-spacing">6</property>
<property name="column-spacing">6</property>
<!-- Increment Hour Button -->
<child>
<object class="GtkButton" id="hour_up_button">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
<property name="valign">center</property>
<property name="halign">center</property>
- <signal name="button-press-event" handler="editor_change_time_pressed_cb" swapped="yes"/>
- <signal name="button-release-event" handler="editor_change_time_released_cb" swapped="yes"/>
+ <property name="icon-name">go-up-symbolic</property>
+ <layout>
+ <property name="column">0</property>
+ <property name="row">0</property>
+ </layout>
<style>
<class name="titlebutton"/>
<class name="circular"/>
<class name="flat"/>
</style>
+ <accessibility>
+ <property name="label" translatable="yes">Increment Hour</property>
+ </accessibility>
<child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">go-up-symbolic</property>
- </object>
- </child>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="AtkObject::accessible-name" translatable="yes">Increment Hour</property>
+ <object class="GtkGestureClick">
+ <property name="propagation-phase">capture</property>
+ <signal name="pressed" handler="editor_change_time_pressed_cb" swapped="yes"/>
+ <signal name="released" handler="editor_change_time_released_cb" swapped="yes"/>
</object>
</child>
</object>
- <packing>
- <property name="left-attach">0</property>
- <property name="top-attach">0</property>
- </packing>
</child>
<!-- Increment Minute Button -->
<child>
<object class="GtkButton" id="minute_up_button">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
<property name="valign">center</property>
<property name="halign">center</property>
- <signal name="button-press-event" handler="editor_change_time_pressed_cb" swapped="yes"/>
- <signal name="button-release-event" handler="editor_change_time_released_cb" swapped="yes"/>
+ <property name="icon-name">go-up-symbolic</property>
+ <layout>
+ <property name="column">1</property>
+ <property name="row">0</property>
+ </layout>
<style>
<class name="titlebutton"/>
<class name="circular"/>
<class name="flat"/>
</style>
+ <accessibility>
+ <property name="label" translatable="yes">Increment Minute</property>
+ </accessibility>
<child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">go-up-symbolic</property>
- </object>
- </child>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="AtkObject::accessible-name" translatable="yes">Increment Minute</property>
+ <object class="GtkGestureClick">
+ <property name="propagation-phase">capture</property>
+ <signal name="pressed" handler="editor_change_time_pressed_cb" swapped="yes"/>
+ <signal name="released" handler="editor_change_time_released_cb" swapped="yes"/>
</object>
</child>
</object>
- <packing>
- <property name="left-attach">1</property>
- <property name="top-attach">0</property>
- </packing>
</child>
<child>
<object class="CcTimeEntry" id="time_entry">
- <property name="visible">True</property>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="AtkObject::accessible-description" translatable="yes">Time</property>
- </object>
- </child>
+ <layout>
+ <property name="column">0</property>
+ <property name="row">1</property>
+ <property name="column-span">2</property>
+ </layout>
+ <accessibility>
+ <property name="label" translatable="yes">Time</property>
+ </accessibility>
</object>
- <packing>
- <property name="left-attach">0</property>
- <property name="top-attach">1</property>
- <property name="width">2</property>
- </packing>
</child>
<!-- Decrement Hour Button -->
<child>
<object class="GtkButton" id="hour_down_button">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
<property name="valign">center</property>
<property name="halign">center</property>
- <signal name="button-press-event" handler="editor_change_time_pressed_cb" swapped="yes"/>
- <signal name="button-release-event" handler="editor_change_time_released_cb" swapped="yes"/>
+ <property name="icon-name">go-down-symbolic</property>
+ <layout>
+ <property name="column">0</property>
+ <property name="row">2</property>
+ </layout>
<style>
<class name="titlebutton"/>
<class name="circular"/>
<class name="flat"/>
</style>
+ <accessibility>
+ <property name="label" translatable="yes">Decrement Hour</property>
+ </accessibility>
<child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">go-down-symbolic</property>
- </object>
- </child>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="AtkObject::accessible-name" translatable="yes">Decrement Hour</property>
+ <object class="GtkGestureClick">
+ <property name="propagation-phase">capture</property>
+ <signal name="pressed" handler="editor_change_time_pressed_cb" swapped="yes"/>
+ <signal name="released" handler="editor_change_time_released_cb" swapped="yes"/>
</object>
</child>
</object>
- <packing>
- <property name="left-attach">0</property>
- <property name="top-attach">2</property>
- </packing>
</child>
<!-- Decrement Minute Button -->
<child>
<object class="GtkButton" id="minute_down_button">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
<property name="valign">center</property>
<property name="halign">center</property>
- <signal name="button-press-event" handler="editor_change_time_pressed_cb" swapped="yes"/>
- <signal name="button-release-event" handler="editor_change_time_released_cb" swapped="yes"/>
+ <property name="icon-name">go-down-symbolic</property>
+ <layout>
+ <property name="column">1</property>
+ <property name="row">2</property>
+ </layout>
<style>
<class name="titlebutton"/>
<class name="circular"/>
<class name="flat"/>
</style>
+ <accessibility>
+ <property name="label" translatable="yes">Decrement Minute</property>
+ </accessibility>
<child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">go-down-symbolic</property>
- </object>
- </child>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="AtkObject::accessible-name" translatable="yes">Decrement Minute</property>
+ <object class="GtkGestureClick">
+ <property name="propagation-phase">capture</property>
+ <signal name="pressed" handler="editor_change_time_pressed_cb" swapped="yes"/>
+ <signal name="released" handler="editor_change_time_released_cb" swapped="yes"/>
</object>
</child>
</object>
- <packing>
- <property name="left-attach">1</property>
- <property name="top-attach">2</property>
- </packing>
</child>
<!-- AM/PM Button -->
<child>
<object class="GtkButton" id="am_pm_button">
- <property name="visible">True</property>
<property name="valign">center</property>
<signal name="clicked" handler="editor_am_pm_button_clicked_cb" swapped="yes"/>
+ <layout>
+ <property name="column">2</property>
+ <property name="row">1</property>
+ </layout>
<child>
<object class="GtkStack" id="am_pm_stack">
- <property name="visible">True</property>
<signal name="notify::visible-child" handler="editor_am_pm_stack_changed_cb" swapped="yes"/>
<child>
<object class="GtkLabel" id="am_label">
- <property name="visible">True</property>
<attributes>
<attribute name="scale" value="1.4"/>
</attributes>
@@ -172,7 +152,6 @@
</child>
<child>
<object class="GtkLabel" id="pm_label">
- <property name="visible">True</property>
<attributes>
<attribute name="scale" value="1.4"/>
</attributes>
@@ -181,10 +160,6 @@
</object>
</child>
</object>
- <packing>
- <property name="left-attach">2</property>
- <property name="top-attach">1</property>
- </packing>
</child>
</object>
diff --git a/panels/common/cc-time-entry.c b/panels/common/cc-time-entry.c
index 8cd21303a..220385648 100644
--- a/panels/common/cc-time-entry.c
+++ b/panels/common/cc-time-entry.c
@@ -41,7 +41,9 @@
struct _CcTimeEntry
{
- GtkEntry parent_instance;
+ GtkWidget parent_instance;
+
+ GtkWidget *text;
guint insert_text_id;
guint time_changed_id;
@@ -51,7 +53,17 @@ struct _CcTimeEntry
gboolean is_am; /* AM if TRUE. PM if FALSE. valid iff is_am_pm set */
};
-G_DEFINE_TYPE (CcTimeEntry, cc_time_entry, GTK_TYPE_ENTRY)
+
+static void editable_insert_text_cb (GtkText *text,
+ char *new_text,
+ gint new_text_length,
+ gint *position,
+ CcTimeEntry *self);
+
+static void gtk_editable_interface_init (GtkEditableInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (CcTimeEntry, cc_time_entry, GTK_TYPE_WIDGET,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gtk_editable_interface_init));
enum {
CHANGE_VALUE,
@@ -80,9 +92,9 @@ time_entry_fill_time (CcTimeEntry *self)
str = g_strdup_printf ("%02d∶%02d", self->hour, self->minute);
- g_signal_handler_block (self, self->insert_text_id);
- gtk_entry_set_text (GTK_ENTRY (self), str);
- g_signal_handler_unblock (self, self->insert_text_id);
+ g_signal_handlers_block_by_func (self->text, editable_insert_text_cb, self);
+ gtk_editable_set_text (GTK_EDITABLE (self->text), str);
+ g_signal_handlers_unblock_by_func (self->text, editable_insert_text_cb, self);
}
static void
@@ -94,18 +106,18 @@ cursor_position_changed_cb (CcTimeEntry *self)
current_pos = gtk_editable_get_position (GTK_EDITABLE (self));
- g_signal_handlers_block_by_func (self, cursor_position_changed_cb, self);
+ g_signal_handlers_block_by_func (self->text, cursor_position_changed_cb, self);
/* If cursor is on ‘:’ move to the next field */
if (current_pos == SEPARATOR_INDEX)
- gtk_editable_set_position (GTK_EDITABLE (self), current_pos + 1);
+ gtk_editable_set_position (GTK_EDITABLE (self->text), current_pos + 1);
/* If cursor is after the last digit and without selection, move to last digit */
if (current_pos > END_INDEX &&
- !gtk_editable_get_selection_bounds (GTK_EDITABLE (self), NULL, NULL))
- gtk_editable_set_position (GTK_EDITABLE (self), END_INDEX);
+ !gtk_editable_get_selection_bounds (GTK_EDITABLE (self->text), NULL, NULL))
+ gtk_editable_set_position (GTK_EDITABLE (self->text), END_INDEX);
- g_signal_handlers_unblock_by_func (self, cursor_position_changed_cb, self);
+ g_signal_handlers_unblock_by_func (self->text, cursor_position_changed_cb, self);
}
static void
@@ -115,23 +127,24 @@ entry_selection_changed_cb (CcTimeEntry *self)
g_assert (CC_IS_TIME_ENTRY (self));
- editable = GTK_EDITABLE (self);
+ editable = GTK_EDITABLE (self->text);
- g_signal_handlers_block_by_func (self, cursor_position_changed_cb, self);
+ g_signal_handlers_block_by_func (self->text, cursor_position_changed_cb, self);
/* If cursor is after the last digit and without selection, move to last digit */
if (gtk_editable_get_position (editable) > END_INDEX &&
!gtk_editable_get_selection_bounds (editable, NULL, NULL))
gtk_editable_set_position (editable, END_INDEX);
- g_signal_handlers_unblock_by_func (self, cursor_position_changed_cb, self);
+ g_signal_handlers_unblock_by_func (self->text, cursor_position_changed_cb, self);
}
static void
-editable_insert_text_cb (CcTimeEntry *self,
+editable_insert_text_cb (GtkText *text,
char *new_text,
gint new_text_length,
- gint *position)
+ gint *position,
+ CcTimeEntry *self)
{
g_assert (CC_IS_TIME_ENTRY (self));
@@ -140,9 +153,10 @@ editable_insert_text_cb (CcTimeEntry *self,
if (new_text_length == 5)
{
+ const gchar *text = gtk_editable_get_text (GTK_EDITABLE (self));
guint16 text_length;
- text_length = gtk_entry_get_text_length (GTK_ENTRY (self));
+ text_length = g_utf8_strlen (text, -1);
/* Return if the text matches XX:XX template (where X is a number) */
if (text_length == 0 &&
@@ -176,7 +190,7 @@ editable_insert_text_cb (CcTimeEntry *self,
self->minute = CLAMP (self->minute, 0, 59);
- g_signal_stop_emission_by_name (self, "insert-text");
+ g_signal_stop_emission_by_name (text, "insert-text");
time_entry_fill_time (self);
*position = pos + 1;
@@ -187,56 +201,23 @@ editable_insert_text_cb (CcTimeEntry *self,
}
/* Warn otherwise */
- g_signal_stop_emission_by_name (self, "insert-text");
+ g_signal_stop_emission_by_name (text, "insert-text");
gtk_widget_error_bell (GTK_WIDGET (self));
}
-static void
-entry_select_all (CcTimeEntry *self)
-{
- gtk_editable_select_region (GTK_EDITABLE (self), 0, -1);
-}
-
-static void
-entry_populate_popup_cb (CcTimeEntry *self,
- GtkWidget *widget)
-{
- GList *children;
-
- if (!GTK_IS_CONTAINER (widget))
- return;
-
- children = gtk_container_get_children (GTK_CONTAINER (widget));
-
- if (GTK_IS_MENU (widget))
- {
- GtkWidget *menu_item;
-
- for (GList *child = children; child; child = child->next)
- gtk_container_remove (GTK_CONTAINER (widget), child->data);
-
- menu_item = gtk_menu_item_new_with_mnemonic (_("_Copy"));
- gtk_widget_set_sensitive (menu_item, gtk_editable_get_selection_bounds (GTK_EDITABLE (self), NULL,
NULL));
- g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (gtk_editable_copy_clipboard), self);
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (widget), menu_item);
-
- menu_item = gtk_menu_item_new_with_mnemonic (_("Select _All"));
- gtk_widget_set_sensitive (menu_item, gtk_entry_get_text_length (GTK_ENTRY (self)) > 0);
- g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (entry_select_all), self);
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (widget), menu_item);
- }
-}
-
-static void
-time_entry_change_value_cb (CcTimeEntry *self,
- GtkScrollType type)
+static gboolean
+change_value_cb (GtkWidget *widget,
+ GVariant *arguments,
+ gpointer user_data)
{
+ CcTimeEntry *self = CC_TIME_ENTRY (widget);
+ GtkScrollType type;
int position;
+
g_assert (CC_IS_TIME_ENTRY (self));
+ type = g_variant_get_int32 (arguments);
position = gtk_editable_get_position (GTK_EDITABLE (self));
if (position > SEPARATOR_INDEX)
@@ -280,17 +261,38 @@ time_entry_change_value_cb (CcTimeEntry *self,
g_clear_handle_id (&self->time_changed_id, g_source_remove);
self->time_changed_id = g_timeout_add (EMIT_CHANGED_TIMEOUT,
(GSourceFunc)emit_time_changed, self);
+
+ return GDK_EVENT_STOP;
+}
+
+static void
+on_text_cut_clipboard_cb (GtkText *text,
+ CcTimeEntry *self)
+{
+ gtk_widget_error_bell (GTK_WIDGET (self));
+ g_signal_stop_emission_by_name (text, "cut-clipboard");
}
static void
-cc_entry_move_cursor (GtkEntry *entry,
- GtkMovementStep step,
- gint count,
- gboolean extend_selection)
+on_text_delete_from_cursor_cb (GtkText *text,
+ GtkDeleteType *type,
+ gint count,
+ CcTimeEntry *self)
+{
+ gtk_widget_error_bell (GTK_WIDGET (self));
+ g_signal_stop_emission_by_name (text, "delete-from-cursor");
+}
+
+static void
+on_text_move_cursor_cb (GtkText *text,
+ GtkMovementStep step,
+ gint count,
+ gboolean extend,
+ CcTimeEntry *self)
{
int current_pos;
- current_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
+ current_pos = gtk_editable_get_position (GTK_EDITABLE (self));
/* If cursor is on ‘:’ move backward/forward depending on the current movement */
if ((step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
@@ -298,61 +300,54 @@ cc_entry_move_cursor (GtkEntry *entry,
current_pos + count == SEPARATOR_INDEX)
count > 0 ? count++ : count--;
- GTK_ENTRY_CLASS (cc_time_entry_parent_class)->move_cursor (entry, step, count, extend_selection);
-}
+ g_signal_handlers_block_by_func (text, on_text_move_cursor_cb, self);
+ gtk_editable_set_position (GTK_EDITABLE (text), current_pos + count);
+ g_signal_handlers_unblock_by_func (text, on_text_move_cursor_cb, self);
-static void
-cc_time_entry_error_bell (GtkEntry *entry)
-{
- gtk_widget_error_bell (GTK_WIDGET (entry));
+ g_signal_stop_emission_by_name (text, "move-cursor");
}
static void
-cc_time_entry_delete_from_cursor (GtkEntry *entry,
- GtkDeleteType type,
- gint count)
+on_text_paste_clipboard_cb (GtkText *text,
+ CcTimeEntry *self)
{
- gtk_widget_error_bell (GTK_WIDGET (entry));
+ gtk_widget_error_bell (GTK_WIDGET (self));
+ g_signal_stop_emission_by_name (text, "paste-clipboard");
}
-static gboolean
-cc_time_entry_drag_motion (GtkWidget *widget,
- GdkDragContext *context,
- gint x,
- gint y,
- guint time)
+static void
+on_text_toggle_overwrite_cb (GtkText *text,
+ CcTimeEntry *self)
{
- return TRUE;
+ gtk_widget_error_bell (GTK_WIDGET (self));
+ g_signal_stop_emission_by_name (text, "toggle-overwrite");
}
static gboolean
-cc_time_entry_key_press (GtkWidget *widget,
- GdkEventKey *event)
+on_key_pressed_cb (GtkEventControllerKey *key_controller,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ CcTimeEntry *self)
{
- CcTimeEntry *self = (CcTimeEntry *)widget;
-
/* Allow entering numbers */
- if (!(event->state & GDK_SHIFT_MASK) &&
- ((event->keyval >= GDK_KEY_KP_0 &&
- event->keyval <= GDK_KEY_KP_9) ||
- (event->keyval >= GDK_KEY_0 &&
- event->keyval <= GDK_KEY_9)))
- return GTK_WIDGET_CLASS (cc_time_entry_parent_class)->key_press_event (widget, event);
+ if (!(state & GDK_SHIFT_MASK) &&
+ ((keyval >= GDK_KEY_KP_0 && keyval <= GDK_KEY_KP_9) ||
+ (keyval >= GDK_KEY_0 && keyval <= GDK_KEY_9)))
+ return GDK_EVENT_PROPAGATE;
/* Allow navigation keys */
- if ((event->keyval >= GDK_KEY_Left &&
- event->keyval <= GDK_KEY_Down) ||
- (event->keyval >= GDK_KEY_KP_Left &&
- event->keyval <= GDK_KEY_KP_Down) ||
- event->keyval == GDK_KEY_Home ||
- event->keyval == GDK_KEY_End ||
- event->keyval == GDK_KEY_Menu)
- return GTK_WIDGET_CLASS (cc_time_entry_parent_class)->key_press_event (widget, event);
-
- if (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
- return GTK_WIDGET_CLASS (cc_time_entry_parent_class)->key_press_event (widget, event);
-
- if (event->keyval == GDK_KEY_Tab)
+ if ((keyval >= GDK_KEY_Left && keyval <= GDK_KEY_Down) ||
+ (keyval >= GDK_KEY_KP_Left && keyval <= GDK_KEY_KP_Down) ||
+ keyval == GDK_KEY_Home ||
+ keyval == GDK_KEY_End ||
+ keyval == GDK_KEY_Menu)
+ return GDK_EVENT_PROPAGATE;
+
+ if (state & (GDK_CONTROL_MASK | GDK_ALT_MASK))
+ return GDK_EVENT_PROPAGATE;
+
+ if (keyval == GDK_KEY_Tab)
{
/* If focus is on Hour field skip to minute field */
if (gtk_editable_get_position (GTK_EDITABLE (self)) <= 1)
@@ -362,11 +357,11 @@ cc_time_entry_key_press (GtkWidget *widget,
return GDK_EVENT_STOP;
}
- return GTK_WIDGET_CLASS (cc_time_entry_parent_class)->key_press_event (widget, event);
+ return GDK_EVENT_PROPAGATE;
}
/* Shift-Tab */
- if (event->keyval == GDK_KEY_ISO_Left_Tab)
+ if (keyval == GDK_KEY_ISO_Left_Tab)
{
/* If focus is on Minute field skip back to Hour field */
if (gtk_editable_get_position (GTK_EDITABLE (self)) >= 2)
@@ -376,28 +371,34 @@ cc_time_entry_key_press (GtkWidget *widget,
return GDK_EVENT_STOP;
}
- return GTK_WIDGET_CLASS (cc_time_entry_parent_class)->key_press_event (widget, event);
+ return GDK_EVENT_PROPAGATE;
}
return GDK_EVENT_STOP;
}
+static GtkEditable *
+cc_time_entry_get_delegate (GtkEditable *editable)
+{
+ CcTimeEntry *self = CC_TIME_ENTRY (editable);
+ return GTK_EDITABLE (self->text);
+}
+
+static void
+gtk_editable_interface_init (GtkEditableInterface *iface)
+{
+ iface->get_delegate = cc_time_entry_get_delegate;
+}
+
static void
cc_time_entry_constructed (GObject *object)
{
+ CcTimeEntry *self = CC_TIME_ENTRY (object);
PangoAttrList *list;
PangoAttribute *attribute;
G_OBJECT_CLASS (cc_time_entry_parent_class)->constructed (object);
- g_object_set (object,
- "input-purpose", GTK_INPUT_PURPOSE_DIGITS,
- "input-hints", GTK_INPUT_HINT_NO_EMOJI,
- "overwrite-mode", TRUE,
- "xalign", 0.5,
- "max-length", 5,
- NULL);
-
time_entry_fill_time (CC_TIME_ENTRY (object));
list = pango_attr_list_new ();
@@ -412,30 +413,56 @@ cc_time_entry_constructed (GObject *object)
attribute = pango_attr_font_features_new ("tnum");
pango_attr_list_insert (list, attribute);
- gtk_entry_set_attributes (GTK_ENTRY (object), list);
+ gtk_text_set_attributes (GTK_TEXT (self->text), list);
pango_attr_list_unref (list);
}
+static void
+cc_time_entry_dispose (GObject *object)
+{
+ CcTimeEntry *self = CC_TIME_ENTRY (object);
+
+ gtk_editable_finish_delegate (GTK_EDITABLE (self));
+ g_clear_pointer (&self->text, gtk_widget_unparent);
+
+ G_OBJECT_CLASS (cc_time_entry_parent_class)->dispose (object);
+}
+
+static void
+cc_time_entry_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ if (gtk_editable_delegate_get_property (object, property_id, value, pspec))
+ return;
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+cc_time_entry_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ if (gtk_editable_delegate_set_property (object, property_id, value, pspec))
+ return;
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
static void
cc_time_entry_class_init (CcTimeEntryClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GtkEntryClass *entry_class = GTK_ENTRY_CLASS (klass);
- GtkBindingSet *binding_set;
object_class->constructed = cc_time_entry_constructed;
-
- widget_class->drag_motion = cc_time_entry_drag_motion;
- widget_class->key_press_event = cc_time_entry_key_press;
-
- entry_class->delete_from_cursor = cc_time_entry_delete_from_cursor;
- entry_class->move_cursor = cc_entry_move_cursor;
- entry_class->toggle_overwrite = cc_time_entry_error_bell;
- entry_class->backspace = cc_time_entry_error_bell;
- entry_class->cut_clipboard = cc_time_entry_error_bell;
- entry_class->paste_clipboard = cc_time_entry_error_bell;
+ object_class->dispose = cc_time_entry_dispose;
+ object_class->get_property = cc_time_entry_get_property;
+ object_class->set_property = cc_time_entry_set_property;
signals[CHANGE_VALUE] =
g_signal_new ("change-value",
@@ -454,36 +481,50 @@ cc_time_entry_class_init (CcTimeEntryClass *klass)
NULL,
G_TYPE_NONE, 0);
- binding_set = gtk_binding_set_by_class (klass);
-
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
- "change-value", 1,
- GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
- "change-value", 1,
- GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_UP);
-
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
- "change-value", 1,
- GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
- "change-value", 1,
- GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_DOWN);
+ gtk_editable_install_properties (object_class, 1);
+
+ gtk_widget_class_set_css_name (widget_class, "entry");
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+
+ gtk_widget_class_add_binding (widget_class, GDK_KEY_Up, 0,
+ change_value_cb, "i", GTK_SCROLL_STEP_UP);
+ gtk_widget_class_add_binding (widget_class, GDK_KEY_KP_Up, 0,
+ change_value_cb, "i", GTK_SCROLL_STEP_UP);
+ gtk_widget_class_add_binding (widget_class, GDK_KEY_Down, 0,
+ change_value_cb, "i", GTK_SCROLL_STEP_DOWN);
+ gtk_widget_class_add_binding (widget_class, GDK_KEY_KP_Down, 0,
+ change_value_cb, "i", GTK_SCROLL_STEP_DOWN);
}
static void
cc_time_entry_init (CcTimeEntry *self)
{
- g_signal_connect_after (self, "notify::cursor-position",
- G_CALLBACK (cursor_position_changed_cb), NULL);
- g_signal_connect_after (self, "notify::selection-bound",
- G_CALLBACK (entry_selection_changed_cb), NULL);
- self->insert_text_id = g_signal_connect (self, "insert-text",
- G_CALLBACK (editable_insert_text_cb), NULL);
- g_signal_connect_after (self, "populate-popup",
- G_CALLBACK (entry_populate_popup_cb), NULL);
- g_signal_connect (self, "change-value",
- G_CALLBACK (time_entry_change_value_cb), NULL);
+ GtkEventController *key_controller;
+
+ key_controller = gtk_event_controller_key_new ();
+ gtk_event_controller_set_propagation_phase (key_controller, GTK_PHASE_CAPTURE);
+ g_signal_connect (key_controller, "key-pressed", G_CALLBACK (on_key_pressed_cb), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), key_controller);
+
+ self->text = g_object_new (GTK_TYPE_TEXT,
+ "input-purpose", GTK_INPUT_PURPOSE_DIGITS,
+ "input-hints", GTK_INPUT_HINT_NO_EMOJI,
+ "overwrite-mode", TRUE,
+ "xalign", 0.5,
+ "max-length", 5,
+ NULL);
+ gtk_widget_set_parent (self->text, GTK_WIDGET (self));
+ gtk_editable_init_delegate (GTK_EDITABLE (self));
+ g_object_connect (self->text,
+ "signal::cut-clipboard", on_text_cut_clipboard_cb, self,
+ "signal::delete-from-cursor", on_text_delete_from_cursor_cb, self,
+ "signal::insert-text", editable_insert_text_cb, self,
+ "signal::move-cursor", on_text_move_cursor_cb, self,
+ "swapped-signal::notify::cursor-position", cursor_position_changed_cb, self,
+ "swapped-signal::notify::selection-bound", entry_selection_changed_cb, self,
+ "signal::paste-clipboard", on_text_paste_clipboard_cb, self,
+ "signal::toggle-overwrite", on_text_toggle_overwrite_cb, self,
+ NULL);
}
GtkWidget *
diff --git a/panels/common/cc-time-entry.h b/panels/common/cc-time-entry.h
index f3ddb8890..f4161434b 100644
--- a/panels/common/cc-time-entry.h
+++ b/panels/common/cc-time-entry.h
@@ -29,8 +29,7 @@
G_BEGIN_DECLS
#define CC_TYPE_TIME_ENTRY (cc_time_entry_get_type ())
-
-G_DECLARE_FINAL_TYPE (CcTimeEntry, cc_time_entry, CC, TIME_ENTRY, GtkEntry)
+G_DECLARE_FINAL_TYPE (CcTimeEntry, cc_time_entry, CC, TIME_ENTRY, GtkWidget)
GtkWidget *cc_time_entry_new (void);
void cc_time_entry_set_time (CcTimeEntry *self,
diff --git a/panels/common/gnome-settings-bus.h b/panels/common/gnome-settings-bus.h
index 763a9cca7..122289f84 100644
--- a/panels/common/gnome-settings-bus.h
+++ b/panels/common/gnome-settings-bus.h
@@ -1,7 +1,7 @@
/* Stub to replace gnome-settings-daemon's
* gnome-settings-bus.h helpers */
-#include <gdk/gdkx.h>
+#include <gdk/x11/gdkx.h>
#ifdef GDK_WINDOWING_WAYLAND
diff --git a/panels/common/gsd-device-manager.c b/panels/common/gsd-device-manager.c
index 9509b3fdd..df24ef7cd 100644
--- a/panels/common/gsd-device-manager.c
+++ b/panels/common/gsd-device-manager.c
@@ -30,10 +30,10 @@
#include "gsd-input-helper.h"
#ifdef GDK_WINDOWING_X11
-#include <gdk/gdkx.h>
+#include <gdk/x11/gdkx.h>
#endif
#ifdef GDK_WINDOWING_WAYLAND
-#include <gdk/gdkwayland.h>
+#include <gdk/wayland/gdkwayland.h>
#endif
typedef struct
@@ -522,18 +522,18 @@ GsdDeviceManager *
gsd_device_manager_get (void)
{
GsdDeviceManager *manager;
- GdkScreen *screen;
+ GdkDisplay *display;
- screen = gdk_screen_get_default ();
- g_return_val_if_fail (screen != NULL, NULL);
+ display = gdk_display_get_default ();
+ g_return_val_if_fail (display != NULL, NULL);
- manager = g_object_get_data (G_OBJECT (screen), "gsd-device-manager-data");
+ manager = g_object_get_data (G_OBJECT (display), "gsd-device-manager-data");
if (!manager) {
manager = g_object_new (GSD_TYPE_DEVICE_MANAGER,
NULL);
- g_object_set_data_full (G_OBJECT (screen), "gsd-device-manager-data",
+ g_object_set_data_full (G_OBJECT (display), "gsd-device-manager-data",
manager, (GDestroyNotify) g_object_unref);
}
diff --git a/panels/common/gsd-input-helper.c b/panels/common/gsd-input-helper.c
index 6ffc18b68..025070e4b 100644
--- a/panels/common/gsd-input-helper.c
+++ b/panels/common/gsd-input-helper.c
@@ -22,7 +22,7 @@
#include <string.h>
#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
+#include <gdk/x11/gdkx.h>
#include <sys/types.h>
#include <X11/Xatom.h>
diff --git a/panels/common/meson.build b/panels/common/meson.build
index 7be1f8207..5e2a862e4 100644
--- a/panels/common/meson.build
+++ b/panels/common/meson.build
@@ -28,7 +28,6 @@ sources = files(
'cc-hostname-entry.c',
'cc-time-entry.c',
'hostname-helper.c',
- 'list-box-helper.c',
)
libwidgets = static_library(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]