Example #1
0
def logout():
    from feeders import logout as logout_feeder
    from feeders import confirm
    proc = i3ci_menu.call(f=DMENU_FONT,
                      lmax=4,
                      nb='#002b36',
                      nf='#eee8dc',
                      sb='#cb4b16',
                      sf='#eee8d5')
    reply = proc.communicate(
        '\n'.join(logout_feeder.feed()).encode('utf-8'))[0]
    if reply:
        action = Action()
        action.add_action(Action.set_mode, ("confirm {0} ?".format(reply),))
        action.process()
        proc = i3ci_menu.call(f=DMENU_FONT,
                          lmax=4,
                          nb='#002b36',
                          nf='#eee8dc',
                          sb='#cb4b16',
                          sf='#eee8d5')
        conf = proc.communicate('\n'.join(confirm.feed()).encode('utf-8'))[0]
        if conf == 'OK':
            action = Action()
            default_mode(action)
            action.process()
            exec_ = os.path.join(MODULE_PATH, 'i3-exit')
            cmd = '{0} --{1}'.format(exec_, reply)
            Popen(cmd, shell=True)
            return
    default_mode()
Example #2
0
def send_workspace_to_output(feeder, output='all'):
    ''' Send the current workspace to the selected output. '''
    if output == 'all':
        # be sure that the workspace exists
        cur_wks = cur_workspace.get_current_workspace()
        if not cur_wks:
            return
        outs = feeder.get_outputs_dictionary()
        # remove the current output
        coutput = cur_output.get_current_output()
        fouts = [k for k, v in outs.iteritems() if v != coutput]
        input_ = '\n'.join(sorted(fouts)).encode('utf-8')
        size = get_max_row(len(input_))
        proc = i3ci_menu.call(f=DMENU_FONT,
                          h=DMENU_HEIGHT,
                          lmax=size,
                          r=False,
                          sb='#268bd2')
        reply = proc.communicate(input_)[0]
        if reply:
            reply = reply.decode('utf-8')
            output = outs[reply]
    action = Action()
    action.add_action(Action.send_workspace_to_output, (output,))
    default_mode(action)
    action.process()
Example #3
0
def launch_app(feeder, app=None, output='all', free=False):
    ''' Launch an application on the specified monitor.
    output='all' means the current workspace on the current monitor.
    If free is true then the application is opened in a new workspace.
    '''
    reply = app
    if not reply:
        input_ = feeder.feed().encode('utf-8')
        size = get_max_row(len(input_))
        proc = i3ci_menu.call(lmax=size,
                          f=DMENU_FONT,
                          h=DMENU_HEIGHT)
        reply = proc.communicate(input_)[0]
    if reply:
        reply = reply.decode('utf-8')
        if '-cd' in reply:
            # MODULE_PATH = os.path.dirname(os.path.abspath(__file__))
            # DMENU = os.path.normpath(os.path.join(MODULE_PATH,
            # '../../bin/i3ci_menu'))
            xcwd = Popen('xcwd', stdin=PIPE, stdout=PIPE).communicate()[0]
            reply = '"' + reply + ' ' + xcwd + '"'
        if not free and (output == 'all' or
                         output == cur_output.get_current_output()):
            # open on the current workspace
            action = Action()
            action.add_action(Action.exec_, (reply,))
            default_mode(action)
            action.process()
        if not free and (output != 'all' and
                         output != cur_output.get_current_output()):
            # open on the visible workspace on another output
            otherw = cur_workspace.feed(output)
            action = Action()
            action.add_action(Action.jump_to_workspace, (otherw,))
            action.add_action(Action.exec_, (reply,))
            default_mode(action)
            action.process()
        elif free and (output == 'all' or
                       output == cur_output.get_current_output()):
            # free workspace on the current output
            freew = free_workspaces.get_free_workspaces()[0]
            action = Action()
            action.add_action(Action.jump_to_workspace, (freew,))
            action.add_action(Action.exec_, (reply,))
            default_mode(action)
            action.process()
        elif free and (output != 'all' and
                       output != cur_output.get_current_output()):
            # free workspace on another output
            freew = free_workspaces.get_free_workspaces()[0]
            action = Action()
            action.add_action(Action.focus_output, (output,))
            action.add_action(Action.jump_to_workspace, (freew,))
            action.add_action(Action.exec_, (reply,))
            default_mode(action)
            action.process()
    else:
        default_mode()
Example #4
0
def execute_cmd(feeder, prefix):
    ''' Execute: i3-msg prefix *user_choice* '''
    proc = i3ci_menu.call(p=feeder.get_prompt(prefix),
                      f=DMENU_FONT,
                      h=DMENU_HEIGHT,
                      sb='#cb4b16')
    reply = proc.communicate('\n'.join(feeder.feed(prefix)).encode('utf-8'))[0]
    if reply:
        reply = reply.decode('utf-8')
        cmd = reply
        if prefix:
            cmd = prefix + ' ' + cmd
        action = Action()
        action.add_action(Action.cmd, (cmd,))
        action.process()
Example #5
0
def jump_to_window(feeder, inst, output='all'):
    ''' Jump to the window chosen by the user using i3ci_menu. '''
    (wins, d) = feeder.feed(inst, output)
    size = get_max_row(len(wins))
    proc = i3ci_menu.call(f=DMENU_FONT,
                      lmax=size,
                      sb='#b58900')
    reply = proc.communicate('\n'.join(wins).encode('utf-8'))[0]
    if reply:
        reply = reply.decode('utf-8')
        action = Action()
        action.add_action(Action.jump_to_window, (d.get(reply),))
        default_mode(action)
        action.process()
    else:
        default_mode()
Example #6
0
def jump_to_workspace(feeder):
    ''' Jump to the workspace chosen by the user using i3ci_menu. '''
    input_ = '\n'.join(feeder.feed()).encode('utf-8')
    size = get_max_row(len(input_))
    proc = i3ci_menu.call(h=DMENU_HEIGHT,
                      lmax=size,
                      r=True,
                      sb='#d33682')
    reply = proc.communicate(input_)[0]
    if reply:
        reply = reply.decode('utf-8')
        action = Action()
        action.add_action(Action.jump_to_workspace, (reply,))
        default_mode(action)
        action.process()
    else:
        default_mode()
Example #7
0
def send_window_to_workspace(feeder):
    ''' Send the current window to the selected workspace. '''
    input_ = '\n'.join(feeder.feed()).encode('utf-8')
    size = get_max_row(len(input_))
    proc = i3ci_menu.call(f=DMENU_FONT,
                      h=DMENU_HEIGHT,
                      lmax=size,
                      r=True,
                      sb='#6c71c4')
    reply = proc.communicate(input_)[0]
    if reply:
        reply = reply.decode('utf-8')
        action = Action()
        action.add_action(Action.send_window_to_workspace, (reply,))
        default_mode(action)
        action.process()
    else:
        default_mode()
Example #8
0
def jump_to_currently_used_workspace(feeder, output='all'):
    ''' Jump to a curently used workspace on the specified outputs
    and chosen by the user using i3ci_menu.
    '''
    input_ = '\n'.join(feeder.feed(output)).encode('utf-8')
    size = get_max_row(len(input_))
    proc = i3ci_menu.call(f=DMENU_FONT,
                      h=DMENU_HEIGHT,
                      lmax=size,
                      r=True,
                      sb='#268bd2')
    reply = proc.communicate(input_)[0]
    if reply:
        reply = reply.decode('utf-8')
        action = Action()
        action.add_action(Action.jump_to_workspace, (reply,))
        default_mode(action)
        action.process()
    else:
        default_mode()
Example #9
0
def _choose_other_windows(feeder, output):
    '''
    Launch a i3ci_menu instance to select a window which is not on the current
    worspace.
    Return a tuple composed of the window name and the window id.
    Return None if nothing has been selected.
    '''
    (wins, d) = feeder.feed(output=output)
    size = get_max_row(len(wins))
    proc = i3ci_menu.call(f=DMENU_FONT,
                      lmax=size,
                      sb='#6c71c4')
    ws = cur_workspace.feed()
    excluded_wins = _get_window_ids_of_workspace(ws)
    if excluded_wins:
        # remove the wins of the current output from the list
        wins = [k for k, v in d.iteritems() if v not in excluded_wins]
    reply = proc.communicate('\n'.join(wins).encode('utf-8'))[0]
    if reply:
        reply = reply.decode('utf-8')
        return reply, d.get(reply)
    else:
        return None, None