From ea2c9deb68da7aa7f5aef30facd7c0c078269399 Mon Sep 17 00:00:00 2001 From: romildo Date: Fri, 17 Mar 2017 21:14:58 -0300 Subject: [PATCH] menubar: consider XDG_HOME_DIR and XDG_DATA_DIRS The freedesktop specifications let desktop files be stored in different directories indicated by the environment variables XDG_DATA_HOME and XDG_DATA_DIRS. Only use the default value for these variables if the variables are not defined. This is important for systmes like NixOS which does not follow the LFS and installs files differently. --- lib/menubar/menu_gen.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/menubar/menu_gen.lua b/lib/menubar/menu_gen.lua index d1455d87..87cbeb20 100644 --- a/lib/menubar/menu_gen.lua +++ b/lib/menubar/menu_gen.lua @@ -7,6 +7,8 @@ --------------------------------------------------------------------------- -- Grab environment +local gtable = require("gears.table") +local gfilesystem = require("gears.filesystem") local utils = require("menubar.utils") local icon_theme = require("menubar.icon_theme") local pairs = pairs @@ -18,14 +20,16 @@ local menu_gen = {} -- Options section -local data_dir = os.getenv("XDG_DATA_HOME") -if not data_dir then - data_dir = os.getenv("HOME") .. '/.local/share' +--- Get the path to the directories where XDG menu applications are installed. +local function get_xdg_menu_dirs() + local dirs = gfilesystem.get_xdg_data_dirs() + table.insert(dirs, 1, gfilesystem.get_xdg_data_home()) + return gtable.map(function(dir) return dir .. 'applications/' end, dirs) end --- Specifies all directories where menubar should look for .desktop -- files. The search is recursive. -menu_gen.all_menu_dirs = { data_dir .. '/applications/', '/usr/share/applications/', '/usr/local/share/applications/' } +menu_gen.all_menu_dirs = get_xdg_menu_dirs() --- Specify the mapping of .desktop Categories section to the -- categories in the menubar. If "use" flag is set to false then any of