Fixing Dual Icons in Docky

Docky is a great little taskbar for Linux, and it does a decent job of replicating the OSX bar.

It does however have a few problems in identifying an application when it’s running, because it’s expecting the xwindows WM_CLASS value to match the name of the executable in the Exec entry of the *.desktop file…

There is a pretty simple way of fixing this, and an ideal candidate to explain is Google Chrome.

To start with, we need to start the offending application.  go ahead and open Google Chrome, and you get two icons in Docky.  One is the launcher icon, and the other is the running instance.

Next, open a terminal and run the command xprop

At this point your pointer becomes a cross, and you need to click the application in question.  xprop will then return the xwindow properties of the window you clicked.  for Google Chrome you should see something like:

_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED(CARDINAL) = 1
_NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_STICK, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_CLOSE, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW
WM_WINDOW_ROLE(STRING) = "browser"
WM_CLASS(STRING) = "Google-chrome-stable", "Google-chrome-stable"
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_NET_WM_PID(CARDINAL) = 26456
WM_LOCALE_NAME(STRING) = "en_GB.UTF-8"
WM_CLIENT_MACHINE(STRING) = "My Computer Name"
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, _NET_WM_PING

The important piece of information in those results is:

WM_CLASS(STRING) = "Google-chrome-stable", "Google-chrome-stable"

Notice the capital ‘G’ in Google there?

next, go to the location of the *.desktop file for that application, which is likely to be:

$ /usr/share/applications

and open the *.desktop file:

sudo gedit google-chrome.desktop

in the file are three sections: [Desktop Entry], [NewWindow Shortcut Group] and [NewIncognito Shortcut Group].  You’ll notice that each of these sections has a line looking something like:

Exec=/usr/bin/google-chrome-stable

Notice the lower-case ‘g’ in Google?

This is where Docky gets all confused, because it launches google-chrome-stable, but the window is called Google-chrome-stable!

All Docky needs is a little hint that is needs to launch the application, but look out for a window with a slightly different name.  To do this, in each section add:

StartupWMClass=Google-chrome-stable

Save the file, close Google Chrome and open it again, and hey-presto, the launcher icon gets the highlight of an open window!!!