main: add timestamp parameter to push/popModal

Right now popModal() passes global.get_current_time() for
its begin_modal() call.  global.get_current_time() is the
timestamp of the last gdk or clutter event processed by the
shell's mutter process.  These values could potentially be
be too stale to use if pushModal() were to get called in
response to an event by another process.

This commit changes pushModal() to have an optional timestamp
argument, which can be used to associate the call with the
event that initiated it.

https://bugzilla.gnome.org/show_bug.cgi?id=637187
This commit is contained in:
Ray Strode 2010-10-20 15:08:14 -04:00
parent bed063eea1
commit dc020628b5

View File

@ -369,6 +369,7 @@ function _findModal(actor) {
/**
* pushModal:
* @actor: #ClutterActor which will be given keyboard focus
* @timestamp: optional timestamp
*
* Ensure we are in a mode where all keyboard and mouse input goes to
* the stage, and focus @actor. Multiple calls to this function act in
@ -379,11 +380,19 @@ function _findModal(actor) {
* modal stack returns to this actor, reset the focus to the actor
* which was focused at the time pushModal() was invoked.
*
* @timestamp is optionally used to associate the call with a specific user
* initiated event. If not provided then the value of
* global.get_current_time() is assumed.
*
* Returns: true iff we successfully acquired a grab or already had one
*/
function pushModal(actor) {
function pushModal(actor, timestamp) {
if (timestamp == undefined)
timestamp = global.get_current_time();
if (modalCount == 0) {
if (!global.begin_modal(global.get_current_time())) {
if (!global.begin_modal(timestamp)) {
log('pushModal: invocation of begin_modal failed');
return false;
}
@ -414,12 +423,21 @@ function pushModal(actor) {
/**
* popModal:
* @actor: #ClutterActor passed to original invocation of pushModal().
* @timestamp: optional timestamp
*
* Reverse the effect of pushModal(). If this invocation is undoing
* the topmost invocation, then the focus will be restored to the
* previous focus at the time when pushModal() was invoked.
*
* @timestamp is optionally used to associate the call with a specific user
* initiated event. If not provided then the value of
* global.get_current_time() is assumed.
*/
function popModal(actor) {
function popModal(actor, timestamp) {
if (timestamp == undefined)
timestamp = global.get_current_time();
modalCount -= 1;
let focusIndex = _findModal(actor);
if (focusIndex >= 0) {
@ -438,7 +456,7 @@ function popModal(actor) {
return;
global.stage.set_key_focus(null);
global.end_modal(global.get_current_time());
global.end_modal(timestamp);
global.set_stage_input_mode(Shell.StageInputMode.NORMAL);
}