support for custom buttons definitions
This commit is contained in:
parent
21340d3446
commit
3fa0c82fd8
18
README.md
18
README.md
|
@ -94,6 +94,24 @@ Customization:
|
|||
| `resize_factor` | 0.01 | default client resize factor |
|
||||
| `stealth` | false | show only button colors on hover (set button colors to border colors) |
|
||||
|
||||
Custom Buttons:
|
||||
------------
|
||||
Add a custom button to `buttons` (`marked` in this example):
|
||||
|
||||
```
|
||||
buttons = { "minimize", "maximize", "close", "marked" }
|
||||
|
||||
```
|
||||
|
||||
Define the button:
|
||||
```
|
||||
button_marked_name = "my fancy custom button",
|
||||
button_marked_size = "25",
|
||||
button_marked_function = function(c) c.marked = not c.marked end,
|
||||
color_marked_focus = "#ff00ff",
|
||||
color_marked_normal = "#ffff00",
|
||||
color_marked_hover = "#ff0000",
|
||||
```
|
||||
|
||||
Example Configuration (as shown on gif):
|
||||
------------
|
||||
|
|
137
init.lua
137
init.lua
|
@ -51,9 +51,12 @@ local menu_move2tag = function(c, scr)
|
|||
for _, t in pairs(s.tags) do
|
||||
if t ~= awful.screen.focused().selected_tag then
|
||||
count = count + 1
|
||||
local entry = { t.index .. ": " .. t.name .. menu_marker(t.selected) .. " ", function()
|
||||
local entry = {
|
||||
t.index .. ": " .. t.name .. menu_marker(t.selected) .. " ",
|
||||
function()
|
||||
c:move_to_tag(t)
|
||||
end }
|
||||
end
|
||||
}
|
||||
table.insert(list, entry)
|
||||
end
|
||||
end
|
||||
|
@ -93,49 +96,72 @@ function module.menu_client(c)
|
|||
table.insert(list, {"move to screen", list_screens})
|
||||
end
|
||||
|
||||
table.insert(list, { "fullscreen" .. menu_marker(c.fullscreen), function()
|
||||
table.insert(list, {
|
||||
"fullscreen" .. menu_marker(c.fullscreen),
|
||||
function()
|
||||
c.fullscreen = not c.fullscreen
|
||||
c:raise()
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(list, { "maximize" .. menu_marker(c.maximized), function()
|
||||
table.insert(list, {
|
||||
"maximize" .. menu_marker(c.maximized),
|
||||
function()
|
||||
c.maximized = not c.maximized
|
||||
c:raise()
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(list, { "master" .. menu_marker(c == awful.client.getmaster()), function()
|
||||
table.insert(list, {
|
||||
"master" .. menu_marker(c == awful.client.getmaster()),
|
||||
function()
|
||||
c:swap(awful.client.getmaster())
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(list, { "sticky" .. menu_marker(c.sticky), function()
|
||||
table.insert(list, {
|
||||
"sticky" .. menu_marker(c.sticky),
|
||||
function()
|
||||
c.sticky = not c.sticky
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(list, { "top" .. menu_marker(c.ontop), function()
|
||||
table.insert(list, {
|
||||
"top" .. menu_marker(c.ontop),
|
||||
function()
|
||||
c.ontop = not c.ontop
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(list, { "minimize" .. menu_marker(c.minimized), function()
|
||||
table.insert(list, {
|
||||
"minimize" .. menu_marker(c.minimized),
|
||||
function()
|
||||
if c.minimized then
|
||||
c.minimized = false
|
||||
c:raise()
|
||||
else
|
||||
c.minimized = true
|
||||
end
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(list, { "floating" .. menu_marker(c.floating), function()
|
||||
table.insert(list, {
|
||||
"floating" .. menu_marker(c.floating),
|
||||
function()
|
||||
c.floating = not c.floating
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(list, { menu_marker(nil) .. "close", function()
|
||||
table.insert(list, {
|
||||
menu_marker(nil) .. "close",
|
||||
function()
|
||||
c:kill()
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
||||
return list
|
||||
end
|
||||
|
||||
|
||||
local rounded_corner_shape = function(radius, position)
|
||||
if position == "bottom" then
|
||||
return function(cr, width, height)
|
||||
|
@ -357,17 +383,13 @@ local function new(config)
|
|||
local smart_border_titlebars = function(c)
|
||||
local button_widgets = {}
|
||||
|
||||
local border_bg = wibox.widget.base.make_widget_declarative({
|
||||
id = "border_bg",
|
||||
bg = color_normal,
|
||||
widget = wibox.container.background
|
||||
})
|
||||
local border_bg = wibox.widget.base.make_widget_declarative(
|
||||
{id = "border_bg", bg = color_normal, widget = wibox.container.background})
|
||||
|
||||
border_bg:connect_signal("button::press", function(_, _, _, button)
|
||||
handle_button_press(c, button)
|
||||
end)
|
||||
|
||||
|
||||
if color_hover then
|
||||
border_bg:connect_signal("mouse::enter", function()
|
||||
border_bg.bg = color_hover
|
||||
|
@ -384,7 +406,8 @@ local function new(config)
|
|||
local border_expander, border_expander_center
|
||||
|
||||
if layout == "fixed" then
|
||||
border_expander_center = wibox.widget.base.make_widget_declarative({
|
||||
border_expander_center = wibox.widget.base.make_widget_declarative(
|
||||
{
|
||||
fill_vertical = true,
|
||||
fill_horizontal = true,
|
||||
content_fill_vertical = true,
|
||||
|
@ -392,7 +415,8 @@ local function new(config)
|
|||
border_bg,
|
||||
widget = wibox.container.place
|
||||
})
|
||||
border_expander = wibox.widget.base.make_widget_declarative({
|
||||
border_expander = wibox.widget.base.make_widget_declarative(
|
||||
{
|
||||
{layout = wibox.layout.fixed.horizontal},
|
||||
border_bg,
|
||||
{layout = wibox.layout.fixed.horizontal},
|
||||
|
@ -403,11 +427,7 @@ local function new(config)
|
|||
local _button_positions = list2map(button_positions)
|
||||
|
||||
for _, pos in pairs(positions) do
|
||||
local tb = awful.titlebar(c, {
|
||||
size = border_width,
|
||||
position = pos,
|
||||
bg = "#00000000"
|
||||
})
|
||||
local tb = awful.titlebar(c, {size = border_width, position = pos, bg = "#00000000"})
|
||||
|
||||
local btn_layout
|
||||
if layout == "fixed" then
|
||||
|
@ -419,18 +439,16 @@ local function new(config)
|
|||
|
||||
if _button_positions[pos] then
|
||||
-- border with buttons
|
||||
local button_layout = wibox.widget.base.make_widget_declarative({
|
||||
id = "button_layout",
|
||||
spacing_widget = spacing_widget,
|
||||
layout = btn_layout
|
||||
})
|
||||
local button_layout = wibox.widget.base.make_widget_declarative(
|
||||
{id = "button_layout", spacing_widget = spacing_widget, layout = btn_layout})
|
||||
|
||||
local titlebar_widget
|
||||
|
||||
if layout == "fixed" then
|
||||
if ori(pos) == "v" then
|
||||
local expander = align_vertical == "center" and border_expander_center or border_expander
|
||||
titlebar_widget = wibox.widget.base.make_widget_declarative({
|
||||
titlebar_widget = wibox.widget.base.make_widget_declarative(
|
||||
{
|
||||
align_vertical == "top" and button_layout or expander,
|
||||
align_vertical == "center" and button_layout or expander,
|
||||
align_vertical == "bottom" and button_layout or expander,
|
||||
|
@ -439,7 +457,8 @@ local function new(config)
|
|||
})
|
||||
else
|
||||
local expander = align_horizontal == "center" and border_expander_center or border_expander
|
||||
titlebar_widget = wibox.widget.base.make_widget_declarative({
|
||||
titlebar_widget = wibox.widget.base.make_widget_declarative(
|
||||
{
|
||||
align_horizontal == "left" and button_layout or expander,
|
||||
align_horizontal == "center" and button_layout or expander,
|
||||
align_horizontal == "right" and button_layout or expander,
|
||||
|
@ -450,12 +469,8 @@ local function new(config)
|
|||
end
|
||||
|
||||
if layout == "ratio" then
|
||||
titlebar_widget = wibox.widget.base.make_widget_declarative({
|
||||
button_layout,
|
||||
id = "titlebar_widget",
|
||||
bg = color_normal,
|
||||
widget = wibox.container.background
|
||||
})
|
||||
titlebar_widget = wibox.widget.base.make_widget_declarative(
|
||||
{button_layout, id = "titlebar_widget", bg = color_normal, widget = wibox.container.background})
|
||||
end
|
||||
|
||||
tb:setup{
|
||||
|
@ -465,7 +480,8 @@ local function new(config)
|
|||
widget = wibox.container.background()
|
||||
}
|
||||
|
||||
local ratio_button_layout = wibox.widget.base.make_widget_declarative({
|
||||
local ratio_button_layout = wibox.widget.base.make_widget_declarative(
|
||||
{
|
||||
homogeneous = layout == "ratio" and true or false,
|
||||
expand = true,
|
||||
layout = ori(pos) == "h" and wibox.layout.grid.horizontal or wibox.layout.grid.vertical
|
||||
|
@ -474,8 +490,20 @@ local function new(config)
|
|||
local list_of_buttons = {}
|
||||
for _, btn in pairs(buttons) do
|
||||
local b = button_definitions[btn]
|
||||
if b then
|
||||
local button_widget = wibox.widget.base.make_widget_declarative({
|
||||
|
||||
if not b then
|
||||
-- custom button
|
||||
b = {}
|
||||
b.name = cfg["button_" .. btn .. "_name"] or btn
|
||||
b.button_size = cfg["button_" .. btn .. "_size"] or button_size
|
||||
b.color_focus = cfg["color_" .. btn .. "_focus"] or "#ff00ff"
|
||||
b.color_normal = cfg["color_" .. btn .. "_normal"] or "#ff00ff"
|
||||
b.color_hover = cfg["color_" .. btn .. "_normal"] or "#ff1aff"
|
||||
b.action = cfg["button_" .. btn .. "_function"] or nil
|
||||
end
|
||||
|
||||
local button_widget = wibox.widget.base.make_widget_declarative(
|
||||
{
|
||||
id = b.name,
|
||||
forced_width = ori(pos) == "h" and b.button_size or nil,
|
||||
forced_height = ori(pos) == "v" and b.button_size or nil,
|
||||
|
@ -526,7 +554,6 @@ local function new(config)
|
|||
|
||||
button_widgets[b.name] = button_widget
|
||||
end
|
||||
end
|
||||
|
||||
if layout == "ratio" then
|
||||
ratio_button_layout:set_children(list_of_buttons)
|
||||
|
@ -539,10 +566,12 @@ local function new(config)
|
|||
if (ori(pos) == "h" and align_horizontal == "left") or (ori(pos) == "v" and align_vertical == "top") then
|
||||
button_layout:ajust_ratio(2, 0, button_ratio, 1.0 - button_ratio)
|
||||
end
|
||||
if (ori(pos) == "h" and align_horizontal == "right") or (ori( pos) == "v" and align_vertical == "bottom") then
|
||||
if (ori(pos) == "h" and align_horizontal == "right") or
|
||||
(ori(pos) == "v" and align_vertical == "bottom") then
|
||||
button_layout:ajust_ratio(2, 1.0 - button_ratio, button_ratio, 0)
|
||||
end
|
||||
if (ori(pos) == "h" and align_horizontal == "center") or (ori( pos) == "v" and align_vertical == "center") then
|
||||
if (ori(pos) == "h" and align_horizontal == "center") or
|
||||
(ori(pos) == "v" and align_vertical == "center") then
|
||||
local side_ratio = (1.0 - button_ratio) / 2
|
||||
button_layout:ajust_ratio(2, side_ratio, button_ratio, side_ratio)
|
||||
end
|
||||
|
@ -597,7 +626,9 @@ local function new(config)
|
|||
client.connect_signal("request::titlebars", smart_border_titlebars)
|
||||
end
|
||||
|
||||
return setmetatable(module, { __call = function(_, ...)
|
||||
return setmetatable(module, {
|
||||
__call = function(_, ...)
|
||||
new(...)
|
||||
return module
|
||||
end })
|
||||
end
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue