Is it possible to get the first click on an inactive window to not register?

Solution 1:

Okay so no one has answered yet. I would really like someone to, but in the meantime, I have a "workaround". If you hold Alt while clicking on a window, it won't register the click. This is normally used for "dragging" the window, so while you're holding Alt, all windows will be draggable from anywhere, not just the titlebar. If you just click, it will bring the window into focus, but it won't actually click in the window. Hope this helps someone.

Solution 2:

Yes, it is possible by using middle-click on mouse.

Middle-click behaviour

A middle-click will usually give focus the window under cursor, then raise it above other windows. This page from Ubuntu Desktop Guide explains the known behaviours of middle-click, except some were undocumented:

  • middle-click on the title bar will cause the window to be sent behind other windows;

  • middle-click on the window control buttons (close, minimize, maximize) will activate corresponding behaviours (close the window, minimize the window, maximize vertically).

There may be additional behaviours when doing a middle-click on the target window, such as window with clickable objects or editable fields or text area.

  • If the window has editable text area, middle-click will position the cursor "as it is", such that cursor does not move and;

  • the middle-click will paste the content, if the clipboard of primary selection is not empty.

A middle-click will paste nothing, if the clipboard of primary selection is empty. This is the default state when everytime user logs into the Ubuntu Desktop.

When user invokes column selection, which is "click on primary button on mouse, drag cursor on some text then release click", the selected text will be copied to PRIMARY. As a result, middle-click will give focus and raise the window, then paste the content into any text area.

Workaround for unwanted paste

To avoid the unwanted paste, clear the clipboard of primary selection before doing a middle-click. One way is to install xclip and run this nullifying command:

xclip -i /dev/null

Then a middle-click will paste nothing; run xclip -o and confirm the output in terminal.

The nullifying command may be assigned to a custom keyboard shortcut such as using any Fn-key for "on demand" method. Otherwise, the command may be set to run at every few seconds by a scheduler for "setup once then forget" method.

Even without any workaround, the clipboard of primary selection will be discarded automatically when closing/exiting the corresponding window, from which text selection has been made. If using an external clipboard manager, make sure the clipboard of primary selection is disabled.

Tested behaviour and workaround in Ubuntu 16.04 (Unity 7.4.0).

TL;DR A middle-click can give focus and raise the window above other windows, without registering the click. Empty the clipboard of primary selection to nullify paste on middle-click.