From 7b8ace725486a3c5072a1da65d9fb5876b05efe6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 24 Aug 2024 21:18:45 +0200 Subject: ... --- accounts/gkleen@sif/hyprland.nix | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/accounts/gkleen@sif/hyprland.nix b/accounts/gkleen@sif/hyprland.nix index 052f35b0..d4105952 100644 --- a/accounts/gkleen@sif/hyprland.nix +++ b/accounts/gkleen@sif/hyprland.nix @@ -256,6 +256,72 @@ in { [[ -n "$FUZZEL_RES" ]] || exit 1 wl-copy "$(cut -d ':' -f 1 <<<"$FUZZEL_RES" | tr -d '\n')" && wtype -k XF86Paste ''}" + "$mainMod, B, exec, ${pkgs.writeShellScript "bring" '' + export PATH="${lib.makeBinPath (with pkgs; [ cfg.programs.fuzzel.package gawk gojq cfg.wayland.windowManager.hyprland.package ])}:$PATH" + + state="$(hyprctl -j clients)" + active_window="$(hyprctl -j activewindow)" + active_workspace="$(hyprctl -j activeworkspace | gojq -r '.id')" + + current_addr="$(echo "$active_window" | gojq -r '.address')" + + window="$(echo "$state" | + gojq -r '.[] | select(.workspace.id == '"$active_workspace"') | select(.monitor != -1 ) | "\(.title)\t\(.address)"' | + fuzzel --log-level=warning --dmenu)" + + addr="$(echo "$window" | awk -F $'\t' '{print $2}')" + + if [[ "$addr" = "$current_addr" ]]; then + exit 0 + fi + + fullscreen_on_same_ws="$(echo "$state" | gojq -r '.[] | select(.fullscreen == true) | select(.workspace.id == '"$active_workspace"') | .address')" + + if [[ "$window" != "" ]]; then + if [[ "$fullscreen_on_same_ws" == "" ]]; then + hyprctl dispatch focuswindow address:"''${addr}" + else + # If we want to focus app_A and app_B is fullscreen on the same workspace, + # app_A will get focus, but app_B will remain on top. + # This monstrosity is to make sure app_A will end up on top instead. + # XXX: doesn't handle fullscreen 0, but I don't care. + hyprctl --batch "dispatch focuswindow address:''${fullscreen_on_same_ws}; dispatch fullscreen 1; dispatch focuswindow address:''${addr}; dispatch fullscreen 1" + fi + fi + ''}" + "$mainMod SHIFT, B, exec, ${pkgs.writeShellScript "bring" '' + export PATH="${lib.makeBinPath (with pkgs; [ cfg.programs.fuzzel.package gawk gojq cfg.wayland.windowManager.hyprland.package ])}:$PATH" + + state="$(hyprctl -j clients)" + active_window="$(hyprctl -j activewindow)" + + current_addr="$(echo "$active_window" | gojq -r '.address')" + + window="$(echo "$state" | + gojq -r '.[] | select(.monitor != -1 ) | "\(.title)\t\(.workspace.name)\t\(.address)"' | + fuzzel --log-level=warning --dmenu)" + + addr="$(echo "$window" | awk -F $'\t' '{print $3}')" + ws="$(echo "$window" | awk -F $'\t' '{print $2}')" + + if [[ "$addr" = "$current_addr" ]]; then + exit 0 + fi + + fullscreen_on_same_ws="$(echo "$state" | gojq -r ".[] | select(.fullscreen == true) | select(.workspace.name == \"$ws\") | .address")" + + if [[ "$window" != "" ]]; then + if [[ "$fullscreen_on_same_ws" == "" ]]; then + hyprctl dispatch focuswindow address:"''${addr}" + else + # If we want to focus app_A and app_B is fullscreen on the same workspace, + # app_A will get focus, but app_B will remain on top. + # This monstrosity is to make sure app_A will end up on top instead. + # XXX: doesn't handle fullscreen 0, but I don't care. + hyprctl --batch "dispatch focuswindow address:''${fullscreen_on_same_ws}; dispatch fullscreen 1; dispatch focuswindow address:''${addr}; dispatch fullscreen 1" + fi + fi + ''}" "$mainMod CTRL, return, togglespecialworkspace, term" "$mainMod CTRL, e, togglespecialworkspace, edit" -- cgit v1.2.3