add option to minimize to other workspace

This commit is contained in:
Jean-Francois Dockes 2010-11-23 11:44:17 +01:00
parent f10e14658f
commit 19f58eb426

View File

@ -13,31 +13,23 @@ import gtk
import wnck import wnck
import os import os
import sys import sys
from optparse import OptionParser
def main(): def main():
# We try to establish a timestamp for the calls to activate(), but parser = OptionParser()
# usually fail (the event_peek() calls return None). parser.add_option("-m", "--move-away", action="store_true", default=False,
# dest="clear_workspace",
# Try to find a nice default value. The x server timestamp is help="iconify to other workspace to avoid crowding panel")
# millisecond from last reset, it wraps around in 49 days, half (options, args) = parser.parse_args()
# the space is set aside for the past So a value just below 2**31
# should be most recent if the server is not too old?
# The right way to do this would probably be to create an unmapped
# window and arrange to receive some real event.
timestamp = 2**31 - 1
screen = wnck.screen_get_default() screen = wnck.screen_get_default()
while gtk.events_pending(): while gtk.events_pending():
event = gtk.gdk.event_peek()
if event != None and event.get_time() != 0:
timestamp = event.get_time()
gtk.main_iteration() gtk.main_iteration()
recollMain = "" recollMain = ""
recollwins = []; recollwins = [];
for window in screen.get_windows(): for window in screen.get_windows():
if window.get_class_group().get_name() == "Recoll": if window.get_class_group().get_name() == "Recoll":
# print "win name: [%s], class: [%s]" % \
# (window.get_name(), window.get_class_group().get_name())
if window.get_name() == "Recoll": if window.get_name() == "Recoll":
recollMain = window recollMain = window
recollwins.append(window) recollwins.append(window)
@ -47,13 +39,26 @@ def main():
sys.exit(0) sys.exit(0)
# Check the main window state, and either activate or minimize all # Check the main window state, and either activate or minimize all
# recoll windows.
workspace = screen.get_active_workspace() workspace = screen.get_active_workspace()
if not recollMain.is_visible_on_workspace(workspace): if not recollMain.is_visible_on_workspace(workspace):
for win in recollwins: for win in recollwins:
win.move_to_workspace(workspace) win.move_to_workspace(workspace)
win.activate(timestamp) if win != recollMain:
win.unminimize(gtk.get_current_event_time())
recollMain.activate(gtk.get_current_event_time())
else: else:
otherworkspace = None
if options.clear_workspace:
# We try to minimize to another workspace
wkspcs = screen.get_workspaces()
for wkspc in wkspcs:
if wkspc.get_number() != workspace.get_number():
otherworkspace = wkspc
break
for win in recollwins: for win in recollwins:
if otherworkspace:
win.move_to_workspace(otherworkspace)
win.minimize() win.minimize()
if __name__ == '__main__': if __name__ == '__main__':