{"record":{"id":"51820394e798265f","repo":"java-native-access/jna","slug":"cannot-get-current-desktop-properties-net-current-desktop-or","errorCode":null,"errorMessage":"Cannot get current desktop properties (_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)","messagePattern":"Cannot get current desktop properties \\(_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property\\)","errorType":"exception","errorClass":"X11Exception","httpStatus":null,"severity":"error","filePath":"contrib/x11/src/jnacontrib/x11/api/X.java","lineNumber":258,"sourceCode":"        }\n\n        /**\n         * Returns the number of the active desktop.\n         *\n         * @return number of the active desktop\n         * @throws X11Exception thrown if X11 window errors occurred\n         */\n        public int getActiveDesktopNumber() throws X11Exception {\n            Window root = getRootWindow();\n            int cur_desktop;\n\n            try {\n                cur_desktop = root.getIntProperty(X11.XA_CARDINAL, \"_NET_CURRENT_DESKTOP\");\n            } catch (X11Exception e) {\n                try {\n                    cur_desktop = root.getIntProperty(X11.XA_CARDINAL, \"_WIN_WORKSPACE\");\n                } catch (X11Exception e1) {\n                    throw new X11Exception(\"Cannot get current desktop properties (_NET_CURRENT_DESKTOP or _WIN_WORKSPACE property)\");\n                }\n            }\n\n            return cur_desktop;\n        }\n\n        /**\n         * Returns the available desktops.\n         *\n         * @return available desktops\n         * @throws X11Exception thrown if X11 window errors occurred\n         */\n        public Desktop[] getDesktops() throws X11Exception {\n            Window root = getRootWindow();\n            String[] desktopNames;\n            try {\n                desktopNames = root.getUtf8ListProperty(getAtom(\"UTF8_STRING\"), \"_NET_DESKTOP_NAMES\");\n            } catch (X11Exception e) {","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/x11/src/jnacontrib/x11/api/X.java#L240-L276","documentation":"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.","triggerScenarios":"Calling X.getActiveDesktopNumber() when the root window has neither _NET_CURRENT_DESKTOP nor _WIN_WORKSPACE; both nested getIntProperty calls fail.","commonSituations":"Headless Xvfb sessions without a window manager, tiling or minimal WMs that don't publish the workspace hint, or querying the wrong DISPLAY.","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"],"exampleFix":"// before\nint desk = x.getActiveDesktopNumber();\n// after\nint desk;\ntry {\n    desk = x.getActiveDesktopNumber();\n} catch (X11Exception e) {\n    desk = 0;\n}","handlingStrategy":"fallback","validationCode":"Process p = Runtime.getRuntime().exec(new String[]{\"xprop\",\"-root\",\"_NET_CURRENT_DESKTOP\"});\nboolean hasHint = p.waitFor() == 0;","typeGuard":null,"tryCatchPattern":"try {\n    desk = x.getActiveDesktopNumber();\n} catch (X11Exception e) {\n    desk = 0; // workspace info unavailable\n}","preventionTips":["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"],"tags":["x11","window-manager","ewmh","property-missing"],"backgroundTag":"resource-not-found","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}