1#!/usr/local/bin/python3.8 2# 3# This script should be linked to a keyboard shortcut. Under gnome, 4# you can do this from the main preferences menu, or directly execute 5# "gnome-keybinding-properties" 6# 7# Make the script executable. Install it somewhere in the executable 8# path ("echo $PATH" to check what's in there), and then just enter 9# its name as the action to perform, or copy it anywhere and copy the 10# full path as the action. 11# 12# The script will start recoll if there is currently no instance 13# running, or else toggle between minimized/shown 14 15import gi 16gi.require_version('Wnck', '3.0') 17from gi.repository import Wnck 18from gi.repository import Gtk 19 20import os 21import sys 22from optparse import OptionParser 23 24def deb(s): 25 print("%s"%s, file=sys.stderr) 26 27def main(): 28 parser = OptionParser() 29 parser.add_option("-m", "--move-away", action="store_true", default=False, 30 dest="clear_workspace", 31 help="iconify to other workspace to avoid crowding panel") 32 (options, args) = parser.parse_args() 33 34 screen = Wnck.Screen.get_default() 35 36 while Gtk.events_pending(): 37 Gtk.main_iteration() 38 39 recollMain = "" 40 recollwins = []; 41 for window in screen.get_windows(): 42 #deb("Got window class name: [%s] name [%s]" % 43 # (window.get_class_group().get_name(), window.get_name())) 44 if window.get_class_group().get_name().lower() == "recoll": 45 if window.get_name().lower().startswith("recoll - "): 46 recollMain = window 47 recollwins.append(window) 48 49 if not recollMain: 50 deb("No Recoll window found, starting program") 51 os.system("recoll&") 52 sys.exit(0) 53 54 # Check the main window state, and either activate or minimize all 55 # recoll windows. 56 workspace = screen.get_active_workspace() 57 if not recollMain.is_visible_on_workspace(workspace): 58 for win in recollwins: 59 win.move_to_workspace(workspace) 60 if win != recollMain: 61 win.unminimize(Gtk.get_current_event_time()) 62 recollMain.activate(Gtk.get_current_event_time()) 63 else: 64 otherworkspace = None 65 if options.clear_workspace: 66 # We try to minimize to another workspace 67 wkspcs = screen.get_workspaces() 68 for wkspc in wkspcs: 69 if wkspc.get_number() != workspace.get_number(): 70 otherworkspace = wkspc 71 break 72 for win in recollwins: 73 if otherworkspace: 74 win.move_to_workspace(otherworkspace) 75 win.minimize() 76 77if __name__ == '__main__': 78 main() 79 80