diff --git a/hypr/helpers/focus-or-start.lua b/hypr/helpers/focus-or-start.lua new file mode 100644 index 0000000..6e7de21 --- /dev/null +++ b/hypr/helpers/focus-or-start.lua @@ -0,0 +1,11 @@ + +function FocusOrStart(command, classPrefix) + for _, window in ipairs(hl.get_windows()) do + if window.class:sub(1, #classPrefix) == classPrefix then + hl.dispatch(hl.dsp.focus({ window = window })) + return + end + end + + hl.exec_cmd(command) +end diff --git a/hypr/hyprland.lua b/hypr/hyprland.lua index 0ed7033..febe9db 100644 --- a/hypr/hyprland.lua +++ b/hypr/hyprland.lua @@ -1,5 +1,7 @@ -- Hyprland 0.56.2 Lua configuration, migrated from hyprland.conf. +require('helpers.focus-or-start') + -- Variables -- ----------------------------------------- @@ -29,9 +31,6 @@ local autostart = { "telegram", } --- Scripts -local focusOrStart = ".config/hypr/scripts/focus-or-start.sh" - -- Environment -- ----------------------------------------- @@ -179,8 +178,12 @@ hl.layer_rule({ 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 .. " + T", hl.dsp.exec_cmd(focusOrStart .. ' "telegram" "org.telegram"')) -hl.bind(kb_super .. " + G", hl.dsp.exec_cmd(focusOrStart .. ' "vivaldi-stable" "vivaldi-stable"')) +hl.bind(kb_super .. " + T", function() + FocusOrStart("telegram", "org.telegram") +end) +hl.bind(kb_super .. " + G", function() + FocusOrStart("vivaldi-stable", "vivaldi-stable") +end) hl.bind(kb_super .. " + S", hl.dsp.exec_cmd(screenshot)) hl.bind(kb_super .. " + X", hl.dsp.window.close()) diff --git a/hypr/scripts/focus-or-start.sh b/hypr/scripts/focus-or-start.sh deleted file mode 100755 index 093d1eb..0000000 --- a/hypr/scripts/focus-or-start.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -execCommand=$1 -className=$2 - -class=$(hyprctl -j clients | jq -r ".[] | select(.class | startswith(\"${className}\")) | .class") - -if [[ $class != "" ]] -then - hyprctl dispatch focuswindow "class:${class}" -else - ${execCommand} & -fi