4

NB: I am not looking for how to switch between windows of the same application. Alt+Tab is great for that.

I often have two browser windows open at once (because they are for distinct profiles). I move my windows around a lot (e.g. Ctrl+Win+ / Ctrl+Win+), and I often have occasion to show a browser in one half of the screen whilst using a text editor in the other half.

Unfortunately, the 'grouping' behaviour of my system (Ubuntu 17.10 + Gnome desktop) means that when I bring the desired browser window to the foreground (to cover up a terminal, for example), both browser windows come forward. Half the time, the second browser window has been left on the opposite half of the screen, so it covers up my text editor, and I can't refer to my code without further moving windows around.

Is there something I can do to keep these windows ungrouped? In my system at home (Ubuntu + Unity), I don't have this problem.

Edit: I've endeavoured to follow the instructions at https://askubuntu.com/a/1054494/117018 for setting distinct WM_CLASS values for my different profiles: I updated my .desktop files, but when I check the WM_CLASS using xprop, my changes appear not to have taken effect: WM_CLASS(STRING) = "google-chrome", "Google-chrome".

I updated the .desktop files thus:

function update ()
{
    f=$1
    newclass=$(basename $f)
    newclass=${newclass#*-}
    newclass=${newclass%.desktop}
    newclass=${newclass/-/_}
    sed -i -e "s/StartupWMClass=.*/StartupWMClass=${newclass}/" -e "s/Exec=\(.*\)/Exec=\1 --class ${newclass}/" "$f"
    echo $f

}

find $HOME/.local/share/applications -name chrome-\* | while read -r f; do
    update "$f"
done


find $HOME/.gnome/apps -name chrome-\* | while read -r f; do
    update "$f"
done

Now, the .desktop files look like the following:

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=Docs
Exec=/opt/google/chrome/google-chrome --profile-directory=Default --app-id=aohghmighlieiainnegkcijnfilokake --class aohghmighlieiainnegkcijnfilokake_Default
Icon=chrome-aohghmighlieiainnegkcijnfilokake-Default
NoDisplay=true
StartupWMClass=aohghmighlieiainnegkcijnfilokake_Default
Jellicle
  • 849
  • 2
    Use different WM_CLASS and corresponding StartupWMClass value in the application launcher for each profile. Possible duplicate of Firefox profiles with different icons in Ubuntu dock – pomsky Nov 30 '18 at 18:43
  • these are just guesses: right click on the app-symbol in the launcher, choose all windows and select the one you want, or on Alt+Tab use the arrow done on the app-symbol and select the one you wish; else i beliefe pomsky is right – d1bro Nov 30 '18 at 19:32
  • @db429, I'm not sure if I understand your "choose all windows" instruction. Is your instruction intended as an alternative to a keyboard shortcut? – Jellicle Nov 30 '18 at 20:18
  • @JellicleCat yes first one is a non-keyboard approach. – d1bro Nov 30 '18 at 20:22
  • 1
    @pomsky, thanks. I've endeavoured to follow your instructions but have not succeeded in changing the WM_CLASS. I've amended my post to give details. – Jellicle Nov 30 '18 at 20:25
  • Not sure if I get all the ins and out of the request, but would using the Alternate tab extension, which separates Windows, not be the solution? That makes Alt+Tab switch between single Windows. Ubuntu Dock can be set to Cycle, so that one click brings the most recent window of the application to the foreground. – vanadium Dec 01 '18 at 12:07
  • @vanadium: thanks, but I don't have root on my work computer, which is the problem machine. I don't think installing gnome extensions is an option for me. – Jellicle Dec 03 '18 at 23:33

2 Answers2

3

As far as I see, Alt + Tab bringing all windows of an application to the front rather than the most recent one, is your issue. The only way to change the Alt+Tab behavour is to use a different switcher. Even if you use stock Ubuntu without any root access, you can achieve that. This requires some commands at the terminal.

Method involving the terminal

gsettings set org.gnome.desktop.wm.keybindings switch-applications []
gsettings set org.gnome.desktop.wm.keybindings switch-applications-backward []
gsettings set org.gnome.desktop.wm.keybindings switch-windows "['<Super>Tab', '<Alt>Tab']"
gsettings set org.gnome.desktop.wm.keybindings switch-windows-backward "['<Shift><Super>Tab', '<Shift><Alt>Tab']"

These commands remove the keybindings from the default "Application switcher" and set them for the "Window switcher". Alt + Tab will now behave in a more traditional way, and allow you to switch between single windows rather than between all windows of a different application.

To restore the default settings, issue four similar commands replacing set by resetand ommitting the setting, e.g.

gsettings reset org.gnome.desktop.wm.keybindings switch-windows-backward

Alternative method installing an extension

Users of Ubuntu that have root access, or where installation of extensions is enabled, may achieve the same effect using the Alternatetab extension. This is an official gnome extension that, in Ubuntu, is included in the package gnome-shell-extensions. It can also be installed from the Gnome Shell extensions website.

vanadium
  • 88,010
1

In Ubuntu 18.04 (not sure about earlier versions), it is possible to assign Alt+Tab to "Switch Windows" instead of "Switch Applications". Then, only the selected browser window will come forward, the other one will stay in the background.

To change this behavior, go to Settings->Devices->Keyboard and assign Alt+Tab to "Switch Windows", see http://ubuntuhandbook.org/index.php/2019/02/alt-tab-display-separate-windows-ubuntu-18-04/.

Thomas
  • 341