From 97d703070a7bfa6129fbb365db2582cec94d6bf2 Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Sun, 15 Sep 2019 19:03:50 -0400 Subject: [PATCH] Mouse thumb gestures move windows around --- i3/desktop.conf | 5 ++-- scripts/i3-mouse.py | 69 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/i3/desktop.conf b/i3/desktop.conf index ec7a7e9..81d47ab 100644 --- a/i3/desktop.conf +++ b/i3/desktop.conf @@ -25,7 +25,7 @@ exec_always --no-startup-id g13d --config ~/.config/g13/resolve.bind --logo ~/.c exec_always --no-startup-id setxkbmap -option 'caps:super' # Starts Jack for audio -exec_always --no-startup-id sh ~/.config/scripts/system-start-audio.sh +exec --no-startup-id sh ~/.config/scripts/system-start-audio.sh # Open Google Play Music on workspace 10 for_window [title="Google Play Music Desktop Player"] move to workspace $ws10 @@ -60,7 +60,8 @@ for_window [title="^Steam Keyboard$"] floating enable for_window [class="^com-intellij-updater-Runner$" title="^Update$"] floating enable for_window [instance="^sun-awt-X11-XDialogPeer$" title="^Complete Installation$"] floating enable -# The side buttons move the window around +# The side buttons move the desktop around bindsym --whole-window button9 exec python3 ~/.config/scripts/i3-mouse.py back bindsym --whole-window button8 exec python3 ~/.config/scripts/i3-mouse.py forward +bindsym $mod+Tab exec python3 ~/.config/scripts/i3-mouse.py thumb diff --git a/scripts/i3-mouse.py b/scripts/i3-mouse.py index d1b575a..c1d819d 100644 --- a/scripts/i3-mouse.py +++ b/scripts/i3-mouse.py @@ -2,14 +2,71 @@ import i3ipc import sys import os +import time +import pyautogui +from enum import Enum +# Enum for mouse direction +class Direction(Enum): + UP = 1 + LEFT = 2 + RIGHT = 3 + DOWN = 4 + NONE = 5 -up = sys.argv[1] == 'up' +# getPoints() returns x and y movement of mouse +def getPoints(): + sen = 10 + t = 0 + delay = 0.01 + + x,y = pyautogui.position() + while True: + time.sleep(delay) + t += delay + if t > 0.5: + return + xp, yp = pyautogui.position() + dx = x - xp + dy = y - yp + if abs(dx) > sen or abs(dy) > sen: + break + return dx, dy + +#pointsToDirection() converts mouse movement points to a direction +def pointsToDirection(points): + if points is None: + return + x, y = points + if abs(x) > abs(y): + if x < 0: + return Direction.RIGHT + else: + return Direction.LEFT + else: + if y > 0: + return Direction.UP + else: + return Direction.DOWN i3 = i3ipc.Connection() focused = i3.get_tree().find_focused() -if focused.window_instance not in ['overwatch.exe']: - if sys.argv[1] == 'forward': - os.system('i3-msg workspace prev_on_output') - else: - os.system('i3-msg workspace next_on_output') +command = sys.argv[1] + +if command in ['back', 'forward']: + if focused.window_instance not in ['overwatch.exe']: + if sys.argv[1] == 'forward': + i3.command('workspace prev_on_output') + else: + i3.command('workspace next_on_output') + +elif command == 'thumb': + direction = pointsToDirection(getPoints()) + if direction == Direction.UP: + i3.command('move up') + elif direction == Direction.RIGHT: + i3.command('move right') + elif direction == Direction.DOWN: + i3.command('move down') + elif direction == Direction.LEFT: + i3.command('move left')