The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
2

How can I configure i3wm to make Alt+Tab action just like in Windows?

asked May 9 '13

rmn190 gravatar image

sometiems it would be convinent to enable that function. but how?

thanks

Comments

+1 for question because of the number of good reactions

joepd gravatar imagejoepd (May 14 '13)edit

6 answers

Sort by » oldest newest most voted
4

answered May 14 '13

updated Nov 13 '13

This is maybe not the most elegant way but just a first quick-and-dirty Python/Bash implementation. I have written a python script that extracts all window id's from the layout tree and prints the one after the currently focused window. The script's output is then used by a bash script to go to this window via i3-msg (could be done in the python script as well I think...) You can then configure your i3 such that you can walk over all windows (with exceptions, see "Drawbacks" below) using e.g. Alt+Tab.

Here is the code for id_list.py:

import json
import subprocess


"""
Execute the given command and return the 
output as a list of lines
"""
def command_output(cmd):
    output = []
    if (cmd):
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, \
                                 stderr=subprocess.STDOUT)
        for line in p.stdout.readlines():
            output.append(line.rstrip())
    return output


def output_to_dict(output_list):
    output_string = ""
    for line in output_list:
        output_string += line
    return json.loads(output_string)


def find_windows(tree_dict, window_list):
    if (tree_dict.has_key("nodes") and len(tree_dict["nodes"]) > 0):
        for node in tree_dict["nodes"]:
            find_windows(node, window_list)
    else:
        if (tree_dict["layout"] != "dockarea" and not tree_dict["name"].startswith("i3bar for output") and not tree_dict["window"] == None):
            window_list.append(tree_dict)

    return window_list        


def main():
    output = command_output("i3-msg -t get_tree")
    tree = output_to_dict(output)
    window_list = find_windows(tree, [])

    next_index = -1
    for i in range(len(window_list)):
        if (window_list[i]["focused"] == True):
            next_index = i+1
            break

#    next_index = len(window_list)
#    for i in range(len(window_list)-1, -1, -1):
#        if (window_list[i]["focused"] == True):
#            next_index = i-1
#            break

    next_id = 0;
    if next_index == -1 or next_index == len(window_list):
        next_id = window_list[0]["window"]
    else:        
        next_id = window_list[next_index]["window"]

    print next_id

main()

and the bash script tab_windows.sh:

#!/bin/bash

id=`python ~/.i3/id_list.py`
i3-msg [id="$id"] focus > /dev/null

Suppose these scripts lay in ~/.i3/ insert the following line into your i3 config: bindsym Mod1+Tab exec ~/.i3/tab_windows.sh

Drawbacks:

  • the script uses the hard-coded string "i3bar on output" to get rid of the i3bars which do not seem to be focusable; didn't find another method to exclude them from the tree
  • windows on a scratchpad cannot be reached with these scripts; I don't see these windows in the layout tree !?
  • script traverses the entire layout tree on every call. Maybe a solution with an id buffer is possible !?

Comments

Thanks a lot! Which bits do I change to make it go backwards?

paramnesioid gravatar imageparamnesioid (Nov 12 '13)edit

Just exchange the second code block inside of "def main():" with the five lines beginning with "#" just below it. Should work. Edit: Yep, works.

mschaefer gravatar imagemschaefer (Nov 13 '13)edit

Oh sorry, I didn't notice that. Thanks.

paramnesioid gravatar imageparamnesioid (Nov 13 '13)edit

You didn't miss anything, I just added these lines ;-)

mschaefer gravatar imagemschaefer (Nov 13 '13)edit

Haha nice work.

paramnesioid gravatar imageparamnesioid (Nov 14 '13)edit
1

answered May 13 '13

joepd gravatar image

It has been asked for multiple times, but won't be implemented.

Maybe it will be more easily findable if quoted here:

  1. Cycling through windows in focus order (like alt-tab) is something we don’t want to implement: The order in which alt+tab switches through windows is not easily predictable (due to our internal tree layout), thus either not doing what you want or making a separate visual element necessary (like a window list).
  2. Having such a visual element as discussed in 1 would need hand-eye coordination: you press a key (hand), then look at the screen, figure out what you want, then press another key.
  3. Direction focus is quicker. Instead of having one shortcut to go through all windows, you have 4. Maybe slowpoke’s window switching script (ask him on IRC) is what you are looking for.

If it’s not, maybe you can build your idea with the IPC interface. It’s not going to be in core i3, though.

Comments

It should be implemented - there's a reason why it's been implemented and used in other desktop environments.

faust gravatar imagefaust (Mar 31 '15)edit

In floating arrangements especially without virtual desktops its tedious to focus the right window if you have lots and therefore much easier to use alt tab shift alt tab to go back and forth between recent ones. Virtual desktops and having all windows on a desktop shown make it $mod+dir better

Michael Rose gravatar imageMichael Rose (Aug 18 '15)edit

Ex. move mouse to bottom of screen, move mouse to right application, if multiple instances exist select from and click vs alt+tab tab or $mod+direction or at worst $mod+num + $mod+direction

Michael Rose gravatar imageMichael Rose (Aug 18 '15)edit
0

answered May 9 '13

matma6 gravatar image

You can use mod+arrows to change focus. What do you mean "alt+tab"? Switching focus inside virtual desktop? Switching focus between all of windows on all of desktops? Changing position?

0

answered May 12 '13

dosimple gravatar image

Closest you can relatively easily get is to use VIM-like marks feature. One may recommend to configure keyboard bindings to mark windows with single letters (see the userguide and man i3-input). With those markings, many things are possible, but I think "Alt+Tab" is not one of them.

Comments

i was shooting for kind of back and forth between only two windows, last and current. it would be much easier to hack something like this, if i3 would allow multiple marks on the same window.

dosimple gravatar imagedosimple (May 15 '13)edit
0

answered May 11 '13

bakeren gravatar image

I assume you want to cycle between windows in the order they last had focus, instead of their orientation on the screen. As far as I know there is no such functionality out of the box in i3wm. At least I didn't find any way to do it when I switched to i3wm. You get used to switching using orientation after a while though.

0

answered May 14 '13

See here:

https://faq.i3wm.org/question/1281/ap...

Question Tools

1 follower

Stats

Asked: May 9 '13

Seen: 7,252 times

Last updated: Nov 13 '13