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 2013-05-09 08:57:37 +0000

rmn190 gravatar image

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

thanks

edit retag flag offensive close merge delete

Comments

+1 for question because of the number of good reactions

joepd gravatar imagejoepd ( 2013-05-14 22:39:46 +0000 )edit

6 answers

Sort by » oldest newest most voted
4

answered 2013-05-14 10:29:51 +0000

updated 2013-11-13 12:34:54 +0000

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 !?
edit flag offensive delete link more

Comments

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

paramnesioid gravatar imageparamnesioid ( 2013-11-12 05:19:51 +0000 )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 ( 2013-11-13 12:36:19 +0000 )edit

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

paramnesioid gravatar imageparamnesioid ( 2013-11-13 15:57:49 +0000 )edit

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

mschaefer gravatar imagemschaefer ( 2013-11-13 18:27:39 +0000 )edit

Haha nice work.

paramnesioid gravatar imageparamnesioid ( 2013-11-14 00:48:57 +0000 )edit
1

answered 2013-05-13 21:40:57 +0000

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.

edit flag offensive delete link more

Comments

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

faust gravatar imagefaust ( 2015-03-31 08:13:57 +0000 )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 ( 2015-08-18 22:33:43 +0000 )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 ( 2015-08-18 22:35:33 +0000 )edit
0

answered 2013-05-09 13:58:36 +0000

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?

edit flag offensive delete link more
0

answered 2013-05-12 22:25:48 +0000

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.

edit flag offensive delete link more

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 ( 2013-05-15 23:08:31 +0000 )edit
0

answered 2013-05-11 23:34:01 +0000

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.

edit flag offensive delete link more
0

answered 2013-05-14 10:54:03 +0000

See here:

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-05-09 08:57:37 +0000

Seen: 7,252 times

Last updated: Nov 13 '13