Package: i3pie
i3piei3wm ipc library for python.Installationpip install i3pieUsage>>>importi3pie>>>withi3pie.Connection()asi3:...tree=i3.get_tree()...tree._pprint()...type='root'name='root'├─type='output'name='HDMI-A-0'│├─type='dockarea'name='bottomdock'│├─type='con'name='content'││├─type='workspace'name='2'│││└─type='con'│││└─window=50331658type='con'class='Nemo'││└─type='workspace'name='1'││└─type='con'││├─window=37748745type='con'class='URxvt'││└─window=25165827type='con'class='firefox'│└─type='dockarea'name='topdock'│└─window=23068674type='con'class='Polybar'└─type='output'name='__i3'└─type='con'name='content'└─type='workspace'name='__i3_scratch'└─type='floating_con'└─window=44040194type='con'class='mpv'Sending commands>>>importi3pie>>>i3=i3pie.Connection()>>>tree=i3.get_tree()>>>focused=tree.focused_window()>>>focused.command('move to workspace 2')CommandReply(success=True)>>>windows=list(tree.current_workspace().windows())>>>i3.command('kill',windows)CommandReply(success=True)Working with the tree>>>importi3pie>>>i3=i3pie.Connection()>>>tree=i3.get_tree()>>>focused=tree.focused_window()>>>print(focused)<Containertype='con'class='URxvt'>>>>focused.workspace()Container(type='workspace',name='1')>>>focused.output()Container(type='output',name='HDMI-A-0')>>>tree=focused.root()>>>print(tree)<Containertype='root'name='root'>>>>list(tree.workspaces())[Container(type='workspace',name='1'),Container(type='workspace',name='2')]>>>list(tree.workspaces(scratchpad=True))[Container(type='workspace',name='__i3_scratch'),Container(type='workspace',name='1'),Container(type='workspace',name='2')]>>>scratchpad=tree.scratchpad()>>>print(scratchpad)<Containertype='workspace'name='__i3_scratch'>>>>list(scratchpad.windows())[Container(window=44040194,type='con',class='mpv')]>>>print(list(scratchpad.windows()))[Container(window=44040194,type='con',class='mpv')]>>>list(tree.outputs())[Container(type='output',name='HDMI-A-0')]>>>tree.find_window(fn=lambdacon:'Firefox'incon.name)Container(window=25165827,type='con',class='firefox')>>>tree.find_workspace(fn=lambdaw:w.num==2)Container(type='workspace',name='2')>>>forwinintree.windows():...ifwin.window_class=='URxvt':...print(win)...<Containertype='con'class='URxvt'>>>>list(tree.filter(fn=lambdacon:con.is_windowandcon.window_class=='mpv'))[]>>>list(tree.filter(fn=lambdacon:con.is_windowandcon.window_class=='mpv',i3=True))[Container(window=44040194,type='con',class='mpv')]Getting workspaces and outputs>>>importi3pie>>>i3=i3pie.Connection()>>>forworkspaceini3.get_workspaces():...print(workspace.name)...12>>>foroutputini3.get_outputs():...print(output.name)...HDMI-A-0xroot-0Getting marks and binding modes>>>importi3pie>>>i3=i3pie.Connection()>>>print(i3.get_marks())<MarksReply['a','_mark']>>>>print(i3.get_binding_modes())<BindingModesReply['open','i3','default']>Subscribe to eventsfromi3pieimportEvent,Connectiondefcallback(self,conn,event,data):window=data['container']ifdata['change']!='new'ornotwindow:returnwindow.command('floating enable')withConnection()asi3:i3.subscribe(Event.WINDOW,callback)i3.listen()ExamplesCycling workspacesimporti3pie,argparsedefmain(i3):parser=argparse.ArgumentParser(description="Cycle i3 workspaces")group=parser.add_mutually_exclusive_group(required=True)group.add_argument("-next",action="store_true",help="focus next workspace")group.add_argument("-prev",action="store_true",help="focus previous workspace")args=parser.parse_args()tree=i3.get_tree()workspaces=list(tree.workspaces())current=tree.current_workspace()idx=workspaces.index(current)direction=1ifargs.nextelse-1target=workspaces[(idx+direction)%len(workspaces)]i3.command(f'workspace "{target.name}"')if__name__=="__main__":withi3pie.Connection()asi3:main(i3)