Skip to content

Instantly share code, notes, and snippets.

@muyesh
Last active September 24, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muyesh/cc37605b5c61e1aa2a3fade879054940 to your computer and use it in GitHub Desktop.
Save muyesh/cc37605b5c61e1aa2a3fade879054940 to your computer and use it in GitHub Desktop.
Ultra Wide Snap Window Tool
#!/bin/bash
# define
LEFT_WINDOW_WIDTH=1920
DEBUG_FLG=0
LOG_FILE="/tmp/maximize.log"
# debug statement
if [ -z "$1" ]
then
: #noop
else
if [ $1 -eq 1 ]
then
DEBUG_FLG=1;
fi
fi
function dlog () {
if [ $DEBUG_FLG -eq 1 ]
then
echo $1 >> $LOG_FILE
fi
}
# get active window
active_id=$(wmctrl -lp |grep "0x.$(printf %x $(xdotool getactivewindow))"|cut -d ' ' -f 1)
current_width=$(wmctrl -lG|grep $active_id|awk '{print $5;}')
current_heght=$(wmctrl -lG|grep $active_id|awk '{print $6;}')
# resize window
wmctrl -i -r $active_id -b remove,maximized_vert
wmctrl -i -r $active_id -b remove,maximized_horz
wmctrl -i -r $active_id -e 0,0,0,$current_width,$current_heght
wmctrl -i -r $active_id -b add,maximized_vert
wmctrl -i -r $active_id -b add,maximized_horz
#!/bin/bash
# define
ULTRA_WIDE_WIDTH=3440
ULTRA_WIDE_HEIGHT=1440
LEFT_WINDOW_WIDTH=1920
DEBUG_FLG=0
LOG_FILE="/tmp/uwsnap.log"
# check arg
if [ $# -eq 0 ]
then
exit 1
fi
# mode
mode=$1
if [ $mode -lt 0 -o $mode -gt 1 ]
then
exit 2
fi
# debug statement
if [ -z "$2" ]
then
: #noop
else
if [ $2 -eq 1 ]
then
DEBUG_FLG=1;
fi
fi
function dlog () {
if [ $DEBUG_FLG -eq 1 ]
then
echo $1 >> $LOG_FILE
fi
}
# count active uw display
count_uw=$(xrandr --query|grep connected|grep -v disconnect|grep "${ULTRA_WIDE_WIDTH}x${ULTRA_WIDE_HEIGHT}"|wc -l)
if [ $count_uw -ne 1 ]
then
exit 3
fi
# get add_x and add_y
dimension_data=$(xrandr --query|grep connected|grep -v disconnect|grep "${ULTRA_WIDE_WIDTH}x${ULTRA_WIDE_HEIGHT}"|sed 's/primary //g'|cut -d' ' -f3)
dlog "dimenstion_data: $dimension_data"
add_x=$(echo $dimension_data|cut -d'+' -f2)
add_y=$(echo $dimension_data|cut -d'+' -f3)
dlog "add_x: $add_x"
dlog "add_y: $add_y"
# get active window
active_id=$(wmctrl -lp |grep "0x.$(printf %x $(xdotool getactivewindow))"|cut -d ' ' -f 1)
# set size
h=$ULTRA_WIDE_HEIGHT
y=$add_y
if [ $mode -eq 0 ]
then
# LEFT SIDE
x=$add_x
w=$LEFT_WINDOW_WIDTH
elif [ $mode -eq 1 ]
then
# RIGHT SIDE
x=$(( $add_x + $LEFT_WINDOW_WIDTH ))
w=$(( $ULTRA_WIDE_WIDTH - $LEFT_WINDOW_WIDTH ))
fi
dlog "x-y-w-h $x,$y,$w,$h"
dlog "-----"
# resize window
wmctrl -i -r $active_id -b remove,maximized_vert
wmctrl -i -r $active_id -b remove,maximized_horz
wmctrl -i -r $active_id -b add,maximized_vert
wmctrl -i -r $active_id -e 0,$x,$y,$w,$h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment