15

I mean the window should move around whenever I try to move the pointer on it. I have a "Analog Clock screenlet" and "file progress dialog box" which I tweaked to stay "Always on Top" of other windows with CCSM but sometimes they get in the way of doing things.

If that's not possible then is there any method so that they hide when I move pointer on them so that I can click on the application directly below?

Further if that is not possible than can we make the windows behave as if they aren't there? I mean I will see the window but the pointer should not recognize it and should work normally on the application below it. I will change the transparency of the applications and will make it work if that's possible?

  • 2
    You want some window to be always shown but they should also allow interacting with other windows below them? – Anwar Sep 9 '16 at 14:13
  • Yes exactly, I dont want to interact with that (eg. "Copy dialog box" with "Always on top" enabled") window (Not even focus on that window) when I move the pointer on that window. I just want to Interact with the window below it. The main window(one which remains on top) should act like a Watermark (you get the idea?) or move aside when I move the pointer towards it. – Hemant Yadav Sep 9 '16 at 14:17
  • 1
    As it's a unusual request, I don't think that anybody done that. But this is definitely possible, you'd need to write an extension for the Window Manager you use (compiz, I guess). Alternatively, have you considered to just keep those windows on a separate desktop, and setup keys so that with "Super+some_number" you could switch between desktops. It is very comfortable for keeping a bunch of windows opened at a time. – Hi-Angel Sep 9 '16 at 16:18
  • 1
    The Gnome Shell extension "Workspaces To Dock" has an option for the dock to dodge windows. This isn't exactly what is asked, but maybe you could look there to get an idea on how to achieve this: github.com/passingthru67/workspaces-to-dock. – Samuel Feb 22 '17 at 19:50
  • Have a look at similar question on the superuser. Someone suggest there is a feature of the compiz plugin "Opacity, Brightness and Saturation" that makes objects with less than 50% opacity click-throughable... – Jan Stavěl Mar 4 '17 at 12:16
2

Bash script and xdotool == cursophobia.sh

Overview
I think I have a solution that will work for you. It is a bash script that allows you to select a window. Once a window is selected, the script continuously polls window and cursor positions at predefined intervals. If the cursor gets too close, the window moves out of the way.

Dependency
This script depends on the xdotool. To install, run sudo apt-get install xdotool

The script: cursophobia.sh
Create a new bash script with the following contents and make it executable.

#!/bin/bash

windowSelectionDelay=5  # How long to wait for user to select a window?
buffer=10               # How close do we need to be to border to get scared?
jump=20                 # How far do we jump away from pointer when scared?
poll=.25                # How often in seconds should we poll window and mouse?
                        # locations. Increasing poll should lighten CPU load.

# ask user which window to make phobic
for s in $(seq 0 $((windowSelectionDelay - 1)))
do
    clear
    echo "Activate the window that you want to be cursophobic: $((windowSelectionDelay - s))"  
    sleep 1
done
wID=$(xdotool getactivewindow)

# find some boundary info and adjustments
# determine where the window is now
info=$(xdotool getwindowgeometry $wID)
base=$(grep -oP "[\d]+,[\d]+" <<< "$info")

# move the window to 0 0 and get real location
xdotool windowmove $wID 0 0
info=$(xdotool getwindowgeometry $wID)
realMins=$(grep -oP "[\d]+,[\d]+" <<< "$info")
xMin=$(cut -f1 -d, <<< "$realMins")
yMin=$(cut -f2 -d, <<< "$realMins")

# find offset values for no movement. This is necessary because moving 0,0
# relative to the current position sometimes actually moves the window
xdotool windowmove --relative $wID 0 0
info=$(xdotool getwindowgeometry $wID)
diff=$(grep -oP "[\d]+,[\d]+" <<< "$info")
xOffset=$[xMin - $(cut -f1 -d, <<< "$diff")]
yOffset=$[yMin- $(cut -f2 -d, <<< "$diff")]

# move window back to original location
x=$(cut -f1 -d, <<< "$base")
y=$(cut -f2 -d, <<< "$base")
xdotool windowmove $wID $[x + xOffset] $[y + yOffset]

dispSize=$(xdotool getdisplaygeometry)
xMax=$(cut -f1 -d ' ' <<< "$dispSize")
yMax=$(cut -f2 -d ' ' <<< "$dispSize")

clear
echo "You can minimize this window, but don't close it, or your window will overcome its cursophobia"
# start an infinite loop polling to see if we need to move the window.
while :
do
    # get information about where the window is
    info=$(xdotool getwindowgeometry $wID)
    position=$(grep -oP "[\d]+,[\d]+" <<< "$info")
    geometry=$(grep -oP "[\d]+x[\d]+" <<< "$info")
    height=$(cut -f2 -dx <<< "$geometry")
    width=$(cut -f1 -dx <<< "$geometry")
    top=$(cut -f2 -d, <<< "$position")
    left=$(cut -f1 -d, <<< "$position")
    bottom=$((top + height))
    right=$((left + width))

    # save mouse coordinates to x & y
    eval "$(xdotool getmouselocation | cut -f 1-2 -d ' ' | tr ' :' '\n=')"

    # If the mouse is too close to the window, move the window
    if [ $x -gt $((left - buffer)) ] && [ $x -lt $((right + buffer)) ] && [ $y -gt $((top - buffer)) ] && [ $y -lt $((bottom + buffer)) ]; then
        #figure out what side we're closest to so we know which direction to move the window
        t="$((y - top)):0 $((jump + (y - top)))"
        l="$((x - left)):$((jump + (x - left))) 0"
        b="$((bottom - y)):0 -$((jump + (bottom - y)))"
        r="$((right - x)):-$((jump + (right - x))) 0"
        coord="$(echo -e "$t\n$l\n$b\n$r" | sort -n | head -n 1 | cut -f2 -d:)"

        # set the offset values for x and y
        newX=$(cut -f1 -d ' ' <<< "$coord")
        newY=$(cut -f2 -d ' ' <<< "$coord")

        #check to make sure we're not out of bounds
        if [ $((right + newX)) -gt $xMax ]; then
            newX=$((-1 * left + xOffset))
        elif [ $((left + newX)) -lt $xMin ]; then
            newX=$((xMax - width))
        fi
        if [ $((bottom + newY)) -gt $yMax ]; then
            newY=$((-1 * top + yOffset))
        elif [ $((top + newY)) -lt $yMin ]; then
            newY=$((yMax - height))
        fi

        # move the window if it has focus
        [ $(xdotool getactivewindow) -eq $wID ] && xdotool windowmove --relative $wID $((newX + xOffset)) $((newY + yOffset))
    fi
    sleep $poll
done

Don't forget to edit the four variables at the very top to your liking. If this script is tasking your CPU, try increasing the poll variable to a larger value.

cursophobia.sh in action
Once you've created your script and made it executable, run it. It will ask you to select a window. Click on the window you want to be cursophobic and wait until the countdown is over. Once the countdown is over, the window you select will be cursophobic. When you're ready to help the window over come its fear of cursors, close the terminal window or kill the script from the terminal window with Ctrl+c

Multiple displays
Please note that this restricts the cursophobic window to a single display. I'm open to edits that would make it work across multiple displays.

| improve this answer | |
  • The fun part is fine; it works. Unfortunately, it totally eats my processor's occupation (around 60%) . It therefore isn't a real usable solution as it is. – Jacob Vlijm Jun 16 '17 at 7:18
  • @JacobVlijm, I made some changes to ease up on the processor. Try it out. – b_laoshi Jun 16 '17 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.