From ab90eaa1145b77b0d9811e49f05f5b8e3ec7dc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= <email@thomasave.be> Date: Mon, 29 May 2023 15:27:20 +0200 Subject: [PATCH] Add mouse utils --- awesome/keys.lua | 3 +-- awesome/mouse_utils.lua | 22 ++++++++++++++++++++++ awesome/rc.lua | 14 ++------------ nvim/lua/mappings.lua | 1 + zsh/.zshrc | 1 + 5 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 awesome/mouse_utils.lua diff --git a/awesome/keys.lua b/awesome/keys.lua index c03b2e9..d34c330 100644 --- a/awesome/keys.lua +++ b/awesome/keys.lua @@ -17,6 +17,7 @@ local naughty = require("naughty") local beautiful = require("beautiful") local volume_widget = require("widgets.volume-widget.volume") local dpi = beautiful.xresources.apply_dpi +local mouse_utils = require("mouse_utils") local modkey = "Mod4" @@ -87,8 +88,6 @@ local function move_client(sel, dir) client.focus = sel sel:raise() end - - -- screen.focus(sel.screen) end end diff --git a/awesome/mouse_utils.lua b/awesome/mouse_utils.lua new file mode 100644 index 0000000..dfe8d6b --- /dev/null +++ b/awesome/mouse_utils.lua @@ -0,0 +1,22 @@ +local mouse_utils = {} + +function mouse_utils.move_mouse_onto_focused_client() + local c = client.focus + if c then + local geometry = c:geometry() + local mouse_coords = mouse.coords() + local margin = 10 + -- Don't move the mouse if it's already over the client + if not (mouse_coords.x > geometry.x - margin + and mouse_coords.x < geometry.x + geometry.width + margin + and mouse_coords.y > geometry.y - margin + and mouse_coords.y < geometry.y + geometry.height + margin) then + + local x = geometry.x + geometry.width/2 + local y = geometry.y + geometry.height/2 + mouse.coords({x = x, y = y}, true) + end + end +end + +return mouse_utils diff --git a/awesome/rc.lua b/awesome/rc.lua index e224b5e..2df039d 100644 --- a/awesome/rc.lua +++ b/awesome/rc.lua @@ -10,6 +10,7 @@ local gears = require("gears") local awful = require("awful") local grid = require("layout.grid") +local mouse_utils = require("mouse_utils") -- =================================================================== @@ -132,17 +133,6 @@ screen.connect_signal("property::geometry", awesome.restart) collectgarbage("setpause", 110) collectgarbage("setstepmul", 1000) -local function move_mouse_onto_focused_client() - local c = client.focus - if c then - local geometry = c:geometry() - local x = geometry.x + geometry.width/2 - local y = geometry.y + geometry.height/2 - mouse.coords({x = x, y = y}, true) - end -end - - client.connect_signal("property::maximized", function(focused) local hide = focused.maximized or focused.fullscreen for i, c in ipairs(client.get()) do @@ -168,7 +158,7 @@ client.connect_signal("focus", function(c) if #c.screen.clients > 1 then c.border_color = beautiful.border_focus end - move_mouse_onto_focused_client() + gears.timer.delayed_call(mouse_utils.move_mouse_onto_focused_client) end) client.connect_signal("unfocus", function(c) diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua index 93aa227..783af70 100644 --- a/nvim/lua/mappings.lua +++ b/nvim/lua/mappings.lua @@ -3,6 +3,7 @@ vim.api.nvim_set_keymap("n", "j", "gj", {}) vim.api.nvim_set_keymap("n", "k", "gk", {}) vim.api.nvim_set_keymap("n", "<S-k>", "<Nop>", {}) vim.api.nvim_set_keymap("v", "<S-y>", "\"+y", { noremap = true }) +vim.api.nvim_set_keymap("n", "<S-p>", "\"+p", { noremap = true }) vim.api.nvim_set_keymap("v", "<S-p>", "\"+p", { noremap = true }) vim.api.nvim_set_keymap("n", "<C-U>", "<C-O>", { noremap = true }) vim.api.nvim_set_keymap("n", "<C-E>", "<C-U>", { noremap = true }) diff --git a/zsh/.zshrc b/zsh/.zshrc index 1a55451..5069fcf 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -197,3 +197,4 @@ alias vim="nvim" alias wget=wget --hsts-file="$XDG_DATA_HOME/wget-hsts" alias xbindkeys="xbindkeys -f $XDG_CONFIG_HOME/xbindkeys/config" alias python=python3 +alias r=". ranger"