Created
October 4, 2018 18:34
-
-
Save JustAPerson/f2aadb7150c852734421aa0662dcc345 to your computer and use it in GitHub Desktop.
Remember mouse positions when alt-tabbing with AwesomeWM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local awful = require('awful'); | |
local memory = {} | |
local function client_focus(c) | |
-- do nothing if focusing client under cursor | |
if mouse.current_client == c then | |
return | |
end | |
-- move mouse either to memory or centered over window | |
local coords = memory[c] or { x = c.width / 2, y = c.height / 2}; | |
coords.x = coords.x + c.x; | |
coords.y = coords.y + c.y; | |
mouse.coords(coords); | |
end | |
local function client_unfocus(c) | |
-- are we leaving the client under the mouse | |
if mouse.current_client == c then | |
-- yes then remember the relative coords | |
mcoords = mouse.coords(); | |
memory[c] = { | |
x = mcoords.x - c.x, | |
y = mcoords.y - c.y, | |
}; | |
else | |
-- no then we've already moved the mouse off this window so | |
-- we should clear memory | |
memory[c] = nil; | |
end | |
end | |
client.connect_signal('focus', client_focus) | |
client.connect_signal('unfocus', client_unfocus) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment