4

Is it possible to configure Lubuntu (i.e. Openbox) such that some action is performed when the mouse cursor is moved to a certain position?

In particular, I would like to run a script when I move the mouse cursor to the top-left corner and keep pushing it up and left. This is similar to some window managers that let you switch to another display when pushing the mouse cursor to either side of the screen.

Glutanimate
  • 21,393
DustByte
  • 641
  • 2
  • 8
  • 18

1 Answers1

5

One way to accomplish this is via xdotool. From xdotool's manual:

behave_screen_edge [options] where command ...

Bind an action to events when the mouse hits the screen edge or corner.

Options are:

--delay MILLISECONDS

Delay in milliseconds before running the command. This allows you to require a given edge or corner to be held for a short period before your command will run. If you leave the edge or corner before the delay expires then the time will reset.

--quiesce MILLISECONDS

Delay in milliseconds before the next command will run. This helps prevent accidentally running your command extra times; especially useful if you have a very short --delay (like the default of 0).

Event timeline

  • Mouse hits an edge or corner.
  • If delay is nonzero, the mouse must stay in this edge or corner until delay time expires.
  • If still in the edge/corner, trigger.
  • If quiesce is nonzero, then there is a cool-down period where the next trigger cannot occur

Valid 'where' values are:

  • left

  • top-left

  • top

  • top-right

  • right

  • bottom-left

  • bottom

  • bottom-right

You can combine the behave_screen_edge option with any of xdotool's inbuilt commands, including the exec command:

exec [options] command [...]

Execute a program. This is often useful when combined with behave_screen_edge to do things like locking your screen.

Options:

--sync

Block until the child process exits. The child process exit status is then passed to the parent process (xdotool) which copies it.


So to trigger a script when hitting the top left corner of your screen you would use the following command:

xdotool behave_screen_edge top-left exec --sync script.sh

The --sync switch ensures that xdotool waits until the script exits before triggering the action again.


xdotool is part of the official Ubuntu repositories and may be installed via:

sudo apt-get install xdotool
Glutanimate
  • 21,393
  • Great! didn't occur to me that xdotool can be used this way. Coincidentally I was going to use xdotool in the script invoked when positioning the mouse cursor. I am not sure exactly what way is best to start the xdotool behave_screen_edge ... script though. I would like it to be started on login. – DustByte Mar 26 '15 at 20:17
  • 1
    @DustByte Glad to hear that this works for you. These Q&As list a few options for setting up autostart on Lubuntu: http://askubuntu.com/a/500147/81372 https://askubuntu.com/questions/81383/how-can-i-add-new-autostart-programs-in-lubuntu http://askubuntu.com/a/55391/81372 – Glutanimate Mar 26 '15 at 22:33
  • Very useful information! – DustByte Mar 27 '15 at 13:22
  • @Glutanimate, would the term "hot corner" be applicable here? It may help those who search for hot corner functionality in Lubuntu. – DK Bose Oct 22 '15 at 13:50
  • @DKBose Yep, makes sense. I edited the question accordingly. – Glutanimate Oct 22 '15 at 18:46