awesomewm-machina/init.lua

136 lines
3.9 KiB
Lua
Raw Normal View History

2021-06-10 16:28:28 +02:00
---------------------------------------------------------> dependencies -- ;
local gears = require("gears")
local awful = require("awful")
local modkey = "Mod4"
local function tablelength(T)
2021-06-10 16:44:01 +02:00
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
2021-06-10 16:28:28 +02:00
end
--------------------------------------------------------------> methods -- ;
local function region_tablist()
local focused_screen = awful.screen.focused()
local workarea = awful.screen.focused().workarea
local selected_tag = awful.screen.focused().selected_tag
local tablist = {}
local active_region = nil
local regions = awful.layout.get(focused_screen).machi_get_regions(workarea, selected_tag)
--+ table of regions on the selected screen and tag
2021-06-10 22:42:03 +02:00
if not client.focus then return {} end
2021-06-10 16:28:28 +02:00
--+ flow control
for i, a in ipairs(regions) do
if a.x <= client.focus.x and client.focus.x < a.x + a.width and
a.y <= client.focus.y and client.focus.y < a.y + a.height
then
active_region = i
end
end
--+ focused client's region
2021-06-10 16:36:59 +02:00
for _, tc in ipairs(screen[focused_screen].tiled_clients) do
if not (tc.floating or tc.immobilized) then
if regions[active_region].x <= tc.x + tc.width + tc.border_width * 2 and
tc.x <= regions[active_region].x + regions[active_region].width and
regions[active_region].y <= tc.y + tc.height + tc.border_width * 2 and
tc.y <= regions[active_region].y + regions[active_region].height
then
tablist[#tablist + 1] = tc
end
end
2021-06-10 16:28:28 +02:00
end
--+ tablist inside the active region
2021-06-10 20:34:19 +02:00
if tablelength(tablist) == 1 then
return {}
end
--> flow control: if there is only one client in the
2021-06-10 22:42:03 +02:00
--> region, there is nothing to shuffle. having this here
--> makes it easier to avoid if nesting later.
2021-06-10 16:28:28 +02:00
return tablist
end
--+ tablist order is adjusted by awesomewm and it will
--> always have the focused client as the first item.
---------------------------------------------------------> key bindings -- ;
local keys = gears.table.join(
awful.key({modkey}, "p", function ()
2021-06-10 16:44:01 +02:00
local tablist = region_tablist()
local next_client = nil
for _, cc in ipairs(tablist) do
2021-06-10 20:34:19 +02:00
client.focus:lower()
next_client = tablist[_+1]
next_client:emit_signal("request::activate", "mouse_enter",{raise = true})
break
--+ activate next client
2021-06-10 16:44:01 +02:00
end
2021-06-10 16:28:28 +02:00
end),
--+ shortcut: shuffle down
2021-06-10 16:44:01 +02:00
awful.key({modkey}, "o", function ()
local tablist = region_tablist()
local prev_client = nil
2021-06-10 16:28:28 +02:00
2021-06-10 16:44:01 +02:00
for i = #tablist, 1, -1 do
prev_client = tablist[i]
prev_client:emit_signal("request::activate", "mouse_enter",{raise = true})
break
--+ activate previous client
end
end),
--+ shortcut: shuffle up
2021-06-10 16:51:39 +02:00
awful.key({modkey}, "Page_Up", function ()
2021-06-10 20:24:28 +02:00
client.focus:geometry({width=800,height=800})
2021-06-10 20:41:12 +02:00
awful.placement.top_right(client.focus)
client.focus:raise()
2021-06-10 16:44:01 +02:00
end),
--+ shortcut: align top-right
2021-06-10 16:51:39 +02:00
awful.key({modkey}, "Page_Down", function ()
2021-06-10 20:24:28 +02:00
client.focus:geometry({width=800,height=800})
awful.placement.bottom_right(client.focus)
2021-06-10 20:41:12 +02:00
client.focus:raise()
2021-06-10 16:44:01 +02:00
end),
--+ shortcut: align bottom-right
2021-06-10 16:51:39 +02:00
awful.key({modkey}, "Home", function ()
2021-06-10 16:44:01 +02:00
if not client.focus.floating then client.focus.floating = true end
awful.placement.centered(client.focus)
2021-06-10 20:41:12 +02:00
client.focus:raise()
2021-06-10 16:44:01 +02:00
end),
--+ shortcut: align center as float
2021-06-10 16:51:39 +02:00
awful.key({modkey}, "Insert", function ()
2021-06-10 16:44:01 +02:00
awful.placement.top_left(client.focus)
2021-06-10 20:41:12 +02:00
client.focus:raise()
2021-06-10 16:44:01 +02:00
end),
--+ shortcut: align top-left
2021-06-10 16:51:39 +02:00
awful.key({modkey}, "Delete", function ()
2021-06-10 16:44:01 +02:00
awful.placement.bottom_left(client.focus)
2021-06-10 20:41:12 +02:00
client.focus:raise()
2021-06-10 16:44:01 +02:00
end)
--+ shortcut: align bottom-left
2021-06-10 16:28:28 +02:00
)
--------------------------------------------------------------> exports -- ;
local module = {
keys = keys,
tablist = tablist
}
return module