java-native-access/jna · error · X11Exception

Cannot get number of desktops properties (_NET_NUMBER_OF_DES

Error message

Cannot get number of desktops properties (_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)

What it means

X.getDesktopCount() tries to read the number of desktops from the root window, first via the EWMH property _NET_NUMBER_OF_DESKTOPS, falling back to the older WinWM/GNOME property _WIN_WORKSPACE_COUNT. If both reads fail (each throws X11Exception), the method wraps the failure in this X11Exception, meaning the window manager on this X display exposes neither hint.

Source

Thrown at contrib/x11/src/jnacontrib/x11/api/X.java:237

            return windowList;
        }

        /**
         * Returns the number of desktops.
         *
         * @return number of desktops
         * @throws X11Exception thrown if X11 window errors occurred
         */
        public int getDesktopCount() throws X11Exception {
            Window root = getRootWindow();

            try {
                return root.getIntProperty(X11.XA_CARDINAL, "_NET_NUMBER_OF_DESKTOPS");
            } catch (X11Exception e) {
                try {
                    return root.getIntProperty(X11.XA_CARDINAL, "_WIN_WORKSPACE_COUNT");
                } catch (X11Exception e1) {
                    throw new X11Exception("Cannot get number of desktops properties (_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)");
                }
            }
        }

        /**
         * Returns the number of the active desktop.
         *
         * @return number of the active desktop
         * @throws X11Exception thrown if X11 window errors occurred
         */
        public int getActiveDesktopNumber() throws X11Exception {
            Window root = getRootWindow();
            int cur_desktop;

            try {
                cur_desktop = root.getIntProperty(X11.XA_CARDINAL, "_NET_CURRENT_DESKTOP");
            } catch (X11Exception e) {
                try {

View on GitHub (pinned to d036ad9781)

Solutions

  1. Ensure a full desktop window manager (GNOME/KDE/Mutter/Compiz/metacity) is running on the target display
  2. Check the DISPLAY environment variable points at the intended X server rather than an empty Xvfb
  3. If the WM lacks EWMH, either set _NET_NUMBER_OF_DESKTOPS yourself via xprop, or catch X11Exception and default to 1 desktop
  4. Use xprop -root _NET_NUMBER_OF_DESKTOPS to verify the property exists before calling

Example fix

// before
int count = x.getDesktopCount();
// after
int count;
try {
    count = x.getDesktopCount();
} catch (X11Exception e) {
    count = 1; // no EWMH-capable WM: assume single desktop
}
Defensive patterns

Strategy: fallback

Validate before calling

// check WM hints exist before calling
Process p = Runtime.getRuntime().exec(new String[]{"xprop","-root","_NET_NUMBER_OF_DESKTOPS"});
boolean ok = p.waitFor() == 0; // if false, WM lacks EWMH hints

Try / catch

try {
    count = x.getDesktopCount();
} catch (X11Exception e) {
    count = 1; // assume single desktop when WM hints absent
}

Prevention

When it happens

Trigger: Calling X.getDesktopCount() (or X.desktops()) on a display whose root window lacks both _NET_NUMBER_OF_DESKTOPS and _WIN_WORKSPACE_COUNT, e.g. getIntProperty throws for both atom names.

Common situations: Running under minimalist window managers or bare Xvfb/no WM at all (no EWMH/WM hints set), headless CI environments, or a WM that predates EWMH support.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/150689016aca84f2. Report an issue: GitHub.