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/>.
-- Client context menu base
2022-08-25 15:27:31 +00:00
local awmtk2 = require ( " awmtk2 " )
local wibox = require ( " wibox " )
local awful = require ( " awful " )
2023-02-03 12:12:22 +00:00
local gears = require ( " gears " )
2022-08-25 15:27:31 +00:00
local builder = require ( " builder " )
2023-03-04 11:25:35 +00:00
local menugen = require ( " context_menu " )
2023-02-03 12:12:22 +00:00
local ask = require ( " asckey " )
2022-09-05 21:54:11 +00:00
local style = awmtk2.create_style ( " client_menu " ,
2023-03-04 11:25:35 +00:00
awmtk2.generic . composite_widget , { } )
2022-08-25 15:27:31 +00:00
local templates = awmtk2.create_template_lib ( " client_menu " , awmtk2.templates , { } )
2023-01-16 12:47:51 +00:00
local t = awmtk2.build_templates ( templates , style , false )
2022-08-25 15:27:31 +00:00
-- Create a global context menu for clients first
2022-08-31 12:20:58 +00:00
-- This saves us memory on not creating separate menus for every client
2022-08-25 15:27:31 +00:00
if not context_menu then
2023-03-04 11:25:35 +00:00
-- load client menu config
local config_file = io.open ( root_path .. " /themes/ " .. global.theme .. ' /config/client_menu.json ' , " r " )
local config
if config_file then
config = config_file : read ( " *a " )
config_file : close ( )
else
config = [[{"list":[{"widget":"widgets.clientcontrols"}]}]]
2022-08-25 15:27:31 +00:00
end
2023-03-04 11:25:35 +00:00
-- NOTE: Please attach your menus to the prime_menu. It should be available as args.menu_parent via passthrough
local prime_menu = menugen ( { items = { } } )
context_menu = awful.popup ( t.popup ( builder (
config ,
{
style = style.base ,
passthrough = {
menu_parent = prime_menu
}
}
) ) )
-- Close context menu on right click
context_menu : connect_signal ( " button::press " , function ( _ , _ , _ , b )
if b == 3 then
2022-08-25 15:27:31 +00:00
context_menu.visible = false
2023-03-04 11:25:35 +00:00
end
end )
-- Close all cascading menus if our menu becomes invisible
context_menu : connect_signal ( " property::visible " , function ( )
if not context_menu.visible then
prime_menu : emit_signal ( " cascade::close " )
end
end )
-- If client became unfocused, close menu
client.connect_signal ( " focus " , function ( )
context_menu.visible = false
end )
-- Close our context menu when any of the attached menus signal cascade::kill
prime_menu : connect_signal ( " cascade::kill " , function ( )
context_menu.visible = false
end )
2022-08-25 15:27:31 +00:00
end
2023-02-03 12:12:22 +00:00
root.keys ( gears.table . join (
root.keys ( ) ,
ask.k ( " :client.menu " , function ( )
context_menu.visible = ( not context_menu.visible )
if context_menu.visible then
context_menu.x = client.focus . x + 10
context_menu.y = client.focus . y + 10
end
end , { description = " Open client menu " , group = " client " } )
) )
2022-08-25 15:27:31 +00:00
return function ( args )
local widget = wibox.widget ( {
widget = awful.widget . clienticon ,
client = args.client
} )
widget : connect_signal ( " button::press " , function ( )
context_menu.visible = ( not context_menu.visible )
if context_menu.visible then
context_menu.x = mouse.coords ( ) . x
context_menu.y = mouse.coords ( ) . y
end
end )
return widget
end