I have a script where I activate a shortcut after clicking a mouse button, but I need the window under the cursor to be focused for this to work. I tried sending a normal click before the shortcut, but it can cause accidental clicks. Is there a way to trigger a raise/focus to the window below the cursor?

  • 1
    Have a look at wmctrl. I don't use KDE, so I don't know if it will work with KDE. Anyhow, you need to communicate with KDE's window manager to achieve this, if not with wmctrl, then through some KDE-specific mechanism. – dirkt May 23 at 5:31

I found a solution:

# Find the id of the window under the cursor
id=`xdotool getmouselocation --shell 2>/dev/null | grep WINDOW | sed "$sedGetValue"`

# Focus the window
wmctrl -iR "$id"
| improve this answer | |

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.