gtk_window_set_focus()



hi,

I have an app to draw seismograms on the screen.  When the user hits the
"Next" button, the app goes away and reads the next batch of traces for
display, does various statistics, plots the output to an internal pixmap
and then renders this to the screen; depending on the number of files to
be read, this could take a fair amount of time (up to a minute).  no
problems there.

One issue that came up over time (when actually unleashed to the end
users...) was that when the program was away reading the files, user
events (e.g., mouse click) would get caught and (maybe) cause problems
since the program was not in the proper state to process this event
properly.

I got around this by introducing an invisible widget used to grab focus
while the program is off reading and processing files, and then ungrabbing
this focus once the program's processing is complete, thus disallowing any
user events to be propogated to the widget receiving the user event.  This
also works just fine.

However, this has now introduced a new problem.  If the user has the mouse
over the Next button (to read traces), clicks this button (thus invoking
the file processing described above), and doesn't move the mouse off this
button, when the program returns (ungrabbing focus of my invisible
widget), focus is not reset to this button.  (Clicking this button again
has no effect; focussing somewhere else and returning to this button
results in a working button.)

To get around this, then, I tried to use gtk_window_get_focus() to save
the widget having focus at the moment my internal processing is invoked,
and then returning this focus to this saved widget when the process is
complete, via the following function:

void focusLock(int lockCmd)
{
  static GtkWidget *oldFocus;

  switch(lockCmd)
  {
    case LOCK:
      oldFocus = gtk_window_get_focus(topWindow);
      gtk_grab_add(invisible);
      break;

    case UNLOCK:
      gtk_grab_remove(invisible);
      gtk_window_set_focus(topWindow, oldFocus);
// tried also gtk_widget_grab_focus(): also no effect
      break;
  }
}

However, using this code, the focus is not reset back to the oldFocus
widget; there is no change in the problem behaviour.  In order to be able
to press the button a second time, I must still move the mouse away from
the button and back over it.

So, I'm wondering, first, is there a way to achieve my above-stated goals
some other (better) way?  Second, if the above methodology is okay, why
does the gtk_window_set_focus() call above not result in the focus being
returned to the widget having focus before my program stole it with
gtk_grab_add()?

Thanks for any ideas in advance, I'm finding myself in a loop of solve one
problem and I simply make another needing solving.

cheers,

richard boaz




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]