[kupfer: 32/51] ui: Use uievents to open and close displays
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 32/51] ui: Use uievents to open and close displays
- Date: Mon, 28 Mar 2011 15:03:45 +0000 (UTC)
commit 599d049e0e1c989b1f5b190a1ebff33f25a3679a
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Mon Mar 28 16:51:46 2011 +0200
ui: Use uievents to open and close displays
kupfer/ui/browser.py | 57 +++---------------------------------------------
kupfer/ui/uievents.py | 36 ++++++++++++++++++++++++++++++-
2 files changed, 39 insertions(+), 54 deletions(-)
---
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index 4e62930..cba429d 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -1745,10 +1745,6 @@ class WindowController (pretty.OutputMixin):
"""
self.window = KupferWindow(gtk.WINDOW_TOPLEVEL)
self.window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
- # this should not really be necessary but we reference all open
- # GdkDisplay and GdkScreen
- self.screens = set()
- self.displays = set()
self.current_screen_handler = 0
data_controller = data.DataController()
@@ -1985,35 +1981,6 @@ class WindowController (pretty.OutputMixin):
self.current_screen_handler = \
screen.connect("monitors-changed", self._monitors_changed)
- def _try_close_unused_displays(self, screen):
- """@screen is current GdkScreen
-
- Try to close inactive displays...
- Take all GtkWindow that are hidden, and move to the
- current screen. If no windows remain then we close
- the display, but we never close the default display.
- """
- display = screen.get_display()
- dm = gtk.gdk.display_manager_get()
- for disp in list(dm.list_displays()):
- if disp != display and disp != gtk.gdk.display_get_default():
- self.output_debug("Trying to close", disp.get_name())
- open_windows = 0
- for window in gtk.window_list_toplevels():
- # find windows on @disp
- if window.get_screen().get_display() != disp:
- continue
- if not window.get_property("visible"):
- self.output_debug("Moving window", window.get_name())
- self.output_debug("Moving", window.get_title())
- window.set_screen(screen)
- else:
- self.output_debug("Open window blocks close")
- open_windows += 1
- if not open_windows:
- self.output_debug("Closing display", disp.get_name())
- disp.close()
-
def _center_window(self, displayname=None):
"""Center Window on the monitor the pointer is currently on"""
def norm_name(name):
@@ -2021,35 +1988,19 @@ class WindowController (pretty.OutputMixin):
if name[-2] == ":":
return name + ".0"
return name
- if displayname:
- dm = gtk.gdk.display_manager_get()
- displayname = norm_name(displayname)
- for disp in dm.list_displays():
- if norm_name(disp.get_name()) == displayname:
- pretty.print_debug(__name__, "Using display", disp.get_name())
- display = disp
- break
- else:
- # we did not reach break in for
- pretty.print_debug(__name__, "Opening display", displayname)
- display = gtk.gdk.Display(displayname)
- self.displays.add(display)
- #dm.set_default_display(display)
+ if not displayname and self.window.has_screen():
+ display = self.window.get_screen().get_display()
else:
- if self.window.has_screen():
- display = self.window.get_screen().get_display()
- else:
- display = gtk.gdk.display_get_default()
+ display = uievents.GUIEnvironmentContext.ensure_display_open(displayname)
screen, x, y, modifiers = display.get_pointer()
self._window_put_on_screen(screen)
- self.screens.add(screen)
monitor_nr = screen.get_monitor_at_point(x, y)
geo = screen.get_monitor_geometry(monitor_nr)
wid, hei = self.window.get_size()
midx = geo.x + geo.width / 2 - wid / 2
midy = geo.y + geo.height / 2 - hei / 2
self.window.move(midx, midy)
- self._try_close_unused_displays(screen)
+ uievents.GUIEnvironmentContext._try_close_unused_displays(screen)
def _should_recenter_window(self):
"""Return True if the mouse pointer and the window
diff --git a/kupfer/ui/uievents.py b/kupfer/ui/uievents.py
index eee72ba..e1ed105 100644
--- a/kupfer/ui/uievents.py
+++ b/kupfer/ui/uievents.py
@@ -48,7 +48,8 @@ class GUIEnvironmentContext (object):
new_display = disp
break
if new_display is None:
- print "Opening display in ensure_display_open", display
+ pretty.print_debug(__name__,
+ "Opening display in ensure_display_open", display)
new_display = gtk.gdk.Display(display)
else:
new_display = gtk.gdk.display_get_default()
@@ -56,6 +57,39 @@ class GUIEnvironmentContext (object):
cls._open_displays = set(dm.list_displays())
return new_display
+ @classmethod
+ def _try_close_unused_displays(cls, screen):
+ """@screen is current GdkScreen
+
+ Try to close inactive displays...
+ Take all GtkWindow that are hidden, and move to the
+ current screen. If no windows remain then we close
+ the display, but we never close the default display.
+ """
+ def debug(*x):
+ pretty.print_debug(__name__, *x)
+ display = screen.get_display()
+ dm = gtk.gdk.display_manager_get()
+ for disp in list(dm.list_displays()):
+ if disp != display and disp != gtk.gdk.display_get_default():
+ debug("Trying to close", disp.get_name())
+ open_windows = 0
+ for window in gtk.window_list_toplevels():
+ # find windows on @disp
+ if window.get_screen().get_display() != disp:
+ continue
+ if not window.get_property("visible"):
+ debug("Moving window", window.get_name())
+ debug("Moving", window.get_title())
+ window.set_screen(screen)
+ else:
+ debug("Open window blocks close")
+ open_windows += 1
+ if not open_windows:
+ debug("Closing display", disp.get_name())
+ disp.close()
+
+
def get_timestamp(self):
return self._timestamp
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]