[polari] roomList: Stop subclassing MenuButton for headers
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] roomList: Stop subclassing MenuButton for headers
- Date: Fri, 3 Sep 2021 09:45:12 +0000 (UTC)
commit 624a571aae4a7473cd35550762aeaf26940ba5d6
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Oct 9 12:54:57 2020 +0200
roomList: Stop subclassing MenuButton for headers
In GTK4, menu buttons contain either an icon or a label. Prepare
for that by changing the parent class and handling clicks ourselves.
While it seems a bit silly to change the parent to a class that no
longer exists in GTK4, this does help to decrease the diff of the
port.
Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/225>
data/resources/room-list-header.ui | 11 +++----
src/roomList.js | 64 ++++++++++++++++++++++++++++----------
2 files changed, 52 insertions(+), 23 deletions(-)
---
diff --git a/data/resources/room-list-header.ui b/data/resources/room-list-header.ui
index a2650371..06e0ec24 100644
--- a/data/resources/room-list-header.ui
+++ b/data/resources/room-list-header.ui
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="Gjs_RoomListHeader" parent="GtkMenuButton">
+ <template class="Gjs_RoomListHeader" parent="GtkEventBox">
<property name="popover">connectionPopover</property>
<property name="margin-bottom">4</property>
- <property name="focus-on-click">False</property>
- <property name="visible">True</property>
+ <property name="can-focus">True</property>
<style>
- <class name="room-list-header"/>
- <class name="activatable" />
+ <class name="activatable"/>
</style>
<child>
<object class="GtkGrid">
@@ -16,7 +14,8 @@
<property name="margin-top">1</property>
<property name="visible">True</property>
<style>
- <class name="dim-label" />
+ <class name="room-list-header"/>
+ <class name="dim-label"/>
</style>
<child>
<object class="GtkLabel" id="label">
diff --git a/src/roomList.js b/src/roomList.js
index 174ede3d..9c3ee757 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -298,16 +298,39 @@ const RoomListHeader = GObject.registerClass({
'popoverProperties',
'spinner',
],
-}, class RoomListHeader extends Gtk.MenuButton {
+ Properties: {
+ 'popover': GObject.ParamSpec.object(
+ 'popover', 'popover', 'popover',
+ GObject.ParamFlags.READWRITE,
+ Gtk.Popover.$gtype),
+ },
+}, class RoomListHeader extends Gtk.EventBox {
_init(params) {
this._account = params.account;
delete params.account;
- params.name = `RoomListHeader ${this._account.display_name}`;
-
this._app = Gio.Application.get_default();
+ this._popover = null;
- super._init(params);
+ super._init({
+ ...params,
+ name: `RoomListHeader ${this._account.display_name}`,
+ });
+
+ this._clickGesture = new Gtk.GestureMultiPress({
+ propagation_phase: Gtk.PropagationPhase.CAPTURE,
+ button: 0,
+ widget: this,
+ });
+
+ this._clickGesture.connect('released', () => {
+ const button = this._clickGesture.get_current_button();
+ if (button !== Gdk.BUTTON_PRIMARY && button !== Gdk.BUTTON_SECONDARY)
+ return;
+
+ this._clickGesture.set_state(Gtk.EventSequenceState.CLAIMED);
+ this._popover?.popup();
+ });
this.popover.name = `ConnectionPopover ${this._account.display_name}`;
@@ -361,6 +384,26 @@ const RoomListHeader = GObject.registerClass({
});
}
+ get popover() {
+ return this._popover;
+ }
+
+ set popover(popover) {
+ if (this._popover === popover)
+ return;
+
+ if (this._popover)
+ this._popover.relative_to = null;
+ this._popover?.run_dispose();
+
+ this._popover = popover;
+
+ if (this._popover)
+ this._popover.relative_to = this;
+
+ this.notify('popover');
+ }
+
_onDisplayNameChanged() {
this._label.label = this._account.display_name;
@@ -379,19 +422,6 @@ const RoomListHeader = GObject.registerClass({
this.get_accessible().set_name(accessibleName);
}
- /* hack: Handle primary and secondary button interchangeably */
- vfunc_button_press_event(event) {
- if (event.button === Gdk.BUTTON_SECONDARY)
- event.button = Gdk.BUTTON_PRIMARY;
- return super.vfunc_button_press_event(event);
- }
-
- vfunc_button_release_event(event) {
- if (event.button === Gdk.BUTTON_SECONDARY)
- event.button = Gdk.BUTTON_PRIMARY;
- return super.vfunc_button_release_event(event);
- }
-
_getConnectionStatus() {
let presence = this._account.requested_presence_type;
if (presence === Tp.ConnectionPresenceType.OFFLINE)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]