From 83c14bfb240b6c6da9eb0bb0251b43c3a4b4216d Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 2 Nov 2026 17:48:57 +0100 Subject: [PATCH] hyprland --- hypr/helpers/exec.lua | 18 ++++++++++++ hypr/helpers/terminal.lua | 60 +++++++++++++++++++++++++++++++++++++++ hypr/hyprland.lua | 12 ++++---- 3 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 hypr/helpers/exec.lua create mode 100644 hypr/helpers/terminal.lua diff --git a/hypr/helpers/exec.lua b/hypr/helpers/exec.lua new file mode 100644 index 0000000..2da387b --- /dev/null +++ b/hypr/helpers/exec.lua @@ -0,0 +1,18 @@ + +local uwsm = os.execute("uwsm check is-active >/dev/null 2>&1") + +local function normalize_cmd(cmd) + if uwsm == true or uwsm == 0 then + cmd = "uwsm-app " .. cmd + end + return cmd +end + +function dispatch(cmd) + return hl.dsp.exec_cmd(normalize_cmd(cmd)) +end + +function exec(cmd) + return hl.exec_cmd(normalize_cmd(cmd)) +end + diff --git a/hypr/helpers/terminal.lua b/hypr/helpers/terminal.lua new file mode 100644 index 0000000..84fb5cb --- /dev/null +++ b/hypr/helpers/terminal.lua @@ -0,0 +1,60 @@ +local definitions = { + ["uwsm"] = { + command = "uwsm-terminal", + test = "command -v uwsm-terminal && uwsm check is-active", + }, + ["ghostty"] = { + command = "ghostty", + args = "-e", + }, + ["kitty"] = { + command = "kitty", + args = "-e", + }, + ["xterm"] = { + command = "xterm", + args = "-e", + }, + ["urxvt"] = { + command = "urxvt", + args = "-e", + }, +} + + +local M = { + terminals = { "uwsm", "ghostty", "kitty", "xterm", "urxvt" } +} + +function M.configure(list) + M.terminals = list +end + +function M.exec(command) + local script = {} + + for _, name in ipairs(M.terminals) do + local term = assert(definitions[name], "Unknown terminal: " .. name) + local test = term.test or ("command -v " .. term.command) + + local cmd = term.command + + if command then + if term.args then + cmd = cmd .. " " .. term.args + end + + cmd = cmd .. " " .. command + end + + table.insert(script, string.format( + "if %s >/dev/null 2>&1; then exec %s; fi", + test, + cmd + )) + end + + return hl.dsp.exec_cmd(table.concat(script, "; ")) +end + +return M diff --git a/hypr/hyprland.lua b/hypr/hyprland.lua index 807b256..4a6b076 100644 --- a/hypr/hyprland.lua +++ b/hypr/hyprland.lua @@ -1,6 +1,8 @@ -- Hyprland 0.56.2 Lua configuration, migrated from hyprland.conf. require('helpers.focus-or-start') +require('helpers.exec') +local terminal = require('helpers.terminal') -- Variables -- ----------------------------------------- @@ -10,7 +12,7 @@ local mainMonitor = "DP-2" local secondMonitor = "HDMI-A-1" -- Programs -local terminal = "ghostty" +-- local terminal = "ghostty" local menu = "rofi -show drun" local runProgram = "rofi -show run" local screenshot = 'grim -g "$(slurp)" - | wl-copy' @@ -174,9 +176,9 @@ hl.layer_rule({ -- Keybindings -- ----------------------------------------- -hl.bind(kb_super .. " + D", hl.dsp.exec_cmd(menu)) -hl.bind(kb_super .. " + P", hl.dsp.exec_cmd(runProgram)) -hl.bind(kb_super .. " + Return", hl.dsp.exec_cmd(terminal)) +hl.bind(kb_super .. " + D", dispatch(menu)) +hl.bind(kb_super .. " + P", dispatch(runProgram)) +hl.bind(kb_super .. " + Return", terminal.exec()) hl.bind(kb_super .. " + T", function() FocusOrStart("telegram", "org.telegram") end) @@ -217,6 +219,6 @@ hl.bind(kb_super .. " + mouse:273", hl.dsp.window.resize()) hl.on("hyprland.start", function() for _, command in ipairs(autostart) do - hl.exec_cmd(command) + exec(command) end end)