def move_window_to_pane( name, pane=None ): """ If pane is None, use the current pane. """ term_cols = 319 term_rows = 87 if pane is None: pane = get_current_tmux_pane() pane_pos = get_tmux_pane_pos_col_row( *pane ) pane_col_pos = pane_pos['x'] pane_row_pos = pane_pos['y'] pane_cols = pane_pos['width'] pane_rows = pane_pos['height'] terminal_position = get_window_position( get_current_window_id() ) width = terminal_position['width'] height = terminal_position['height'] pos_x = terminal_position['pos_x'] pos_y = terminal_position['pos_y'] delta_x = width / term_cols delta_y = height / term_rows start_x = delta_x * pane_col_pos + pos_x start_y = delta_y * pane_row_pos + pos_y size_x = delta_x * pane_cols size_y = delta_y * pane_rows wid = find_wid_by_name( name ) if wid: xdotool( "windowsize", wid, size_x, size_y, "windowmove", wid, start_x, start_y )
def cmd_emoji(): emoji_json = os.path.expanduser('~/.config/dm/emoji.json') emoji_source = 'https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json' if not os.path.exists(emoji_json): urlretrieve(emoji_source, filename=emoji_json) with open(emoji_json, encoding='utf-8') as f: emoji = json.load(f) o = output(dmenu((i['description'] for i in emoji if 'emoji' in i))) xdotool('type', next((i['emoji'] for i in emoji if i['description'] == o)))
def select_multi(self, app): if not app in self._appmap: return for a in self._appmap[app]: self.select_only(a) sh.xdotool("key", "Escape") return True
def select(self, apps): if isinstance(apps, list): for app in apps: if self.select(app): break success = True try: sh.wmctrl("-x", "-a", apps) except sh.ErrorReturnCode: success = False sh.xdotool("key", "Escape") return success
if 'nodes' in element: for node in element['nodes']: find(node, results) return results tree = json.loads(sh.i3_msg('-t', 'get_tree').stdout) return find(tree) if __name__ == '__main__': # Sleep some time to provide time to release all pressed keys sh.sleep(1) try: with open(config_file_path) as f: window = json.load(f) print(f"Using '{config_file_path}' config: {window}") print("Delete config file if you need to change windows:") print(f" rm {config_file_path}") try: current_window_id = _i3_get_current_windows()[0]['window'] sh.xdotool('windowactivate', window['id']) sh.xdotool('key', window['key']) sh.xdotool('windowactivate', current_window_id) except sh.ErrorReturnCode: print("Some command fails") except FileNotFoundError: print(f"File '{config_file_path}' not found") init()
def main(click_mode): words = json.load( open( '/home/ANT.AMAZON.COM/frapil/linux-tweaks/mouse/words_dictionary.json', 'r')) short_words = set() for word in words: if len(word) == letters and all(x == 1 for x in Counter(word).values()): short_words.add(word) text = "\n".join( separator.join(short_words.pop() for _ in range(columns)) for _ in range(lines)) p = Process(target=show_grid, args=( text, delay, )) p.start() if click_mode == 'single': try: command = str(sh.dmenu(sh.echo())).strip() except sh.ErrorReturnCode_1 as e: command = '' p.terminate() try: sh.killall('osd_cat') except sh.ErrorReturnCode_1 as e: pass if command: if command == '.': with open(command_file_path, 'r') as command_file: command = command_file.read() with open(text_file_path, 'r') as text_file: text = text_file.read() for keys in command.split(): if keys == 'r': #reload main() return print('Looking for', keys) action = "click" if ',' in keys: # Hold action = "mousedown" if '.' in keys: # Release action = "mouseup" button_id = 1 if ']' in keys and '[' in keys: # Middle click button_id = 2 elif ']' in keys: # Right click button_id = 3 elif '{' in keys: # Wheel up button_id = 4 elif '}' in keys: # Wheel down button_id = 5 keys = keys.replace(',', '') keys = keys.replace('.', '') keys = keys.replace('[', '') keys = keys.replace(']', '') keys = keys.replace('{', '') keys = keys.replace('}', '') try: column_number, line_number, x_offset, y_offset = find_coordinates( keys, text) except TypeError: print(keys, 'no found') continue x_coordinate = first_word_mouse_location[ 'x'] + column_number * column_spacing y_coordinate = first_word_mouse_location[ 'y'] + line_number * line_spacing x_coordinate += x_offset y_coordinate += y_offset digits = list(filter(str.isdigit, keys)) if digits: number = int(''.join(digits)) else: number = 1 print('Clicking', 'x:', x_coordinate, 'y:', y_coordinate, 'times:', number) for _ in range(number): sh.xdotool("mousemove", x_coordinate, y_coordinate, action, button_id) time.sleep(0.1) with open(command_file_path, 'w') as command_file: command_file.write(command) with open(text_file_path, 'w') as text_file: text_file.write(text)
def ls(self, cmd="", out=sys.stdout): # identifier of the item def ident(i): return ("%9s: ") % i # print to `out` def printout(kind, item): out.write(ident(kind) + item + "\n") # print only if not printed before def printout_if_needed(kind, item): if kind not in self.recent or item not in self.recent[kind]: printout(kind, item) # print pinned items first for item in self.pinned: printout("pinned", item) # load hud menu items and print if needed self.hud_interface = menus.hud.hud_load(self.window_id) if self.hud_interface is not None: if self.window_id is None: title = sh.xdotool("getactivewindow", "getwindowname").strip() else: title = sh.xdotool("getwindowname", self.window_id).strip() menuitems, mainbar = self.hud_interface.list() # print title and main bar if any if title: printout("menu", title) if mainbar: printout("menu", mainbar) # print recent menu items if "menu" in self.recent: for item in self.recent["menu"]: if item in menuitems: printout("menu", item) # print other menu items for item in menuitems: printout_if_needed("menu", item) # print other recent items for kind in ["bins", "games", "power"]: if kind in self.recent: for item in self.recent[kind]: printout(kind, item) # print power options for item in self.power: printout_if_needed("power", item) # print keyboard shortcuts for item in menus.keys.get_doc(): printout("shortcuts", item) # print games for item in self.games: printout_if_needed("games", item) # print other bins for item in self.path_bins(): printout_if_needed("bins", item)
def find_wid_by_name( name ): answer = xdotool('search', '--name', name ) for line in answer.splitlines(): return line
} ] ''' first we will refresh the screenshot ''' sudo('/home/pi/fb2png', '-p', '/dev/shm/fb.png') ''' then we will check the color of pixel 0,0 ''' output = convert('/dev/shm/fb.png', '-format', '%[pixel: u.p{0,0}]', 'info:') regexp = "(?:(^.*?\((\d+),(\d+),(\d+)\)$)|(\S+))" match = re.search(regexp, str(output)) if match is not None: if re.search('^srgb.*$', match.group(0)) is None: logging.info("we got a color instead of an srgb value.") else: point = {} point['red'] = int(match.group(2)) point['green'] = int(match.group(3)) point['blue'] = int(match.group(4)) ''' if our color in 0,0 matches our known widget border color, then we think we're in windowed mode. ''' if point in border_colors: logging.info("screen appears to be windowed, executing xdotool") new_env = os.environ.copy() new_env["DISPLAY"] = ":0" xdotool('key', 'F11', _env=new_env) else: logging.info("color doesn't match known window border color, assuming fullscreen.") else: logging.info("convert did not produce output we would expect. Output: {output}".format(output=output)) sys.exit(1)
def select(self, apps): success = self.select_only(apps) sh.xdotool("key", "Escape") return success