← Back to team overview

unity-dev team mailing list archive

Re: Window Focus in Unity

 

Hi Izidor,

generally speaking there's no standardized way which would force the
window manager to move focus to the new window, it depends on the window
manager as well as user's settings (see for example compiz's focus
stealing prevention setting). You might have better luck if you use
gtk's present_with_timestamp() (or qt equivalent), but you need to pass
a valid timestamp from X - which you can get from a user interaction (a
key/mouse button press; also note that using equivalent of
GDK_CURRENT_TIME is useless as that is just defined as 0 and is pretty
much the same as if you didn't pass any timestamp).

But as I said, even though this might work for you, it will not work in
all cases.

Michal


On 04/16/2012 09:08 PM, Izidor Matušov wrote:
> Hi,
>
> I've run additional experiments and found that the described focus
> model is the same in Unity 2D & GNOME Shell. I've added a reproducer
> for PyQt4 [1] and it still happens.
>
> Could you give me a tip which library / technology influence this
> focus behavior? Where to look next?
>
> Thanks
>
> Izidor
>
> 1: https://code.launchpad.net/~izidor/%2Bjunk/focus-model/
>
> Am 03.04.2012 23:31, schrieb Izidor Matušov:
>> Hi,
>>
>> I am one of maintainers of Getting Things GNOME! (GTG), a task manager
>> application. I would like to add a feature where you trigger a keyboard
>> shortcut and you can immediately start typing a new task you want to do
>> in future, e.g. you browse web and you remember that you have to call
>> your cousin tomorrow. I was able to setup all needed parts but a new
>> window doesn't get focus. You have to switch to the window by mouse or
>> keyboard what kills the feature :-(
>>
>> I've prepared a simple demo to test:
>> https://code.launchpad.net/~izidor/%2Bjunk/focus-model/
>>
>> Run the main application (app.py) which provides a DBus method to open a
>> new window. In another terminal window, run Launcher.py which calls that
>> method and makes the app open a new window.
>>
>> As you can see in image 01.png, a very strange thing happens: the new
>> window is put in over all windows but it doesn't get focus, i.e. when
>> you start typing, you don't change the text of the entry.
>>
>> I have hard times to understand Window Focus Model in Unity. It seems to
>> me that a new window gets a focus only:
>> * when its application had already focus
>> * or when the window is the first shown window of an application
>>
>> Another thing is when I use window.preset(), the window is put into the
>> background and an animation in Unity Launcher is shown. (Try it by
>> uncommenting a line in app.py).
>>
>> This behavior affect all other AppIndicators I use too:
>> * when you open Empathy contact list from the indicator-messages, the
>> window doesn't get focus either, see 02.png. When I type, I type in the
>> gnome-terminal in background. (You might need to open the window and
>> close it few times to prevent showing the window for the first time of
>> application)
>>
>> * Hamster Appindicator ( http://albertomilone.com/wordpress/?p=502 ) --
>> after showing the first window, it doesn't get any focus
>>
>> * GTG's Appindicator -- Although it doesn't run over DBus, it has the
>> same problem. You have to choose an action from appindicator and then
>> switch to a new window.
>>
>> * Banshee from Sound Menu is a little bit tricker: almost every time you
>> close banshee, you turn it off. The next time you open it, banshee
>> starts as a new process and an exception is applied.
>>
>> However, this doesn't apply to Skype whose contact list can be shown
>> from its status icon with focus.
>>
>> I use Ubuntu 11.10, unity 4.28.0-0ubuntu2.
>>
>> My question is: How to give focus to a new window so the user can write
>> in it without switching windows? Is this Window Focus by intention or it
>> is a bug?
>>
>> Thanks,
>> Izidor
>
>



References