2022-08-31 12:20:58 +00:00
-- This file is part of Reno desktop.
--
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
-- Global context menu base
2022-08-23 13:03:15 +00:00
local awmtk2 = require ( " awmtk2 " )
local wibox = require ( " wibox " )
local gears = require ( " gears " )
local awful = require ( " awful " )
2023-03-04 11:25:35 +00:00
local menugen = require ( " context_menu " )
2022-08-25 15:27:31 +00:00
local builder = require ( " builder " )
2022-08-23 13:03:15 +00:00
return function ( args )
2022-09-05 21:54:11 +00:00
local style = awmtk2.create_style ( " root_menu " ,
2022-09-06 22:40:51 +00:00
awmtk2.generic . composite_widget , { } )
2022-08-25 15:27:31 +00:00
local templates = awmtk2.create_template_lib ( " root_menu " , awmtk2.templates , { } )
2023-01-16 12:47:51 +00:00
local t = awmtk2.build_templates ( templates , style , args.vertical )
2023-03-04 11:25:35 +00:00
-- Layout configuration
2022-08-25 15:27:31 +00:00
local config_file = io.open ( root_path .. " /themes/ " .. global.theme .. " /config/root_menu.json " , " r " )
local config
if config_file then
config = config_file : read ( " *a " )
config_file : close ( )
2023-03-04 11:25:35 +00:00
else
2022-08-25 15:27:31 +00:00
config = [[{"list": [{"widget": "widgets.rootcontrols"}],"vertical": true}]]
end
2023-03-04 11:25:35 +00:00
-- NOTE: **PLEASE** attach your other menus to this thing, ok? IF YOU DON'T, THE MENUS WILL WORK LIKE SHIT
-- NOTE 2: THERE IS NO OTHER "PROPER" FIX FOR THIS, JUST LOOK AT THE PREVIOUS SYSTEM (SPOILER: it was ABSOLUTE GARBAGE)
-- Primary menu to which other menus get attached
local prime_menu = menugen ( { items = { } } )
-- Not yet loaded menu popup (TODO: maybe make it more obvious that it's a global?)
2022-08-25 15:27:31 +00:00
root_menu = awful.popup ( t.popup ( {
markup = " brainhurt the game " ,
2023-03-04 11:25:35 +00:00
prime_menu ,
2022-08-25 15:27:31 +00:00
widget = wibox.widget . textbox
} ) )
2023-03-04 11:25:35 +00:00
-- Close popup on right click
root_menu : connect_signal ( " button::press " , function ( _ , _ , _ , b )
2022-08-25 15:27:31 +00:00
if b == 3 then
root_menu.visible = false
end
end )
2023-03-04 11:25:35 +00:00
-- Build the menu based on the json config
2022-08-25 15:27:31 +00:00
root_menu.widget = wibox.widget ( t.popup ( builder (
config ,
{
style = style.base ,
screen = mouse.screen ,
passthrough = {
2023-03-04 11:25:35 +00:00
-- This is the menu to which other menus should attach (available as args.menu_parent)
menu_parent = prime_menu ,
2022-08-25 15:27:31 +00:00
}
2023-03-04 11:25:35 +00:00
}
2022-08-25 15:27:31 +00:00
) ) . widget )
2023-03-04 11:25:35 +00:00
-- Close the menu if prime_menu received a cascade::kill signal
prime_menu : connect_signal ( " cascade::kill " , function ( )
root_menu.visible = false
end )
-- Close the prime_menu if our menu becomes invisible
2022-08-25 15:27:31 +00:00
root_menu : connect_signal ( " property::visible " , function ( )
2023-03-04 11:25:35 +00:00
if not root_menu.visible then
prime_menu : emit_signal_recursive ( " cascade::close " )
2022-08-25 15:27:31 +00:00
end
end )
2023-03-04 11:25:35 +00:00
-- Make the root_menu pop up on the desktop on right click
2022-08-25 15:27:31 +00:00
local buttons = root.buttons ( )
root.buttons ( gears.table . join ( buttons ,
awful.button ( { } , 3 , function ( )
root_menu.visible = ( not root_menu.visible )
if root_menu.visible then
root_menu : move_next_to ( gears.table . join ( mouse.coords ( ) , {
width = 0 ,
height = 0
} ) )
end
end )
) )
return root_menu
2023-03-04 11:25:35 +00:00
end