From 96fad77198599e859e6425a19fd9303d0c9813a3 Mon Sep 17 00:00:00 2001 From: Yingjie Wang Date: Sat, 30 May 2026 01:56:57 -0400 Subject: [PATCH] new: add wondow binds --- lua/binds/init.lua | 1 + lua/binds/window.lua | 138 +++++++++++++++++++++++++++++++++++++++++++ lua/conf/layout.lua | 4 +- 3 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 lua/binds/window.lua diff --git a/lua/binds/init.lua b/lua/binds/init.lua index 756103f..0ff90bc 100644 --- a/lua/binds/init.lua +++ b/lua/binds/init.lua @@ -3,6 +3,7 @@ local bind = require("lua.lib.bind") local pieces = { "apps", + "window", } M.binds = {} diff --git a/lua/binds/window.lua b/lua/binds/window.lua new file mode 100644 index 0000000..4858943 --- /dev/null +++ b/lua/binds/window.lua @@ -0,0 +1,138 @@ +local bind = require("lua.lib.bind") +local utils = require("lua.lib.utils") + +local M = {} + +local function maximize_active_window() + local actions = { + scrolling = hl.dsp.layout("colresize 1.0"), + } + local fallback = hl.dsp.window.fullscreen({ mode = "maximized" }) + return bind.layout_dispatcher(actions, fallback) +end + +M.binds = { + { + keys = bind.with_leader("Q"), + dispatcher = hl.dsp.window.close(), + desc = "Close the window", + }, + { + keys = bind.with_leader("SHIFT + Q"), + dispatcher = hl.dsp.window.kill(), + desc = "Kill the window", + }, + { + keys = bind.with_leader("F"), + dispatcher = hl.dsp.window.fullscreen({}), + desc = "Toggle fullscreen the window", + }, + { + keys = bind.with_leader("SHIFT + F"), + dispatcher = maximize_active_window(), + desc = "Toggle maximize the window", + }, + { + keys = bind.with_leader("CTRL + SHIFT + F"), + dispatcher = hl.dsp.window.fullscreen_state({ internal = 0, client = 2, action = "toggle" }), + desc = "Toggle fake the window it's fullscreened", + }, + { + keys = bind.with_leader("T"), + dispatcher = hl.dsp.window.float(), + desc = "Toggle float the window", + }, + { + keys = bind.with_leader("R"), + dispatcher = bind.layout_dispatcher({ + dwindle = hl.dsp.layout("rotatesplit"), + }, hl.dsp.no_op()), + desc = "Toggle split", + }, + { + keys = bind.with_leader("CTRL + R"), + dispatcher = bind.layout_dispatcher({ + dwindle = hl.dsp.layout("swapsplit"), + master = hl.dsp.layout("swapnext"), + }, hl.dsp.no_op()), + }, +} + +for key, dir in pairs({ + H = "left", + L = "right", + K = "up", + J = "down", +}) do + table.insert(M.binds, { + keys = bind.with_leader("SHIFT+" .. key), + dispatcher = hl.dsp.window.move({ direction = string.sub(dir, 1, 1) }), + desc = "Move window " .. dir, + }) + table.insert(M.binds, { + keys = bind.with_leader(key), + dispatcher = hl.dsp.focus({ direction = string.sub(dir, 1, 1) }), + desc = "Move window " .. dir, + }) + table.insert(M.binds, { + keys = bind.with_leader("CTRL + " .. key), + dispatcher = hl.dsp.window.move({ direction = string.sub(dir, 1, 1), group_aware = true }), + desc = "Move window " .. dir .. " with group_aware", + }) +end + +M.binds = utils.list_extend(M.binds, { + { + keys = bind.with_leader("SHIFT + left"), + dispatcher = hl.dsp.window.resize({ x = -100, y = 0, relative = true }), + desc = "Resize window x-100", + }, + { + keys = bind.with_leader("SHIFT + right"), + dispatcher = hl.dsp.window.resize({ x = 100, y = 0, relative = true }), + desc = "Resize window x+100", + }, + { + keys = bind.with_leader("SHIFT + up"), + dispatcher = hl.dsp.window.resize({ x = 0, y = -100, relative = true }), + desc = "Resize window y-100", + }, + { + keys = bind.with_leader("SHIFT + down"), + dispatcher = hl.dsp.window.resize({ x = 0, y = 100, relative = true }), + desc = "Resize window y+100", + }, +}) + +M.binds = utils.list_extend(M.binds, { + { + keys = bind.with_leader("mouse:272"), + dispatcher = hl.dsp.window.drag(), + desc = "Drag window", + }, + { + keys = bind.with_leader("mouse:273"), + dispatcher = hl.dsp.window.resize(), + desc = "Resize window", + }, +}) + +M.binds = utils.list_extend(M.binds, { + { + keys = bind.with_leader("G"), + dispatcher = hl.dsp.group.toggle(), + desc = "Toggle a group", + }, + { + keys = bind.with_leader("CTRL + Tab"), + dispatcher = hl.dsp.group.next(), + desc = "Switch to next window in group", + }, + { + keys = bind.with_leader("CTRL + SHIFT + Tab"), + dispatcher = hl.dsp.group.prev(), + desc = "Switch to previous window in group", + }, +}) + +return M diff --git a/lua/conf/layout.lua b/lua/conf/layout.lua index b235a45..3859bdd 100644 --- a/lua/conf/layout.lua +++ b/lua/conf/layout.lua @@ -5,7 +5,9 @@ M.confs = { general = { layout = settings["default_layout"], }, - dwindle = {}, + dwindle = { + preserve_split = true, + }, master = {}, scrolling = {}, monocle = {},