custom menu entries

This commit is contained in:
BZ 2020-10-11 12:57:15 +02:00
parent 80a212806c
commit b771ae1e53
2 changed files with 89 additions and 4 deletions

View File

@ -96,6 +96,7 @@ Customization:
| `snapping` | false | enable snapping mode (see snapping section) |
| `snapping_max_distance` | nil | maximum snapping distance (mouse to client border) |
| `snapping_center_mouse` | false | center mouse on client when snapping |
| `custom_menu_entries` | {} | list of custom menu entries (see custom menues section) |
Snapping:
------------
@ -124,6 +125,48 @@ awful.mouse.append_global_mousebindings({
```
Custom Menues:
------------
It is possible to add your own menu entries. Entries can be added globally or only for certain classes based on regex matching.
```
custom_menu_entries = {
["Chromium"] = {
{
text = "toggle tabbar",
func = function(c)
keygrabber.stop()
root.fake_input("key_press", "F11")
awful.spawn.easy_async_with_shell("sleep 0.15", function()
c.fullscreen = false
end)
root.fake_input("key_release", "F11")
end
}
},
-- for every client:
[".*"] = {
{
text = "toggle top overlay",
func = function(c)
if c.floating and c.ontop and c.sticky then
c.floating = false
c.ontop = false
c.sticky = false
else
c.floating = true
c.width = 640
c.height = 360
c.ontop = true
c.sticky = true
awful.placement.top_right(c)
end
end
}
}
}
```
Custom Buttons:
------------

View File

@ -3,7 +3,6 @@ local gears = require("gears")
local awful = require("awful")
local theme = require("beautiful")
local naughty = require("naughty")
local dpi = theme.xresources.apply_dpi
local module = {}
@ -25,6 +24,14 @@ local function list2map(list)
return set
end
local function len(T)
local count = 0
for _ in pairs(T) do
count = count + 1
end
return count
end
local function doubleclicked(obj)
if obj.doubleclick_timer then
obj.doubleclick_timer:stop()
@ -84,7 +91,7 @@ local menu_move2screen = function(c)
return nil
end
function module.menu_client(c)
function module.menu_client(custom_menu, c)
local list = {}
local list_tags = menu_move2tag(c)
@ -160,6 +167,39 @@ function module.menu_client(c)
end
})
if custom_menu and len(custom_menu) > 0 then
local function generate_menu_entry(e)
if e and type(e) == 'table' and e.text then
local text = ""
if type(e.text) == 'string' then
text = e.text
end
if type(e.text) == 'function' then
text = e.text(c)
end
return {
text,
function()
if e.func then
e.func(c)
end
end
}
end
end
for regex, entries in pairs(custom_menu) do
if string.find(c.class, regex) then
for _, e in ipairs(entries) do
local menu_entry = generate_menu_entry(e)
if menu_entry then
table.insert(list, menu_entry)
end
end
end
end
end
return list
end
@ -229,6 +269,8 @@ local function new(config)
local show_button_tooltips = cfg.show_button_tooltips or false -- tooltip might intercept mouseclicks; not recommended!
local show_title_tooltip = cfg.show_title_tooltip or false -- might fuck up sloppy mouse focus; not recommended!
local custom_menu_entries = cfg.custom_menu_entries or {}
menu_selection_symbol = cfg.menu_selection_symbol or ""
local layout = cfg.layout or "fixed" -- "fixed" | "ratio"
@ -256,7 +298,7 @@ local function new(config)
if c.client_menu then
c.client_menu:hide()
end
c.client_menu = awful.menu(module.menu_client(c))
c.client_menu = awful.menu(module.menu_client(custom_menu_entries, c))
c.client_menu:toggle()
end
@ -377,7 +419,7 @@ local function new(config)
color_hover = color_top_hover,
button_size = button_top_size,
action = function(cl)
cl.top = not cl.top
cl.ontop = not cl.ontop
end
}