superclick dualmonitor
This commit is contained in:
parent
df83a48318
commit
c4d44c5ad9
81
bin/superclick
Executable file → Normal file
81
bin/superclick
Executable file → Normal file
@ -19,7 +19,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
_config() {
|
||||
|
||||
CONFIG_FILE="$HOME/.config/superclick.cfg"
|
||||
mkdir -p $CONFIG_DIR
|
||||
if [ ! -f $CONFIG_FILE ]; then
|
||||
@ -34,21 +34,35 @@ EOF
|
||||
fi
|
||||
source <(grep = $CONFIG_FILE)
|
||||
GAP=${gap:-16}
|
||||
|
||||
_config() {
|
||||
## OUTER GAP
|
||||
if [[ "$show_outer_gap" == "true" ]]; then OUT_GAP=$((GAP/2)) ; else OUT_GAP="0" ; fi
|
||||
[[ "$show_outer_gap" == "true" ]] && OUT_GAP=$((GAP/2)) || OUT_GAP="0"
|
||||
|
||||
OFFSET=$(wmctrl -d |grep "*" | awk -F' ' '{print $8}')
|
||||
OFF_X="${OFFSET%,*}"
|
||||
OFF_Y="${OFFSET#*,}"
|
||||
|
||||
REALSIZE=$(wmctrl -d |grep "*" | awk -F' ' '{print $9}')
|
||||
|
||||
AVAIL_X="${REALSIZE%x*}"
|
||||
AVAIL_Y="${REALSIZE#*x}"
|
||||
|
||||
OFF_X="${OFFSET%,*}"
|
||||
OFF_Y="${OFFSET#*,}"
|
||||
}
|
||||
|
||||
_movewin() {
|
||||
while read -r line; do
|
||||
info=$(echo $line | awk '{print $3}')
|
||||
if [[ $info == primary ]]; then
|
||||
info=$(echo $line | awk '{print $4}')
|
||||
fi
|
||||
read M_WIDTH M_HEIGHT M_X_OFF M_Y_OFF <<< $(echo $info | awk -F[x+] '{print $1, $2, $3, $4}')
|
||||
if (( P_X >= M_X_OFF && P_X <= M_WIDTH + M_X_OFF && P_Y >= M_Y_OFF && P_Y <= M_HEIGHT + M_Y_OFF )); then
|
||||
break
|
||||
fi
|
||||
done < <(xrandr | grep " connected")
|
||||
|
||||
AVAIL_X=$((M_WIDTH-OFF_X))
|
||||
AVAIL_Y=$((M_HEIGHT-OFF_Y))
|
||||
|
||||
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))
|
||||
@ -58,54 +72,55 @@ _movewin() {
|
||||
|
||||
case $POS_CODE in
|
||||
00|"topleft") # top-left
|
||||
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));
|
||||
W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((M_X_OFF+OFF_X+OUT_GAP)) YPOS=$((M_Y_OFF+OFF_Y+OUT_GAP));
|
||||
[[ "$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))
|
||||
W=$WIDTH_FULL H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((M_X_OFF+0+OFF_X+OUT_GAP)) YPOS=$((M_Y_OFF+0+OFF_Y+OUT_GAP))
|
||||
[[ "$X" -eq "$XPOS" && "$WIDTH" -eq "$WIDTH_FULL+$BORDERCOMP_X" ]] && W=$WIDTH_SMALL XPOS=$((M_X_OFF+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))
|
||||
W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((M_X_OFF+AVAIL_X/2+OFF_X+GAP/2)) YPOS=$((M_Y_OFF+OFF_Y+OUT_GAP))
|
||||
|
||||
[[ "$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))
|
||||
[[ "$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))
|
||||
[[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" && "$HEIGHT" -eq "$((HEIGHT_HALF+BORDERCOMP_Y))" ]] && W="$WIDTH_SMALL" XPOS=$((M_X_OFF+OFF_X+AVAIL_X-WIDTH_SMALL-OUT_GAP-BORDERCOMP_X))
|
||||
[[ "$X" -eq "$((M_X_OFF+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=$((M_X_OFF+AVAIL_X-WIDTH_WIDE+OFF_X-OUT_GAP-BORDERCOMP_X))
|
||||
;;
|
||||
01|left) # left
|
||||
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))
|
||||
W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y-BORDERCOMP_Y-OUT_GAP*2)) XPOS=$((M_X_OFF+0+OFF_X+OUT_GAP)) YPOS=$((M_Y_OFF+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;;
|
||||
11|center) # center
|
||||
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))
|
||||
[[ "$X" -eq "$((OFF_X+AVAIL_X/2-WIDTH_SMALL/2-BORDERCOMP_X/2))" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((WIDTH_SMALL+BORDERCOMP_X))" ]] && W=$((AVAIL_X/10*8)) H=$((AVAIL_Y/10*8)) XPOS=$((AVAIL_X/10)) YPOS=$((AVAIL_Y/10))
|
||||
W=$WIDTH_FULL H=$HEIGHT_FULL XPOS=$((M_X_OFF+OFF_X+OUT_GAP)) YPOS=$((M_Y_OFF+OFF_Y+OUT_GAP))
|
||||
[[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$WIDTH_FULL+BORDERCOMP_X" ]] && W=$WIDTH_SMALL XPOS=$((M_X_OFF+OFF_X+AVAIL_X/2-WIDTH_SMALL/2-BORDERCOMP_X/2))
|
||||
[[ "$X" -eq "$((M_X_OFF+OFF_X+AVAIL_X/2-WIDTH_SMALL/2-BORDERCOMP_X/2))" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((WIDTH_SMALL+BORDERCOMP_X))" ]] && W=$((AVAIL_X/10*8)) H=$((AVAIL_Y/10*8)) XPOS=$((M_X_OFF+AVAIL_X/10)) YPOS=$((M_Y_OFF+AVAIL_Y/10))
|
||||
;;
|
||||
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))
|
||||
W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y-BORDERCOMP_Y-OUT_GAP*2)) XPOS=$((M_X_OFF+AVAIL_X/2+OFF_X+GAP/2)) YPOS=$((M_Y_OFF+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=$((M_X_OFF+OFF_X+AVAIL_X-WIDTH_SMALL-OUT_GAP-BORDERCOMP_X))
|
||||
[[ "$X" -eq "$((M_X_OFF+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=$((M_X_OFF+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))
|
||||
W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((M_X_OFF+0+OFF_X+OUT_GAP)) YPOS=$((M_Y_OFF+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))
|
||||
W=$WIDTH_FULL H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((M_X_OFF+0+OFF_X+OUT_GAP)) YPOS=$((M_Y_OFF+AVAIL_Y/2+OFF_Y+GAP/2))
|
||||
[[ "$X" -eq "$XPOS" && "$WIDTH" -eq "$WIDTH_FULL+$BORDERCOMP_X" ]] && W=$WIDTH_SMALL XPOS=$((M_X_OFF+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));;&
|
||||
W=$((AVAIL_X/2-OUT_GAP-GAP/2-BORDERCOMP_X)) H=$((AVAIL_Y/2-BORDERCOMP_Y-OUT_GAP-GAP/2)) XPOS=$((M_X_OFF+AVAIL_X/2+OFF_X+GAP/2)) YPOS=$((M_Y_OFF+AVAIL_Y/2+OFF_Y+GAP/2))
|
||||
[[ "$X" -eq "$XPOS" && "$Y" -eq "$YPOS" && "$WIDTH" -eq "$((W+BORDERCOMP_X))" ]] && W="$WIDTH_SMALL" XPOS=$((M_X_OFF+OFF_X+AVAIL_X-WIDTH_SMALL-OUT_GAP-BORDERCOMP_X))
|
||||
[[ "$X" -eq "$((M_X_OFF+AVAIL_X-WIDTH_SMALL+OFF_X-OUT_GAP-BORDERCOMP_X))" && "$Y" -eq "$YPOS" && "$WIDTH" -lt "$((WIDTH_HALF+BORDERCOMP_X))" ]] && W=$WIDTH_WIDE XPOS=$((M_X_OFF+AVAIL_X-WIDTH_WIDE+OFF_X-OUT_GAP-BORDERCOMP_X));;&
|
||||
esac
|
||||
xdotool windowsize $WINDOW $W $H
|
||||
xdotool windowmove $WINDOW $XPOS $YPOS
|
||||
xdotool windowsize $WINDOW $W $H
|
||||
|
||||
if [ $activate_window == "true" ]; then xdotool windowactivate $WINDOW; fi
|
||||
#_debug
|
||||
}
|
||||
_getwin() { #get active window (only when invoked by keyboard)
|
||||
_config
|
||||
@ -120,6 +135,10 @@ _getwin() { #get active window (only when invoked by keyboard)
|
||||
BORDERCOMP_X=$((BORDER_L+BORDER_R))
|
||||
BORDERCOMP_Y=$((BORDER_T+BORDER_B))
|
||||
eval $(xdotool getwindowgeometry --shell $WINDOW)
|
||||
|
||||
#CLICK_POINT - here it is active window position
|
||||
P_X="$X"
|
||||
P_Y="$Y"
|
||||
_movewin
|
||||
}
|
||||
|
||||
@ -157,6 +176,10 @@ clicksnap() {
|
||||
BORDERCOMP_X=$((BORDER_L+BORDER_R))
|
||||
BORDERCOMP_Y=$((BORDER_T+BORDER_B))
|
||||
|
||||
#CLICK_POINT
|
||||
P_X="$Mouse_x"
|
||||
P_Y="$Mouse_y"
|
||||
|
||||
_movewin
|
||||
}
|
||||
|
||||
@ -164,6 +187,12 @@ moveto() {
|
||||
POS_CODE="$1"
|
||||
_getwin
|
||||
|
||||
}
|
||||
_debug() {
|
||||
cat <<EOF > "$HOME/.config/superclick_debug"
|
||||
Clickpoint ${P_X} ${P_Y}
|
||||
Available area: $AVAIL_X $AVAIL_Y Monitor W,H and OFFSET $M_WIDTH x $M_HEIGHT $M_X_OFF $M_Y_OFF
|
||||
EOF
|
||||
}
|
||||
trainer(){
|
||||
case "$LANG" in
|
||||
|
Loading…
Reference in New Issue
Block a user