Web lists-archives.com

Re: Get GtkWindow focus from XI Event




Thank you very much.
Your reply fixes my problem.
I thought your suggestion to use gdk_x11_display_get_user_time() + a time lag previously instead of the event time by mistake.

Fujiwara

On 05/12/17 00:35, Rui Tiago Cação Matos-san wrote:
Hi,

On Thu, May 11, 2017 at 2:24 PM, Takao Fujiwara <tfujiwar@xxxxxxxxxx> wrote:
I have a focus problem with the attached program.
1. When press Ctrl-Alt-v, my window is launched with the keyboard focus.
2. Click [x] button and close the window.
3. When press Ctrl-Alt-v again, my window is launched but the focus status
is different by desktop.

XFCE4 desktop can get the keyboard focus correctly.
But GNOME, MATE or Plasma desktop cannot get the keyboard focus in the
second Ctrl-Alt-v.

Basically you're hitting the window manager's focus stealing
prevention logic. See below how you can fix it:

static void
run_window ()
{
    GtkWidget *window;
    GMainLoop *loop;

    loop = g_main_loop_new (NULL, FALSE);
    window = my_window_new (loop);
    gtk_widget_show_all(window);

call gtk_window_present_with_time() here

    g_main_loop_run (loop);
}

static void
event_handler (GdkEvent *event,
               gpointer  data)
{
    static int times = 0;
    if (((GdkEventAny*)event)->window == gdk_get_default_root_window() &&
         event->type == GDK_KEY_PRESS) {
        guint keyval = ((GdkEventKey*)event)->keyval;
        guint modifiers = ((GdkEventKey*)event)->state;
        if (keyval >= GDK_KEY_A && keyval <= GDK_KEY_Z &&
            (modifiers & GDK_SHIFT_MASK) != 0) {
            keyval = keyval - GDK_KEY_A + GDK_KEY_a;
        }
        if (keyval == shortcut_keysym &&
            modifiers == shortcut_modifiers) {

get the event timestamp here with gdk_event_get_time()

            run_window ();
            times++;
            if (times > 1) {
                ungrab_keycode (keyval, modifiers);
                gtk_main_quit();
            }
        }
    }
    gtk_main_do_event (event);
}


Rui


_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-devel-list