aboutsummaryrefslogtreecommitdiff
path: root/src/er_xdg_pipe_menu_desktop_entry.erl
diff options
context:
space:
mode:
authorChristopher R. Nelson <christopher.nelson@languidnights.com>2026-07-21 10:54:00 -0400
committerChristopher R. Nelson <christopher.nelson@languidnights.com>2026-07-21 10:54:00 -0400
commit46b72a375101b54819f8750750017bd71e7c3798 (patch)
treee8d72906b59252bd01939a5806235ccc75934f56 /src/er_xdg_pipe_menu_desktop_entry.erl
parent6bbc784b4cf0717ddc7f5c3ad32c1d5e2d486877 (diff)
Group menu items into per-category submenus
Parse the Categories key from .desktop files and have the renderer emit one <menu> submenu per category (via xmerl), with items sorted within each; entries in multiple categories appear in each submenu, and uncategorized entries fall into a catch-all "Other" submenu. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'src/er_xdg_pipe_menu_desktop_entry.erl')
-rw-r--r--src/er_xdg_pipe_menu_desktop_entry.erl16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/er_xdg_pipe_menu_desktop_entry.erl b/src/er_xdg_pipe_menu_desktop_entry.erl
index bbd2594..9a71013 100644
--- a/src/er_xdg_pipe_menu_desktop_entry.erl
+++ b/src/er_xdg_pipe_menu_desktop_entry.erl
@@ -3,8 +3,9 @@
%%
%% Reads the `[Desktop Entry]' group of a desktop entry file and
%% extracts the fields needed to build a menu item: `Name', `Exec'
-%% and (optionally) `Icon'. Other groups (e.g. `[Desktop Action ...]')
-%% and localized keys (e.g. `Name[fr]') are ignored.
+%% and (optionally) `Icon' and `Categories'. Other groups (e.g.
+%% `[Desktop Action ...]') and localized keys (e.g. `Name[fr]') are
+%% ignored.
%% @end
%%%-------------------------------------------------------------------
@@ -16,7 +17,7 @@
-define(GROUP, <<"Desktop Entry">>).
-define(WANTED_KEYS, [
- <<"Name">>, <<"Exec">>, <<"Icon">>, <<"NoDisplay">>, <<"Hidden">>, <<"Type">>
+ <<"Name">>, <<"Exec">>, <<"Icon">>, <<"Categories">>, <<"NoDisplay">>, <<"Hidden">>, <<"Type">>
]).
-define(FIELD_CODES, "fFuUdDnNickvm").
@@ -99,11 +100,20 @@ to_entry(Fields) ->
name = Name,
exec = strip_field_codes(Exec),
icon = maps:get(<<"Icon">>, Fields, undefined),
+ categories = parse_categories(maps:get(<<"Categories">>, Fields, undefined)),
hidden = is_hidden(Fields)
}}
end
end.
+%% `Categories' is a `;'-separated list, conventionally with a
+%% trailing separator (e.g. `Utility;Development;'); empty segments
+%% from that trailing separator (or repeated ones) are dropped.
+parse_categories(undefined) ->
+ [];
+parse_categories(Bin) ->
+ [C || C <- binary:split(Bin, <<";">>, [global]), C =/= <<>>].
+
%% Niche variations (e.g. a Type-less override dropped into
%% ~/.local/share/applications) are left to be special-cased there
%% rather than accounted for here.