Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

111 lines
4.3 KiB

-- 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
local awmtk2 = require("awmtk2")
local wibox = require("wibox")
local awful = require("awful")
local gears = require("gears")
local builder = require("builder")
local ask = require("asckey")
local digger = require("digger")
local style = awmtk2.create_style("client_menu",
awmtk2.generic.composite_widget,{})
local templates = awmtk2.create_template_lib("client_menu",awmtk2.templates,{})
local t = awmtk2.build_templates(templates,style,false)
-- Create a global context menu for clients first
-- This saves us memory on not creating separate menus for every client
if not context_menu then
-- 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"}]}]]
end
context_menu = awful.popup(t.popup(builder(
config,
{
style = style.base,
}
)))
-- Close context menu on right click
context_menu:connect_signal("button::press",function(_,_,_,b)
if b == 3 then
context_menu.visible = false
end
end)
-- Generate a list of all existing menu_root objects
local menus = digger(context_menu.widget,"menu_root")
local context_menu_size = context_menu.width * context_menu.height
context_menu.widget:connect_signal("widget::size_changed",function()
-- Attach callbacks to close context_menu to new buttons
local already_managed = {}
for _,v in pairs(menus) do
already_managed[v] = true
end
menus = digger(context_menu.widget,"menu_root")
for _,v in pairs(menus) do
if not already_managed[v] then
v:connect_signal("cascade::kill",function()
context_menu.visible = false
end)
end
end
end)
-- Close all cascading menus if our menu becomes invisible
context_menu:connect_signal("property::visible",function()
local current_context_menu_size = context_menu.height * context_menu.width
if current_context_menu_size ~= context_menu_size then
context_menu:emit_signal("widget::size_changed")
context_menu_size = current_context_menu_size
end
if not context_menu.visible then
for _,v in pairs(menus) do
v:emit_signal_recursive("cascade::kill")
end
end
end)
-- If client became unfocused, close menu
client.connect_signal("focus",function()
context_menu.visible = false
end)
-- If any of the menus emits cascade::kill, close the menu
for _,v in pairs(menus) do
v:connect_signal("cascade::kill",function()
context_menu.visible = false
end)
end
end
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"})
))
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