java-native-access/jna · error · X11Exception

Cannot get current desktop properties (_NET_CURRENT_DESKTOP

Error message

Cannot get current desktop properties (_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)

What it means

X.getActiveDesktopNumber() reads the currently active workspace from the root window, preferring the EWMH atom _NET_CURRENT_DESKTOP and falling back to _WIN_WORKSPACE. If both property reads throw X11Exception, it rethrows this combined X11Exception indicating the active-desktop hint is unavailable on this display.

Source

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

        }

        /**
         * 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 {
                    cur_desktop = root.getIntProperty(X11.XA_CARDINAL, "_WIN_WORKSPACE");
                } catch (X11Exception e1) {
                    throw new X11Exception("Cannot get current desktop properties (_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)");
                }
            }

            return cur_desktop;
        }

        /**
         * Returns the available desktops.
         *
         * @return available desktops
         * @throws X11Exception thrown if X11 window errors occurred
         */
        public Desktop[] getDesktops() throws X11Exception {
            Window root = getRootWindow();
            String[] desktopNames;
            try {
                desktopNames = root.getUtf8ListProperty(getAtom("UTF8_STRING"), "_NET_DESKTOP_NAMES");
            } catch (X11Exception e) {

View on GitHub (pinned to d036ad9781)

Solutions

  1. Run an EWMH-compliant window manager on the target display
  2. Verify with xprop -root _NET_CURRENT_DESKTOP that the property exists
  3. Confirm DISPLAY resolves to the display where the WM actually runs
  4. Catch X11Exception and fall back to 0 (assume first desktop) when workspace info isn't needed

Example fix

// before
int desk = x.getActiveDesktopNumber();
// after
int desk;
try {
    desk = x.getActiveDesktopNumber();
} catch (X11Exception e) {
    desk = 0;
}
Defensive patterns

Strategy: fallback

Validate before calling

Process p = Runtime.getRuntime().exec(new String[]{"xprop","-root","_NET_CURRENT_DESKTOP"});
boolean hasHint = p.waitFor() == 0;

Try / catch

try {
    desk = x.getActiveDesktopNumber();
} catch (X11Exception e) {
    desk = 0; // workspace info unavailable
}

Prevention

When it happens

Trigger: Calling X.getActiveDesktopNumber() when the root window has neither _NET_CURRENT_DESKTOP nor _WIN_WORKSPACE; both nested getIntProperty calls fail.

Common situations: Headless Xvfb sessions without a window manager, tiling or minimal WMs that don't publish the workspace hint, or querying the wrong DISPLAY.

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/51820394e798265f. Report an issue: GitHub.