How to get virtual desktop numbers for each monitor?

Hi there,

Nooooooob for gtk development.

I recently need to write a plugin for plank, this plugin is used for mmanage virtual desktops on each monitor.

I found that, the environments of these 3 below are related to virtual desktops:

$ >> xprop -root
_NET_CURRENT_DESKTOP(CARDINAL) = 1
_NET_NUMBER_OF_DESKTOPS(CARDINAL) = 3
_NET_DESKTOP_NAMES(UTF8_STRING) = "Work", "Work", "2"

I have 2 monitors, and one monitor contains 2 virtual desktops: “Work” & “2”, the other monitor contains only 1 virtual desktop: “Work”.

What do I need to know is:

  1. How many desktops on current monitor
  2. What is the name of each desktop
  3. Which desktop I am currently be with: this seems can be achieve by accessing _NET_DESKTOP_NAMES[] string array by index _NET_CURRENT_DESKTOP

Variable _NET_NUMBER_OF_DESKTOPS only tells total number of desktops on all monitor, this is NOT what I needed.

Any example codes or library functions ?

You haven’t specified the version of GTK you’re using.

Sorry, gtk3

ldd /usr/bin/plank | grep -i gtk
	libgtk-3.so.0 => /usr/lib/libgtk-3.so.0

With GTK3 you should probably look into using libwnck: GNOME / libwnck · GitLab

It was used to build the pager applet in the old GNOME2 days, and it can be used for querying X11 window managers that follow the EWMH specification.