{"record":{"id":"150689016aca84f2","repo":"java-native-access/jna","slug":"cannot-get-number-of-desktops-properties-net-number-of","errorCode":null,"errorMessage":"Cannot get number of desktops properties (_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)","messagePattern":"Cannot get number of desktops properties \\(_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT\\)","errorType":"exception","errorClass":"X11Exception","httpStatus":null,"severity":"error","filePath":"contrib/x11/src/jnacontrib/x11/api/X.java","lineNumber":237,"sourceCode":"            return windowList;\n        }\n\n        /**\n         * Returns the number of desktops.\n         *\n         * @return number of desktops\n         * @throws X11Exception thrown if X11 window errors occurred\n         */\n        public int getDesktopCount() throws X11Exception {\n            Window root = getRootWindow();\n\n            try {\n                return root.getIntProperty(X11.XA_CARDINAL, \"_NET_NUMBER_OF_DESKTOPS\");\n            } catch (X11Exception e) {\n                try {\n                    return root.getIntProperty(X11.XA_CARDINAL, \"_WIN_WORKSPACE_COUNT\");\n                } catch (X11Exception e1) {\n                    throw new X11Exception(\"Cannot get number of desktops properties (_NET_NUMBER_OF_DESKTOPS or _WIN_WORKSPACE_COUNT)\");\n                }\n            }\n        }\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 {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/x11/src/jnacontrib/x11/api/X.java#L219-L255","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure a full desktop window manager (GNOME/KDE/Mutter/Compiz/metacity) is running on the target display","Check the DISPLAY environment variable points at the intended X server rather than an empty Xvfb","If the WM lacks EWMH, either set _NET_NUMBER_OF_DESKTOPS yourself via xprop, or catch X11Exception and default to 1 desktop","Use xprop -root _NET_NUMBER_OF_DESKTOPS to verify the property exists before calling"],"exampleFix":"// before\nint count = x.getDesktopCount();\n// after\nint count;\ntry {\n    count = x.getDesktopCount();\n} catch (X11Exception e) {\n    count = 1; // no EWMH-capable WM: assume single desktop\n}","handlingStrategy":"fallback","validationCode":"// check WM hints exist before calling\nProcess p = Runtime.getRuntime().exec(new String[]{\"xprop\",\"-root\",\"_NET_NUMBER_OF_DESKTOPS\"});\nboolean ok = p.waitFor() == 0; // if false, WM lacks EWMH hints","typeGuard":null,"tryCatchPattern":"try {\n    count = x.getDesktopCount();\n} catch (X11Exception e) {\n    count = 1; // assume single desktop when WM hints absent\n}","preventionTips":["Always run an EWMH-compliant window manager on the target display","Validate the display/WM with xprop -root before automation runs","Never assume desktop count; treat it as optional metadata","Default to 1 desktop in headless/CI environments"],"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"}