alexandernst
alexandernst

Reputation: 15099

Stealing focus (for a good reason)

I'm working on a clone of Yakuake and, if you have used it, you'd know that one of it's features is stealing the focus for easiness.

Basically, you hit the "show" hotkey, the app appears and you can write on it. You could be doing whatever thing with whatever app, (being Yakuake hidden), but as soon as you hit the hotkey, Yakuake appears and steals the focus. I want to do the same with my app.

I know there are some window manager rules that prevent applications from doing this, but Yakuake is doing it, why I'm not able to do it?

Also, this application is meant to be compatible with Windows, Linux and Mac, so no KDE or Gnome or < insert_your_favourite_window_manager_here > hacks; I won't go the detect-WM-and-do-hack way.

PS: I'm doing that app in C++ and Qt4.

EDIT:

Just to make it clear, I'm not asking for any code (but if you actually have some example, I appreaciate it). I'm asking for a way for doing it. What should I do to make the WM assign the focus to my app. Is there any standard way for doing so?

Upvotes: 2

Views: 1225

Answers (3)

alexandernst
alexandernst

Reputation: 15099

The solution is simpler than I thought. I did an animation with a duration of 0s and at the end of the animation I just did a focus. This did the work.

Upvotes: 1

KaZ
KaZ

Reputation: 1163

If you want to do it with a "show" hotkey or shortcut you'll have to create and use a hook on the keybord.

Qt don't provide such things so you'll have to do it by yourself.

you can have a look at this post : QT background process

I don't know for other OS.

When you'll get the right keyboard event from your hook, you can create a window with the "allwas on top hint" and that should by ok.

Upvotes: 0

xtofl
xtofl

Reputation: 41509

There is the Qt::WindowStaysOnTopHint....

Upvotes: 1

Related Questions