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
- Run an EWMH-compliant window manager on the target display
- Verify with xprop -root _NET_CURRENT_DESKTOP that the property exists
- Confirm DISPLAY resolves to the display where the WM actually runs
- 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
- Require EWMH-capable WMs for workspace-aware features
- Probe _NET_CURRENT_DESKTOP with xprop in environment checks
- Treat active-desktop as best-effort data, not a hard requirement
- Log the WM name/version to diagnose missing hints
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
- Cannot get number of desktops properties (_NET_NUMBER_OF_DES
- Cannot get desktop names properties (_NET_DESKTOP_NAMES or _
- Cannot get window manager info properties. (_NET_SUPPORTING_
- Cannot get client list properties (_NET_CLIENT_LIST or _WIN_
- Cannot send <msg> event.
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/51820394e798265f.
Report an issue: GitHub.