snapping mode

This commit is contained in:
BZ 2020-08-17 01:22:47 +02:00
parent e8cf1895b9
commit 80a212806c
2 changed files with 111 additions and 3 deletions

View File

@ -93,6 +93,37 @@ Customization:
| `menu_selection_symbol` | "✔" | default menu selection indicator | | `menu_selection_symbol` | "✔" | default menu selection indicator |
| `resize_factor` | 0.01 | default client resize factor | | `resize_factor` | 0.01 | default client resize factor |
| `stealth` | false | show only button colors on hover (set button colors to border colors) | | `stealth` | false | show only button colors on hover (set button colors to border colors) |
| `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 |
Snapping:
------------
When `useless_gaps` are disabled it is very easy and fast to control clients by using the mouse since you only have to move your mouse to the edge of the screen to hit the client border.
However, when `useless_gaps` are enabled it can be frustrating to hit the border.
Therefore `snapping` will snap to the closest client if you click on the desktop/wallpaper.
<p align="center">
<img src="https://s7.gifyu.com/images/snapping.gif">
</p>
Please note that `snapping` currently requires `awesomewm git` version.
Unfortunately it is not possible to remove default mouse bindings, therefore you have to remove these on your own.
Remove the following from `rc.lua`:
```
-- {{{ Mouse bindings
-- @DOC_ROOT_BUTTONS@
awful.mouse.append_global_mousebindings({
awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewprev),
awful.button({ }, 5, awful.tag.viewnext),
})
-- }}}
```
Custom Buttons: Custom Buttons:
------------ ------------

View File

@ -2,12 +2,13 @@ local wibox = require("wibox")
local gears = require("gears") local gears = require("gears")
local awful = require("awful") local awful = require("awful")
local theme = require("beautiful") local theme = require("beautiful")
local naughty = require("naughty")
local dpi = theme.xresources.apply_dpi local dpi = theme.xresources.apply_dpi
local module = {} local module = {}
local client = client local client, screen, mouse = client, screen, mouse
local screen = screen
local function ori(pos) local function ori(pos)
if pos == "left" or pos == "right" then if pos == "left" or pos == "right" then
@ -222,6 +223,10 @@ local function new(config)
local stealth = cfg.stealth or false local stealth = cfg.stealth or false
local snapping = cfg.snapping or false
local snapping_center_mouse = cfg.snapping_center_mouse or false
local snapping_max_distance = cfg.snapping_max_distance or nil
local show_button_tooltips = cfg.show_button_tooltips or false -- tooltip might intercept mouseclicks; not recommended! 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 show_title_tooltip = cfg.show_title_tooltip or false -- might fuck up sloppy mouse focus; not recommended!
menu_selection_symbol = cfg.menu_selection_symbol or "" menu_selection_symbol = cfg.menu_selection_symbol or ""
@ -270,13 +275,17 @@ local function new(config)
end end
local button_funcs = {} local button_funcs = {}
button_funcs[1] = function(c)
local left_click_function = function(c)
if doubleclicked(c) then if doubleclicked(c) then
button_double_click(c) button_double_click(c)
else else
button_left_click(c) button_left_click(c)
end end
end end
button_funcs[1] = left_click_function
button_funcs[2] = function(c) button_funcs[2] = function(c)
button_middle_click(c) button_middle_click(c)
end end
@ -380,6 +389,74 @@ local function new(config)
button_positions = {button_positions} button_positions = {button_positions}
end end
if snapping then
if awful and awful.mouse and awful.mouse.append_global_mousebindings then
local mouse_closest_client = function()
local s = awful.screen.focused()
local m_x = mouse.coords().x
local m_y = mouse.coords().y
local closest_distance, closest_c
for _, c in ipairs(s.all_clients) do
if c:isvisible() then
local x = c.x + (c.width / 2)
local y = c.y + (c.height / 2)
local dx = math.max(math.abs(m_x - x) - (c.width / 2), 0)
local dy = math.max(math.abs(m_y - y) - (c.height / 2), 0)
local distance = math.sqrt(dx * dx + dy * dy)
if (not snapping_max_distance or (distance <= snapping_max_distance)) and
(not closest_distance or distance < closest_distance) then
closest_distance = distance
closest_c = c
end
end
end
return closest_c
end
awful.mouse.append_global_mousebindings({
awful.button({}, 1, function()
local c = mouse_closest_client()
if c then
if snapping_center_mouse then
mouse.coords {x = c.x + c.width / 2, y = c.y + c.height / 2}
end
left_click_function(c)
end
end),
awful.button({}, 2, function()
local c = mouse_closest_client()
if c then
button_middle_click(c)
end
end),
awful.button({}, 3, function()
local c = mouse_closest_client()
if c then
button_right_click(c)
end
end),
awful.button({}, 4, function()
local c = mouse_closest_client()
if c then
button_wheel_up(c)
end
end),
awful.button({}, 5, function()
local c = mouse_closest_client()
if c then
button_wheel_down(c)
end
end)
})
else
naughty.notify({title = "smart_borders", text = "snapping requires awesomewm git version!", timeout = 0})
end
end
local smart_border_titlebars = function(c) local smart_border_titlebars = function(c)
local button_widgets = {} local button_widgets = {}