浏览代码

better hyprland layout handling + removed keybind.conf

Noah Vogt 2 天之前
父节点
当前提交
103bdda413

+ 3 - 2
dot-config/hypr/hyprland.conf

@@ -62,9 +62,9 @@ permission = /usr/lib/xdg-desktop-portal-hyprland, screencopy, allow
 # https://wiki.hypr.land/Configuring/Variables/#general
 general {
     gaps_in = 5
-    gaps_out = 20
+    gaps_out = 15
 
-    border_size = 3
+    border_size = 2
 
     # https://wiki.hypr.land/Configuring/Variables/#variable-types for info about colors
     col.active_border = rgba(33ccffee)
@@ -270,6 +270,7 @@ bind = $mainMod SHIFT, L, exec, systemctl suspend
 bind = $mainMod, F, fullscreen, 0
 
 # Master Layout Control
+bind = $mainMod, Z, exec, ~/.config/hypr/scripts/toggle-layout.sh
 bind = $mainMod SHIFT, Return, layoutmsg, swapwithmaster
 bind = $mainMod, J, layoutmsg, cyclenext
 bind = $mainMod, K, layoutmsg, cycleprev

+ 0 - 165
dot-config/hypr/keybind.conf

@@ -1,165 +0,0 @@
-# ################### It just works™ keybinds ###################
-# Volume
-bindl = ,XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle
-bindle=, XF86AudioRaiseVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
-bindle=, XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
-
-# Brightness
-# bindle=, XF86MonBrightnessUp, exec, light -A 5
-# bindle=, XF86MonBrightnessDown, exec, light -U 5
-bindle=, XF86MonBrightnessUp, exec, ags run-js 'brightness.screen_value += 0.05;'
-bindle=, XF86MonBrightnessDown, exec, ags run-js 'brightness.screen_value -= 0.05;'
-
-# ####################################### Applications ########################################
-# Apps: just normal apps
-bind = Super, Return, exec, $terminal
-bind = Super, E, exec, nautilus --new-window
-bind = Super, V, exec, chromium
-# bind = ControlSuperAlt, E, exec, /usr/bin/microsoft-edge-stable --password-store=gnome --enable-features=UseOzonePlatform --ozone-platform=wayland --gtk-version=4
-# bind = Super, Z, exec, kitty -e neomutt
-
-# Apps: Settings and config
-bind = Super, A, exec, pavucontrol
-
-# Actions
-bind = Super, Period, exec, fuzzelunicode
-bind = SuperShift, Period, exec, fuzzelnerd
-bind = Super, G, exec, fuzzel-greek-letters-prompt
-bind = Super, O, exec, open-stream
-bind = Super, Q, killactive,
-bind = SuperAlt, Space, togglefloating,
-bind = SuperShift, T, exec, ~/.config/hypr/scripts/toggle-theme.sh
-# german
-bind = SuperShift Alt, T, exec, grim -g "$(slurp -d -c D1E5F4BB -b 1B232866 -s 00000000)" "tmp.png" && tesseract -l deu "tmp.png" - | wl-copy && rm "tmp.png"
-
-# Media
-# bind = SuperShift, N, exec, playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"`
-bindl  = , XF86AudioNext,           exec, ags run-js "Mpris.getPlayer()?.next()"
-# bind = SuperShift, B, exec, playerctl previous
-# bind = SuperShift, P, exec, playerctl play-pause
-
-#Lock screen  |  blur: --effect-blur=20x202
-# bind = Super, L, exec, gtklock
-bind = SuperShift, L, exec, gtklock
-bindl = SuperShift, L, exec, sleep 0.1 && sus
-
-# App launcher
-bind = ControlSuper, Slash, exec, pkill anyrun || anyrun
-
-# ##################################### AGS keybinds #####################################
-bindr = ControlSuper, R, exec, hyprctl reload; killall ags activewin.sh activews.sh gohypr bash ydotool; ags &
-bindir = Super, Super_L, exec, fuzzel
-# bind = Super, O, exec, ags -t 'sideleft'
-# bind = Super, N, exec, ags -t 'sideright'
-# bind = Super, M, exec, ags run-js 'openMusicControls.value = (!Mpris.getPlayer() ? false : !openMusicControls.value);'
-bind = SuperShift, K, exec, ags -t 'osk'
-bind = ControlAlt, Delete, exec, ags -t 'session'
-bindr = Control, Control_R, exec, ags run-js 'indicator.popup(-1);'
-bindr = Control, Control_R, exec, ags run-js 'Notifications.notifications.forEach((notif) => notif.dismiss())'
-bindle = , XF86AudioRaiseVolume, exec, ags run-js 'indicator.popup(1);'
-bindle = , XF86AudioLowerVolume, exec, ags run-js 'indicator.popup(1);'
-bindle = , XF86MonBrightnessUp, exec, ags run-js 'indicator.popup(1);'
-bindle = , XF86MonBrightnessDown, exec, ags run-js 'indicator.popup(1);'
-bindr = Control, Control_R, exec, ags run-js 'App.closeWindow("sideright");'
-bindr = Control, Control_R, exec, ags run-js 'App.closeWindow("cheatsheet");'
-bindr = Control, Control_R, exec, ags run-js 'App.closeWindow("osk");'
-bindr = Control, Control_R, exec, ags run-js 'App.closeWindow("session");'
-bindr = Control, Control_R, exec, ags run-js 'openMusicControls.value = false'
-
-# ##################################### Plugins #########################################
-# bind = ControlSuper, P, exec, hyprctl plugin load '/home/end/.config/hypr/plugins/droidbars.so'
-# bind = ControlSuper, O, exec, hyprctl plugin unload '/home/end/.config/hypr/plugins/droidbars.so'
-
-# # Testing
-bind = SuperAlt, f12, exec, notify-send "Millis since epoch" "$(date +%s%N | cut -b1-13)" -a 'Hyprland keybind'
-bind = SuperAlt, P, exec, notify-send "Urgent notification" "Ah hell no" -u critical -a 'Hyprland keybind'
-
-# ########################### Keybinds for Hyprland ############################
-# Swap windows
-bind = SuperShift, left, movewindow, l
-bind = SuperShift, right, movewindow, r
-bind = SuperShift, up, movewindow, u
-bind = SuperShift, down, movewindow, d
-# Move focus
-bind = Super, left, movefocus, l
-bind = Super, right, movefocus, r
-bind = Super, up, movefocus, u
-bind = Super, down, movefocus, d
-bind = Super, BracketLeft, movefocus, l
-bind = Super, BracketRight, movefocus, r
-
-# Workspace, window, tab switch with keyboard
-bind = ControlSuper, right, workspace, +1
-bind = ControlSuper, left, workspace, -1
-bind = ControlSuper, BracketLeft, workspace, -1
-bind = ControlSuper, BracketRight, workspace, +1
-bind = ControlSuper, up, workspace, -5
-bind = ControlSuper, down, workspace, +5
-bind = Super, Page_Down, workspace, +1
-bind = Super, Page_Up, workspace, -1
-bind = ControlSuper, Page_Down, workspace, +1
-bind = ControlSuper, Page_Up, workspace, -1
-bind = SuperAlt, Page_Down, movetoworkspace, +1
-bind = SuperAlt, Page_Up, movetoworkspace, -1
-bind = SuperShift, Page_Down, movetoworkspace, +1
-bind = SuperShift, Page_Up, movetoworkspace, -1
-bind = ControlSuperShift, Right, movetoworkspace, +1
-bind = ControlSuperShift, Left, movetoworkspace, -1
-bind = SuperShift, mouse_down, movetoworkspace, -1
-bind = SuperShift, mouse_up, movetoworkspace, +1
-bind = SuperAlt, mouse_down, movetoworkspace, -1
-bind = SuperAlt, mouse_up, movetoworkspace, +1
-
-# Window split ratio
-binde = Super, H, layoutmsg, mfact -0.05
-binde = Super, L, layoutmsg, mfact +0.05
-
-# Fullscreen
-bind = Super, F, fullscreen, 0
-# bind = SuperShift, F, fakefullscreen, 0
-
-# Switching
-bind = Super, 1, workspace, 1
-bind = Super, 2, workspace, 2
-bind = Super, 3, workspace, 3
-bind = Super, 4, workspace, 4
-bind = Super, 5, workspace, 5
-bind = Super, 6, workspace, 6
-bind = Super, 7, workspace, 7
-bind = Super, 8, workspace, 8
-bind = Super, 9, workspace, 9
-bind = Super, 0, workspace, 10
-bind = Super, S, togglespecialworkspace,
-
-# Move window to workspace Super + Alt + [0-9]
-bind = Super Shift, 1, movetoworkspacesilent, 1
-bind = Super Shift, 2, movetoworkspacesilent, 2
-bind = Super Shift, 3, movetoworkspacesilent, 3
-bind = Super Shift, 4, movetoworkspacesilent, 4
-bind = Super Shift, 5, movetoworkspacesilent, 5
-bind = Super Shift, 6, movetoworkspacesilent, 6
-bind = Super Shift, 7, movetoworkspacesilent, 7
-bind = Super Shift, 8, movetoworkspacesilent, 8
-bind = Super Shift, 9, movetoworkspacesilent, 9
-bind = Super Shift, 0, movetoworkspacesilent, 10
-bind = ControlShiftSuper, Up, movetoworkspacesilent, special
-bind = SuperAlt, S, movetoworkspacesilent, special
-
-# Scroll through existing workspaces with (Control) + Super + scroll
-bind = Super, mouse_up, workspace, +1
-bind = Super, mouse_down, workspace, -1
-bind = ControlSuper, mouse_up, workspace, +1
-bind = ControlSuper, mouse_down, workspace, -1
-
-# Move/resize windows with Super + LMB/RMB and dragging
-bindm = Super, mouse:272, movewindow
-bindm = Super, mouse:273, resizewindow
-# bindm = Super, mouse:274, movewindow
-bind = ControlSuper, Backslash, resizeactive, exact 640 480
-
-# Master Layout Control
-bind = SuperShift, Return, layoutmsg, swapwithmaster
-bind = Super, J, layoutmsg, cyclenext
-bind = Super, K, layoutmsg, cycleprev
-bind = Super, I, layoutmsg, addmaster
-bind = Super, D, layoutmsg, removemaster

+ 44 - 0
dot-config/hypr/scripts/layout-listener.sh

@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# Script run by a waybar module that displays an icon of the current hyprland
+# layout. Triggered via a toggle script and hyperland socket events.
+
+# Save the parent process ID so toggle-layout.sh can signal it
+PID_FILE="${XDG_RUNTIME_DIR:-/tmp}/hypr_layout_persistent.pid"
+echo $$ >"$PID_FILE"
+
+print_layout() {
+    LAYOUT=$(hyprctl -j activeworkspace | jq -r '.tiledLayout')
+    if [ -z "$LAYOUT" ] || [ "$LAYOUT" = "null" ]; then
+        LAYOUT=$(hyprctl -j getoption general:layout | jq -r '.str')
+    fi
+
+    case "$LAYOUT" in
+    "master") echo "" ;;
+    "monocle") echo "" ;;
+    "dwindle") echo "" ;;
+    *) echo "$LAYOUT" ;;
+    esac
+}
+
+# When USR1 is received from toggle-layout.sh, print the layout
+trap 'print_layout' USR1
+
+# Print once at startup
+print_layout
+
+# Background task: listen for Hyprland events and print layout directly
+# This subshell inherits stdout, so Waybar sees the output instantly
+socat -U - "UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do
+    case "$line" in
+    workspace* | layoutmsg* | activelayout*)
+        print_layout
+        ;;
+    esac
+done &
+
+# Keep the parent script alive to receive signals from toggle-layout.sh
+while true; do
+    sleep 3600 &
+    wait $!
+done

+ 26 - 0
dot-config/hypr/scripts/layout-status.sh

@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Script to output the current Hyprland layout for Waybar
+# Icons:  (Master)  (Monocle)  (Dwindle)
+
+LAYOUT=$(hyprctl -j activeworkspace | jq -r '.tiledLayout')
+
+# If layout is empty/null, default to whatever the general config says
+if [ -z "$LAYOUT" ] || [ "$LAYOUT" = "null" ]; then
+    LAYOUT=$(hyprctl -j getoption general:layout | jq -r '.str')
+fi
+
+case "$LAYOUT" in
+"master")
+    echo ""
+    ;;
+"monocle")
+    echo ""
+    ;;
+"dwindle")
+    echo ""
+    ;;
+*)
+    echo "$LAYOUT"
+    ;;
+esac

+ 20 - 0
dot-config/hypr/scripts/toggle-layout.sh

@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# Script to toggle between master and monocle layouts for the active hyprland
+# workspace
+
+WS_INFO=$(hyprctl -j activeworkspace)
+WS_ID=$(echo "$WS_INFO" | jq -r '.id')
+CURRENT_LAYOUT=$(echo "$WS_INFO" | jq -r '.tiledLayout')
+
+if [ "$CURRENT_LAYOUT" = "master" ]; then
+    hyprctl keyword "workspace $WS_ID,layout:monocle"
+else
+    hyprctl keyword "workspace $WS_ID,layout:master"
+fi
+
+# Signal the persistent layout script accurately (by pid file)
+PID_FILE="${XDG_RUNTIME_DIR:-/tmp}/hypr_layout_persistent.pid"
+if [ -f "$PID_FILE" ]; then
+    kill -USR1 "$(cat "$PID_FILE")" 2>/dev/null
+fi

+ 25 - 14
dot-config/waybar/config.jsonc

@@ -8,7 +8,8 @@
     "spacing": 4,
 
     "modules-left": [
-        "hyprland/workspaces"
+        "hyprland/workspaces",
+        "custom/layout"
     ],
     "modules-center": ["clock"],
     "modules-right": ["network#vpn", "network", "backlight", "battery", "pulseaudio", "bluetooth", "custom/notification"],
@@ -35,20 +36,21 @@
     },
 
     "hyprland/workspaces": {
-        "format": "{id}",
-        "on-click": "activate",
-        "all-outputs": true,
-        "active-only": false,
-        "persistent-workspaces": {
-            "*": 10
-        },
-        "format-icons": {
-            "active": "",
-            "default": ""
-        },
-        "on-scroll-up": "hyprctl dispatch workspace e+1",
-        "on-scroll-down": "hyprctl dispatch workspace e-1"
+    "format": "{id}{windows}",
+    "format-window-separator": "",
+    "window-rewrite-default": "·",
+    "window-rewrite": {
+        ".*": "·"
+    },
+    "on-click": "activate",
+    "all-outputs": true,
+    "active-only": false,
+    "persistent-workspaces": {
+        "*": 10
     },
+    "on-scroll-up": "hyprctl dispatch workspace e+1",
+    "on-scroll-down": "hyprctl dispatch workspace e-1"
+},
 
     "clock": {
         "format": "  {:%H:%M}",
@@ -56,6 +58,15 @@
         "format-alt": "  {:%A, %d %B %Y}"
     },
 
+
+    "custom/layout": {
+        "exec": "~/.config/hypr/scripts/layout-listener.sh",
+        "return-type": "plain",
+        "tooltip": false,
+        "format": "{} ",
+        "on-click": "~/.config/hypr/scripts/toggle-layout.sh"
+    },
+
     "backlight": {
         "device": "intel_backlight",
         "format": "{icon}  {percent}%",