[epiphany/wip/exalm/cleanups-again: 4/5] location-entry: Rework activation
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/cleanups-again: 4/5] location-entry: Rework activation
- Date: Fri, 25 Feb 2022 15:18:56 +0000 (UTC)
commit 4892f434cc0b465830ef183922a5846a4dd5b3a7
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Feb 25 17:58:20 2022 +0500
location-entry: Rework activation
Introduce ephy_link_flags_from_modifiers() - unlike
ephy_link_flags_from_current_event(), it's portable to GTK4.
Instead of connecting to the activate signal of the entry inside
EphyLocationEntry, expose this signal on EphyLocationEntry itself.
Add a modifiers parameter to it, and use ephy_link_flags_from_modifiers()
with it.
While we're still using ephy_gui_get_current_event() inside location entry,
at this point it's encapsulated and can be reimplemented in GTK4 relatively
easily.
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1081>
lib/widgets/ephy-location-entry.c | 26 ++++++++++++++++++++++
src/ephy-link.c | 46 ++++++++++++++++++++++-----------------
src/ephy-link.h | 3 +++
src/ephy-location-controller.c | 11 ++++++----
4 files changed, 62 insertions(+), 24 deletions(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 597e92916..e6b7b1689 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -97,6 +97,7 @@ enum {
};
enum signalsEnum {
+ ACTIVATE,
USER_CHANGED,
READER_MODE_CHANGED,
GET_LOCATION,
@@ -490,6 +491,20 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
g_object_class_override_property (object_class, PROP_ADDRESS, "address");
g_object_class_override_property (object_class, PROP_SECURITY_LEVEL, "security-level");
+ /**
+ * EphyLocationEntry::activate:
+ * @flags: the #GdkModifierType from the activation event
+ *
+ * Emitted when the entry is activated.
+ *
+ */
+ signals[ACTIVATE] = g_signal_new ("activate", G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 1,
+ GDK_TYPE_MODIFIER_TYPE);
+
/**
* EphyLocationEntry::user-changed:
* @entry: the object on which the signal is emitted
@@ -1030,6 +1045,16 @@ reader_mode_clicked_cb (EphyLocationEntry *self)
self->reader_mode_active);
}
+static void
+activate_cb (EphyLocationEntry *self)
+{
+ GdkModifierType modifiers;
+
+ ephy_gui_get_current_event (NULL, &modifiers, NULL, NULL);
+
+ g_signal_emit (G_OBJECT (self), signals[ACTIVATE], 0, modifiers);
+}
+
static void
ephy_location_entry_construct_contents (EphyLocationEntry *entry)
{
@@ -1052,6 +1077,7 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry->url_entry), GTK_ENTRY_ICON_PRIMARY, _("Show website
security status and permissions"));
gtk_entry_set_width_chars (GTK_ENTRY (entry->url_entry), 0);
gtk_entry_set_placeholder_text (GTK_ENTRY (entry->url_entry), _("Search for websites, bookmarks, and open
tabs"));
+ g_signal_connect_swapped (entry->url_entry, "activate", G_CALLBACK (activate_cb), entry);
/* Add special widget css provider */
context = gtk_widget_get_style_context (GTK_WIDGET (entry->url_entry));
diff --git a/src/ephy-link.c b/src/ephy-link.c
index cc7f69386..61dbb3735 100644
--- a/src/ephy-link.c
+++ b/src/ephy-link.c
@@ -95,30 +95,36 @@ ephy_link_open (EphyLink *link,
}
EphyLinkFlags
-ephy_link_flags_from_current_event (void)
+ephy_link_flags_from_modifiers (GdkModifierType modifiers,
+ gboolean middle_click)
{
- GdkEventType type = GDK_NOTHING;
- guint state = 0, button = (guint) - 1, keyval = (guint) - 1;
- EphyLinkFlags flags = 0;
-
- ephy_gui_get_current_event (&type, &state, &button, &keyval);
-
- if (button == GDK_BUTTON_MIDDLE && (type == GDK_BUTTON_PRESS || type == GDK_BUTTON_RELEASE)) {
- if (state == GDK_SHIFT_MASK) {
- flags = EPHY_LINK_NEW_WINDOW;
- } else if (state == 0 || state == GDK_CONTROL_MASK) {
- flags = EPHY_LINK_NEW_TAB | EPHY_LINK_NEW_TAB_APPEND_AFTER;
+ if (middle_click) {
+ if (modifiers == GDK_SHIFT_MASK) {
+ return EPHY_LINK_NEW_WINDOW;
+ } else if (modifiers == 0 || modifiers == GDK_CONTROL_MASK) {
+ return EPHY_LINK_NEW_TAB | EPHY_LINK_NEW_TAB_APPEND_AFTER;
}
} else {
- gboolean navigation_keys = (keyval == GDK_KEY_Left) || (keyval == GDK_KEY_Right);
-
- if (((state == (GDK_MOD1_MASK | GDK_SHIFT_MASK)) && !navigation_keys) ||
- (state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) {
- flags = EPHY_LINK_NEW_WINDOW;
- } else if (((state == GDK_MOD1_MASK) && !navigation_keys) || (state == GDK_CONTROL_MASK)) {
- flags = EPHY_LINK_NEW_TAB | EPHY_LINK_NEW_TAB_APPEND_AFTER | EPHY_LINK_JUMP_TO;
+ if ((modifiers == (GDK_MOD1_MASK | GDK_SHIFT_MASK)) ||
+ (modifiers == (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) {
+ return EPHY_LINK_NEW_WINDOW;
+ } else if ((modifiers == GDK_MOD1_MASK) || (modifiers == GDK_CONTROL_MASK)) {
+ return EPHY_LINK_NEW_TAB | EPHY_LINK_NEW_TAB_APPEND_AFTER | EPHY_LINK_JUMP_TO;
}
}
- return flags;
+ return 0;
+}
+
+EphyLinkFlags
+ephy_link_flags_from_current_event (void)
+{
+ GdkEventType type = GDK_NOTHING;
+ guint state = 0, button = (guint) - 1;
+
+ ephy_gui_get_current_event (&type, &state, &button, NULL);
+
+ return ephy_link_flags_from_modifiers (state, button == GDK_BUTTON_MIDDLE &&
+ (type == GDK_BUTTON_PRESS ||
+ type == GDK_BUTTON_RELEASE));
}
diff --git a/src/ephy-link.h b/src/ephy-link.h
index 762e7ff2a..ab3667538 100644
--- a/src/ephy-link.h
+++ b/src/ephy-link.h
@@ -58,6 +58,9 @@ EphyEmbed *ephy_link_open (EphyLink *link,
EphyEmbed *embed,
EphyLinkFlags flags);
+EphyLinkFlags ephy_link_flags_from_modifiers (GdkModifierType modifiers,
+ gboolean middle_click);
+
EphyLinkFlags ephy_link_flags_from_current_event (void);
G_END_DECLS
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index e9bfc27ff..7d39a16b4 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -79,19 +79,22 @@ G_DEFINE_TYPE_WITH_CODE (EphyLocationController, ephy_location_controller, G_TYP
NULL))
static void
-entry_activate_cb (GtkEntry *entry,
+entry_activate_cb (EphyLocationEntry *entry,
+ GdkModifierType modifiers,
EphyLocationController *controller)
{
const char *content;
char *address;
char *effective_address;
+ GtkEntry *inner_entry;
if (controller->sync_address_is_blocked) {
controller->sync_address_is_blocked = FALSE;
g_signal_handlers_unblock_by_func (controller, G_CALLBACK (sync_address), entry);
}
- content = gtk_entry_get_text (entry);
+ inner_entry = ephy_location_entry_get_entry (entry);
+ content = gtk_entry_get_text (inner_entry);
if (content == NULL || content[0] == '\0')
return;
@@ -151,7 +154,7 @@ entry_activate_cb (GtkEntry *entry,
#endif
ephy_link_open (EPHY_LINK (controller), effective_address, NULL,
- ephy_link_flags_from_current_event () | EPHY_LINK_TYPED);
+ ephy_link_flags_from_modifiers (modifiers, FALSE) | EPHY_LINK_TYPED);
g_free (effective_address);
}
@@ -321,7 +324,7 @@ ephy_location_controller_constructed (GObject *object)
entry, "editable",
G_BINDING_SYNC_CREATE);
- g_signal_connect_object (entry, "activate",
+ g_signal_connect_object (widget, "activate",
G_CALLBACK (entry_activate_cb),
controller, 0);
g_signal_connect_object (widget, "get-location",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]