From 740c7bf4a1d24dacb002a40c88349e99ac02554e Mon Sep 17 00:00:00 2001 From: Daniel Napora Date: Mon, 12 Feb 2024 07:28:04 +0100 Subject: [PATCH] snapwin from keyboard fix --- bin/mabox-obstart | 3 +++ bin/snapwin | 50 ++++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/bin/mabox-obstart b/bin/mabox-obstart index a24041a..0d7dd62 100755 --- a/bin/mabox-obstart +++ b/bin/mabox-obstart @@ -114,6 +114,9 @@ virtualboxes if command -v phwmon.py &>/dev/null; then phwmon fi + +PKGS=$(checkupdates | wc -l) +mb-setvar updates=${PKGS} } case "$1" in diff --git a/bin/snapwin b/bin/snapwin index 5a9785a..ceba72a 100755 --- a/bin/snapwin +++ b/bin/snapwin @@ -56,7 +56,7 @@ GAP=${gap:-16} } _movewin() { - echo "AVAIL_X: $AVAIL_X | OFF_X: $OFF_X | OUT_GAP: $OUT_GAP | GAP: $GAP | \n BORDERCOMP_X: $BORDERCOMP_X BORDERCOMP_Y: $BORDERCOMP_Y" + #notify-send.sh "Window: $WINDOW" "POS_CODE: $POS_CODE" WIDTH_FULL=$((AVAIL_X-OUT_GAP*2-BORDERCOMP_X)) WIDTH_HALF=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) WIDTH_SMALL=$((AVAIL_X/3-OUT_GAP-GAP/2-BORDERCOMP_X)) @@ -64,37 +64,32 @@ _movewin() { HEIGHT_FULL=$((AVAIL_Y-OUT_GAP*2-BORDERCOMP_Y)) HEIGHT_HALF=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) - echo "HEIGHT_HALF $HEIGHT_HALF" - echo "Width FULL: $WIDTH_FULL" - echo "Width HALF: $WIDTH_HALF" - echo "Width SMALL: $WIDTH_SMALL" - echo "Width WIDE: $WIDTH_WIDE" case $POS_CODE in 00|"topleft") # top-left #echo "xdotool getwindowgeometry --shell $WINDOW" - eval xdotool getwindowgeometry --shell "$WINDOW" + #eval xdotool getwindowgeometry --shell "$WINDOW" W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((OFF_X+OUT_GAP)) YPOS=$((OFF_Y+OUT_GAP)); #echo -e "XPOS: $XPOS \nYPOS: $YPOS \nW: $W \nWINDOW $WINDOW" #echo "W+BORDERCOMP_X: $((W+BORDERCOMP_X))" [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" && "$HEIGHT" -eq "$((HEIGHT_HALF+BORDERCOMP_Y))" ]] && W=$WIDTH_SMALL [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$WIDTH_HALF+BORDERCOMP_X" && "$HEIGHT" -eq "$((HEIGHT_HALF+BORDERCOMP_Y))" ]] && W=$WIDTH_WIDE - ;; + ;;& 10|top) # top W=$WIDTH_FULL H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((0+OFF_X+OUT_GAP)) YPOS=$((0+OFF_Y+OUT_GAP)) [[ "$X" -eq "$XPOS" && "$WIDTH" -eq "$WIDTH_FULL+$BORDERCOMP_X" ]] && W=$WIDTH_SMALL XPOS=$((OFF_X+AVAIL_X/2-WIDTH_SMALL/2-BORDERCOMP_X/2)) - ;; + ;;& 20|topright) # top-right W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((AVAIL_X/2+OFF_X+GAP/2)) YPOS=$((OFF_Y+OUT_GAP)) - eval xdotool getwindowgeometry --shell "$WINDOW" + #eval xdotool getwindowgeometry --shell "$WINDOW" [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" && "$HEIGHT" -eq "$((HEIGHT_HALF+BORDERCOMP_Y))" ]] && W="$WIDTH_SMALL" XPOS=$((OFF_X+AVAIL_X-WIDTH_SMALL-OUT_GAP-BORDERCOMP_X)) # echo -e "XPOS: $XPOS \nYPOS: $YPOS \nW: $W \nWINDOW $WINDOW" [[ "$X" -eq "$((AVAIL_X-WIDTH_SMALL+OFF_X-OUT_GAP-BORDERCOMP_X))" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$((WIDTH_HALF+BORDERCOMP_X))" && "$HEIGHT" -eq "$((HEIGHT_HALF+BORDERCOMP_Y))" ]] && W=$WIDTH_WIDE XPOS=$((AVAIL_X-WIDTH_WIDE+OFF_X-OUT_GAP-BORDERCOMP_X)) - ;; + ;;& 01|left) # left - eval xdotool getwindowgeometry --shell "$WINDOW" + #eval xdotool getwindowgeometry --shell "$WINDOW" W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y-BORDERCOMP_Y-OUT_GAP*2)) XPOS=$((0+OFF_X+OUT_GAP)) YPOS=$((0+OFF_Y+OUT_GAP)) [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" && "$HEIGHT" -eq "$((HEIGHT_FULL+BORDERCOMP_Y))" ]] && W=$WIDTH_SMALL [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$WIDTH_HALF+BORDERCOMP_X" && "$HEIGHT" -eq "$((HEIGHT_FULL+BORDERCOMP_Y))" ]] && W=$WIDTH_WIDE;; @@ -102,27 +97,27 @@ case $POS_CODE in HEIGHT_SMALL=$((AVAIL_Y/3-OUT_GAP-GAP/2-BORDERCOMP_Y)) W=$WIDTH_FULL H=$HEIGHT_FULL XPOS=$((OFF_X+OUT_GAP)) YPOS=$((OFF_Y+OUT_GAP)) [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$WIDTH_FULL+BORDERCOMP_X" ]] && W=$WIDTH_SMALL XPOS=$((OFF_X+AVAIL_X/2-WIDTH_SMALL/2-BORDERCOMP_X/2)) - ;; + ;;& 21|right) # right W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y-BORDERCOMP_Y-OUT_GAP*2)) XPOS=$((AVAIL_X/2+OFF_X+GAP/2)) YPOS=$((0+OFF_Y+OUT_GAP)) [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" && "$HEIGHT" -eq "$((HEIGHT_FULL+BORDERCOMP_Y))" ]] && W="$WIDTH_SMALL" XPOS=$((OFF_X+AVAIL_X-WIDTH_SMALL-OUT_GAP-BORDERCOMP_X)) [[ "$X" -eq "$((AVAIL_X-WIDTH_SMALL+OFF_X-OUT_GAP-BORDERCOMP_X))" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$((WIDTH_HALF+BORDERCOMP_X))" && "$HEIGHT" -eq "$((HEIGHT_FULL+BORDERCOMP_Y))" ]] && W=$WIDTH_WIDE XPOS=$((AVAIL_X-WIDTH_WIDE+OFF_X-OUT_GAP-BORDERCOMP_X)) - ;; + ;;& 02|bottomleft) # bottom-left W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((0+OFF_X+OUT_GAP)) YPOS=$((AVAIL_Y/2+OFF_Y+GAP/2)) [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" ]] && W=$WIDTH_SMALL [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$WIDTH_HALF+BORDERCOMP_X" ]] && W=$WIDTH_WIDE - ;; + ;;& 12|bottom) # bottom W=$WIDTH_FULL H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((0+OFF_X+OUT_GAP)) YPOS=$((AVAIL_Y/2+OFF_Y+GAP/2)) [[ "$X" -eq "$XPOS" && "$WIDTH" -eq "$WIDTH_FULL+$BORDERCOMP_X" ]] && W=$WIDTH_SMALL XPOS=$((OFF_X+AVAIL_X/2-WIDTH_SMALL/2-BORDERCOMP_X/2)) - ;; + ;;& 22|bottomright) # bottom-right W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((AVAIL_X/2+OFF_X+GAP/2)) YPOS=$((AVAIL_Y/2+OFF_Y+GAP/2)) [[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" ]] && W="$WIDTH_SMALL" XPOS=$((OFF_X+AVAIL_X-WIDTH_SMALL-OUT_GAP-BORDERCOMP_X)) - [[ "$X" -eq "$((AVAIL_X-WIDTH_SMALL+OFF_X-OUT_GAP-BORDERCOMP_X))" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$((WIDTH_HALF+BORDERCOMP_X))" ]] && W=$WIDTH_WIDE XPOS=$((AVAIL_X-WIDTH_WIDE+OFF_X-OUT_GAP-BORDERCOMP_X));; + [[ "$X" -eq "$((AVAIL_X-WIDTH_SMALL+OFF_X-OUT_GAP-BORDERCOMP_X))" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$((WIDTH_HALF+BORDERCOMP_X))" ]] && W=$WIDTH_WIDE XPOS=$((AVAIL_X-WIDTH_WIDE+OFF_X-OUT_GAP-BORDERCOMP_X));;& esac - +#notify-send.sh "$WINDOW $W $H" "$XPOS $YPOS" xdotool windowsize $WINDOW $W $H xdotool windowmove $WINDOW $XPOS $YPOS #echo "Po akcji ==============" @@ -149,6 +144,13 @@ _getwin() { #get active window (only when invoked by keyboard) #echo "winFRAME: $winFRAME" BORDERCOMP_X=$((BORDER_L+BORDER_R)) BORDERCOMP_Y=$((BORDER_T+BORDER_B)) + eval $(xdotool getwindowgeometry --shell $WINDOW) + #notify-send.sh -u critical "KEYS" "HEX_ID: $HEX_ID\nWINDOW $WINDOW\nwinFRAME: $winFRAME\nBORDERCOMP $BORDERCOMP_X $BORDERCOMP_Y \ +#X: $X\n \ +#Y: $Y\n \ +#WINDOW: $WINDOW\n \ +#WIDTH: $WIDTH\n \ +#HEIGHT: $HEIGHT" #echo "BORDERCOMP_X $BORDERCOMP_X" #echo "Przekazuję ID OKNA: $WINDOW" _movewin @@ -184,14 +186,17 @@ clicksnap() { fi CHILD=$(printf %i $CHILD_ID) - #echo "CHILD Potrzebny dla FRAME: $CHILD" read BORDER_L BORDER_R BORDER_T BORDER_B <<< "$(xprop -id $CHILD _NET_FRAME_EXTENTS | awk ' {gsub(/,/,"");print $3,$4,$5,$6}')" BORDERCOMP_X=$((BORDER_L+BORDER_R)) BORDERCOMP_Y=$((BORDER_T+BORDER_B)) - #echo "BORDERCOMP_X $BORDERCOMP_X" - #echo "BORDERCOMP_Y $BORDERCOMP_Y" - #echo "Przekazuję ID OKNA: $WINDOW" + + #notify-send.sh -u critical "Click" "WINDOW: $WINDOW\nHEX_ID: $HEX_ID\nCHILD_ID $CHILD_ID\nCHILD: $CHILD\nBORDERCOMP $BORDERCOMP_X $BORDERCOMP_Y \ +#X: $X\n \ +#Y: $Y\n \ +#WINDOW: $WINDOW\n \ +#WIDTH: $WIDTH\n \ +#HEIGHT: $HEIGHT" _movewin } @@ -209,4 +214,5 @@ case "$1" in "") clicksnap ;; topleft|top|topright|left|center|right|bottomleft|bottom|bottomright) moveto "$1" ;; -h|--help) usage ;; + #*) moveto "$1";; esac