Skip to content

Commit

Permalink
switch to the new Qubes Valentina menu
Browse files Browse the repository at this point in the history
  • Loading branch information
3hhh committed Mar 27, 2023
1 parent ba2cea6 commit a6b279f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 102 deletions.
40 changes: 32 additions & 8 deletions 0005-Add-QubesOS-specific-menu.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,49 @@ Subject: [PATCH] Add QubesOS specific menu

Signed-off-by: Bahtiar `kalkin-` Gadimov <[email protected]>
---
awesomerc.lua | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/awesomerc.lua b/awesomerc.lua
index d6da869e..a01cdec6 100644
--- a/awesomerc.lua
+++ b/awesomerc.lua
@@ -99,12 +99,9 @@ myawesomemenu = {
@@ -99,13 +99,8 @@
{ "quit", function() awesome.quit() end },
}

-mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
- { "open terminal", terminal }
- }
- })
+mymainmenu = awful.menu({ items = qubes.make_menu() })

-
-mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
- menu = mymainmenu })
+mylauncher = awful.widget.launcher({ image = '/usr/share/icons/hicolor/16x16/apps/qubes-logo-icon.png',
menu = mymainmenu })

+ command = 'qubes-app-menu' })
-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
@@ -237,7 +232,6 @@
-- {{{ Mouse bindings
-- @DOC_ROOT_BUTTONS@
root.buttons(gears.table.join(
- awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev)
))
@@ -267,8 +261,6 @@
end,
{description = "focus previous by index", group = "client"}
),
- awful.key({ modkey, }, "w", function () mymainmenu:show() end,
- {description = "show main menu", group = "awesome"}),

-- Layout manipulation
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end,
@@ -483,6 +475,7 @@
-- Floating clients.
{ rule_any = {
instance = {
+ "qubes-app-menu",
"DTA", -- Firefox addon DownThemAll.
"copyq", -- Includes session name in class.
"pinentry",
1 change: 1 addition & 0 deletions awesome.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ BuildRequires: lua-lgi >= 0.8.0
BuildRequires: pkgconfig(pango) >= 1.19.3
BuildRequires: pkgconfig(pangocairo) >= 1.19.3
Requires: qubes-desktop-linux-common
Requires: qubes-desktop-linux-menu
Requires: lua-lgi >= 0.8.0
# next two loaded via lgi
Requires: pango%{?_isa} >= 1.19.3
Expand Down
94 changes: 0 additions & 94 deletions qubes.lua.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@
-- license: GPL-2+
----------------------------------------------------------------------------

local io = io
local math = math
local string = string
local tonumber = tonumber
local table = table

local client = require('awful.client')
local util = require('awful.util')
local color = require('gears.color')
local gstring = require('gears.string')
local beautiful = require('beautiful')
local menubar = require('menubar')

local qubes = {}

local HOME = os.getenv("HOME")

-- the following three functions are lifted from
-- /usr/lib64/python2.7/colorsys.py

Expand Down Expand Up @@ -177,92 +169,6 @@ function qubes.set_name(c)
end
end

local function is_accessible(path)
if path == nil then return false end
return os.rename(path, path) and true or false
end

function qubes.make_menuitem(vm, program)
local appicon = program.icon_path
if not is_accessible(appicon) then appicon = nil end

return {program.Name, program.cmdline, appicon}
end

--menuitemfunc & vmicon are optional parameters
function qubes.make_vm_menu(vmname, desktop_files, menuitemfunc, vmicon)
local menu = {}
local menuitemfunc = menuitemfunc or qubes.make_menuitem

if vmname == nil then return nil end

local vmicon = vmicon
if vmicon == nil then
vmicon_name = pread('qvm-prefs -- ' .. vmname .. ' icon'):sub(1, -2)
vmicon = '/usr/share/icons/hicolor/128x128/devices/' .. vmicon_name .. '.png'
end

for _, dfile in pairs(desktop_files) do
if dfile ~= nil then
local dpath = HOME .. '/.local/share/applications/' .. dfile
if is_accessible(dpath) then
local menuitem = menuitemfunc(vmname, menubar.utils.parse_desktop_file(dpath))
if menuitem ~= nil then table.insert(menu, menuitem) end
end
end
end

if next(menu) == nil then
return nil
else
--NOTE: awesome will not display menu entries with invalid icon paths
return {vmname, menu, vmicon}
end
end

--filter, menuitemfunc & menuicon are optional parameters
--menu is an output parameter passed by reference
local function parse_menufile_dir(menu, menufile_dir, filter, menuitemfunc, menuicon)
local menufunc = qubes.make_vm_menu
local menuitemfunc = menuitemfunc or qubes.make_menuitem

--since awesome only supports .desktop files, but Qubes also uses .menu files, we "parse" the .menu files with sed to find the relevant .desktop files for a VM
local last_desktop_files = {}
local last_name = nil
local cmd=[[bash -c 'for file in ]] .. menufile_dir .. [[/*.menu; do sort -b "$file"; done']]
--the sorting is needed to support arbitrary ordering of the xml tags
for line in io.popen(cmd):lines() do
local nmatch = string.match(line, '<Name>(.*)</Name>')
if nmatch ~= nil and nmatch ~= "Applications" then
--name of the 1st level menu:
last_name = string.match(nmatch,'^qubes%-vm%-directory%-(.*)$') or nmatch
if last_name ~= nil then table.insert(menu, menufunc(last_name, last_desktop_files, menuitemfunc, menuicon)) end
if filter ~= nil then menufunc = filter(last_name) end
last_desktop_files = {}
else
--potential desktop file:
local fmatch = string.match(line, '<Filename>(.*%.desktop)</Filename>')
if fmatch ~= nil then table.insert(last_desktop_files, fmatch) end
end
end
end

--filter & menuitemfunc are optional parameters
function qubes.make_menu(filter, menuitemfunc)
local menu = {}

--add the awesome-specific menus
--this is enitrely optional and enables users to create xdg menu files at the below file path in order to populate the first menu entries (e.g. for awesome-specific control tools)
--the desktop files referenced from the .menu files must be stored at ~/.local/share/applications/
--it will remain invisible until that directory has .menu files referencing valid .desktop files
parse_menufile_dir(menu, '~/.config/awesome/xdg-menu', filter, menuitemfunc, '/usr/share/icons/hicolor/16x16/apps/qubes-logo-icon.png')

--add the VM application menus
parse_menufile_dir(menu, '~/.config/menus/applications-merged', filter, menuitemfunc)

return menu
end

return qubes

-- vim: ts=4 sw=4 et

0 comments on commit a6b279f

Please sign in to comment.