Skip to content

Instantly share code, notes, and snippets.

@JustAPerson
Created October 4, 2018 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustAPerson/f2aadb7150c852734421aa0662dcc345 to your computer and use it in GitHub Desktop.
Save JustAPerson/f2aadb7150c852734421aa0662dcc345 to your computer and use it in GitHub Desktop.
Remember mouse positions when alt-tabbing with AwesomeWM
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