def set_window_mark_callback(event, data, subscription): ''' Callback to automatically set a mark on a created window. ''' obj = 'container' con_id = None name = None window = None if event.setdefault(obj, None): con_id = event[obj].setdefault('id', None) name = event[obj].setdefault('name', None) window = event[obj].setdefault('window', None) if window: dpy = display.Display() xwin = dpy.create_resource_object('window', window) name, _ = xwin.get_wm_class() cnames = i3.msg('get_marks') if name in cnames: i = 1 bname = name name = '{0}-{1}'.format(bname, i) while name in cnames: i += 1 name = '{0}-{1}'.format(bname, i) if con_id and name: i3.msg('command', '[con_id={0}] mark "{1}"'.format(con_id, name)) thread.interrupt_main()
def rename_workspace(old, new_number): '''Rename a given workspace.''' m = workspace_number_re.match(old) if not m: return new = '%d%s' % (new_number, m.group('name')) return i3.msg(0, "rename workspace {} to {}".format(old, new))
def rename_workspace(old, new_number): """Rename a given workspace.""" m = workspace_number_re.match(old) if not m: return new = "%d%s" % (new_number, m.group("name")) return i3.msg(0, "rename workspace {} to {}".format(old, new))
def get_current_output(): workspaces = i3.msg('get_workspaces') workspace = i3.filter(tree=workspaces, focused=True) if workspace: return workspace[0]['output'] else: return None
def get_current_workspace(): ''' Returns the current workspace ''' workspaces = i3.msg('get_workspaces') workspace = i3.filter(tree=workspaces, focused=True) if workspace: return workspace[0]['name'] return ''
def get_current_workspace(mon='all'): ''' Returns the current workspace name. ''' workspaces = i3.msg('get_workspaces') if mon == 'all' or mon == get_current_output(): return i3.filter(tree=workspaces, focused=True)[0]['name'] else: return i3.filter(tree=workspaces, output=mon, visible=True)[0]['name']
def get_current_output(): ''' Returns the current output name (the output with focus) ''' workspaces = i3.msg('get_workspaces') workspace = i3.filter(tree=workspaces, focused=True) if workspace: return workspace[0]['output'] else: return None
def get_free_workspaces(): ''' Returns the free workspaces (the workspace with focus) ''' res = [] all_workspaces = workspaces.get_workspaces_no_prefix() used_workspaces = i3.msg('get_workspaces') for w in all_workspaces: if not i3.filter(tree=used_workspaces, name=w): res.append(w) return res
def get_outputs_dictionary(): ''' Returns a dictionary where key is a natural output name like "monitor 1" and value is the low level name like "xinerama-0"''' res = {} outputs = i3.msg('get_outputs') for i, o in enumerate(outputs): res['monitor {0}'.format(i + 1)] = o['name'] return res
def get_free_workspaces(): ''' Returns the free workspace names as a list ''' res = [] all_workspaces = get_workspace_name_catalog() used_workspaces = i3.msg('get_workspaces') for wks in all_workspaces: if not i3.filter(tree=used_workspaces, name=wks): res.append(wks) return res
def get_outputs_dictionary(): ''' Returns a dictionary where key is a natural output name like "monitor 1" and value is the low level name like "xinerama-0"''' res = {} outputs = i3.msg('get_outputs') for i, o in enumerate(outputs): res['monitor {0}'.format(i+1)] = o['name'] return res
def get_workspaces(mon='all'): ''' Returns a structure containing all the opened workspaces. ''' used = [] ws_tree = i3.msg('get_workspaces') outs = get_outputs_dictionary() for o in outs.itervalues(): if mon == 'all' or mon == o: for ws in get_workspace_name_catalog(): if i3.filter(tree=ws_tree, output=o, name=ws): used.append(ws) used.append('`') return sorted(used)
def get_current_workspaces(mon='all'): ''' Returns a list of the names of all currently used workspaces on the specified output. ''' all_ws = get_workspace_name_catalog() used = [] ws_tree = i3.msg('get_workspaces') outs = get_outputs_dictionary() for o in outs.itervalues(): if mon == 'all' or mon == o: for ws in all_ws: if i3.filter(tree=ws_tree, output=o, name=ws): used.append(ws) return sorted(used)
def get_cur_workspaces(output='all'): ''' Return a list of all currently used workspaces on the specified output. ''' all_ws = workspaces.get_workspaces_no_prefix() used = [] ws_tree = i3.msg('get_workspaces') outs = outputs.get_outputs_dictionary() for o in outs.itervalues(): if output == 'all' or output == o: for ws in all_ws: if i3.filter(tree=ws_tree, output=o, name=ws): used.append(ws) used.append('`') return sorted(used)
def main(socket, type, timeout, message): """ Excepts arguments and evaluates them. """ if not socket: socket = i3.get_socket_path() if not socket: print("Couldn't get socket path. Are you sure i3 is running?") return False # Initializes default socket with given path and timeout try: i3.default_socket(i3.Socket(path=socket, timeout=timeout)) except i3.ConnectionError: print("Couldn't connect to socket at '%s'." % socket) return False # Format input if type in i3.EVENT_TYPES: event_type = type event = message type = 'subscribe' elif type == 'subscribe': message = message.split(' ') message_len = len(message) if message_len >= 1: event_type = message[0] if message_len >= 2: event = ' '.join(message[1:]) else: event = '' else: # Let if fail event_type = '' try: if type == 'subscribe': i3.subscribe(event_type, event) else: output = i3.msg(type, message) print(output) except i3.i3Exception as i3error: print(i3error)
def load(): try: workspace_mapping = pickle.load(open(PATH, "rb")) except Exception: print("Can't find existing mappings...") sys.exit(1) for workspace in workspace_mapping: i3.msg( 'command', f"workspace {workspace['name']}", ) i3.msg( 'command', f"move workspace to output workspace['output']", ) for workspace in filter(lambda w: w['visible'], workspace_mapping): i3.msg( 'command', f"workspace workspace['name']", )
def get_current_workspace(output='all'): workspaces = i3.msg('get_workspaces') if output == 'all' or output == cur_output.feed(): return i3.filter(tree=workspaces, focused=True) else: return i3.filter(tree=workspaces, output=output, visible=True)
if workspace['visible']: return workspace['name'] if __name__ == '__main__': if len(sys.argv) < 2: showHelp() sys.exit(1) if sys.argv[1] == 'save': print("Storing...") workspace_mapping = {} for workspace in i3.get_workspaces(): workspace_mapping[workspace['name']] = workspace['output'] pickle.dump(workspace_mapping, open("%s/.i3/workspace_mapping" % os.path.expanduser("~"), "wb")) elif sys.argv[1] == 'restore': print("Restoring") try: workspace_mapping = pickle.load(open("%s/.i3/workspace_mapping" % os.path.expanduser("~"), "rb")) except Exception: print("Can't find existing mappings...") sys.exit(1) current_workspace = get_visible_workspace() for workspace in i3.get_workspaces(): if workspace['name'] in workspace_mapping: i3.msg('command', 'workspace %s' % workspace['name']) i3.msg('command', 'move workspace to output %s' % workspace_mapping[workspace['name']]) i3.msg('command', 'workspace %s' % current_workspace) else: showHelp() sys.exit(1)
def move_container_to_workspace(workspace): return i3.msg(0, "move container to workspace number {}".format(workspace))
def move_window_here(window): """Does `move workspace current` on the specified window.""" return i3.msg(0, "%s move workspace current" % i3.container(id=window))
def move_container_to_workspace(workspace): """Moves the current container to the selected workspace""" return i3.msg(0, "move container to workspace {}".format(workspace))
def goto_workspace(workspace): return i3.msg(0, "workspace {}".format(workspace))
import i3, sys # get a list of workspaces for workspace in i3.get_workspaces(): # get the workspace tree data workspace_tree = i3.filter(num=workspace.get('num')) # get a list of existing leaf windows in that workspace for window in i3.filter(workspace_tree, nodes=[]): # do something useful here if window.get('name').startswith(sys.argv[1]): i3.msg('command', '[con_id="{}"] focus'.format(window.get('id'))) print("1") sys.exit(1) print("0") sys.exit(0)
def process(self): i3.msg('command', ','.join(self._actions))
def move_window_here(window): '''Does `move workspace current` on the specified window.''' return i3.msg(0, "{} move workspace current".format(i3.container(id=window)))
def move_container_to_workspace(workspace): """Moves the current container to the selected workspace""" ret = i3.msg(0, "move container to workspace {}".format(workspace)) if follow or (follow_if_empty and is_current_workspace_empty()): goto_workspace(workspace) return ret
#!/usr/bin/python import i3 outputs = i3.get_outputs() output0 = outputs[0] output1 = outputs[1] for workspace in i3.get_workspaces(): if workspace['output'] == output1['name']: i3.msg('command', 'workspace %s' % workspace['name']) i3.msg('command', 'move workspace to output %s' % output0['name'])
def move_container_to_workspace(workspace): '''Moves the current container to the selected workspace''' return i3.msg(0, "move container to workspace {}".format(workspace))
#!/usr/bin/python import i3 outputs = i3.get_outputs() # set current workspace to output 0 i3.workspace(outputs[0]['current_workspace']) i3.msg('command', 'move workspace to output right') # ..and move it to the other output. # outputs wrap, so the right of the right is left ;) # rinse and repeat i3.workspace(outputs[2]['current_workspace']) i3.msg('command', 'move workspace to output left')
def move_window_here(window): '''Does `move workspace current` on the specified window.''' return i3.msg(0, "{} move workspace current".format( i3.container(id=window)))
def rename_workspace(old, new): '''Rename a given workspace.''' return i3.msg(0, "rename workspace {} to {}".format(old, new))
import sys import subprocess import i3 def workspaces(): reply = i3.msg( 'get_workspaces' ) return [ w[ 'name' ] for w in reply ] def win_menu( clients ): """ Displays a window menu using dmenu. Returns window id. """ command = [ '/usr/bin/dmenu' ] command += sys.argv[ 1 : ] dmenu = subprocess.Popen( command , stdin = subprocess.PIPE , stdout = subprocess.PIPE ) menu_str = '\n'.join( sorted( clients ) ) # Popen.communicate returns a tuple stdout, stderr win_str = dmenu.communicate( menu_str.encode( 'utf-8' ) )[ 0 ].decode( 'utf-8' ).rstrip() return win_str if __name__ == '__main__': clients = workspaces() ws_name = win_menu( clients ) if ws_name: i3.msg( 'command', 'workspace ' + ws_name )
Vim�UnDo�S���Sfya]�i�ؚ�[�JG^62�>.Ej5 Z��� _�3)����Z���26j) new_layout = 'horizontal'5�_�5����Z�� �45 sys.5�_�4����Z�� �35k5�_�4����Z��"�36k 5�_�5����Z��;�24k) new_layout = 'horizontal'�35l �46l i3.5�_�4����Z��R�35j5�_�3)����Z��Y�26j) new_layout = 'horizontal'5�_� 5����Z��p�45 i3.parse_msg_type5�_� 5����Z��q �45 5�_� ����Z����j import i3�k5�_� 3)����Z����24j) new_layout = 'horizontal' i3.fil5�_� 4����Z����355�_� 3)����Z����24j) new_layout = 'horizontal' 5�_� 6����Z��=�57k! #i3.split(new_layout)5�_�5����Z��@�46k os.5�_�5����Z��F�46k 5�_�5����Z��j�46k os.system('i3 split'5�_�5����Z��|�46k! os.system('i3 split '5�_�5!����Z��} �46k. os.system('i3 split '+ new_layout)5�_�5����Z����465�_�5����Z����46j i3.split(new_layout)5�_� 4����Z����355�_�5����Z��9�46j" // i3.split(new_layout)5�_�5����Z���46j i3.5�_�5����Z���46j i3.msg()5�_�5����Z���46j i3.msg()5�_�5����Z��$�46j i3.5�_�5����Z��$�46j i3.5�_�5����Z��1�46j 5��
def workspaces(): reply = i3.msg( 'get_workspaces' ) return [ w[ 'name' ] for w in reply ]