def run_gestures(gestures, process_id, process_status, start_time, timeout, windows): """Run the provided interaction gestures.""" xdotool_path = _xdotool_path() if not xdotool_path: logs.log_error('Xdotool not installed, cannot emulate gestures.') return if not windows: windows += find_windows_for_process(process_id) for window in windows: # Activate the window so that it can receive gestures. shell.execute_command('%s windowactivate --sync %d' % (xdotool_path, window)) for gesture in gestures: # If process had exited or our timeout interval has exceeded, # just bail out. if process_status.finished or time.time() - start_time >= timeout: return gesture_type, gesture_cmd = gesture.split(',') if gesture_type == 'windowsize': shell.execute_command( '%s %s %d %s' % (xdotool_path, gesture_type, window, gesture_cmd)) else: shell.execute_command( '%s %s -- %s' % (xdotool_path, gesture_type, gesture_cmd))
def find_windows_for_process(process_id): """Return visible windows belonging to a process.""" pids = utils.get_process_ids(process_id) if not pids: return [] xdotool_path = _xdotool_path() if not xdotool_path: logs.log_error('Xdotool not installed, cannot locate process windows.') return [] visible_windows = [] for pid in pids: windows = (shell.execute_command( '%s search --all --pid %d --onlyvisible' % (xdotool_path, pid))) for line in windows.splitlines(): if not line.isdigit(): continue visible_windows.append(int(line)) return visible_windows