[gnome-games] game-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] game-icon-view: Support right click and long press events
- Date: Tue, 23 Mar 2021 21:10:25 +0000 (UTC)
commit 93e135a1e5860f8539a158d6b0f12fc9ca730f96
Author: Neville <nevilleantony98 gmail com>
Date: Tue Aug 25 18:59:20 2020 +0530
game-icon-view: Support right click and long press events
This will be used in the upcoming commits to allow selection mode when
they are long pressed or right clicked.
src/ui/game-icon-view.ui | 86 +++++++++++++++++++++++++---------------------
src/ui/game-icon-view.vala | 27 +++++++++++++++
2 files changed, 73 insertions(+), 40 deletions(-)
---
diff --git a/src/ui/game-icon-view.ui b/src/ui/game-icon-view.ui
index ed636e58..0f163e22 100644
--- a/src/ui/game-icon-view.ui
+++ b/src/ui/game-icon-view.ui
@@ -4,61 +4,67 @@
<template class="GamesGameIconView" 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="GamesGameThumbnail" 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="GamesGameIconView"
bind-property="is_selection_mode"/>
<child>
- <object class="GtkCheckButton" id="checkbox">
+ <object class="GamesGameThumbnail" id="thumbnail">
<property name="visible">True</property>
- <property name="halign">end</property>
- <property name="valign">end</property>
- <property name="active" bind-source="GamesGameIconView" 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="GamesGameIconView"
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="GamesGameIconView" bind-property="checked"
bind-flags="bidirectional"/>
+ <style>
+ <class name="check"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkImage">
+ <property name="visible" bind-source="GamesGameIconView"
bind-property="is-favorite"/>
+ <property name="icon-name">starred-symbolic</property>
+ <property name="halign">end</property>
+ <property name="valign">start</property>
+ <style>
+ <class name="favorite-star"/>
+ </style>
+ </object>
+ </child>
</object>
</child>
- <child type="overlay">
- <object class="GtkImage">
- <property name="visible" bind-source="GamesGameIconView" bind-property="is-favorite"/>
- <property name="icon-name">starred-symbolic</property>
- <property name="halign">end</property>
- <property name="valign">start</property>
- <style>
- <class name="favorite-star"/>
- </style>
- </object>
+ <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>
- <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>
+
</template>
</interface>
diff --git a/src/ui/game-icon-view.vala b/src/ui/game-icon-view.vala
index 605be5f9..e9d71660 100644
--- a/src/ui/game-icon-view.vala
+++ b/src/ui/game-icon-view.vala
@@ -2,12 +2,16 @@
[GtkTemplate (ui = "/org/gnome/Games/ui/game-icon-view.ui")]
private class Games.GameIconView : Gtk.FlowBoxChild {
+ public signal void secondary_click ();
+
[GtkChild]
private unowned GameThumbnail thumbnail;
[GtkChild]
private unowned Gtk.Label title;
private ulong game_replaced_id;
+ private Gtk.GestureMultiPress multi_press_gesture;
+ private Gtk.GestureLongPress long_press_gesture;
private Game _game;
public Game game {
@@ -33,6 +37,29 @@ private class Games.GameIconView : Gtk.FlowBoxChild {
public bool is_selection_mode { get; set; }
public bool is_favorite { get; set; }
+ construct {
+ add_events (Gdk.EventMask.TOUCH_MASK);
+
+ multi_press_gesture = new Gtk.GestureMultiPress (this);
+ multi_press_gesture.button = 0;
+ 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 GameIconView (Game game) {
Object (game: game);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]