1

I would like to count the number of active windows open apart from that of the window manager I am using. I am aware that wmctrl can do this, however, when I do the following:

wmctrl -l

on my Ubuntu 14.04 64-bit desktop using unity as the window manager, the output I get is:

0x03c00002  0 stepup XdndCollectionWindowImp
0x03c00005  0 stepup unity-launcher
0x03c00008  0 stepup unity-panel
0x03c0000b  0 stepup unity-dash
0x03c0000c  0 stepup Hud
0x02c0000a  0 stepup Desktop
0x02e000b3  0 stepup How to count the number of active windows open irrespective of window manager? - Unix & Linux Stack Exchange - Mozilla Firefox
0x0340000c  0 stepup Terminal

However, I would want to ignore the windows that unity/gnome/KDE, etc. uses and count just the windows the user has opened on his own. How do I this?

1

There is no formal definition of window belonging to the window manager or “opened on his own”. Technically, the window manager role doesn't call for any window: it's other parts of the desktop environment (typically called widgets) that have windows. There is no attribute on a window or on an application that says “this is part of the desktop environment”.

You can run wmctrl -lx and identify the windows you don't care about by their class. I haven't checked what classes the various common desktop environments use, fill in the list as desired.

wmctrl -lx | awk '$3 !~ /^(Unity-.*|Kwin|Boringstuff)$/'

Alternatively, maybe detecting non-sticky windows will fit your bill. Sticky windows are the ones that are displayed on all workspaces. I don't know if this works with all window managers.

for w in $(wmctrl -l | awk '{print $1}'); do
  if ! xprop -id $w _NET_WM_STATE | grep -q _NET_WM_STATE_STICKY; then
    wmctrl -l -i $w
  fi
done
  • At least for unity, most of the windows have "N/A" as their class, so that would probably help. Would have appreciated a window-manager-independent solution. +1 for now, will accept if no better solution props up. – jobin May 9 '14 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.