Obtaining pointer to the window with focus



I've not seen a clear answer to this obvious question. Maybe I'm not searching for the right terms.

What I want to do is create a dialog if an error occurs, and I want it to appear atop the window that 
currently has focus. This seems like a standard thing to do, so it's weird I can't find a clear explanation.

What I have found suggests something like:

GtkWidget *widget, *focussed_window;
GList *list = NULL;  // NULL means empty list

list = gtk_window_list_toplevels ();

g_list_foreach (list, (GFunc) g_object_ref, NULL);

while ((widget = g_list_next (list)) != NULL) {  // line 577
  if (gtk_window_has_toplevel_focus ((GtkWindow *) window)) {
    focussed_window = widget;  // We found the window that currently has focus.
  }
g_list_free (list);


Is this the correct approach? If so, can someone show me how that would be coded in C? 


This does not compile. I get:

func.c:577: warning: assignment from incompatible pointer type


Dave


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