awesomewm-micky/init.lua

112 lines
3.3 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 -- ;
2022-09-25 09:52:06 +02:00
local stay_classes = {
2021-06-05 06:44:43 +02:00
awesome
2021-06-06 16:28:55 +02:00
-- taskbar
2021-06-05 06:44:43 +02:00
}
--+ 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
2022-09-25 09:52:06 +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()
2022-09-25 09:52:06 +02:00
mouse.coords({
2021-06-04 08:57:52 +02:00
x = cgeometry.x + cgeometry.width / 2,
2022-09-25 09:52:06 +02:00
y = cgeometry.y + cgeometry.height / 2
2021-06-04 08:57:52 +02:00
})
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-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-07-06 22:16:20 +02:00
gears.timer.weak_start_new(0.15, function()
2021-06-05 06:44:43 +02:00
local client_under_mouse = mouse.current_client
2021-06-05 07:02:13 +02:00
local should_stay = set_contains(stay_classes, client_under_mouse.class)
2021-06-03 15:28:23 +02:00
2021-06-05 07:02:13 +02:00
if should_stay then return false end
2022-09-25 09:52:06 +02:00
--+ exclusions
2021-07-06 22:16:20 +02:00
2021-06-05 07:02:13 +02:00
if not client_under_mouse then
2021-06-06 16:28:55 +02:00
micky()
return false
2021-06-03 15:28:23 +02:00
end
2021-06-05 07:02:13 +02:00
--+ nothing under the mouse, move directly
2021-07-06 22:16:20 +02:00
if focused_client:geometry().x ~= client_under_mouse:geometry().x
2022-09-25 09:52:06 +02:00
or focused_client:geometry().y ~= client_under_mouse:geometry().y
then
micky()
return false
2021-06-05 07:02:13 +02:00
end
--+ no need to relocate the mouse if already over
--> the client.
2021-06-03 15:28:23 +02:00
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
2021-06-03 14:08:59 +02:00
2022-09-25 09:52:06 +02:00
local killed_client = c
--+ client the focus is going towards
if not client_under_mouse then
2021-06-06 16:28:55 +02:00
return false
end
if client_under_mouse ~= c then
2021-06-04 08:57:52 +02:00
micky()
2022-09-25 09:52:06 +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
2022-09-25 09:52:06 +02:00
-- awful.key({}, 'XF86HomePage', function ()
-- awful.client.run_or_raise(chromium, matcher('Google-chrome'))
-- mouser()
2021-05-29 06:01:09 +02:00
-- end),
2021-06-03 15:28:23 +02:00
-- naughty.notify({text=current_client.name})
-- naughty.notify({text=focused_client.name})
2021-06-06 16:28:55 +02:00
-- naughty.notify({text=inspect(c:geometry())})
-- naughty.notify({text=inspect(mouse.current_widget_geometry)})
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
2021-06-06 16:28:55 +02:00
-- 4: assume, it was a mouse click
-- proximity detection sometimes, it's annoying this thing
-- centers while we are super close to the next window we
-- should add promixity detection, and if too close to the
2022-09-25 09:52:06 +02:00
-- upcoming client, we should let the mouse stay.