[gnome-games/wip/exalm/buildable: 6/6] display-box: Use FullscreenBox



commit e4e268a56b8c01636f6cba24b67eea0407257266
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Oct 14 17:57:51 2018 +0500

    display-box: Use FullscreenBox
    
    Make use of FullscreenBox to remove all code for handling fullscreen.

 data/ui/display-box.ui  | 26 ++++-----------
 src/ui/display-box.vala | 85 +++----------------------------------------------
 2 files changed, 11 insertions(+), 100 deletions(-)
---
diff --git a/data/ui/display-box.ui b/data/ui/display-box.ui
index 3ec046ab..8c9af997 100644
--- a/data/ui/display-box.ui
+++ b/data/ui/display-box.ui
@@ -1,30 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.16"/>
-  <template class="GamesDisplayBox" parent="GtkEventBox">
+  <template class="GamesDisplayBox" parent="GtkBin">
     <property name="visible">True</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">
+      <object class="GamesFullscreenBox" id="fullscreen_box">
         <property name="visible">True</property>
-        <child type="overlay">
-          <object class="GtkRevealer" id="fullscreen_header_bar_revealer">
+        <child type="titlebar">
+          <object class="GamesDisplayHeaderBar" id="fullscreen_header_bar">
             <property name="visible">True</property>
-            <property name="valign">start</property>
-            <property name="hexpand">True</property>
-            <property name="transition-type">slide-down</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="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>
+            <property name="show_close_button">False</property>
+            <signal name="back" handler="on_fullscreen_header_bar_back"/>
           </object>
         </child>
         <child>
diff --git a/src/ui/display-box.vala b/src/ui/display-box.vala
index 704f354d..7b5c8f4a 100644
--- a/src/ui/display-box.vala
+++ b/src/ui/display-box.vala
@@ -1,9 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/display-box.ui")]
-private class Games.DisplayBox : Gtk.EventBox {
-       private const uint INACTIVITY_TIME_MILLISECONDS = 2000;
-
+private class Games.DisplayBox : Gtk.Bin {
        public signal void back ();
 
        public bool is_fullscreen { get; set; }
@@ -30,7 +28,7 @@ private class Games.DisplayBox : Gtk.EventBox {
        }
 
        [GtkChild]
-       private Gtk.Overlay overlay;
+       private FullscreenBox fullscreen_box;
        [GtkChild]
        private Gtk.Stack stack;
        [GtkChild]
@@ -38,19 +36,15 @@ private class Games.DisplayBox : Gtk.EventBox {
        [GtkChild]
        private Gtk.EventBox display_bin;
        [GtkChild]
-       private Gtk.Revealer fullscreen_header_bar_revealer;
-       [GtkChild]
        private DisplayHeaderBar fullscreen_header_bar;
-       private Binding visible_binding;
        private Binding fullscreen_binding;
 
        private long timeout_id;
 
        construct {
-               visible_binding = bind_property ("is-fullscreen", fullscreen_header_bar_revealer, "visible",
-                                                BindingFlags.BIDIRECTIONAL);
-               fullscreen_binding = bind_property ("is-fullscreen", fullscreen_header_bar, "is-fullscreen",
-                                                BindingFlags.BIDIRECTIONAL);
+               fullscreen_binding = bind_property ("is-fullscreen", fullscreen_box,
+                                                   "is-fullscreen",
+                                                   BindingFlags.BIDIRECTIONAL);
                timeout_id = -1;
        }
 
@@ -59,80 +53,11 @@ private class Games.DisplayBox : Gtk.EventBox {
                error_display.running_game_failed (game, error_message);
        }
 
-       [GtkCallback]
-       private void on_fullscreen_changed () {
-               if (is_fullscreen)
-                       on_activity ();
-               else
-                       on_restore ();
-       }
-
        [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);
-                       timeout_id = -1;
-               }
-
-               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 on_restore () {
-               if (timeout_id != -1) {
-                       Source.remove ((uint) timeout_id);
-                       timeout_id = -1;
-               }
-
-               fullscreen_header_bar_revealer.reveal_child = false;
-               show_cursor (true);
-       }
-
-       private void show_cursor (bool show) {
-               var window = get_window ();
-               if (window == null)
-                       return;
-
-               if ((show && window.cursor == null) ||
-                   (!show && window.cursor != null))
-                       return;
-
-               if (!show) {
-                       var display = window.get_display ();
-                       window.cursor = new Gdk.Cursor.for_display (display, Gdk.CursorType.BLANK_CURSOR);
-               }
-               else
-                       window.cursor = null;
-       }
-
        private void set_display (Gtk.Widget display) {
                remove_display ();
                display_bin.add (display);


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