[Sugar-devel] [PATCH sugar-toolkit] Don't cache window size in palettewindow invoker

godiard at sugarlabs.org godiard at sugarlabs.org
Thu Aug 23 10:55:43 EDT 2012


From: Gonzalo Odiard <godiard at gmail.com>

The screen size can change, by example when the screen rotate,
and the stored values are not useful anymore.
Without this patch the device icons palettes in the Journal
or in the frame are not displayed if the screen is rotated
to right or left.

Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
---
 src/sugar/graphics/palettewindow.py | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/sugar/graphics/palettewindow.py b/src/sugar/graphics/palettewindow.py
index 5281e54..a19db62 100644
--- a/src/sugar/graphics/palettewindow.py
+++ b/src/sugar/graphics/palettewindow.py
@@ -453,8 +453,6 @@ class Invoker(gobject.GObject):
 
         self.parent = None
 
-        self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
-                                              gtk.gdk.screen_height())
         self._position_hint = self.ANCHORED
         self._cursor_x = -1
         self._cursor_y = -1
@@ -502,20 +500,17 @@ class Invoker(gobject.GObject):
                                  palette_width, palette_height)
 
     def _in_screen(self, rect):
-        return rect.x >= self._screen_area.x and \
-               rect.y >= self._screen_area.y and \
-               rect.x + rect.width <= self._screen_area.width and \
-               rect.y + rect.height <= self._screen_area.height
+        return rect.x >= 0 and rect.y >= 0 and \
+               rect.x + rect.width <= gtk.gdk.screen_width() and \
+               rect.y + rect.height <= gtk.gdk.screen_height()
 
     def _get_area_in_screen(self, rect):
         """Return area of rectangle visible in the screen"""
 
-        x1 = max(rect.x, self._screen_area.x)
-        y1 = max(rect.y, self._screen_area.y)
-        x2 = min(rect.x + rect.width,
-                self._screen_area.x + self._screen_area.width)
-        y2 = min(rect.y + rect.height,
-                self._screen_area.y + self._screen_area.height)
+        x1 = max(rect.x, 0)
+        y1 = max(rect.y, 0)
+        x2 = min(rect.x + rect.width, gtk.gdk.screen_width())
+        y2 = min(rect.y + rect.height, gtk.gdk.screen_height())
 
         return (x2 - x1) * (y2 - y1)
 
@@ -545,8 +540,8 @@ class Invoker(gobject.GObject):
         rect.x = max(0, rect.x)
         rect.y = max(0, rect.y)
 
-        rect.x = min(rect.x, self._screen_area.width - rect.width)
-        rect.y = min(rect.y, self._screen_area.height - rect.height)
+        rect.x = min(rect.x, gtk.gdk.screen_width() - rect.width)
+        rect.y = min(rect.y, gtk.gdk.screen_height() - rect.height)
 
         return rect
 
@@ -572,7 +567,8 @@ class Invoker(gobject.GObject):
         iv = best_alignment[3]
 
         rect = self.get_rect()
-        screen_area = self._screen_area
+        screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(),
+                                              gtk.gdk.screen_height())
 
         if best_alignment in self.LEFT or best_alignment in self.RIGHT:
             dtop = rect.y - screen_area.y
-- 
1.7.11.2



More information about the Sugar-devel mailing list