Example #1
0
def xmonify():
    # 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

    # The following is done in a hackish way as there is no way to wait for a
    # successfull ending of previous command

    for window in other:
        status = i3.focus(con_id=window['id'])
        status = i3.move('workspace temp')

    for window in current:
        status = i3.focus(con_id=window['id'])
        status = i3.move('workspace 1')

    counter = 0
    for window in other:
        status = i3.focus(con_id=window['id'])
        status = i3.move('workspace 1')

        if counter==0:
            status = i3.command("split", "v")

        counter += 1

    for window in current:
        i3.focus(con_id=window['id'])
Example #2
0
    def dispatch_i3msg_com(
        command: str, data: Location = Location(1189, 652)) -> list:
        """Internal function used to dispatch specific command strings to
        i3-ipc. Data may also be a string."""

        dispatcher = {
            # Dictionary of commands to execute with i3 comx
            "resize":
            lambda *d: i3.resize("set", d[0], d[1]),
            "move":
            lambda *d: i3.move("window", "position", d[0], d[1]),
            "float":
            lambda *d: i3.floating("enable"),
            "reset":
            lambda *d:
            (i3.resize("set", f"{d[0]}ppt", f"{d[0]}ppt") and i3.move(
                "window", " position", "center")),
            "custom": (lambda *d: i3.resize("set", d[0], d[0]) and i3.move(
                "window", "position", "center")),
        }
        if isinstance(data, str):
            return dispatcher[command](data)
        elif isinstance(data, Location):
            w = str(data.width) if data.width > 0 else "0"
            h = str(data.height) if data.height > 0 else "0"
            return dispatcher[command](w, h)
Example #3
0
def xmonify():
    # 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

    # The following is done in a hackish way as there is no way to wait for a
    # successfull ending of previous command

    for window in other:
        status = i3.focus(con_id=window['id'])
        status = i3.move('workspace temp')

    for window in current:
        status = i3.focus(con_id=window['id'])
        status = i3.move('workspace 1')

    counter = 0
    for window in other:
        status = i3.focus(con_id=window['id'])
        status = i3.move('workspace 1')

        if counter == 0:
            status = i3.command("split", "v")

        counter += 1

    for window in current:
        i3.focus(con_id=window['id'])
Example #4
0
def main():
    windows = scratchpad_windows()
    # search for focused window among scratchpad windows
    if i3.filter(windows, focused=True):
        # move that window back to scratchpad
        i3.move('scratchpad')
    # show the next scratchpad window
    i3.scratchpad('show')
Example #5
0
def moveto_ws():
    direction = sys.argv[2]
    if direction == 'prev':
        i3.move('container to workspace' + prev_ws())
    elif direction == 'next':
        i3.move('container to workspace' + next_ws())
    else:
        print("unsupported second parameters")
Example #6
0
def main():
    windows = scratchpad_windows()
    # search for focused window among scratchpad windows
    if i3.filter(windows, focused=True):
        # move that window back to scratchpad
        i3.move('scratchpad')
    # show the next scratchpad window
    i3.scratchpad('show')
Example #7
0
def main():
    active_screens = get_active_screens()
    current_workspace = get_focused_workspace()

    other_screen = next(
        filter(lambda x: x['current_workspace'] != current_workspace['name'],
               active_screens))

    i3.move("workspace to output", other_screen['name'])
Example #8
0
def make_focused(current_id):
    """Make the focused window floating, set its dimensions
    and position.
    """

    i3.focus(con_id=current_id)
    i3.floating('enable')
    i3.resize(f'set {WIDTH} {HEIGHT}')
    i3.move('position center')
Example #9
0
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)
Example #10
0
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')
Example #11
0
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))
Example #12
0
def main(argv1):
    currentLang = os.popen(
        "~/softwares/xkblayout-state/xkblayout-state print %n").read()

    if currentLang == "Hebrew":
        if argv1 == "whats-app":
            argv1 = "slack"
        else:
            argv1 = "whats-app"
    os.system("setxkbmap us")
    apps = ["slack", "whats-app"]
    if isAppInFocus(argv1):
        i3.focus(instance=argv1)
        i3.move('scratchpad')
        for app in apps:
            if isAppInFocus(app):
                i3.move('scratchpad')
    else:
        if argv1 == "whats-app":
            os.system("setxkbmap il")

        i3.scratchpad('show', instance=argv1 + ".*")
Example #13
0
def main():
    # The color count should correspond to the output count
    color_count = 5

    # Spread color_count hues evenly in HSV space
    hues = np.linspace(0, 1, num=color_count + 1)[:-1]

    rgbs = []
    # Convert each hue to RGB
    for hue in hues:
        rgbs.append(colorsys.hsv_to_rgb(hue, 1, 1))

    rgbs = list(zip(np.arange(len(rgbs)), rgbs))

    print("indexes: %s" % [idx for idx, rgb in rgbs])

    for idx, color in rgbs:
        display_rect(color, idx)
        plt.show(False)
        i3.focus(title=str(idx))
        i3.move('workspace 10')

    input()
Example #14
0
                              '-nf',
                              '#00C1FF',
                              '-sb',
                              '#00A0DD',
                              '-sf',
                              '#FFFFFF'],
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
    menu_str = '\n'.join(sorted(clients.keys()))
    # Popen.communicate returns a tuple stdout, stderr
    win_str = dmenu.communicate(menu_str.encode('utf-8'))[0].decode().rstrip()
    return win_str

if __name__ == '__main__':
    clients = i3clients()
    win_str = win_menu(clients)
    try:
        clients[win_str]
    except:
        i3.mark(win_str)
        raise SystemExit
    con_id = clients[win_str]['con_id']
    i3.focus(con_id=con_id)
    workspaces = i3.get_workspaces()
    for w in workspaces:
        if w["focused"]:
            goto = w["num"]
            break
    i3.move("container", "to", "workspace", str(goto))
    i3.workspace(str(goto))
Example #15
0
#!/usr/bin/env python3

import i3

scratch = i3.filter(name="__i3_scratch")[0]

if scratch["floating_nodes"]:
	i3.scratchpad("show")
else:
	i3.move("scratchpad")

Example #16
0
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)
Example #17
0
def cmd_move_and_focus(wmove):
    wid = dest_wid(wmove)
    print 'move & focus', wmove, '->', wid
    wid = str(wid)
    i3.move('workspace', wid)
    i3.workspace(wid)
Example #18
0
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)
i3.rename('workspace to', a_workspace)
time.sleep(0.025)
Example #19
0
def make_float(current_id):
    i3.focus(con_id=current_id)
    i3.floating('enable')
    i3.resize('set 1000 1000')
    i3.move('position center')
Example #20
0
def revisualize(node, workspace_name):
    i3.focus(con_id=node['id'])
    i3.move('to workspace ' + workspace_name)
    i3.floating('disable')
Example #21
0
def make_float(current_id):
    size = get_size()
    i3.focus(con_id=current_id)
    i3.floating('enable')
    i3.resize('set {} {}'.format((size + int(size*.56)), size))
    i3.move('position center')
Example #22
0
def make_float(current_id):
    size = get_size()
    i3.focus(con_id=current_id)
    i3.floating('enable')
    i3.resize('set {} {}'.format((size + int(size * .56)), size))
    i3.move('position center')
Example #23
0
#!/usr/bin/env python

import i3
import time

currentWindow = i3.filter(focused=True)[0]
this_id = currentWindow['id']
i3.focus(con_id=this_id)
i3.move('scratchpad')
i3.focus(con_id=this_id)
i3.move('to workspace 10')
i3.floating('disable')

#parentContainer = i3.parent(currentWindow['id'])
#print(parentContainer)
#nodes = parentContainer['nodes']
#print([node['name'] for node in nodes])
#for node in nodes:
#    i3.focus(con_id=node['id'])
#    i3.move('scratchpad')
#
#i3.focus(parentContainer['id'])
#i3.focus(con_id=node['id'])
#i3.move('to workspace 10')

##if parentContainer['layout'] in ['splitv', 'stacked']:
##    direction = 'down'
##else:
##    direction = 'right'
#
#nodes = parentContainer['nodes']
Example #24
0
import sys

import i3

outputs = i3.get_outputs()
outputs = i3.filter(outputs, active=True)
workspaces = i3.get_workspaces()
currentfocus = i3.filter(workspaces, focused=True)[0]['output']

current = 0
for i, workspace in enumerate(outputs):
    if workspace['name'] == currentfocus:
        current = i
next_workspace = current + 1
if outputs[next_workspace % len(outputs)]['name'] == 'xroot-0':
    next_workspace += 1

i3.move('workspace to output %s' %
        outputs[next_workspace % len(outputs)]['name'])
Example #25
0
import i3
import sys

outputs = i3.get_outputs()
outputs = i3.filter(outputs, active=True)
outputs = [o["name"] for o in outputs]
if len(outputs) == 1:
    sys.exit(0)
workspaces = i3.get_workspaces()

candidates = [1, 2, 3]

other_workspace = [o for o in outputs if o not in ["eDP1", "xroot-0"]][0]

for w in workspaces:
    if w["num"] not in candidates:
        continue
    if w["output"] == "eDP1":
        i3.move("workspace to output %s" % (other_workspace),
                workspace=w["name"])

# for workspace in workspaces:
# 	if workspace['output']
Example #26
0
#!/usr/bin/env python
# https://faq.i3wm.org/question/3189/how-can-i-sort-windows-inside-a-container-automatically/

import i3

currentWindow = i3.filter(focused=True)[0]

parentContainer = i3.parent(currentWindow['id'])
if parentContainer['layout'] in ['splitv', 'stacked']:
    direction = 'down'
else:
    direction = 'right'

nodes = parentContainer['nodes']

snodes = sorted(nodes, key=lambda n:n['name'])

for node in snodes[1:]:
    i3.focus(con_id=node['id'])
    i3.move('scratchpad')

i3.focus(con_id=nodes[0]['id'])

for node in snodes[1:]:
    i3.focus(con_id=node['id'])
    i3.floating('disable')

i3.focus(con_id=currentWindow['id'])
Example #27
0

def get_workspace(container):
    if container['type'] == 'workspace':
        return container
    return get_workspace(i3.parent(container['id']))


def get_leaves(node):
    if len(node['nodes']) == 0:
        return [node]
    children = []
    for child in node['nodes']:
        children.extend(get_leaves(child))
    return children


currentWindow = i3.filter(focused=True)[0]
workspace = get_workspace(currentWindow)
workspace_name = workspace['name']

leaves = get_leaves(workspace)
for leaf in leaves:
    i3.focus(con_id=leaf['id'])
    i3.move('scratchpad')

for leaf in leaves:
    i3.focus(con_id=leaf['id'])
    i3.move('to workspace ' + workspace_name)
    i3.floating('disable')
Example #28
0
    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)
Example #29
0
        extra.append(leaf)
left.sort(key=lambda n:n['name'])
right.sort(key=lambda n:n['name'])
extra.sort(key=lambda n:n['name'])

print("left")
print([node['name'] for node in left])
print("right")
print([node['name'] for node in right])
print("extra")
print([node['name'] for node in extra])


for leaf in leaves:
    i3.focus(con_id=leaf['id'])
    i3.move('scratchpad')

i3.focus(con_id=workspace['id'])
i3.layout('splitv')
for leaf in left:
    revisualize(leaf, workspace['name'])

first_right = right.pop(0)
revisualize(first_right, workspace['name'])
i3.move('right')
i3.split('v')
i3.focus(con_id=first_right['id'])
for leaf in right:
    revisualize(leaf, workspace['name'])

Example #30
0
#!/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"]))
	
Example #31
0
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)
Example #32
0
def cmd_move(wmove):
    wid = dest_wid(wmove)
    print 'move', wmove, '->', wid
    i3.move('workspace', str(wid))
Example #33
0
#!/usr/bin/python3
import i3

current_output_name = [ws for ws in i3.get_workspaces()
                       if ws["focused"]][0]["output"]
output_names = [
    output["name"] for output in i3.get_outputs()
    if output["current_workspace"] != None
]

index = output_names.index(current_output_name)
next_output_index = (index + 1) % len(output_names)
next_output_name = output_names[next_output_index]

i3.move(f"workspace to {next_output_name}")
Example #34
0
        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)
Example #35
0
    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)
Example #36
0
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)
	
	
Example #37
0
File: swap.py Project: foop/config
#!/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.move("workspace", "to", "output", "right")

# rinse and repeat
i3.workspace(outputs[1]['current_workspace'])
i3.move("workspace", "to", "output", "right")
Example #38
0
#!/usr/bin/env python3

import i3
from utils import find_matching, window, focused_tree, focused_window
from uuid import uuid4 as uuid

if __name__ == "__main__":
    mark = str(uuid())
    workspace = focused_tree()
    focused = focused_window()
    i3.focus(con_id=workspace["id"])
    i3.mark(mark)
    windows = find_matching(window, workspace)
    for w in windows:
        i3.focus(con_id=w["id"])
        i3.move("window to mark {}".format(mark))
    i3.focus(con_id=workspace["id"])
    i3.unmark(mark)
    i3.focus(con_id=focused["id"])