def rotate_workspaces_to_right_and_keep_ws_names(): # Get all visible workspace(s) - the workspace(s) currently visible on output(s) workspaces = i3.filter(i3.get_workspaces(), visible=True) # Get list containing num of the visible workspaces ws_names = [ ws['num'] for ws in workspaces ] # Get focused workspace id/name ws_focused = i3.filter(workspaces, focused=True)[0]['num'] # Get index of focused node in ws_names idx = ws_names.index(ws_focused) # Create a range that starts from the index of the focused node so the # focused output is the last to be rotated to the right. This results in # the focus to stay on the same output ws_range = [ index%len(ws_names) for index in range(idx-1,idx+len(ws_names)-1) ] # For each visible workspace for i in ws_range: # Set focus to workspace by id/name i3.workspace( str(ws_names[i]) ) # Move focused workspace to output on the right i3.command('move workspace to output right')
def goto_ws(): direction = sys.argv[2] if direction == 'prev': i3.workspace(prev_ws()) elif direction == 'next': i3.workspace(next_ws()) else: print("unsupported second parameters")
def migrate(src, dst, exclude=[]): workspaces = i3.get_workspaces() for w in workspaces: if w['name'] in exclude: continue if w['output'] != dst['name']: i3.workspace(w['name']) i3.command('move', 'workspace to output right')
def cmd_move_group_output(output): ws = i3.get_workspaces() group, current_wnum = get_wgroup(ws) wids = wids_by_furthest(ws, group, current_wnum) print 'move_group_output', output, '->', wids i3_move_args = ['workspace', 'to', output] for wid in wids: i3.workspace(str(wid)) i3.move(*i3_move_args)
def main(): workspaces = i3.get_workspaces() workints = list() for w in workspaces: workints.append(w['num']) for i in range(1, 11): if i not in workints: i3.workspace(str(i)) break
def moveandgoto_ws(): direction = sys.argv[2] if direction == 'prev': i3.move('container to workspace' + prev_ws()) i3.workspace(prev_ws()) elif direction == 'next': i3.move('container to workspace' + next_ws()) i3.workspace(next_ws()) else: print("unsupported second parameters")
def apply_output_order(order=list(range(5))): # The length changes in the loop due to pop() so we need to save it iters = len(order) while len(order) > 0: idx = order.pop() for i in range(iters): i3.workspace('10') i3.focus(title=str(idx)) result = i3.move('left')
def main(): i3.workspace(str(first_free())) i3.layout('default') i3.exec(browser) time.sleep(1) # give browser window time to spawn i3.exec(term) time.sleep(0.5) # give terminal window time to spawn i3.split('v') i3.layout('stacking') i3.focus('left') i3.split('v') i3.layout('stacking')
def run(num): # current workspace current = [ws for ws in i3.get_workspaces() if ws["focused"]][0] # switch to workspace named 'fibonacci' i3.workspace("fibonacci") i3.layout("default") fibonacci(num) time.sleep(3) # close all opened terminals for n in range(num): i3.kill() time.sleep(0.5) i3.workspace(current["name"])
def run(num): # current workspace current = [ws for ws in i3.get_workspaces() if ws['focused']][0] # switch to workspace named 'fibonacci' i3.workspace('fibonacci') i3.layout('default') fibonacci(num) time.sleep(3) # close all opened terminals for n in range(num): i3.kill() time.sleep(0.5) i3.workspace(current['name'])
def main(): tree = i3.get_tree() result = [] for output in tree['nodes']: if output['name'].startswith('__'): continue result.extend(handle_output(output['nodes'])) print(result) text_list = [] for workspace in result: text_list.append('%s -> #%s' % (workspace['name'], workspace['num'])) answer = dmenu(sorted(text_list), dmenu_cmd('select window: ', )) if answer: num = answer.split('#')[-1] i3.workspace(num)
def cycle(): # get workspace focused on each screen workspace_per_screen = i3.get_outputs() # get currently focused windows current = i3.filter(nodes=[], focused=True) # get unfocused windows other = i3.filter(nodes=[], focused=False) # focus each previously unfocused window for 0.5 seconds for window in other: i3.focus(con_id=window['id']) time.sleep(0.5) # focus the old workspace on each screen for wks in workspace_per_screen: i3.workspace(wks['current_workspace']) # focus the original windows for window in current: i3.focus(con_id=window['id'])
def main(projectName): print(projectName) if (projectName is None) or (len(projectName) == 0): sys.exit(0) new_workspaces = [] for output in i3.filter(tree=i3.get_outputs(), active=True): current_workspace_name = output['current_workspace'] print(current_workspace_name) current_workspace = i3.filter(tree=i3.get_workspaces(), name=current_workspace_name) if not current_workspace[0]['focused']: print("Current workspace, {}, not focussed".format( current_workspace_name)) i3.workspace(current_workspace_name) i3.workspace(projectName + '-' + output['name']) subprocess.call(['startWorkOn', projectName])
def main(): # workspaces workspaces = i3.get_workspaces() workints = list() # get currently focused windows current = i3.filter(nodes=[], focused=True) # find a free one for w in workspaces: workints.append(w['num']) for i in range(1, 11): if i not in workints: break print(i) for window in current: i3.move("container", "to", "workspace", str(i)) i3.workspace(str(i))
def rotate_workspaces_to_right(): # Get all visible workspace(s) - the workspace(s) currently visible on output(s) workspaces = i3.filter(i3.get_workspaces(), visible=True) # Get list containing num of the visible workspaces ws_names = [ ws['num'] for ws in workspaces ] # Get focused workspace id/name ws_focused = i3.filter(workspaces, focused=True)[0]['num'] # Get index of focused node in ws_names idx = ws_names.index(ws_focused) # Create a range that starts from the index of the focused node so the # focused output is the last to be rotated to the right. This results in # the focus to stay on the same output ws_range = [ index%len(ws_names) for index in range(idx-1,idx+len(ws_names)-1) ] # Rename the first workspace to the temporary name i3.command('rename workspace {0} to {1}'.format(ws_names[idx],WS_TMP_NAME)) # For each visible workspace for i in ws_range: # Get name of workspace to be in focus ws_name = WS_TMP_NAME if i==idx else ws_names[i] # Set focus to workspace by id/name i3.workspace( str(ws_name) ) # Rename focused workspace to id/name of workspace to the right i3.command('rename workspace {0} to {1}'.format( ws_name, ws_names[(i+1) % len(ws_names)] ) ) # Move focused workspace to output on the right i3.command('move workspace to output right')
#!/usr/bin/python3 import i3 # retrieve only active outputs outputs = list(filter(lambda output: output['active'], i3.get_outputs())) current_ws = i3.filter(i3.get_workspaces(), focused=True)[0]['name'] for output in outputs: # set current workspace to the one active on that output i3.workspace(output['current_workspace']) # ..and move it to the output to the right. # outputs wrap, so the right of the right is left ;) i3.command('move', 'workspace to output right') i3.workspace(current_ws)
#!/usr/bin/python2.7 import i3 outputs = i3.get_outputs() actives = [ x for x in outputs if x['active'] ] if len(actives) == 2: # set current workspace to output 0 i3.workspace(actives[0]['current_workspace']) # ..and move it to the other output. # outputs wrap, so the right of the right is left ;) i3.command('move', 'workspace to output right') # rinse and repeat i3.workspace(actives[1]['current_workspace']) i3.command('move', 'workspace to output right')
def is_w_focused(o): wss = i3.get_workspaces() name = o[u'current_workspace'] current = None for w in wss: if w[u'name'] == o['current_workspace']: current = w break return current[u'focused'] outputs = i3.get_outputs() l = [] first = None for w in outputs: if w[u'current_workspace'] is not None: l.append(w) if first is None: first = w if is_w_focused(w) else None for o in l: if not is_w_focused(o): i3.workspace(o['current_workspace']) i3.command('move', 'workspace to output left') # Makes sure to go back to the initial window if not is_w_focused(first): i3.workspace(first[u'current_workspace'])
action='store_const', help='swich to the provious workspace (by default it goes to next)', const="prev", default="next") parser.add_argument('--next', dest='direction', action='store_const', help='swich to the next workspace (default)', const="next", default="next") args = parser.parse_args() workspaces = [] for workspace in i3.get_workspaces(): if workspace['visible']: workspaces.append(workspace) workspaces.extend(workspaces) if args.direction == "prev": workspaces.reverse() switch_to = False for workspace in workspaces: if switch_to: i3.workspace(workspace['name']) break if workspace['focused']: switch_to = True
workspaces_dir = os.path.join("~", ".i3", "workspaces") workspaces_dir = os.path.expanduser(workspaces_dir) workspaces = [file for file in os.listdir(workspaces_dir) if file.endswith(".conf")] workspace = dmenu([os.path.splitext(w)[0] for w in workspaces]) workspace = workspace.strip() + ".conf" workspace = os.path.join(workspaces_dir, workspace) workspace = json.load(open(workspace)) existing_workspaces = i3.get_workspaces() wname = workspace.get("name") if wname: i3.workspace(wname) if wname in [w["name"] for w in existing_workspaces]: sys.exit(0) root = workspace.get("root", "") root = os.path.expanduser(root) containers = [] for container in workspace["containers"]: c = Container(container) c.run(root) containers.append(c) # here because we can modify the size only when we have all containers launched for c in containers: c.apply_size()
def goto_workspace(name): """Jump to the given workspace.""" return i3.workspace(name)
if not os.path.exists(configfile): return default with open(configfile) as f: for line in f: if line.startswith("set $ws"): line_content = line.rstrip("\n") ws_start = " ".join(line_content.split()[0:2]) ws_name = line_content.replace(ws_start, "").strip() ws_names.append(ws_name) return ws_names if ws_names else default if __name__ == '__main__': ws_names = get_workspace_names() ws_nums = [] for w in i3.get_workspaces(): ws_nums.append(w['num']) i = 1 while i in ws_nums: i += 1 first_free = ws_names[i-1] if "--move-to" in sys.argv: i3.move("container", "to", "workspace", first_free) elif "--take-with" in sys.argv: i3.move("container", "to", "workspace", first_free) i3.workspace(first_free) else: i3.workspace(first_free)
#!/usr/bin/python2.7 import i3 workspaces = [ws for ws in enumerate(i3.get_workspaces())] focused_id = [i for i, ws in workspaces if ws['focused']][0] i3.command('move', 'workspace to output left') i3.workspace(workspaces[1 - focused_id][1]['name']) i3.command('move', 'workspace to output right')
import i3 outputs = [output for output in i3.get_outputs() if output['active']] workspaces = i3.get_workspaces() if len(outputs) == 2: for workspace in workspaces: print(workspace['name']) i3.workspace(workspace['name']) i3.command('move', 'workspace to output right')
# # All the letters must be added to the i3 configuration, ie: # bindsym Mod4+u exec python ~/.i3/scripts/ws_letter.py a # ... # bindsym Mod4+u exec python ~/.i3/scripts/ws_letter.py z # # using ziberna's i3-py library: https://github.com/ziberna/i3-py import i3 import sys def cut_number(string): if string.find(": ") > 0: return string[string.rfind(": ")+2:] return string ws = i3.get_workspaces() ws_map = {} for ws in i3.get_workspaces(): letter_name = cut_number(ws['name'])[:1] if letter_name >= 'a' and letter_name <= 'z': ws_map[letter_name] = ws['name'] if len(sys.argv) == 2: if ws_map.has_key(sys.argv[1]): i3.workspace(ws_map[sys.argv[1]])
elif method=="random": return choice(window_list) else: return None if __name__ == '__main__': args = parser.parse_args() # prepare to_play = args.files max_play = args.n video_commands = shlex.split(MPLAYER_CMD) dev_null = os.open("/dev/null", os.O_WRONLY) i3.workspace('videowall') i3.layout('default') print "max is %d" % (max_play) playing_videos = [] while len(to_play)>0: # start playing while len(playing_videos)<max_play and len(to_play)>0: video=to_play.pop() print "Going to play %s" % (video) cmd = list(video_commands) cmd.append(video) print "cmd=%s" % (cmd) i3.workspace('videowall')
#!/usr/bin/python2.7 import i3 outputs = i3.get_outputs() # set current workspace to output 0 i3.workspace(outputs[2]['current_workspace']) # ..and move it to the other output. # outputs wrap, so the right of the right is left ;) i3.command('move', 'workspace to output right') # rinse and repeat i3.workspace(outputs[5]['current_workspace']) i3.command('move', 'workspace to output right')
import time import i3 TEMP_WORKSPACE = "swap_outputs.py" active_outputs = [out for out in i3.get_outputs() if out['active']] # Do nothing if there aren't more than one active ouput if len(active_outputs) < 2: sys.exit() a, b = active_outputs[:2] print("{} <-> {}".format(a['current_workspace'], b['current_workspace'])) a_workspace = a['current_workspace'] i3.workspace(a_workspace) time.sleep(0.025) i3.move('workspace to output right') time.sleep(0.025) i3.workspace(a_workspace) time.sleep(0.025) i3.rename('workspace to', TEMP_WORKSPACE) time.sleep(0.025) b_workspace = b['current_workspace'] i3.workspace(b_workspace) time.sleep(0.025) i3.move('workspace to output right') time.sleep(0.025) i3.workspace(b_workspace) time.sleep(0.025)
import argparse import sys import i3 workspaces = i3.get_workspaces()[:-1] workspaces.append(workspaces[0]) print(workspaces) for i in range(len(workspaces)): if workspaces[i]["focused"] == True: i3.workspace(workspaces[i + 1]["name"]) sys.exit() # i3.workspace(workspaces[1]["name"])
parser = argparse.ArgumentParser(description='Creates new workspace') parser.add_argument('--move', dest='move', action='store_const', help='move focused window to new workspace', const=True, default=False) parser.add_argument( '--send', dest='send', action='store_const', help= 'send focus window to new workspace while staying on current workspace', const=True, default=False) args = parser.parse_args() workspaces = [] for workspace in i3.get_workspaces(): workspaces.append(workspace['name']) for i in range(1, 100): # I guess 100 workspaces its already too much if str(i) not in workspaces: if args.send or args.move: i3.command('move', 'container to workspace {i}'.format(i=i)) if not args.send: i3.workspace(str(i)) break
def opendev(): i3.workspace("Dev") i3.workspace("Atom") i3.workspace("GitKraken") print("Dev Workspaces Opened")
""" Swap the windows on two monitors. """ import i3 if __name__ == '__main__': active_outputs = [out for out in i3.get_outputs() if out['active']] num_monitors = 2 for i in range(2): i3.workspace(active_outputs[i]['current_workspace']) i3.command('move', 'workspace to output right')
workspaces = i3.get_workspaces() currentnum = i3.filter(workspaces, focused=True)[0]['num'] if sys.argv[1] == 'next': workspace_next = i3.filter(workspaces, num=currentnum+1) if len(workspace_next) == 0: workspace_next = workspaces[0] else: workspace_next = workspace_next[0] else: workspace_next = i3.filter(workspaces, num=currentnum-1) if len(workspace_next) == 0: workspace_next = workspaces[-1] else: workspace_next = workspace_next[0] print workspace_next ws_nodes = i3.filter(num=currentnum)[0]['nodes'] ws_nodes = ws_nodes + i3.filter(num=currentnum)[0]['floating_nodes'] curr = i3.filter(ws_nodes, focused=True)[0] i3.move('container to workspace number %s' % workspace_next['num']) i3.workspace('number %s' % workspace_next['num']) # ids = [win['id'] for win in i3.filter(ws_nodes, nodes=[])] # if sys.argv[0] == 'next': # next_idx = (ids.index(curr['id']) + 1) % len(ids) # else: # next_idx = (ids.index(curr['id']) - 1) % len(ids) # next_id = ids[next_idx] # i3.focus(con_id=next_id)
#!/usr/bin/env python3 import i3 # Unfortunatelly this doesn't seem to be reliable outputs = sorted((out for out in i3.get_outputs() if out["active"]), key=lambda o: o["rect"]["x"]) outputs.append(outputs[0]) for left, right in zip(outputs, outputs[1:]): i3.workspace(left["current_workspace"]) i3.move("workspace to output {}".format(right["name"]))
#!/usr/bin/python3 import i3 # retrieve only active outputs outputs = list(filter(lambda output: output["active"], i3.get_outputs())) current_ws = i3.filter(i3.get_workspaces(), focused=True)[0]["name"] for output in outputs: # set current workspace to the one active on that output i3.workspace(output["current_workspace"]) # ..and move it to the output to the right. # outputs wrap, so the right of the right is left ;) i3.command("move", "workspace to output right") i3.workspace(current_ws)
def next_free_workspace_index(): """ Returns the integer index of the next free workspace index. """ # Get all of the workspces workspaces = i3.get_workspaces() ws_indices = sorted([ws['num'] for ws in workspaces]) # Workspaces are 1 indexed, use 0 so we can catch if workspace 1 is not used prev_ws = 0 # First check for gaps for ws in ws_indices: next_ws = prev_ws + 1 if ws != next_ws: return next_ws else: prev_ws += 1 # We didn't find any gaps return prev_ws + 1 if __name__ == '__main__': i3.workspace(str(next_free_workspace_index())) with open(os.devnull) as devnull: subprocess.call('i3-sensible-terminal', stdout=devnull, stderr=devnull)
#!/usr/bin/env python3 # import i3 import sys active_outputs = [o for o in i3.get_outputs() if o['active']] if len(active_outputs) < 2: print("Too few outputs. Exiting.") sys.exit(0) else: i3.workspace(active_outputs[0]['current_workspace']) i3.command('move', 'workspace to output right') i3.workspace(active_outputs[1]['current_workspace']) i3.command('move', 'workspace to output right') # vim:fenc=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4
#!/usr/bin/python import i3 from sys import exit import argparse import sys from common.i3common import * # Requirements: https://github.com/ziberna/i3-py if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-first') parser.add_argument('-second') args = parser.parse_args() if not args.first or not args.second: exit('Workspace 1 and workspace 2 are required (-first and -second)') workspace = get_current_workspace() if workspace['name'] == args.first: i3.workspace(args.second) else: i3.workspace(args.first)
import i3 import pprint # spaces = i3.get_workspaces() def outputs(): puts = i3.get_outputs() act = [item for item in puts if item['active']] s = sorted(act, key=lambda x: x['rect']['x']) return s outs = outputs() # pprint.pprint(outs) c = outs[0]['current_workspace'] pprint.pprint(c) many = len(outs) spaces = 10/many current = 1 for output in outs: for i in xrange(spaces): print output['name'] print current i3.workspace(str(current)) i3.command('move', 'workspace to output ' + output['name']) current += 1 i3.workspace(c)
menu = subprocess.Popen( ["rofi", "-dmenu", "-width", "33", "-p", "window: "], stdin=subprocess.PIPE, stdout=subprocess.PIPE) menu_str = "\n".join(sorted(clients.keys())) # Popen.communicate returns a tuple stdout, stderr win_bytes = menu.communicate(menu_str.encode("utf-8"))[0] win_str = win_bytes.decode().rstrip("\n") return win_str if __name__ == "__main__": # Remember current workspace name for ws in i3.get_workspaces(): if ws["focused"]: wsname = ws["name"] break # Get ID and string of the window to focus clients = i3clients() win_str = win_menu(clients) con_id = clients[win_str] if win_str in clients else 0 # No window selected if not con_id: sys.exit(0) # Focus the window i3.focus(con_id=con_id) # If "--get", move the window to the remembered workspace if "--get" in sys.argv: i3.move("container", "to", "workspace", wsname) i3.workspace(wsname)
def workspaceswitcher(workspace, xpos, ypos): if bs[0] == xpos and bs[1] == ypos and bs[2] == 127: i3.workspace(workspace)
def switch_workspace(num): """Switches to workspace number""" i3.workspace('number %d' % num)
#!/usr/bin/python2.7 import i3 outputs = i3.get_outputs() # Move all workspace to the right, if output is active for i in range(len(outputs)): if (outputs[i]['active'] == True): i3.workspace(outputs[i]['current_workspace']) i3.command('move workspace to output right')
import i3 import pprint # spaces = i3.get_workspaces() def outputs(): puts = i3.get_outputs() act = [item for item in puts if item['active']] s = sorted(act, key=lambda x: x['rect']['x']) return s outs = outputs() # pprint.pprint(outs) c = outs[0]['current_workspace'] pprint.pprint(c) many = len(outs) spaces = 10 / many current = 1 for output in outs: for i in xrange(spaces): print output['name'] print current i3.workspace(str(current)) i3.command('move', 'workspace to output ' + output['name']) current += 1 i3.workspace(c)
workspaces = i3.get_workspaces() currentnum = i3.filter(workspaces, focused=True)[0]['num'] if sys.argv[1] == 'next': workspace_next = i3.filter(workspaces, num=currentnum + 1) if len(workspace_next) == 0: workspace_next = workspaces[0] else: workspace_next = workspace_next[0] else: workspace_next = i3.filter(workspaces, num=currentnum - 1) if len(workspace_next) == 0: workspace_next = workspaces[-1] else: workspace_next = workspace_next[0] print(workspace_next) ws_nodes = i3.filter(num=currentnum)[0]['nodes'] ws_nodes = ws_nodes + i3.filter(num=currentnum)[0]['floating_nodes'] curr = i3.filter(ws_nodes, focused=True)[0] i3.move('container to workspace number %s' % workspace_next['num']) i3.workspace('number %s' % workspace_next['num']) # ids = [win['id'] for win in i3.filter(ws_nodes, nodes=[])] # if sys.argv[0] == 'next': # next_idx = (ids.index(curr['id']) + 1) % len(ids) # else: # next_idx = (ids.index(curr['id']) - 1) % len(ids) # next_id = ids[next_idx] # i3.focus(con_id=next_id)
def openchat(): i3.workspace("GenChat") i3.workspace("GenChat2") i3.workspace("Telegram") print("Chat Workspaces Opened")
def openweb(): i3.workspace("Vivaldi") i3.workspace("Telegram") i3.workspace("GenChat") print("Web Workspaces Opened")
if "random" in config: rfile = os.path.expanduser(config['random']['file']) else: rfile = default_rfile try: words = open(rfile) except: words = open(default_rfile) total_chars = words.seek(0, 2) position = random.randint(0, total_chars) words.seek(position) rname = words.readline() rname = words.readline().replace("\n", "") space = {"name": rname} wksname = str(number) + ": " + space['name'] return wksname if __name__ == '__main__': import argparse parser = argparse.ArgumentParser(description = "Change to a workspace based on number, not name. Uses JSON config file") parser.add_argument("--move", help="move to workspace", action="store_true") parser.add_argument("workspace", help="workspace number", metavar="<workspace number>", type = int) args = parser.parse_args() name = get_workspace(args.workspace) print(name) if (args.move): i3.movetoworkspace(name) else: i3.workspace(name)
import i3 import sys from utils import find_matching, workspace # This script asumes that workspace names are numbers DEFAULT_NAMES = set(range(1,11)) def first_free(occupied): free = DEFAULT_NAMES - set(occupied) return str(min(free)) if free else None if __name__ == "__main__": if len(sys.argv) != 2: print("{} focus|move".format(sys.argv[0]), file=sys.stderr) sys.exit(1) first = first_free((int(w["name"]) for w in find_matching(workspace()))) if not first: print("All workspaces are occupied") sys.exit(3) action = sys.argv[1] if action == "focus": i3.workspace(first) elif action == "move": i3.move("container to workspace {}".format(first)) else: print("Unknown action", file=sys.stderr) sys.exit(2)
def goto_workspace(name): '''Jump to the given workspace.''' return i3.workspace(name)
else: i3.resize("grow", "width", "{x} px or {x} ppt".format(x = delta_w)) if delta_h < 0: i3.resize("shrink", "height", "{x} px or {x} ppt".format(x = -delta_h)) else: i3.resize("grow", "height", "{x} px or {x} ppt".format(x = delta_h)) def make(tasks): for task in tasks: if task[0] == "run": Process( target = subprocess.call, args = (tuple(task[1].split(" ")), ) ).start() time.sleep(1) elif task[0] == "resize": resize(task[1]) elif task[0] == "orientation": doOrientation(task[1]) elif task[0] == "layout": i3.layout(task[1]) time.sleep(1) print "Workspace file?" data = pickle.load(open(raw_input(), "r")) print "Workspace name?" name = raw_input() curr = [ws for ws in i3.get_workspaces() if ws["focused"]][0]["name"] i3.workspace(name) make(data) i3.workspace(curr)
#!/usr/bin/python2.7 import i3 outputs = i3.get_outputs() # set current workspace to output 0 i3.workspace(outputs[0]['current_workspace']) # ..and move it to the other output. # outputs wrap, so the right of the right is left ;) i3.command('move', 'workspace to output right') # rinse and repeat i3.workspace(outputs[1]['current_workspace']) i3.command('move', 'workspace to output right')
The formatted string of the window to focus. """ menu = subprocess.Popen(["rofi", "-dmenu", "-width", "33", "-p", "window: "], stdin=subprocess.PIPE, stdout=subprocess.PIPE) menu_str = "\n".join(sorted(clients.keys())) # Popen.communicate returns a tuple stdout, stderr win_bytes = menu.communicate(menu_str.encode("utf-8"))[0] win_str = win_bytes.decode().rstrip("\n") return win_str if __name__ == "__main__": # Remember current workspace name for ws in i3.get_workspaces(): if ws["focused"]: wsname = ws["name"] break # Get ID and string of the window to focus clients = i3clients() win_str = win_menu(clients) con_id = clients[win_str] if win_str in clients else 0 # No window selected if not con_id: sys.exit(0) # Focus the window i3.focus(con_id=con_id) # If "--get", move the window to the remembered workspace if "--get" in sys.argv: i3.move("container", "to", "workspace", wsname) i3.workspace(wsname)
#!/usr/bin/env python import i3 outputs = i3.get_outputs() workspaces = i3.get_workspaces() # find the focused workspace focused_workspace = next(filter(lambda s: s["focused"], workspaces)) # TODO instead use move workspace to output next? # find the non-focused output secondary_output = next( filter( lambda output: output["active"] and output["name"] != focused_workspace["output"], outputs, )) # move the current workspace to the secondary output i3.command("move", f"workspace to output {secondary_output['name']}") # focus the initially focused workspace i3.workspace(focused_workspace["name"])