#!/usr/bin/env python # cycle-workspace # Moves the currently active workspace to the next active display # Depends on i3-py (`pip install i3-py`) import i3 import sys # figure out what is on, and what is currently on your screen. workspace_origin = list(filter(lambda s: s['focused'], i3.get_workspaces()))[0] outputs = list(filter(lambda s: s['active'], i3.get_outputs())) def rename(origin, destination): if destination >= 1 and destination <= 10: workspace_destination="10" elif destination >= 11 and destination <= 20: workspace_destination="20" elif destination >= 21 and destination <= 30: workspace_destination="30" return workspace_destination workspace_destination = workspace_origin if sys.argv[1] == "right": workspace_origin_x = workspace_origin['rect']['x'] workspace_origin_width = workspace_origin['rect']['width'] next_workspace_start = workspace_origin_x + workspace_origin_width for output in outputs: if output['rect']['x'] == next_workspace_start: workspace_destination = output if sys.argv[1] == "left": workspace_origin_x = workspace_origin['rect']['x'] workspace_origin_width = workspace_origin['rect']['width'] next_workspace_start = workspace_origin_x - workspace_origin_width for output in outputs: if output['rect']['x'] == next_workspace_start: workspace_destination = output if (workspace_destination != workspace_origin): # Because workspace name are fixed to screen, just rename workspace can change workspace to another screen. # Get temprory workspace of the screen destination (10, 20 or 30) workspace_number_destination = rename(workspace_origin['name'], int(workspace_destination['current_workspace'])) # Move origin workspace to the correct screen i3.command('move', 'workspace to output '+workspace_destination['name']) # Rename origin workspace to temporary workspace of the screen destination i3.command('rename', 'workspace '+str(workspace_origin['name'])+' to '+workspace_number_destination) # Change focus to the workspace destination i3.workspace(workspace_destination['current_workspace']) # Move destination workspace to the correct screen i3.command('move', 'workspace to output '+workspace_origin['output']) # Rename workspace destination to the origin workspace i3.command('rename', 'workspace '+workspace_destination['current_workspace']+' to '+str(workspace_origin['name'])) # Rename temporary workspace to workspace destination i3.command('rename', 'workspace '+workspace_number_destination+' to '+workspace_destination['current_workspace']) # Change focus the workspace destination i3.workspace(workspace_destination['current_workspace'])