[gnome-games] ui: Add the fullscreen header bar to the DisplayBox



commit 8676b9f5eb1015b6124718be149641c279fee374
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat Jul 30 18:04:27 2016 +0200

    ui: Add the fullscreen header bar to the DisplayBox
    
    This will be used in a subsequent commit to support fullscreen.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769329

 data/ui/display-box.ui  |   30 ++++++++++++++++
 src/ui/display-box.vala |   88 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 114 insertions(+), 4 deletions(-)
---
diff --git a/data/ui/display-box.ui b/data/ui/display-box.ui
index 41a0754..6ed51d7 100644
--- a/data/ui/display-box.ui
+++ b/data/ui/display-box.ui
@@ -3,5 +3,35 @@
   <requires lib="gtk+" version="3.16"/>
   <template class="GamesDisplayBox" parent="GtkEventBox">
     <property name="visible">True</property>
+    <property name="can-focus">False</property>
+    <property name="events">GDK_POINTER_MOTION_MASK</property>
+    <signal name="notify::is-fullscreen" handler="on_fullscreen_changed"/>
+    <signal name="motion-notify-event" handler="on_motion_event"/>
+    <child>
+      <object class="GtkOverlay" id="overlay">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child type="overlay">
+          <object class="GtkRevealer" id="fullscreen_header_bar_revealer">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">fill</property>
+            <property name="valign">start</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">False</property>
+            <property name="transition-type">slide-down</property>
+            <property name="events">GDK_POINTER_MOTION_MASK</property>
+            <signal name="motion-notify-event" handler="on_motion_event"/>
+            <child>
+              <object class="GamesDisplayHeaderBar" id="fullscreen_header_bar">
+                <property name="visible">True</property>
+                <property name="show_close_button">False</property>
+                <signal name="back" handler="on_fullscreen_header_bar_back"/>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/src/ui/display-box.vala b/src/ui/display-box.vala
index 83eaaee..3744da1 100644
--- a/src/ui/display-box.vala
+++ b/src/ui/display-box.vala
@@ -2,7 +2,15 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/display-box.ui")]
 private class Games.DisplayBox : Gtk.EventBox {
-       public signal void game_activated (Game game);
+       private const uint INACTIVITY_TIME_MILLISECONDS = 2000;
+
+       public signal void back ();
+
+       public bool is_fullscreen { set; get; }
+
+       public DisplayHeaderBar header_bar {
+               get { return fullscreen_header_bar; }
+       }
 
        private Runner _runner;
        public Runner runner {
@@ -19,15 +27,87 @@ private class Games.DisplayBox : Gtk.EventBox {
                get { return _runner; }
        }
 
+       [GtkChild]
+       private Gtk.Overlay overlay;
+       [GtkChild]
+       private Gtk.Revealer fullscreen_header_bar_revealer;
+       [GtkChild]
+       private DisplayHeaderBar fullscreen_header_bar;
+       private Binding visible_binding;
+
+       private long timeout_id;
+
+       construct {
+               visible_binding = bind_property ("is-fullscreen", fullscreen_header_bar_revealer, "visible",
+                                                BindingFlags.BIDIRECTIONAL);
+               timeout_id = -1;
+       }
+
+       [GtkCallback]
+       private void on_fullscreen_changed () {
+               on_activity ();
+       }
+
+       [GtkCallback]
+       private void on_fullscreen_header_bar_back () {
+               back ();
+       }
+
+       [GtkCallback]
+       private bool on_motion_event (Gdk.EventMotion event) {
+               on_activity ();
+
+               return false;
+       }
+
+       private void on_activity () {
+               if (timeout_id != -1)
+                       Source.remove ((uint) timeout_id);
+
+               if (!is_fullscreen)
+                       return;
+
+               timeout_id = Timeout.add (INACTIVITY_TIME_MILLISECONDS, on_inactivity);
+               fullscreen_header_bar_revealer.reveal_child = true;
+               show_cursor (true);
+       }
+
+       private bool on_inactivity () {
+               timeout_id = -1;
+
+               if (!is_fullscreen)
+                       return false;
+
+               fullscreen_header_bar_revealer.reveal_child = false;
+               show_cursor (false);
+               overlay.grab_focus ();
+
+               return false;
+       }
+
+       private void show_cursor (bool show) {
+               var window = get_window ();
+               if (window == null)
+                       return;
+
+               if ((show && window.cursor == null) ||
+                   (!show && window.cursor != null))
+                       return;
+
+               // FIXME Gdk.Cursor.new() is deprecated but I didn't manage to make
+               // Gdk.Cursor.from_display().
+               window.cursor = show ? null : new Gdk.Cursor (Gdk.CursorType.BLANK_CURSOR);
+       }
+
        private void set_display (Gtk.Widget display) {
                remove_display ();
-               add (display);
+               overlay.add (display);
                display.visible = true;
        }
 
        private void remove_display () {
-               var child = get_child ();
+               var child = overlay.get_child ();
                if (child != null)
-                       remove (get_child ());
+                       overlay.remove (child);
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]