1

The default Keyboard Shortcuts in Ubuntu to maximize a window (Super+Up) or snap it to the sides (Super+Left/Right) relates to the current active window.

While setting up mouse gestures using logiops, I found out that this is a weird behavior. I rather want to maximize/minimize/snap affect the window below my mouse pointer just like the scroll wheel does.

How to do this, e.g. using xdotool ?

pLumo
  • 26,947

1 Answers1

0

You can use xdotool to get the window at the current mouse location (getmouselocation) and then the commands windowminimize or windowactivate + key.


I made a little script ~/bin/xdowindow (and made it executable using chmod +x):

#!/bin/sh

[ "$1" = "Maximize" ] && set -- Up

eval $(xdotool getmouselocation --shell)

case $1 in Minimize) xdotool windowminimize "$WINDOW" ;; Left|Right|Up) xdotool windowactivate "$WINDOW" key --clearmodifiers super+$1 ;; *) exit 1 ;; esac

Set custom keyboard shortcuts:

Custom shortcuts

And then use them in logiops setup:

          {
            direction: "Right";
            mode: "OnRelease";
            action = {
              type: "Keypress";
              keys: [ "KEY_LEFTALT", "KEY_M" ]; // snap window to right
            }
          },

Note:

xdotool won't work together with wayland, maybe ydotool can be used then. I will test once I use wayland myself or someone else may jump in and translate the tool.

pLumo
  • 26,947
  • The key actions of xdotool definitely will not work on Wayland. Might be good to add a note as next month, the new LTS will default to using Wayland. – vanadium Apr 04 '22 at 12:14
  • oh, didn't know that... Is there any replacement? – pLumo Apr 04 '22 at 12:17
  • ydotool can issue keyboard strokes and mouse clicks, but lacks window management features. A more severe Wayland problem: there is no uniform way to obtain information about the running windows: it is the compositor that implements that, so methods to achieve that are different between, Gnome Shell, Plasma and Sway. – vanadium Apr 04 '22 at 13:13