[gnome-music: 9/11] toolbar: Hide close button if not maximized and header bar is not title bar



commit d17df910dc0486460d129942f6457a236d010d1c
Author: Arnel A. Borja <arnelborja src gnome org>
Date:   Sat Aug 3 20:30:44 2013 +0800

    toolbar: Hide close button if not maximized and header bar is not title bar
    
    If GTK+ version is older than 3.9 which allows custom title bars, show the
    close button of the header bar if we are maximized and selection mode is not
    enabled.

 gnomemusic/toolbar.py |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/toolbar.py b/gnomemusic/toolbar.py
index 8ea49d6..ac21664 100644
--- a/gnomemusic/toolbar.py
+++ b/gnomemusic/toolbar.py
@@ -1,4 +1,4 @@
-from gi.repository import Gtk, GObject
+from gi.repository import Gtk, Gdk, GObject
 
 if Gtk.get_minor_version() > 8:
     from gi.repository.Gtk import StackSwitcher
@@ -20,6 +20,7 @@ class Toolbar(GObject.GObject):
         'state-changed': (GObject.SIGNAL_RUN_FIRST, None, ())
     }
     _selectionMode = False
+    _maximized = False
 
     def __init__(self):
         GObject.GObject.__init__(self)
@@ -38,6 +39,8 @@ class Toolbar(GObject.GObject):
         self._search_button = self._ui.get_object("search-button")
         self._back_button.connect('clicked', self.on_back_button_clicked)
         self._close_button.connect('clicked', self._close_button_clicked)
+        if Gtk.get_minor_version() <= 8:
+            self._close_button.connect('hierarchy-changed', self._on_hierarchy_changed)
 
     def _close_button_clicked(self, btn):
         if Gtk.get_minor_version() > 8:
@@ -48,6 +51,18 @@ class Toolbar(GObject.GObject):
     def reset_header_title(self):
         self.header_bar.set_custom_title(self._stack_switcher)
 
+    def _on_hierarchy_changed(self, widget, previous_toplevel):
+        if previous_toplevel:
+            previous_toplevel.disconnect(self._window_state_handler)
+        self._close_button.get_toplevel().add_events(Gdk.EventMask.STRUCTURE_MASK)
+        self._window_state_handler = \
+            self._close_button.get_toplevel().connect('window-state-event', self._on_window_state_event)
+
+    def _on_window_state_event(self, widget, event):
+        if event.changed_mask & Gdk.WindowState.MAXIMIZED:
+            self._maximized = bool(event.new_window_state & Gdk.WindowState.MAXIMIZED)
+            self._update()
+
     def set_stack(self, stack):
         self._stack_switcher.set_stack(stack)
 
@@ -87,5 +102,10 @@ class Toolbar(GObject.GObject):
             self.reset_header_title()
 
         self._back_button.set_visible(not self._selectionMode and self._state == ToolbarState.SINGLE)
-        self._close_separator.set_visible(not self._selectionMode)
-        self._close_button.set_visible(not self._selectionMode)
+
+        if Gtk.get_minor_version() > 8:
+            self._close_separator.set_visible(not self._selectionMode)
+            self._close_button.set_visible(not self._selectionMode)
+        else:
+            self._close_separator.set_visible(not self._selectionMode and self._maximized)
+            self._close_button.set_visible(not self._selectionMode and self._maximized)


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