Close

Fixing Alt-Tab behavior, V2.0

A project log for Potpourri

Definition: A mixture of things, especially a musical or literary medley

peter-walshPeter Walsh 01/11/2017 at 02:250 Comments

TL;DR

  1. New version of the <alt><tab> selector is available
  2. Environment variables can define the task order
  3. Project files and wiki are on github

A new version of Alt-Tab

After nosing around the completely undocumented Cinnamon code for several more hours, I could find no place where the taskbar stores it's task list.

I *did* find a function that let me safely poke around in the source files and see what information is available:

Main.warningNotify(String1,String2);

Later, I found a function that appears to get an environment variable:

GLib.getenv(ORDERENV);
And one that appears get the workspace name and index:
Main.getWorkspaceName(global.screen.get_active_workspace().index());
So I wrote a better version of the Alt-Tab switcher that lets the user use environment variables to set the sort order.

You can find the new file and documentation on the GitHub project, including installation instructions and more documentation.


Overview of the new version

Check the GitHub project, for more/better documentation.

The new Alt-Tab order is determined by the CLASS and TITLE of the application window.

The CLASS identifies the application, and will be something like "Firefox" or "Nemo".

The TITLE identifies what the application is showing, such as a specific web page (Firefox) or directory (Nemo). The TITLE is the string shown in the taskbar, and will be something like "Google - Mozilla Firefox" (for Firefox) or "Home" (for Nemo), depending on what your application is showing.

To show all window classes and titles:

#
# List all window titles
#
wmctrl -l -x | awk '{print substr($0,index($0,$5))}'

#
# List all window classes
#
wmctrl -l -x | awk '{ print substr($3,1+index($3,".")) }'


Setting the sort order

Environment variables in the user's .profile file can define the sort order.

  1. In workspace n, the sort order is determined by "ALT_TAB_WORKSPACEn" if this variable exists.
  2. Otherwise, the sort order is determined by "ALT_TAB_ORDER" if this variable exists.
  3. Otherwise, the windows are sorted by title.

The ALT_TAB_xxxx variables contain multiple CLASS:TITLE specifiers separated by semicolon.

Workspaces are numbered from 1, not zero. The first (leftmost) workspace is "WORKSPACE1".

The variables are part of the user's original login, so changes must be made to the user's .profile file (and not, for example, the .bashrc file). After editing, log out and log back in for changes to take effect.


Examples

Example1:

export ALT_TAB_WORKSPACE1="Firefox;Nemo;Gnome-terminal"
export ALT_TAB_WORKSPACE2="Gnome-terminal:Edit;Gnome-terminal:Work;VirtualBox;Firefox;Nemo"

In WORKSPACE1 the alt-tab listing will have firefox leftmost (in first position), Nemo in 2nd position, the terminal in third position. Other windows will be to the right of the terminal.

In WORKSPACE2 the alt-tab listing will have both terminals leftmost, but the one titled "Edit" will come before (to the left) of the one titled "Work", in 2nd position. VirtualBox, Firefox, and Nemo will follow, then any unspecified windows.

Other workspaces will be sorted by title (the default).


Example2:

export ALT_TAB_ORDER="Firefox;Nemo;Gnome-terminal"
export ALT_TAB_WORKSPACE2="Gnome-terminal:Edit;Gnome-terminal:Work;VirtualBox;Firefox;Nemo"

WORKSPACE2 Alt-Tab will be as described above.

All other workspaces will show Firefox->Nemo->Gnome.


Example3:

#
# No preference in window order
#
#export ALT_TAB_ORDER="Firefox;Nemo;Gnome-terminal"

Alt-tab will sort by title, the default.


Named Workspaces

If you have named your workspace, use "ALT_TAB_" with the new workspace name.

Example4:

#
# Workspace named "PERSONAL"
#
export ALT_TAB_PERSONAL="Thunderbird;Firefox;Nemo"

The renamed workspace "PERSONAL" will show in the order Thunderbird -> Firefox -> Nemo

All other workspaces will sort by title, the default.

Discussions