Okular instances does not group under single icon in desktop dock on Ubuntu 17.10

After upgrading to Ubuntu 17.10, multiple instances of okular will no longer group under a single icon in the desktop dock.

I am running 17.10 under X.org, and if it matters: I am viewing PDF files with okular. All other applications I have tested work correctly. For example, multiple instances of gnome-terminal and emacs will group under a single item in the desktop dock. There was no problem with grouping for okular in 17.04.

Why is it important to have them grouped? It enables one to use a keyboard shortcut to switch between applications of the same type (Alt+|). It also makes it easier to switch between different applications (Alt+Tab) since there are fewer instances to cycle through.

How can I get okular instances to group correctly in 17.10?


Solution 1:

  1. Copy the okularApplication_pdf.desktop file from /usr/share/applications to ~/.local/share/applications. For that you may run

    cp /usr/share/applications/okularApplication_pdf.desktop ~/.local/share/applications/
    
  2. Open the copied file with a text editor. For example by running

    gedit ~/.local/share/applications/okularApplication_pdf.desktop
    
  3. Add (or modify) the following line to the file

    StartupWMClass=okular
    
  4. Save the file.

Adapted from this answer.

Edit:

If you have installed okular as a snap, you will find the desktop file at /var/lib/snapd/desktop/applications/okular_org.kde.okular.desktop

In this case the following could become your step 1:

cp /var/lib/snapd/desktop/applications/okular_org.kde.okular.desktop ~/.local/share/applications/

Then follow steps 2 to 4 as mentioned in the previous method.