fix(bitwarden): resize, center, and fix background execution
- Float to 600x800 centered on the active monitor after title match - Fix socat -u so the daemon works when launched in the background - Add debug logging to /tmp/hypr-window-rules.log Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
socat = "${pkgs.socat}/bin/socat";
|
socat = "${pkgs.socat}/bin/socat";
|
||||||
|
|
||||||
hypr-window-rules = pkgs.writeShellScriptBin "hypr-window-rules" ''
|
hypr-window-rules = pkgs.writeShellScriptBin "hypr-window-rules" ''
|
||||||
|
LOG=/tmp/hypr-window-rules.log
|
||||||
|
log() { echo "[$(date +%T)] $*" >> "$LOG"; }
|
||||||
|
|
||||||
handle() {
|
handle() {
|
||||||
local event="$1"
|
local event="$1"
|
||||||
case "$event" in
|
case "$event" in
|
||||||
@@ -13,23 +16,50 @@
|
|||||||
local title="''${data#*,}"
|
local title="''${data#*,}"
|
||||||
|
|
||||||
if echo "$title" | grep -qi "bitwarden"; then
|
if echo "$title" | grep -qi "bitwarden"; then
|
||||||
|
log "bitwarden title detected: addr=$addr title=$title"
|
||||||
local info
|
local info
|
||||||
info=$(${hyprctl} clients -j | ${jq} -r --arg addr "$addr" \
|
info=$(${hyprctl} clients -j | ${jq} -r --arg addr "$addr" \
|
||||||
'.[] | select(.address == $addr) | "\(.class)|\(.floating)"')
|
'.[] | select(.address == $addr) | "\(.class)|\(.floating)"')
|
||||||
local class="''${info%|*}"
|
local class="''${info%|*}"
|
||||||
local floating="''${info#*|}"
|
local floating="''${info#*|}"
|
||||||
|
log " -> class=$class floating=$floating"
|
||||||
|
|
||||||
if [[ "$class" == "firefox" && "$floating" == "false" ]]; then
|
if [[ "$class" == "firefox" && "$floating" == "false" ]]; then
|
||||||
${hyprctl} dispatch togglefloating "address:$addr"
|
${hyprctl} dispatch togglefloating "address:$addr"
|
||||||
|
|
||||||
|
local target_w=600
|
||||||
|
local target_h=800
|
||||||
|
|
||||||
|
local mon_id
|
||||||
|
mon_id=$(${hyprctl} clients -j | ${jq} -r --arg addr "$addr" \
|
||||||
|
'.[] | select(.address == $addr) | .monitor')
|
||||||
|
|
||||||
|
local center
|
||||||
|
center=$(${hyprctl} monitors -j | ${jq} -r \
|
||||||
|
--argjson id "$mon_id" --argjson tw "$target_w" --argjson th "$target_h" \
|
||||||
|
'.[] | select(.id == $id) |
|
||||||
|
"\(.x + ((.width / .scale) - $tw) / 2 | floor)|\(.y + ((.height / .scale) - $th) / 2 | floor)"')
|
||||||
|
|
||||||
|
local cx="''${center%%|*}"
|
||||||
|
local cy="''${center#*|}"
|
||||||
|
|
||||||
|
${hyprctl} dispatch resizewindowpixel "exact $target_w $target_h, address:$addr"
|
||||||
|
${hyprctl} dispatch movewindowpixel "exact $cx $cy, address:$addr"
|
||||||
|
log " -> floated, resized to $target_w x $target_h, moved to $cx,$cy"
|
||||||
|
else
|
||||||
|
log " -> skipped (class or floating mismatch)"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
${socat} - \
|
log "started (HYPRLAND_INSTANCE_SIGNATURE=$HYPRLAND_INSTANCE_SIGNATURE)"
|
||||||
|
${socat} -u \
|
||||||
"UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" \
|
"UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" \
|
||||||
|
- \
|
||||||
| while IFS= read -r line; do handle "$line"; done
|
| while IFS= read -r line; do handle "$line"; done
|
||||||
|
log "socat exited"
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
home.packages = [hypr-window-rules];
|
home.packages = [hypr-window-rules];
|
||||||
|
|||||||
Reference in New Issue
Block a user