Re: Key press synthesis (for WebKitGTK)




How about you send the event as `user_data` to `soup_request_send()` (or whatever method you use) and send 
that to the webkit widget?

If I understood you correctly, that's what I'm doing in the code I've posted in
my first email.

I add the event to the 'user_data' (here window_event) in
soup_session_queue_message:

--8<---------------cut here---------------start------------->8---
void window_send_event(GtkWidget *widget, GdkEventKey *event, gpointer data) {
  // ...  Some provision to avoid infinite loops...

        WindowEvent *window_event = g_new(WindowEvent, 1);
        Window *window = (Window *)data;
        window_event->window = window;
        window_event->event = event;

        g_debug("Sending keypress XML-RPC message for window %p", window_event->window);
        soup_session_queue_message(xmlrpc_env, msg, &window_event_callback, window_event);
}
--8<---------------cut here---------------end--------------->8---

And the Soup callback creates a new event from the old one.  It sends it with gtk_main_do_event.

--8<---------------cut here---------------start------------->8---
void window_event_callback(SoupSession *_session, SoupMessage *msg, gpointer data) {
        // ...
        if (!g_variant_get_boolean(consumed)) {
                g_debug("Event not consumed, forwarding to GTK");

                WindowEvent *window_event = (WindowEvent *)data;

                GdkDevice *device = NULL;
                GdkDisplay *display = gdk_display_get_default();
                GdkSeat *seat = gdk_display_get_default_seat(display);
                device = gdk_seat_get_keyboard(seat);

                GdkEvent *event = gdk_event_new(GDK_KEY_PRESS);
                event->key = *(window_event->event);
                event->key.string = g_strdup(window_event->event->string);
                event->key.time = gtk_get_current_event_time();
                event->key.window = 
g_object_ref(gtk_widget_get_window(GTK_WIDGET(window_event->window->base)));
                gdk_event_set_device(event, device);

                gtk_main_do_event(event);
                gdk_event_free(event);

                g_debug("Event emitted");
        }
}
--8<---------------cut here---------------end--------------->8---

Did I misunderstand what you meant?

-- 
Pierre Neidhardt
https://ambrevar.xyz/


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