hot_corners

This commit is contained in:
BZ 2021-03-20 19:03:22 +01:00
parent 0539aae6aa
commit f769617c1b
2 changed files with 148 additions and 7 deletions

View File

@ -8,6 +8,7 @@ smart_borders for awesomewm
Features:
------------
- Full titlebar functionality without sacrificing space
- Hot corners
- Improved mouse controls
- Custom client menu
- Anti-aliased rounded corners
@ -97,6 +98,10 @@ Customization:
| `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) |
| `hot_corners` | {} | hot_corners definitions (see hot corners section)|
| `hot_corners_color` | "#00000000" | color of hot_corners |
| `hot_corners_width` | dpi(1) | width of hot_corners |
| `hot_corners_height` | dpi(1) | height of hot_corners |
Snapping:
------------
@ -125,6 +130,56 @@ awful.mouse.append_global_mousebindings({
```
Hot Corners:
------------
<p align="center">
<img src="https://s4.gifyu.com/images/hot_corner.gif">
</p>
Execute custom functions at the corners of your screen (e.g. appmenu, volume control, etc.).
```
hot_corners = {
["top_right"] = {
left_click = function()
require("naughty").notify({text = "left_click"})
end,
right_click = function()
require("naughty").notify({text = "right_click"})
end,
middle_click = function()
require("naughty").notify({text = "middle_click"})
end,
forward_click = function()
require("naughty").notify({text = "forward_click"})
end,
back_click = function()
require("naughty").notify({text = "back_click"})
end,
wheel_up = function()
require("naughty").notify({text = "wheel_up"})
end,
wheel_down = function()
require("naughty").notify({text = "wheel_down"})
end,
enter = function()
require("naughty").notify({text = "enter"})
end,
leave = function()
require("naughty").notify({text = "leave"})
end
}
}
```
Possible positions are "top_left", "top_right", "bottom_left", "bottom_right" or any `awful.placement` defintion (e.g. "centered").
Execution can also be scriped:
```
echo "awesome.emit_signal('hot_corners::top_right::left_click')" | awesome-client
```
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.
@ -174,7 +229,6 @@ Add a custom button to `buttons` (`marked` in this example):
```
buttons = { "minimize", "maximize", "close", "marked" }
```
Define the button:
@ -209,7 +263,6 @@ s.mytasklist = awful.widget.tasklist {
}
```
Example Configuration (as shown on top gif):
------------
```

View File

@ -217,6 +217,76 @@ local rounded_corner_shape = function(radius, position)
return nil
end
local add_hot_corner = function(args)
args = args or {}
local position = args.position or ""
local placement = awful.placement[position]
if not placement then
return
end
local actions = args.buttons or {}
local s = args.screen or awful.screen.focused()
local width = args.width
local height = args.height
local color = args.color
local corner = awful.popup({
screen = s,
placement = placement,
ontop = true,
border_width = 0,
minimum_height = height,
maximum_height = height,
minimum_width = width,
maximum_width = width,
bg = color,
widget = wibox.widget.background
})
-- this will run for every screen, so we have to make sure to only add one signal handler for every assigned signal
local must_connect_signal = (s.index == 1)
local function signal_name(pos, action)
return "hot_corners::" .. pos .. "::" .. action
end
local defs = {
{name = "left_click", button = 1},
{name = "middle_click", button = 2},
{name = "right_click", button = 3},
{name = "wheel_up", button = 4},
{name = "wheel_down", button = 5},
{name = "back_click", button = 8},
{name = "forward_click", button = 9}
}
local buttons = {}
for _, btn in ipairs(defs) do
if actions[btn.name] then
local signal = signal_name(position, btn.name)
table.insert(buttons, awful.button({}, btn.button, function()
awesome.emit_signal(signal)
end))
if must_connect_signal then
awesome.connect_signal(signal, actions[btn.name])
end
end
end
corner:buttons(buttons)
for _, action in pairs({"enter", "leave"}) do
if actions[action] then
local signal = signal_name(position, action)
corner:connect_signal("mouse::" .. action, function()
awesome.emit_signal(signal)
end)
if must_connect_signal then
awesome.connect_signal(signal, actions[action])
end
end
end
end
local function new(config)
local cfg = config or {}
local positions = cfg.positions or {"left", "right", "top", "bottom"}
@ -268,6 +338,11 @@ local function new(config)
local snapping_center_mouse = cfg.snapping_center_mouse or false
local snapping_max_distance = cfg.snapping_max_distance or nil
local hot_corners = cfg.hot_corners or {}
local hot_corners_color = cfg.hot_corners_color or "#00000000"
local hot_corners_width = cfg.hot_corners_width or dpi(1)
local hot_corners_height = cfg.hot_corners_height or dpi(1)
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!
@ -434,6 +509,19 @@ local function new(config)
end
}
for s in screen do
for pos, buttons in pairs(hot_corners) do
add_hot_corner({
buttons = buttons,
screen = s,
position = pos,
color = hot_corners_color,
width = hot_corners_width,
height = hot_corners_height
})
end
end
if layout ~= "fixed" and layout ~= "ratio" then
layout = "fixed"
end