[gnome-games] display-header-bar: Don't autohide when popovers are open



commit 896bd3ce541b55925dce02119fcf9d209f52332b
Author: sevagen <sevagenv gmail com>
Date:   Tue Feb 18 22:14:41 2020 +0530

    display-header-bar: Don't autohide when popovers are open
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-games/issues/192

 data/ui/display-box.ui         |  5 +++--
 data/ui/display-header-bar.ui  |  5 ++++-
 data/ui/media-menu-button.ui   |  1 +
 src/ui/display-box.vala        |  7 +++++++
 src/ui/display-header-bar.vala | 18 ++++++++++++++++--
 src/ui/media-menu-button.vala  |  2 ++
 6 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/data/ui/display-box.ui b/data/ui/display-box.ui
index c7d11d8c..bcff5ba0 100644
--- a/data/ui/display-box.ui
+++ b/data/ui/display-box.ui
@@ -3,16 +3,17 @@
   <requires lib="gtk+" version="3.24"/>
   <template class="GamesDisplayBox" parent="GtkBin">
     <property name="visible">True</property>
+    <signal name="notify::is-showing-snapshots" handler="block_autohide_changed"/>
     <child>
-      <object class="GamesFullscreenBox">
+      <object class="GamesFullscreenBox" id="fullscreen_box">
         <property name="visible">True</property>
-        <property name="autohide" bind-source="GamesDisplayBox" bind-property="is-showing-snapshots" 
bind-flags="bidirectional|sync-create|invert-boolean"/>
         <property name="is-fullscreen" bind-source="GamesDisplayBox" bind-property="is-fullscreen" 
bind-flags="bidirectional"/>
         <child type="titlebar">
           <object class="GamesDisplayHeaderBar" id="fullscreen_header_bar">
             <property name="visible">True</property>
             <property name="show-title-buttons">False</property>
             <property name="is-showing-snapshots" bind-source="GamesDisplayBox" 
bind-property="is-showing-snapshots" bind-flags="bidirectional"/>
+            <signal name="notify::is-menu-open" handler="block_autohide_changed"/>
             <signal name="back" handler="on_fullscreen_header_bar_back"/>
             <signal name="size-allocate" handler="on_fullscreen_header_bar_size_allocated"/>
           </object>
diff --git a/data/ui/display-header-bar.ui b/data/ui/display-header-bar.ui
index a8dbba47..003ce9ea 100644
--- a/data/ui/display-header-bar.ui
+++ b/data/ui/display-header-bar.ui
@@ -71,6 +71,7 @@
                 <property name="valign">center</property>
                 <property name="can-focus">False</property>
                 <property name="menu-model">secondary_menu</property>
+                <signal name="notify::active" handler="on_menu_state_changed"/>
                 <style>
                   <class name="image-button"/>
                 </style>
@@ -113,7 +114,9 @@
               </packing>
             </child>
             <child>
-              <object class="GamesMediaMenuButton" id="media_button"/>
+              <object class="GamesMediaMenuButton" id="media_button">
+                <signal name="notify::active" handler="on_menu_state_changed"/>
+              </object>
               <packing>
                 <property name="pack-type">end</property>
               </packing>
diff --git a/data/ui/media-menu-button.ui b/data/ui/media-menu-button.ui
index 323f0897..6fff5a39 100644
--- a/data/ui/media-menu-button.ui
+++ b/data/ui/media-menu-button.ui
@@ -8,6 +8,7 @@
         <property name="can-focus">False</property>
         <property name="valign">center</property>
         <property name="popover">popover</property>
+        <property name="active" bind-source="GamesMediaMenuButton" bind-property="active" 
bind-flags="bidirectional"/>
         <child internal-child="accessible">
           <object class="AtkObject" id="a11y-display-discs">
             <property name="accessible-name" translatable="yes">Media</property>
diff --git a/src/ui/display-box.vala b/src/ui/display-box.vala
index 261faf1f..6e446a6f 100644
--- a/src/ui/display-box.vala
+++ b/src/ui/display-box.vala
@@ -61,6 +61,8 @@ private class Games.DisplayBox : Gtk.Bin {
        [GtkChild]
        private DisplayBin display_bin;
        [GtkChild]
+       private FullscreenBox fullscreen_box;
+       [GtkChild]
        private DisplayHeaderBar fullscreen_header_bar;
        [GtkChild]
        private FlashBox flash_box;
@@ -85,6 +87,11 @@ private class Games.DisplayBox : Gtk.Bin {
                error_display.game_crashed (game, error_message);
        }
 
+       [GtkCallback]
+       public void block_autohide_changed () {
+               fullscreen_box.autohide = !fullscreen_header_bar.is_menu_open && !is_showing_snapshots;
+       }
+
        [GtkCallback]
        private void on_fullscreen_header_bar_back () {
                back ();
diff --git a/src/ui/display-header-bar.vala b/src/ui/display-header-bar.vala
index 4595bf33..6dacf1e5 100644
--- a/src/ui/display-header-bar.vala
+++ b/src/ui/display-header-bar.vala
@@ -4,6 +4,8 @@
 private class Games.DisplayHeaderBar : Gtk.Bin {
        public signal void back ();
 
+       private ulong extra_widget_notify_block_autohide_id;
+
        [GtkChild]
        private MediaMenuButton media_button;
 
@@ -13,6 +15,7 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
        public bool can_fullscreen { get; set; }
        public bool is_fullscreen { get; set; }
        public bool is_showing_snapshots { get; set; }
+       public bool is_menu_open { get; private set; }
 
        public MediaSet? media_set {
                set { media_button.media_set = value; }
@@ -43,13 +46,18 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
                        if (extra_widget == value)
                                return;
 
-                       if (extra_widget != null)
+                       if (extra_widget != null) {
+                               extra_widget.disconnect (extra_widget_notify_block_autohide_id);
                                ingame_header_bar.remove (extra_widget);
+                               extra_widget_notify_block_autohide_id = 0;
+                       }
 
                        _extra_widget = value;
 
-                       if (extra_widget != null)
+                       if (extra_widget != null) {
+                               extra_widget_notify_block_autohide_id = 
extra_widget.notify["block-autohide"].connect (on_menu_state_changed);
                                ingame_header_bar.pack_end (extra_widget);
+                       }
                }
        }
 
@@ -89,6 +97,12 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
                settings.set_boolean ("fullscreen", true);
        }
 
+       [GtkCallback]
+       private void on_menu_state_changed () {
+               is_menu_open = media_button.active || secondary_menu_button.active ||
+                              (extra_widget != null && extra_widget.block_autohide);
+       }
+
        [GtkCallback]
        private void on_restore_clicked () {
                is_fullscreen = false;
diff --git a/src/ui/media-menu-button.vala b/src/ui/media-menu-button.vala
index 3b7f7c64..a1a9ec17 100644
--- a/src/ui/media-menu-button.vala
+++ b/src/ui/media-menu-button.vala
@@ -9,6 +9,8 @@ private class Games.MediaMenuButton : Gtk.Bin {
        [GtkChild]
        private Gtk.ListBox list_box;
 
+       public bool active { get; set; }
+
        private MediaSet _media_set;
        public MediaSet media_set {
                get { return _media_set; }


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