awesomewm-micky/init.lua

94 lines
2.8 KiB
Lua
Raw Normal View History

2021-06-03 15:28:23 +02:00
--------------------------------------------------------------> dependencies ;
2021-05-29 06:01:09 +02:00
local gears = require('gears')
2021-06-05 06:44:43 +02:00
local inspect = require('inspect')
-----------------------------------------------------------------> locals -- ;
local stay_classes = {
awesome
}
--+ class names defined here would insist micky stays where
--> he is at.
2021-05-29 06:01:09 +02:00
2021-06-03 15:28:23 +02:00
-------------------------------------------------------------------> methods ;
2021-05-29 06:01:09 +02:00
2021-06-05 06:44:43 +02:00
local function set_contains(set, key)
return set[key] ~= nil
end
2021-06-04 08:57:52 +02:00
local micky = function ()
2021-06-03 15:28:23 +02:00
gears.timer.weak_start_new(0.05, function()
2021-05-29 06:01:09 +02:00
local c = client.focus
local cgeometry = c:geometry()
2021-06-04 08:57:52 +02:00
mouse.coords({
x = cgeometry.x + cgeometry.width / 2,
y = cgeometry.y + cgeometry.height / 2
})
2021-05-29 06:01:09 +02:00
end)
2021-06-03 15:28:23 +02:00
end
--+ relocate mouse after slightly waiting for focus to
--> complete. you can adjust the timer if you are on a slow
--> cpu to give more time for the client to appear.
2021-05-29 06:01:09 +02:00
2021-06-03 15:28:23 +02:00
---------------------------------------------------------------------> signal ;
2021-05-29 06:01:09 +02:00
client.connect_signal("focus", function(c)
2021-06-05 06:44:43 +02:00
-- naughty.notify({text=inspect(mouse.coords())})
2021-06-03 15:28:23 +02:00
local focused_client = c
--+ client the focus is going towards
2021-05-29 06:01:09 +02:00
2021-06-03 15:28:23 +02:00
gears.timer.weak_start_new(0.05, function()
2021-06-05 06:44:43 +02:00
local client_under_mouse = mouse.current_client
2021-06-03 15:28:23 +02:00
2021-06-05 06:44:43 +02:00
if not set_contains(stay_classes, client_under_mouse.class) then
if not client_under_mouse then
micky() return false
end
--+ nothing under the mouse, move directly
2021-06-03 15:28:23 +02:00
2021-06-05 06:44:43 +02:00
if focused_client ~= client_under_mouse then
micky() return false
end
--+ no need to relocate the mouse if already over
--> the client.
2021-06-03 15:28:23 +02:00
end
end)
--+ mouse.current_client would point to the previous
--> client without the callback.
2021-05-29 06:01:09 +02:00
end)
2021-06-03 14:08:59 +02:00
client.connect_signal("unmanage", function(c)
2021-06-05 06:44:43 +02:00
local client_under_mouse = mouse.current_client
-- naughty.notify({text=inspect(c:geometry())})
2021-06-03 14:08:59 +02:00
2021-06-05 06:44:43 +02:00
if client_under_mouse and c ~= client_under_mouse then
2021-06-04 08:57:52 +02:00
micky()
2021-06-03 15:28:23 +02:00
end
2021-06-04 08:57:52 +02:00
--+ no need for the callback here.
2021-06-03 15:28:23 +02:00
end)
2021-06-03 14:08:59 +02:00
2021-06-03 15:28:23 +02:00
---------------------------------------------------------------------> export ;
2021-05-29 06:01:09 +02:00
2021-06-04 08:57:52 +02:00
return micky
2021-05-29 06:01:09 +02:00
2021-06-04 08:57:52 +02:00
--+ can also manually invoke the function through
--> shortcuts, but this is not necessary with this new
--> version.
2021-05-29 06:01:09 +02:00
-- awful.key({}, 'XF86HomePage', function ()
-- awful.client.run_or_raise(chromium, matcher('Google-chrome'))
-- mouser()
-- end),
2021-06-03 15:28:23 +02:00
-- naughty.notify({text=current_client.name})
-- naughty.notify({text=focused_client.name})
2021-06-05 06:44:43 +02:00
-- todo: disable mouse movement if unmanage was initiated by mouse click
-- it seems the only way to do it externally would be to
-- 1: get the geometry and location of the client in unmanage state
-- 2: get mouse position
-- 3: guess the Y area, like top 20 pixels or relative to the client
-- 4: assume, it was a mouse click