[gnome-games] collection-icon-view: Support right click and long press events
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] collection-icon-view: Support right click and long press events
- Date: Tue, 23 Mar 2021 21:10:25 +0000 (UTC)
commit 4c43820bac7f284f3522c6e71af224f24ef99fa7
Author: Neville <nevilleantony98 gmail com>
Date: Tue Aug 25 19:19:56 2020 +0530
collection-icon-view: Support right click and long press events
src/ui/collection-icon-view.ui | 65 +++++++++++++++++++++-------------------
src/ui/collection-icon-view.vala | 26 ++++++++++++++++
2 files changed, 61 insertions(+), 30 deletions(-)
---
diff --git a/src/ui/collection-icon-view.ui b/src/ui/collection-icon-view.ui
index a4db4917..9be30335 100644
--- a/src/ui/collection-icon-view.ui
+++ b/src/ui/collection-icon-view.ui
@@ -4,47 +4,52 @@
<template class="GamesCollectionIconView" parent="GtkFlowBoxChild">
<property name="visible">True</property>
<child>
- <object class="GtkBox">
+ <object class="GtkEventBox">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
<child>
- <object class="GtkOverlay">
+ <object class="GtkBox">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
<child>
- <object class="GamesCollectionThumbnail" id="thumbnail">
+ <object class="GtkOverlay">
<property name="visible">True</property>
- </object>
- </child>
- <child type="overlay">
- <object class="GtkRevealer">
- <property name="visible">True</property>
- <property name="transition-type">crossfade</property>
- <property name="reveal-child" bind-source="GamesCollectionIconView"
bind-property="is_selection_mode"/>
<child>
- <object class="GtkCheckButton" id="checkbox">
+ <object class="GamesCollectionThumbnail" id="thumbnail">
<property name="visible">True</property>
- <property name="halign">end</property>
- <property name="valign">end</property>
- <property name="active" bind-source="GamesCollectionIconView" bind-property="checked"
bind-flags="bidirectional"/>
- <style>
- <class name="check"/>
- </style>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkRevealer">
+ <property name="visible">True</property>
+ <property name="transition-type">crossfade</property>
+ <property name="reveal-child" bind-source="GamesCollectionIconView"
bind-property="is_selection_mode"/>
+ <child>
+ <object class="GtkCheckButton" id="checkbox">
+ <property name="visible">True</property>
+ <property name="halign">end</property>
+ <property name="valign">end</property>
+ <property name="active" bind-source="GamesCollectionIconView"
bind-property="checked" bind-flags="bidirectional"/>
+ <style>
+ <class name="check"/>
+ </style>
+ </object>
+ </child>
</object>
</child>
</object>
</child>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="title">
- <property name="visible">True</property>
- <property name="ellipsize">middle</property>
- <property name="justify">center</property>
- <property name="lines">2</property>
- <property name="max-width-chars">0</property>
- <property name="wrap">True</property>
- <property name="wrap-mode">word-char</property>
+ <child>
+ <object class="GtkLabel" id="title">
+ <property name="visible">True</property>
+ <property name="ellipsize">middle</property>
+ <property name="justify">center</property>
+ <property name="lines">2</property>
+ <property name="max-width-chars">0</property>
+ <property name="wrap">True</property>
+ <property name="wrap-mode">word-char</property>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/src/ui/collection-icon-view.vala b/src/ui/collection-icon-view.vala
index 1722d8ba..47b4cca9 100644
--- a/src/ui/collection-icon-view.vala
+++ b/src/ui/collection-icon-view.vala
@@ -2,11 +2,16 @@
[GtkTemplate (ui = "/org/gnome/Games/ui/collection-icon-view.ui")]
private class Games.CollectionIconView : Gtk.FlowBoxChild {
+ public signal void secondary_click ();
+
[GtkChild]
private unowned Gtk.Label title;
[GtkChild]
private unowned CollectionThumbnail thumbnail;
+ private Gtk.GestureMultiPress multi_press_gesture;
+ private Gtk.GestureLongPress long_press_gesture;
+
public bool checked { get; set; }
public bool is_selection_mode { get; set; }
@@ -23,6 +28,27 @@ private class Games.CollectionIconView : Gtk.FlowBoxChild {
construct {
get_style_context ().add_class ("collection-icon-view");
+
+ add_events (Gdk.EventMask.TOUCH_MASK);
+
+ multi_press_gesture = new Gtk.GestureMultiPress (this);
+ multi_press_gesture.button = 3;
+ multi_press_gesture.pressed.connect (() => {
+ var event = Gtk.get_current_event ();
+
+ if (event.triggers_context_menu ()) {
+ secondary_click ();
+ multi_press_gesture.set_state (Gtk.EventSequenceState.CLAIMED);
+ } else {
+ multi_press_gesture.set_state (Gtk.EventSequenceState.DENIED);
+ }
+ });
+
+ long_press_gesture = new Gtk.GestureLongPress (this);
+ long_press_gesture.pressed.connect (() => {
+ secondary_click ();
+ long_press_gesture.set_state (Gtk.EventSequenceState.CLAIMED);
+ });
}
public CollectionIconView (Collection collection) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]