Fix cursor icon search paths to follow XDG Icon Theme Specification#4731
Fix cursor icon search paths to follow XDG Icon Theme Specification#4731
Conversation
Co-authored-by: AlanGriffiths <[email protected]>
|
@copilot it is poor style to declare variables before they can be initialized |
…lization Co-authored-by: AlanGriffiths <[email protected]>
TICS Quality Gate✔️ Passedmir
|
There was a problem hiding this comment.
Pull request overview
This PR fixes cursor icon search paths in src/miral/xcursor.c to comply with the XDG Icon Theme Specification. Previously, Mir used a hardcoded XCURSORPATH that omitted $XDG_DATA_DIRS/icons. The fix introduces a dynamic path builder that constructs the correct XDG-spec-compliant search order at runtime, falling back to the legacy path.
Changes:
- Added
_XcursorBuildXdgPath()that dynamically constructs the cursor search path per the XDG Icon Theme spec:$HOME/.icons,$XDG_DATA_DIRS/icons(expanded),/usr/share/pixmaps, then legacyXCURSORPATHentries XcursorLibraryPath()updated to call_XcursorBuildXdgPath()whenXCURSOR_PATHenv var is not set, withXCURSORPATHmacro as last resort fallback
src/miral/xcursor.c
Outdated
| } | ||
|
|
||
| { | ||
| int const written = snprintf (p_out, remaining, "/usr/share/pixmaps:%s", XCURSORPATH); |
There was a problem hiding this comment.
The generated path contains duplicate entries. /usr/share/pixmaps is explicitly added at line 667 (before XCURSORPATH), but XCURSORPATH itself already contains /usr/share/pixmaps. Similarly, when using the default XDG_DATA_DIRS, /usr/share/icons appears both in the XDG expansion and in XCURSORPATH. Additionally, $HOME/.icons (expanded on line 648) appears again as ~/.icons in the legacy XCURSORPATH fallback (which gets tilde-expanded at runtime in _XcursorBuildThemeDir).
These duplicates cause each directory to be searched twice, resulting in redundant filesystem operations. To avoid this, /usr/share/pixmaps could be stripped from XCURSORPATH before appending, or the snprintf format on line 667 could use a trimmed version of the legacy path that excludes entries already covered by the XDG prefix entries.
There was a problem hiding this comment.
Fixed in 790607b. Introduced XCURSORLEGACYPATH containing only the entries not already covered by the XDG prefix (~/.cursors:/usr/share/cursors/xorg-x11:ICONDIR) and used that in _XcursorBuildXdgPath instead of the full XCURSORPATH. The generated path now has no duplicates — ~/.icons, $XDG_DATA_DIRS/icons entries, and /usr/share/pixmaps each appear exactly once. The full XCURSORPATH is retained as the last-resort fallback when malloc fails.
…nly path Co-authored-by: AlanGriffiths <[email protected]>
Mir's cursor icon search path (
XCURSORPATH) was a hardcoded legacy list that omitted$XDG_DATA_DIRS/icons— meaning/usr/local/share/iconsand any custom data dirs were never searched.Per the XDG Icon Theme Specification, apps should look in
$HOME/.icons,$XDG_DATA_DIRS/icons, and/usr/share/pixmaps(in that order).What's new?
_XcursorBuildXdgPath()insrc/miral/xcursor.cthat dynamically constructs the cursor search path whenXCURSOR_PATHis not set$HOME/.icons(backwards compat)$XDG_DATA_DIRS/icons— expanded per-entry; defaults to/usr/local/share/icons:/usr/share/iconswhenXDG_DATA_DIRSis unset/usr/share/pixmaps~/.cursors,/usr/share/cursors/xorg-x11,ICONDIR) via newXCURSORLEGACYPATHmacro — entries already covered by the XDG prefix are excluded to avoid redundant filesystem searchesXCURSOR_PATHenv var override continues to take priority (unchanged behaviour)XCURSORPATHmacro retained as last-resort fallback when dynamic path allocation failssnprintfwith remaining-buffer tracking used throughout_XcursorBuildXdgPath()How to test
Set a cursor theme via
miral::CursorThemeand verify cursors load from paths under$XDG_DATA_DIRS/icons(e.g./usr/local/share/icons/<theme>/cursors/). Setting a customXDG_DATA_DIRSshould cause that directory's icons subtree to be searched.Checklist
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.