コード例 #1
1
ファイル: rotate_right.py プロジェクト: meganerd/bin
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')
コード例 #2
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'])
コード例 #3
0
def i3rnwps():
    rnwps = {}
    wps = i3.get_workspaces()
    for wp in wps:
        workspace = i3.filter(num=wp['num'])
        if not workspace:
            continue
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        instances = {}
        # Adds windows and their ids to the rnwps dictionary
        if len(windows) == 1:
            win =windows[0]
            if win.has_key('window_properties'):
                rnwps[workspace['name']] = "%i: %s" % (workspace['num'], win['window_properties']['class'])
        elif len(windows) == 0: 
            rnwps[workspace['name']] = "%i: Empty" % (workspace['num'])
        else:
            names={}
            for win in windows:
                if win.has_key('window_properties'):
                    if not names.has_key(win['window_properties']['class']):
                        names[win['window_properties']['class']]=1
                    else:
                        names[win['window_properties']['class']]=names[win['window_properties']['class']]+1
            str="%i: " %(workspace['num'])
            for name in names.keys():
               str+="%ix%s " %(names[name], name)
            rnwps[workspace['name']] = str 
    return rnwps
コード例 #4
0
ファイル: i3_actions.py プロジェクト: plankiton/i3ci
def _get_window_workspace(win_id):
    cworkspaces = cur_workspaces.get_cur_workspaces()
    for ws in cworkspaces:
        ws_tree = i3.filter(name=ws)
        if i3.filter(tree=ws_tree, id=win_id):
            return ws
    return None
コード例 #5
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'])
コード例 #6
0
ファイル: winmenu.py プロジェクト: karlch/dotfiles
def i3clients():
    """Populate a dictionary with window strings for rofi.

    Structure of the dictionary:
        key: Formatted string containing workspace name and window name.
        value: ID of the window to be able to focus it.

    Return:
        The generated dictionary.
    """
    clients = {}
    tree = i3.get_tree()
    # Iterate over all workspaces
    for ws in i3.get_workspaces():
        wsname = ws["name"]
        wsshow = re.sub(r'[0-9]+(:)', "", wsname)
        workspace = i3.filter(tree, name=wsname)[0]
        # We do not want to go to the focused window
        windows = [
            win for win in i3.filter(workspace, nodes=[]) if not win["focused"]
        ]
        # Build the formatted string to pass to rofi and add it to the
        # dictionary
        for window in windows:
            wsname = re.sub("<.*?>", "", wsshow)
            win_str = "%-6s %-50s" % (wsname, window["name"])
            clients[win_str] = window["id"]
    return clients
コード例 #7
0
ファイル: i3_actions.py プロジェクト: plankiton/i3ci
def _get_window_ids_of_workspace(ws):
    res = []
    wks = i3.filter(name=ws)
    wins = i3.filter(tree=wks, nodes=[])
    for w in wins:
        res.append(w['id'])
    return res
コード例 #8
0
ファイル: focus_next.py プロジェクト: meganerd/bin
def focus_next_on_any_output():

    # 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
    workspaces_num = [ ws['num'] for ws in workspaces ]

    # Get visible nodes 
    nodes = [ i3.filter(num=ws_num)[0]['nodes'] for ws_num in workspaces_num ]

    # Get focused node
    curr = i3.filter(nodes, focused=True)[0]

    # Get ids of all nodes
    ids = [win['id'] for win in i3.filter(nodes, nodes=[])]

    # Get index of next node
    next_idx = (ids.index(curr['id']) + 1) % len(ids)

    # Set id of next node
    next_id = ids[next_idx]

    # Focus next node
    i3.focus(con_id=next_id)
コード例 #9
0
ファイル: switchto.py プロジェクト: joelermantraut/dotfiles
def cycle(window_exe, window_title, window_class):
    current = i3.filter(nodes=[], focused=True)

    try:
        current_title = current[0]["window_properties"]["title"]
        current_class = current[0]["window_properties"]["class"]
        # There are not this parameters in current
        # That happens when trying to run a program in a empty workspace
    except:
        i3.command('exec', window_exe)
        return

    if current_class == window_class or current_title == window_title:
        return
    else:
        other = i3.filter(nodes=[], focused=False)
        for window in other:
            try:
                this_window_title = window['window_properties']['title']
                this_window_class = window['window_properties']['class']
                if this_window_class == window_class or this_window_title == window_title:
                    i3.focus(con_id=window['id'])
                    return
            except:
                pass

    i3.command('exec', window_exe)
コード例 #10
0
def i3clients():
    """
    Returns a dictionary of key-value pairs of a window text and window id.
    Each window text is of format "[workspace] window title (instance number)"
    """
    clients = {}
    for ws_num in range(1, 11):
        workspace = i3.filter(num=ws_num)
        if not workspace:
            continue
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        instances = {}

        def windows_all():
            for window in windows:
                if window['window'] is not None:
                    yield window
                for node in window['floating_nodes']:
                    for subwindow in node['nodes']:
                        yield subwindow

        # Adds windows and their ids to the clients dictionary
        for window in windows_all():
            win_str = '[%s] %s' % (workspace['name'], window['name'])
            # Appends an instance number if other instances are present
            if win_str in instances:
                instances[win_str] += 1
                win_str = '%s (%d)' % (win_str, instances[win_str])
            else:
                instances[win_str] = 1
            clients[win_str] = window['id']
    return clients
コード例 #11
0
def i3clients():
    """
    Returns a dictionary of key-value pairs of a window text and window id.
    Each window text is of format "[workspace] window title (instance number)"
    """
    clients = {}
    for ws_num in range(1,11):
        workspace = i3.filter(num=ws_num)
        if not workspace:
            continue
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        instances = {}

        # Adds windows and their ids to the clients dictionary
        for window in windows:
            winprops = window.get("window_properties", {})
            cls = winprops.get("class", "empty")

            win_str = '[%s] %s "%s"' % (workspace['name'], cls, window['name'])
            # Appends an instance number if other instances are present
            if win_str in instances:
                instances[win_str] += 1
                win_str = '%s (%d)' % (win_str, instances[win_str])
            else:
                instances[win_str] = 1
            clients[win_str] = window['id']
    return clients
コード例 #12
0
ファイル: winmenu.py プロジェクト: karlch/dotfiles
def i3clients():
    """Populate a dictionary with window strings for rofi.

    Structure of the dictionary:
        key: Formatted string containing workspace name and window name.
        value: ID of the window to be able to focus it.

    Return:
        The generated dictionary.
    """
    clients = {}
    tree = i3.get_tree()
    # Iterate over all workspaces
    for ws in i3.get_workspaces():
        wsname = ws["name"]
        wsshow = re.sub(r'[0-9]+(:)', "", wsname)
        workspace = i3.filter(tree, name=wsname)[0]
        # We do not want to go to the focused window
        windows = [win for win in i3.filter(workspace, nodes=[])
                   if not win["focused"]]
        # Build the formatted string to pass to rofi and add it to the
        # dictionary
        for window in windows:
            wsname = re.sub("<.*?>", "", wsshow)
            win_str = "%-6s %-50s" % (wsname, window["name"])
            clients[win_str] = window["id"]
    return clients
コード例 #13
0
ファイル: utils.py プロジェクト: sergiogbr/config.mac
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']
コード例 #14
0
ファイル: utils.py プロジェクト: sergiogbr/config.mac
def get_window_workspace(win_id):
    cworkspaces = get_current_workspaces()
    for wks in cworkspaces:
        ws_tree = i3.filter(name=wks)
        if i3.filter(tree=ws_tree, id=win_id):
            return wks
    return None
コード例 #15
0
def i3rnwps():
    rnwps = {}
    wps = i3.get_workspaces()
    for wp in wps:
        workspace = i3.filter(num=wp['num'])
        if not workspace:
            continue
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        instances = {}
        # Adds windows and their ids to the rnwps dictionary
        if len(windows) == 1:
            win = windows[0]
            if win.has_key('window_properties'):
                rnwps[workspace['name']] = "%i: %s" % (
                    workspace['num'], win['window_properties']['class'])
        elif len(windows) == 0:
            rnwps[workspace['name']] = "%i: Empty" % (workspace['num'])
        else:
            names = {}
            for win in windows:
                if win.has_key('window_properties'):
                    if not names.has_key(win['window_properties']['class']):
                        names[win['window_properties']['class']] = 1
                    else:
                        names[win['window_properties']['class']] = names[
                            win['window_properties']['class']] + 1
            str = "%i: " % (workspace['num'])
            for name in names.keys():
                str += "%ix%s " % (names[name], name)
            rnwps[workspace['name']] = str
    return rnwps
コード例 #16
0
ファイル: utils.py プロジェクト: sergiogbr/config.mac
def get_workspace_of_window(win_id):
    ''' Returns the workspace name of the specified window. '''
    cworkspaces = get_current_workspaces()
    for wks in cworkspaces:
        ws_tree = i3.filter(name=wks)
        if i3.filter(tree=ws_tree, id=win_id):
            return wks
    return None
コード例 #17
0
def get_windows_from_current_workspace():
    res = []
    ws = get_current_workspace()
    workspace = i3.filter(name=ws)
    if workspace:
        workspace = workspace[0]
        return i3.filter(workspace, nodes=[])
    return res
コード例 #18
0
def getIds():
    num = i3.filter(i3.get_workspaces(), focused=True)[0]['num']
    ws_nodes = i3.filter(num=num)[0]['nodes']
    ws_nodes = ws_nodes + i3.filter(num=num)[0]['floating_nodes']
    curr = i3.filter(ws_nodes, focused=True)[0]

    ids = [win['id'] for win in i3.filter(ws_nodes, nodes=[])]

    return ids, curr['id']
コード例 #19
0
ファイル: utils.py プロジェクト: sergiogbr/config.mac
def get_window_ids(workspace):
    ''' Returns the windows IDs of the window contained on the specified
    workspace. '''
    res = []
    wks = i3.filter(name=workspace)
    wins = i3.filter(tree=wks, nodes=[])
    for w in wins:
        res.append(w['id'])
    return res
コード例 #20
0
def get_scratchpad(unused=None):
    """
    Get all windows on the scratchpad.

    NOTE: The argument is not used but needed for compatibilty with get_windows
    """
    scratchpad = i3.filter(name="__i3_scratch")[0]
    nodes = scratchpad["floating_nodes"]
    windows = i3.filter(tree=nodes, nodes=[])
    return create_lookup_table(windows)
コード例 #21
0
def get_windows_from_current_workspace():
    res = []
    ws = get_current_workspace()
    workspace = i3.filter(name=ws)
    if workspace:
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        for window in windows:
            res.append(window['id'])
    return res
コード例 #22
0
ファイル: winmenu.py プロジェクト: nathantypanski/dotfiles
def i3clients():
    """
    Returns a dictionary with convoluted strings with window information as keys, 
    and the i3 window id as values. Each window text is of format 
    "[workspace] mark window title (instance number)."
    """
    clients = {}
    lengths = {'workspace': 0, 'mark': 0}
    tree = i3.get_tree()
    for ws in i3.get_workspaces():
        wsname = ws['name']
        if len(wsname) > lengths['workspace']:
            lengths['workspace'] = len(wsname)
        workspace = i3.filter(tree, name=wsname)
        if not workspace:
            continue
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        instances = {}
        # Adds windows and their ids to the clients dictionary
        for window in windows:
            windowdict = {
                    'con_id': window['id'], \
                    'ws': wsname, \
                    'name': window['name']}
            try: 
                windowdict['mark'] = window['mark']
                if len(window['mark']) > lengths['mark']:
                    lengths['mark'] = len(window['mark'])
            except KeyError:
                windowdict['mark'] = ""
            if window['name'] in instances: 
                instances[window['name']] += 1
            else: 
                instances[window['name']]  = 1
            windowdict['instance'] = instances[window['name']]
            # win_str = '[%s] %s' % (workspace['name'], window['name'])
            clients[window['id']] = windowdict

    # Now build the strings to pass to dmenu: 
    newdict = {}
    clientlist = []
    for con_id in clients.keys():
        clientlist.append(con_id)
    for con_id in clientlist:
        wslen = lengths['workspace']
        mlen = lengths['mark']
        win_str = '[{k:<{v}}] {l:<{w}} {m} ({n})'.format(\
                k=clients[con_id]['ws'], v=wslen, \
                l=clients[con_id]['mark'], w=mlen, \
                m=clients[con_id]['name'], \
                n=clients[con_id]['instance'])
        clients[win_str] = clients[con_id]
        del clients[con_id]
    return clients
コード例 #23
0
ファイル: winmenu.py プロジェクト: janoliver/i3-py-scripts
def i3clients():
    """
    Returns a dictionary with convoluted strings with window information as keys, 
    and the i3 window id as values. Each window text is of format 
    "[workspace] mark window title (instance number)."
    """
    clients = {}
    lengths = {'workspace': 0, 'mark': 0}
    tree = i3.get_tree()
    for ws in i3.get_workspaces():
        wsname = ws['name']
        if len(wsname) > lengths['workspace']:
            lengths['workspace'] = len(wsname)
        workspace = i3.filter(tree, name=wsname)
        if not workspace:
            continue
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        instances = {}
        # Adds windows and their ids to the clients dictionary
        for window in windows:
            windowdict = {
                    'con_id': window['id'], \
                    'ws': wsname, \
                    'name': window['name']}
            try: 
                windowdict['mark'] = window['mark']
                if len(window['mark']) > lengths['mark']:
                    lengths['mark'] = len(window['mark'])
            except KeyError:
                windowdict['mark'] = ""
            if window['name'] in instances: 
                instances[window['name']] += 1
            else: 
                instances[window['name']]  = 1
            windowdict['instance'] = instances[window['name']]
            # win_str = '[%s] %s' % (workspace['name'], window['name'])
            clients[window['id']] = windowdict

    # Now build the strings to pass to dmenu: 
    newdict = {}
    clientlist = []
    for con_id in clients.keys():
        clientlist.append(con_id)
    for con_id in clientlist:
        wslen = lengths['workspace']
        mlen = lengths['mark']
        win_str = u'[{k:<{v}}] {l:<{w}} {m} ({n})'.format(\
                k=clients[con_id]['ws'], v=wslen, \
                l=clients[con_id]['mark'], w=mlen, \
                m=clients[con_id]['name'], \
                n=clients[con_id]['instance'])
        clients[win_str] = clients[con_id]
        del clients[con_id]
    return clients
コード例 #24
0
ファイル: i3_actions.py プロジェクト: plankiton/i3ci
def _get_windows_from_workspace(ws):
    res = []
    if ws is None:
        ws = cur_workspace.feed()
    workspace = i3.filter(name=ws)
    if workspace:
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        for window in windows:
            res.append(window['id'])
    return res
コード例 #25
0
def focus_next():
    num = i3.filter(i3.get_workspaces(), focused=True)[0]['num']
    ws_nodes = i3.filter(num=num)[0]['nodes']
    curr = i3.filter(ws_nodes, focused=True)[0]

    ids = [win['id'] for win in i3.filter(ws_nodes, nodes=[])]

    next_idx = (ids.index(curr['id']) + 1) % len(ids)
    next_id = ids[next_idx]

    i3.focus(con_id=next_id)
コード例 #26
0
ファイル: utils.py プロジェクト: sergiogbr/config.mac
def get_windows_from_workspace(ws):
    ''' Returns all the window IDs for the specified workspace. '''
    res = []
    if ws is None:
        ws = get_current_workspace()
    workspace = i3.filter(name=ws)
    if workspace:
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        for window in windows:
            res.append(window['id'])
    return res
コード例 #27
0
def cycle():
    # 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 original windows
    for window in current:
        i3.focus(con_id=window['id'])
コード例 #28
0
def fill_apps(*_):
    for con in i3.filter(type="workspace"):
        if con["name"] in I3_VETO_NAMES: continue
        store.append(["Workspace: " + con["name"], con["id"], "", "gtk-home"])
    for app in Gio.app_info_get_all():
        store.append([app.get_name(), -1, app.get_id(), "gtk-execute"])
        apps[app.get_id()] = app
    for con in i3.filter(type="con", nodes=[]):
        if con["name"] in I3_VETO_NAMES: continue
        store.append(["App: " + con["name"], con["id"], "", "gtk-fullscreen"])
    store.append(["Exit foolauncher", -2, "EXIT", "gtk-quit"])
    selectFirst()
コード例 #29
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def cycle():
    # 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 original windows
    for window in current:
        i3.focus(con_id=window['id'])
コード例 #30
0
ファイル: i3_cycle.py プロジェクト: quintenpalmer/dotfiles
def copied_alt_tab():

    num = i3.filter(i3.get_workspaces(), focused=True)[0]['num']
    all_nodes = flatten_lists(list(map(get_nodes, i3.filter())))
    curr = i3.filter(all_nodes, focused=True)[0]
    print(get_id(curr))

    ids = list(map(get_id, all_nodes)) + [get_id(curr)]
    print(ids)

    next_id = ids[(ids.index(curr['id']) + 2) % len(ids)]
    print(next_id)

    i3.focus(con_id=next_id)
コード例 #31
0
ファイル: utils.py プロジェクト: sergiogbr/config.mac
def get_windows(win_inst=None, mon='all'):
    ''' Returns a dictionary of key-value pairs of a window text and
    window id.
    Each window text is of format "[instance] window title (instance number)"
    '''
    dpy = display.Display()
    res = {}
    lmax = 0
    for ws in get_current_workspaces(mon):
        workspace = i3.filter(name=ws)
        if not workspace:
            continue
        workspace = workspace[0]
        wname = workspace['name']
        windows = i3.filter(workspace, nodes=[])
        instances = {}
        # adds windows and their ids to the clients dictionary
        for window in windows:
            if window['window'] is None:
                continue
            xwin = dpy.create_resource_object('window', window['window'])
            inst, _ = xwin.get_wm_class()
            if inst:
                eligible = win_inst is None or win_inst == inst
                if eligible and mon != 'all':
                    # list only the windows on the specified output
                    id_ = window['id']
                    tree = i3.filter(name=mon)
                    eligible = i3.filter(tree, id=id_)
                if eligible:
                    win = window['name']
                    if win_inst:
                        win = u'({0}) {1}'.format(wname, win)
                    else:
                        if len(inst) + 2 > lmax:
                            lmax = len(inst) + 2
                        win = u'({0}) [{1}] {2}'.format(wname, inst, win)
                    # appends an instance number if other instances are
                    # present
                    if win in instances:
                        instances[win] += 1
                        win = '%s (%d)' % (win, instances[win])
                    else:
                        instances[win] = 1
                    res[win] = window['id']
    if lmax:
        res = _format_dict(res, lmax)
    return res
コード例 #32
0
ファイル: workspace.py プロジェクト: Tehforsch/i3Contexts
 def empty(self):
     i3TreeNodes = i3.filter(name=self.name)
     # This workspace is not open - it's empty
     if len(i3TreeNodes) == 0:
         return True
     # If it does not have child nodes, it's empty
     return len(i3TreeNodes[0]["nodes"]) == 0
コード例 #33
0
ファイル: i3-cycle.py プロジェクト: 0xANDREW/bins
def cycle():
    """
    Cycles the windows in an i3 workspace.
    """

    last_focused_id = _load()

    # Get focused workspace name
    wksp_name = _get_focused_workspace()['name']

    # Get actual workspace tree object
    wksp = i3.filter(type='workspace', name=wksp_name)[0]

    # Get list of all windows in workspace
    wksp_windows = _leaves(wksp['nodes'])
    window_ids = map(lambda n: n['id'], wksp_windows)

    # Go to next window if saved state exists
    if last_focused_id in window_ids:
        next_idx = window_ids.index(last_focused_id) + 1

        if next_idx >= len(wksp_windows):
            next_idx = 0

        next_focus_id = wksp_windows[next_idx]['id']

    # Set default state, first unfocused
    else:
        unfocused = filter(lambda n: not n['focused'], wksp_windows)
        next_focus_id = unfocused[0]['id']

    _write(next_focus_id)
    i3.focus(con_id=next_focus_id)
コード例 #34
0
ファイル: termdir.py プロジェクト: BitOfAByte/termdir
def main():
    '''
    Messy code that should be pretty reliable
    I have no idea how to chose a shell if a process has multiple subprocesses
    '''
    focused = i3.filter(focused=True)[0]
    window_id = focused['window']
    if window_id is None:
        #no focused window
        print(DEFAULT_DIR)
        return
    parent_pid_cmd = 'xprop -id {} | grep PID'.format(window_id)
    parent_pid_line = subprocess.run(parent_pid_cmd, shell=True,
                                     stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
    parent_pid = int(parent_pid_line.split(' ')[-1])
    child_pid_cmd = 'ps --ppid {}'.format(parent_pid)
    child_pids_sub = subprocess.run(child_pid_cmd, shell=True, stdout=subprocess.PIPE)
    child_pids = child_pids_sub.stdout.decode('utf-8').split('\n')[1:-1]
    child_pids = [line.strip() for line in child_pids]
    child_pids = [(int(val.split(' ')[0]), val.split(' ')[-1]) for val in child_pids]
    child_pids = [val[0] for val in child_pids if val[1] in SHELLS]
    if child_pids:
        child_pid = child_pids[0]       #should probably be better planned
        child_path_cmd = 'pwdx {}'.format(child_pid)
        child_path_line = subprocess.run(child_path_cmd, shell=True,
                                         stdout=subprocess.PIPE).stdout.decode('utf-8')
        child_path = child_path_line[len(str(child_pid))+2:]
        print(child_path)
    else:
        print(DEFAULT_DIR)
コード例 #35
0
def set_layout():
    """
        Set the layout/split for the currently
        focused window to either vertical or
        horizontal, depending on its width/height
    """
    current_win = i3.filter(nodes=[], focused=True)
    for win in current_win:
        parent = find_parent(win["id"])

        if (
            parent
            and "rect" in parent
            and parent["layout"] != "tabbed"
            and parent["layout"] != "stacked"
        ):
            height = parent["rect"]["height"]
            width = parent["rect"]["width"]

            if height > width:
                new_layout = "vertical"
            else:
                new_layout = "horizontal"

            i3.split(new_layout)
コード例 #36
0
 def test_filter_function_wikipedia(self):
     """You have to have a Wikipedia tab opened in a browser."""
     func = lambda node: 'Wikipedia' in node['name']
     nodes = i3.filter(function=func)
     self.assertTrue(nodes != [])
     for node in nodes:
         self.assertTrue('free encyclopedia' in node['name'])
コード例 #37
0
def cycle():
    """
    Cycles the windows in an i3 workspace.
    """

    last_focused_id = _load()

    # Get focused workspace name
    wksp_name = _get_focused_workspace()['name']

    # Get actual workspace tree object
    wksp = i3.filter(type='workspace', name=wksp_name)[0]

    # Get list of all windows in workspace
    wksp_windows = _leaves(wksp['nodes'])
    window_ids = map(lambda n: n['id'], wksp_windows)

    # Go to next window if saved state exists
    if last_focused_id in window_ids:
        next_idx = window_ids.index(last_focused_id) + 1

        if next_idx >= len(wksp_windows):
            next_idx = 0

        next_focus_id = wksp_windows[next_idx]['id']

    # Set default state, first unfocused
    else:
        unfocused = filter(lambda n: not n['focused'], wksp_windows)
        next_focus_id = unfocused[0]['id']

    _write(next_focus_id)
    i3.focus(con_id=next_focus_id)
コード例 #38
0
ファイル: noteit.py プロジェクト: ya790206/auto_config
def main():
    wid = str([i.get('window') for i in i3.filter(nodes=[]) if i.get('focused')][0])

    home = expanduser("~")
    todo_db_path = os.path.join(home, '.i3_title_todo')
    if os.path.exists(todo_db_path):
        with open(todo_db_path, 'r') as ftr:
            db = json.loads(ftr.read())
    else:
        db = {}

    answer = dmenu(db.get(wid, []), dmenu_cmd('note: ')).strip()

    if answer:
        print(type(wid))
        todo_list = db.get(wid, [])
        print(type(wid))
        if answer not in todo_list:
            todo_list.append(answer)
        print(type(wid))
        db[wid] = todo_list
        with open(todo_db_path, 'w') as ftr:
            ftr.write(json.dumps(db))
        answer = "<span foreground='red'>%s</span>" % wid
        os.system('''i3-msg title_format "<b>%class | %title | {note}</b> " '''.format(note=answer))
コード例 #39
0
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 ''
コード例 #40
0
ファイル: test.py プロジェクト: Adaephon-GH/i3-py
 def test_filter_function_wikipedia(self):
     """You have to have a Wikipedia tab opened in a browser."""
     func = lambda node: 'Wikipedia' in node['name']
     nodes = i3.filter(function=func)
     self.assertTrue(nodes != [])
     for node in nodes:
         self.assertTrue('free encyclopedia' in node['name'])
コード例 #41
0
ファイル: cur_output.py プロジェクト: syl20bnr/i3ci
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
コード例 #42
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
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')
コード例 #43
0
def focused():
  focs=i3.filter(focused=True)
  for n in focs:
    props = n.get('window_properties',{})
    t = props.get('title','')
    c = props.get('class', '')
    focwin = '{} {}'.format(t, ['{}','({})'][int(len(c)>0)].format(c))
  return focwin
コード例 #44
0
ファイル: cycle.py プロジェクト: janoliver/i3-py-scripts
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'])
コード例 #45
0
ファイル: workspaces.py プロジェクト: tonk/dotfiles
def rename(args):
    cur_ws = i3.filter(i3.get_workspaces(), focused = True)[0]
    input = sh.i3_input.bake(P = "Rename workspace: ")

    if "--keep-num" in args and cur_ws["num"]:
        input(F = ('rename workspace to "%d: %%s"' % cur_ws["num"]))
    else:
        input(F = 'rename workspace to "%s"')
コード例 #46
0
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'])
コード例 #47
0
ファイル: active.py プロジェクト: j-a-m-l/.dot
def focus(event):

    # Restore old focused window TODO first workspace
    if 'old' in event:
        unfocused = i3.filter(tree=event['old'], nodes=[])
        for window in unfocused:
            set_border(window, focused_inactive_border)

    # Change new focused window
    if 'current' in event:
        unfocused = i3.filter(tree=event['current'], nodes=[], focused=False)
        for window in unfocused:
            set_border(window, unfocused_border)

        focused = i3.filter(tree=event['current'], nodes=[], focused=True)
        for window in focused:
            set_border(window, focused_border)
コード例 #48
0
 def test_filter2(self):
     unfocused_windows = i3.filter(focused=False)
     parent_count = 0
     for window in unfocused_windows:
         self.assertEqual(window['focused'], False)
         if window['nodes'] != []:
             parent_count += 1
     self.assertGreater(parent_count, 0)
コード例 #49
0
ファイル: utils.py プロジェクト: sergiogbr/config.mac
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
コード例 #50
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')
コード例 #51
0
ファイル: test.py プロジェクト: Adaephon-GH/i3-py
 def test_filter2(self):
     unfocused_windows = i3.filter(focused=False)
     parent_count = 0
     for window in unfocused_windows:
         self.assertEqual(window['focused'], False)
         if window['nodes'] != []:
             parent_count += 1
     self.assertGreater(parent_count, 0)
コード例 #52
0
ファイル: children.py プロジェクト: daedric/i3scripts
def get_scratchpad_children():
    container = i3.filter(name="__i3_scratch")[0]
    children = container["floating_nodes"]
    nodes = []
    for child in children:
        nodes += child.get("nodes", [])

    return _format_nodes(nodes)
コード例 #53
0
ファイル: focused_window.py プロジェクト: kktt007/dotfiles-11
def focused():
    focs = i3.filter(focused=True)
    for n in focs:
        props = n.get('window_properties', {})
        t = props.get('title', '')
        c = props.get('class', '')
        focwin = '{} {}'.format(t, ['{}', '({})'][int(len(c) > 0)].format(c))
    return focwin
コード例 #54
0
ファイル: free_workspaces.py プロジェクト: syl20bnr/i3ci
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
コード例 #55
0
ファイル: focus_num.py プロジェクト: tonk/dotfiles
def focus_num(switch_to_num):
    parent = i3.parent(i3.filter(focused=True)[0]['id'])

    print(parent)
    if len(parent['nodes']) >= switch_to_num:
        switch_to_cont = parent['nodes'][switch_to_num]
        i3.focus(con_id=switch_to_cont['id'])
        while i3.focus('child')[0]:
            pass
コード例 #56
0
ファイル: bar.py プロジェクト: rstnd/statusbar
def title():
    try:
        focused = i3.filter(nodes=[], focused=True)[0]
        t = focused["window_properties"]["title"]
    except:
        t = ""
    if len(t) > 35:
        t = t[:35]
    return t
コード例 #57
0
ファイル: alttab.py プロジェクト: BasedArno/config-files
def focus_next():
	# get the workspaces
	num = i3.filter(i3.get_workspaces(), focused=True)[0]['num']
	# get all windows
	all_nodes = i3.filter(num=num)[0]['nodes']
	#for node in i3.filter(num=num)[0]['floating_nodes']:
	#	if not node['window'] == None:
	#		all_nodes = all_nodes + node
	#all_nodes = all_nodes + i3.filter(num=num)[0]['floating_nodes']
	# find the currently focused window
	current_win = i3.filter(all_nodes, focused=True)[0]

	# find all id's
	all_ids = [win['id'] for win in i3.filter(all_nodes, nodes=[])]
	# get the next one
	next_idx = (all_ids.index(current_win['id']) + 1) % len(all_ids)
	next_win = all_ids[next_idx]

	# fokus
	i3.focus(con_id=next_win)
コード例 #58
0
ファイル: winmenu.py プロジェクト: jkoz/home
def i3clients():
    clients = {}
    for ws_num in range(1,11):
        workspace = i3.filter(num=ws_num)
        if not workspace:
            continue
        workspace = workspace[0]
        windows = i3.filter(workspace, nodes=[])
        instances = {}
        # Adds windows and their ids to the clients dictionary
        for window in windows:
            win_str = '[%s] %s' % (workspace['name'], window['name'])
            # Appends an instance number if other instances are present
            if win_str in instances:
                instances[win_str] += 1
                win_str = '%s (%d)' % (win_str, instances[win_str])
            else:
                instances[win_str] = 1
            clients[win_str] = window['id']
    return clients
コード例 #59
0
def get_all_windows():
	'''Get all windows INCLUDING floating ones'''
	windows = []
	for root in i3.filter():
		for output in root['nodes']:
			for section in output['nodes']:
				for workspace in section['nodes']:
					if workspace['nodes']:
						windows.extend(get_window_tree_leafs(workspace['nodes']))
					if workspace['floating_nodes']:
						windows.extend(get_window_tree_leafs(workspace['floating_nodes']))
	return windows