From 0569223a8fa0e7c5d90bb39f1a89cf733aca7a6a Mon Sep 17 00:00:00 2001 From: anakha Date: Mon, 28 Jun 2021 01:58:41 -0400 Subject: [PATCH] bindings update --- init.lua | 13 +++++-- methods.lua | 98 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 100 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 44af97d..d937496 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,7 @@ local geoms = machina.geoms local shuffle = machina.shuffle local my_shifter = machina.my_shifter local expand_vertical = machina.expand_vertical +local move_to = machina.move_to ---------------------------------------------------------- key bindings -- ; @@ -36,7 +37,15 @@ local bindings = { awful.key({modkey}, "[", my_shifter("backward")), awful.key({modkey}, "]", my_shifter("forward")), - --▨ move (clock) + --▨ move (clockwise) + + awful.key({modkey, "Shift"}, "Insert", move_to("top-left")), + awful.key({modkey, "Shift"}, "Page_Up", move_to("top-right")), + awful.key({modkey, "Shift"}, "Home", move_to("center")), + awful.key({modkey, "Shift"}, "End", move_to("center")), + awful.key({modkey, "Shift"}, "Delete", move_to("bottom-left")), + awful.key({modkey, "Shift"}, "Page_Down", move_to("bottom-right")), + --▨ move (positional) awful.key({modkey, "Shift" }, "[", shift_by_direction("left", true)), awful.key({modkey, "Shift" }, "]", shift_by_direction("right", true)), @@ -48,13 +57,13 @@ local bindings = { awful.key({modkey}, "Page_Up", expand_horizontal("right")), awful.key({modkey}, "Home", expand_horizontal("center")), awful.key({modkey}, "Page_Down", expand_vertical), + --▨ expand (neighbor) awful.key({modkey}, "End", function() client.focus.maximized_vertical = false client.focus.maximized_horizontal = false awful.client.floating.toggle() end), --|toggle floating status - --▨ expand awful.key({modkey}, "Left", focus_by_direction("left")), awful.key({modkey}, "j", focus_by_direction("left")), diff --git a/methods.lua b/methods.lua index 38c6bea..7a5aa3f 100644 --- a/methods.lua +++ b/methods.lua @@ -1,26 +1,76 @@ ---------------------------------------------------------------- locals -- ; local grect = require("gears.geometry").rectangle + local geoms = {} geoms.crt43 = function () return { - x = awful.screen.focused().workarea.width - client.focus:geometry().width, - y = awful.screen.focused().workarea.height - client.focus:geometry().height, - width = 1280, - height = 1024 + x=awful.screen.focused().workarea.width - client.focus:geometry().width, + y=awful.screen.focused().workarea.height - client.focus:geometry().height, + width=1280, + height=1024 } end geoms.p1080 = function () return { - x = awful.screen.focused().workarea.width - client.focus:geometry().width, - y = awful.screen.focused().workarea.height - client.focus:geometry().height, - width = awful.screen.focused().workarea.width * 0.65, - height = awful.screen.focused().workarea.height * 0.90 + x=awful.screen.focused().workarea.width - client.focus:geometry().width, + y=awful.screen.focused().workarea.height - client.focus:geometry().height, + width=awful.screen.focused().workarea.width * 0.65, + height=awful.screen.focused().workarea.height * 0.90 } end +geoms["center"] = function(useless_gap) + return { + x=awful.screen.focused().workarea.width/2 - client.focus.width/2, + y=awful.screen.focused().workarea.height/2 - client.focus.height/2 + } +end + +geoms["top-left"] = function(useless_gap) + return { + x=useless_gap, + y=useless_gap + } +end + +geoms["bottom-left"] = function(useless_gap) + return { + x=useless_gap, + y=awful.screen.focused().workarea.height - useless_gap - client.focus.height + } +end + +geoms["top-right"] = function(useless_gap) + return { + x=awful.screen.focused().workarea.width - useless_gap - client.focus.width, + y=useless_gap + } +end + +geoms["bottom-right"] = function(useless_gap) + return { + x=awful.screen.focused().workarea.width - useless_gap - client.focus.width, + y=awful.screen.focused().workarea.height - useless_gap - client.focus.height + } +end + +--------------------------------------------------------------- helpers -- ; + +local function getLowest(table) + local low = math.huge + local index + for i, v in pairs(table) do + if v < low then + low = v + index = i + end + end + return index +end + local function compare(a,b) return a.v < b.v end @@ -31,6 +81,13 @@ local function tablelength(T) return count end +local function notify(x) + return naughty.notify({preset = naughty.config.presets.critical, text=inspect(x)}) +end + + +----------------------------------------- focus_by_direction(direction) -- ; + local function focus_by_direction(direction) return function() if not client.focus then return false end @@ -39,6 +96,8 @@ local function focus_by_direction(direction) end end +--------------------------------------------------------- screen_info() -- ; + local function screen_info() local focused_screen = awful.screen.focused() or nil local workarea = focused_screen.workarea or nil @@ -97,6 +156,26 @@ local function get_regions() return machi_regions, machi_fn end +----------------------------------------------------------- get_edges() -- ; + + +local function move_to(location) + return function() + local useless_gap = nil + local regions = get_regions() + local edges = {x={},y={}} + + for i,region in ipairs(regions) do + edges.x[region.x] = region.x + region.width + edges.y[region.y] = region.y + region.height + end + + useless_gap = getLowest(edges.x) + client.focus:geometry(geoms[location](useless_gap)) + return + end +end + -------------------------------------------------- get_active_regions() -- ; local function get_active_regions() @@ -522,7 +601,8 @@ module = { geoms = geoms, shuffle = shuffle, my_shifter = my_shifter, - expand_vertical = expand_vertical + expand_vertical = expand_vertical, + move_to = move_to } return module