Find out if window is active

Hi folks,

I am trying to find out if a window is active or not, I have tried three different approaches:

* get a GdkWindow pointer from the "window" property of my GtkWindow and check if it is FOCUSED
 * use the function gtk_window_has_toplevel_focus()
 * use the function gtk_window_is_active()

Here is the code:

    gboolean has_focus = FALSE;
    GdkWindow* window;
    g_object_get(GTK_WIDGET(tw->window), "window", &window, NULL);
    has_focus = (gdk_window_get_state(window) == GDK_WINDOW_STATE_FOCUSED);
    //has_focus = gtk_window_has_toplevel_focus(GTK_WINDOW(tw->window));
    //has_focus = gtk_window_is_active(GTK_WINDOW(tw->window));
    g_message("has_focus %d", has_focus);

if (config_getbool("grab_focus") && !has_focus && tw->current_state == DOWN) {
        tilda_window_set_active (tw);
    } else {

Unfortunately if I compile and run, the has_focus variable remains true, even if I focus another window. I experience the same behaviour for all three solutions. Is there anything im missing?

Btw., the window in question is set to be always on top, im not sure if that matters.


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