Use more actor.grab_key_focus() and less stage.connect('key-press-event')

Until recently, the clutter keyboard focus was almost always kept on
the stage, and bits of code that wanted to do stuff with the keyboard
would just watch for key-press-events on the stage. In several places,
the code wasn't even bothering to ensure that the focus was on the
stage, which caused problems with other actors that explicitly grabbed
focus.

A previous fix for this (f21403fd) was to always reset the focus to
the stage after calling pushModal(), but a better fix is to just
actually make use of the keyboard focus everywhere rather than having
everyone try to read events off the stage.

Now pushModal(actor) also does actor.grab_key_focus(), and various
bits of code have been changed to read key events off their own
toplevels rather than off the stage, meaning there's no chance of them
accidentally getting someone else's events.

https://bugzilla.gnome.org/show_bug.cgi?id=618885
This commit is contained in:
Dan Winship
2010-11-03 13:30:08 -04:00
parent 69bed929af
commit 4dd4c9f99f
5 changed files with 45 additions and 115 deletions

View File

@ -350,13 +350,13 @@ function _findModal(actor) {
* @actor: #ClutterActor which will be given keyboard focus
*
* Ensure we are in a mode where all keyboard and mouse input goes to
* the stage. Multiple calls to this function act in a stacking fashion;
* the effect will be undone when an equal number of popModal() invocations
* have been made.
* the stage, and focus @actor. Multiple calls to this function act in
* a stacking fashion; the effect will be undone when an equal number
* of popModal() invocations have been made.
*
* Next, record the current Clutter keyboard focus on a stack. If the modal stack
* returns to this actor, reset the focus to the actor which was focused
* at the time pushModal() was invoked.
* Next, record the current Clutter keyboard focus on a stack. If the
* modal stack returns to this actor, reset the focus to the actor
* which was focused at the time pushModal() was invoked.
*
* Returns: true iff we successfully acquired a grab or already had one
*/
@ -386,7 +386,7 @@ function pushModal(actor) {
}
modalActorFocusStack.push([actor, curFocus]);
global.stage.set_key_focus(null);
global.stage.set_key_focus(actor);
return true;
}
@ -416,6 +416,7 @@ function popModal(actor) {
if (modalCount > 0)
return;
global.stage.set_key_focus(null);
global.end_modal(global.get_current_time());
global.set_stage_input_mode(Shell.StageInputMode.NORMAL);
}