[pitivi] Degrade gracefully on small screen resolutions



commit 51e61cfa79a5403390e45c370cf1bd68dfb90187
Author: Jean-François Fortin Tam <nekohayo gmail com>
Date:   Mon Nov 16 16:24:29 2015 -0500

    Degrade gracefully on small screen resolutions
    
    When the main window's width is too big to fit the screen comfortably,
    hide non-essential widgets and avoid doing size requests on the viewer.
    
    This makes us compatible with 1024x768 again.
    
    Fixes https://phabricator.freedesktop.org/T3407

 pitivi/application.py  |    1 +
 pitivi/mainwindow.py   |   23 +++++++++++++++++++++++
 pitivi/medialibrary.py |    4 ++++
 pitivi/viewer.py       |   14 +++++++++++---
 4 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index 036b3d0..ef10a5a 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -194,6 +194,7 @@ class Pitivi(Gtk.Application, Loggable):
             return
         self.gui = PitiviMainWindow(self)
         self.add_window(self.gui)
+        self.gui.checkScreenConstraints()
         # We might as well show it.
         self.gui.show()
 
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 23b89e8..bbf2aed 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -392,6 +392,29 @@ class PitiviMainWindow(Gtk.ApplicationWindow, Loggable):
                 value = self.vpaned.size_request().height / 2
             self.settings.mainWindowVPanePosition = value
 
+    def checkScreenConstraints(self):
+        """
+        Measure the approximate minimum size required by the main window
+        and shrink some widgets to fit smaller screen resolutions.
+        """
+        # This code works, but keep in mind get_preferred_size's output
+        # is only an approximation. As of 2015, GTK still does not have
+        # a way, even with client-side decorations, to tell us the exact
+        # minimum required dimensions of a window.
+        min_size, natural_size = self.get_preferred_size()
+        screen_width = self.get_screen().get_width()
+        screen_height = self.get_screen().get_height()
+        self.debug("Minimum UI size is " +
+                str(min_size.width) + "x" + str(min_size.height))
+        self.debug("Screen size is " +
+                str(screen_width) + "x" + str(screen_height))
+        if min_size.width >= 0.9 * screen_width:
+            self.medialibrary.activateCompactMode()
+            self.viewer.activateCompactMode()
+            min_size, natural_size = self.get_preferred_size()
+            self.info("Minimum UI size has been reduced to " +
+                   str(min_size.width) + "x" + str(min_size.height))
+
     def switchContextTab(self, bClip):
         """
         Switch the tab being displayed on the second set of tabs,
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 41a9a07..8ecb328 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -143,6 +143,7 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
         self._view_error_button = builder.get_object("view_error_button")
         toolbar = builder.get_object("medialibrary_toolbar")
         toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR)
+        self._import_button = builder.get_object("media_import_button")
         self._remove_button = builder.get_object("media_remove_button")
         self._clipprops_button = builder.get_object("media_props_button")
         self._insert_button = builder.get_object("media_insert_button")
@@ -1150,3 +1151,6 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
                     for path in self._draggedPaths]
         return [self.modelFilter[path][COL_ASSET]
                 for path in self.getSelectedPaths()]
+
+    def activateCompactMode(self):
+        self._import_button.set_is_important(False)
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index fefe536..063a06c 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -89,6 +89,7 @@ class ViewerContainer(Gtk.Box, Loggable):
         self.docked = True
         self.seeker = Seeker()
         self.target = None
+        self._compactMode = False
 
         # Only used for restoring the pipeline position after a live clip trim
         # preview:
@@ -144,9 +145,11 @@ class ViewerContainer(Gtk.Box, Loggable):
             self.pack_start(self.target, True, True, 0)
             screen = Gdk.Screen.get_default()
             height = screen.get_height()
-            if height >= 800:
-                # show the controls and force the aspect frame to have at least the same
-                # width (+110, which is a magic number to minimize dead padding).
+            # Force the aspect frame to have at least the same width as
+            # the toolbar +110 (magic number to minimize dead padding).
+            # TODO: review this code to create a smarter algorithm,
+            # and use get_preferred_size() instead of size_request()
+            if not self._compactMode and height >= 800:
                 req = self.buttons.size_request()
                 width = req.width
                 height = req.height
@@ -284,6 +287,11 @@ class ViewerContainer(Gtk.Box, Loggable):
         self.show_all()
         self.external_vbox.show_all()
 
+    def activateCompactMode(self):
+        self.back_button.hide()
+        self.forward_button.hide()
+        self._compactMode = True  # Prevent set_size_request later
+
     def setDisplayAspectRatio(self, ratio):
         self.debug("Setting aspect ratio to %f [%r]", float(ratio), ratio)
         self.target.setDisplayAspectRatio(ratio)


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