diff --git a/hypr/hyprland.conf b/hypr/hyprland.conf index f6d23ee..07de4b0 100644 --- a/hypr/hyprland.conf +++ b/hypr/hyprland.conf @@ -1,6 +1,9 @@ -exec-once=hyprpaper env = WLR_DRM_DEVICES,/dev/dri/card0:/dev/dri/card1 env = WLR_NO_HARDWARE_CURSORS,1 + +$scripts = /home/user/.config/scripts + +exec-once=hyprpaper monitor=DP-2,preferred,0x550,1 monitor=DP-1,preferred,1920x0,1,bitdepth,10 monitor=HDMI-A-1,preferred,5760x550,1 @@ -117,9 +120,9 @@ gestures { $mainMod = SUPER # Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more -bindr = $mainMod, SUPER_L, exec, /home/user/.config/scripts/toggle_rofi.sh -bindr = $mainMod, SUPER_R, exec, /home/user/.config/scripts/toggle_rofi.sh -bind = $mainMod, return, exec, /home/user/.config/scripts/launch_alacritty.sh $(hyprctl activewindow -j | jq .pid) +bindr = $mainMod, SUPER_L, exec, $scripts/toggle_rofi.sh +bindr = $mainMod, SUPER_R, exec, $scripts/toggle_rofi.sh +bind = $mainMod, return, exec, $scripts/launch_alacritty.sh $(hyprctl activewindow -j | jq .pid) bind = $mainMod SHIFT, return, exec, alacritty bind = $mainMod, Q, killactive, bind = $mainMod, A, exec, nautilus @@ -132,9 +135,9 @@ bind = CONTROL_L ALT_L, L, exec, swaylock bind = $mainMod, C, exec, cliphist list | awk '{print $0, "\0icon\x1fcom.github.davidmhewitt.clipped"}' | rofi -dmenu -display-columns 2 | cliphist decode | wl-copy bind = $mainMod, Y, exec, /home/user/.config/rofi/rofi-ykman.sh bind = Super_L Control_L, Q, exec, systemctl suspend -bind = $mainMod, Escape, exec, rofi -show power-menu -modi power-menu:/home/user/.config/scripts/rofi-power-menu +bind = $mainMod, Escape, exec, rofi -show power-menu -modi power-menu:$scripts/rofi-power-menu -bind = ,XF86PowerOff, exec, rofi -show power-menu -modi power-menu:/home/user/.config/scripts/rofi-power-menu +bind = ,XF86PowerOff, exec, rofi -show power-menu -modi power-menu:$scripts/rofi-power-menu bind = ,XF86MonBrightnessUp, exec, xbacklight -inc 10 bind = ,XF86MonBrightnessDown, exec, xbacklight -dec 10 bind = ,XF86AudioRaiseVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 10%+ --limit 1.0 @@ -150,10 +153,10 @@ bind = $mainMod,XF86AudioLowerVolume, exec, playerctl previous bind = , Print, exec, grim -g "$(slurp -d)" - | wl-copy # Move focus with mainMod + arrow keys -bind = $mainMod, H, movefocus, l -bind = $mainMod, L, movefocus, r -bind = $mainMod, K, movefocus, u -bind = $mainMod, J, movefocus, d +bind = $mainMod, H, exec, $scripts/vim-hypr-nav.sh l +bind = $mainMod, L, exec, $scripts/vim-hypr-nav.sh r +bind = $mainMod, K, exec, $scripts/vim-hypr-nav.sh u +bind = $mainMod, J, exec, $scripts/vim-hypr-nav.sh d bind = $mainMod CONTROL_L, H, swapwindow, l bind = $mainMod CONTROL_L, L, swapwindow, r bind = $mainMod CONTROL_L, K, swapwindow, u diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index cbd24bb..c2b9387 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,6 +1,5 @@ { "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, - "awesomewm-vim-tmux-navigator": { "branch": "master", "commit": "b56319dc9378564d2e1d2123751d6b4a893abfc2" }, "bufferline.nvim": { "branch": "main", "commit": "6ecd37e0fa8b156099daedd2191130e083fb1490" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, @@ -31,6 +30,7 @@ "trim.nvim": { "branch": "master", "commit": "629b96a303a3a0bb5fd050e6cd9d627ca7831cc7" }, "trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" }, "vim-bracketed-paste": { "branch": "master", "commit": "45411da73cc159e4fc2138d930553d247bbfbcdc" }, + "vim-hypr-nav": { "branch": "main", "commit": "6ab4865a7eb5aad35305298815a4563c9d48556a" }, "vim-rooter": { "branch": "master", "commit": "1353fa47ee3a81083c284e28ff4f7d92655d7c9e" }, "vim-snippets": { "branch": "master", "commit": "b039190177d97a968d80518470910aae7faf182a" }, "vimtex": { "branch": "master", "commit": "7d1dbd0eebe041fbda4d1132622bf051b1546497" }, diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index b31154d..63f6d59 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -15,8 +15,8 @@ vim.opt.rtp:prepend(lazypath) require('lazy').setup({ 'ConradIrwin/vim-bracketed-paste', 'airblade/vim-rooter', + 'nuchs/vim-hypr-nav', 'debugloop/telescope-undo.nvim', - 'intrntbrn/awesomewm-vim-tmux-navigator', 'mhartington/formatter.nvim', {'vimwiki/vimwiki', init = function () vim.g.vimwiki_list = {{path = '~/Workspace/DnD/Lumentis Campaign Setting/', syntax = 'markdown', ext = '.md'}} diff --git a/scripts/vim-hypr-nav.sh b/scripts/vim-hypr-nav.sh new file mode 100755 index 0000000..1eca3b0 --- /dev/null +++ b/scripts/vim-hypr-nav.sh @@ -0,0 +1,62 @@ +#!/bin/sh +# +# vim-hypr-nav - Use the same bindings to move focus between hyprland windows +# and vim splits. Requires the accompanying vim plugin and jq. + +dir="$1" + +case "$dir" in + u) ;; + r) ;; + d) ;; + l) ;; + *) + echo "USAGE: $0 u|r|d|l" + exit 1 +esac + +get_descendant_vim_pid() { + pid="$1" + terms="$2" + + if grep -iqE '^g?(view|n?vim?x?)(diff)?$' "/proc/$pid/comm"; then + if embed_pid="$(pgrep --parent "$pid" --full 'nvim --embed')"; then + echo "$embed_pid" + else + echo "$pid" + fi + + return 0 + fi + + for child in $(pgrep --runstates D,I,R,S --terminal "$terms" --parent "$pid"); do + if get_descendant_vim_pid "$child" "$terms"; then + # already echo'd PID in recursive call + return 0 + fi + done + + return 1 +} + +if focused_pid="$(hyprctl activewindow -j | jq -e '.pid')"; then + terms="$(find /dev/pts -type c -not -name ptmx | sed s#^/dev/## | tr '\n' ,)" + if vim_pid="$(get_descendant_vim_pid "$focused_pid" "$terms")"; then + servername_file="${XDG_RUNTIME_DIR:-/tmp}/vim-hypr-nav.$vim_pid.servername" + read -r program servername <"$servername_file" + + if [ "$program" = vim ]; then + serverarg=--servername + elif [ "$program" = nvim ]; then + serverarg=--server + fi + + if [ -n "$serverarg" ] && [ -n "$servername" ]; then + "$program" "$serverarg" "$servername" \ + --remote-expr "VimHyprNav('$dir')" >/dev/null 2>&1 \ + && exit 0 + fi + fi +fi + +hyprctl dispatch movefocus "$dir"