Re: Key press synthesis (for WebKitGTK)

2018-11-23 Thread Gergely Polonkai
Hello,

from the manual
(https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-key-press-event),
the signature of key-press-event handlers is:

```
gboolean
user_function (GtkWidget *widget,
   GdkEvent  *event,
   gpointer   user_data)
```

From the same manual:

> Returns
>
> TRUE to stop other handlers from being invoked for the event. FALSE to
> propagate the event further.

So if you change your handler’s return type from `void` to `gboolean`
and return `FALSE` if the lisp thingy doesn’t understand your key, it
will be automatically propagated to the next handler (which, hopefully,
will insert your "a" key.

Best,
Gergely

Pierre Neidhardt writes:

> Hi all!
>
> I'm working on the GTK port of Next browser (http://next.atlas.engineer/,
> source: https://source.atlas.engineer/public/next).
>
> I have a window with a WebKitGTK view in it.
>
> I intercept all key-press-events and send them to a third-party Lisp program 
> via
> XML-RPC.
>
> Whenever the Lisp program does not recognize the key bindings, it notifies the
> GTK program.  From there, GTK must forward the key press to the WebKit view.
>
> Example:
>
> - The focus is on a text field on a web page.
> - I press "a".
> - "a" is sent to the Lisp third party program.
> - Lisp does not know what to do with "a", and sends a message back to the GTK 
> program.
> - The GTK program must insert "a" in the text field in the WebKit view.
>
>
> To achieve that, I think I need to synthesize a key press event during the 
> last
> step.
> (Unless someone can think of a direct way to forward a key press to the WebKit
> view.)
>
> Here is what I've got:
>
> - In the widget creation function:
>
> --8<---cut here---start->8---
>   g_signal_connect(buffer->web_view, "key-press-event", 
> G_CALLBACK(window_send_event), window);
> --8<---cut here---end--->8---
>
> A 'window_send_event' callback for all key-presses.  I use Libsoup to send an
> XML-RPC message containing the keypress to the Lisp program:
>
> --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 finally, the callback when the response arrives from the Lisp program:
>
> --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---
>
> The
>
> --8<---cut here---start->8---
>   gtk_main_do_event(event);
> --8<---cut here---end--->8---
>
> call is not caught anywhere though.  Any idea why?
>
> I've tried with different event settings and sometimes I get
>
> --8<---cut here---start->8---
> (next-gtk-webkit:10768): GLib-GObject-WARNING **: 15:31:27.027: 
> gsignal.c:2172: signal id '68' cannot be chained from current emission stage 
> for instance '0x1c3a2a0'
> --8<---cut here---end--->8---
>
> I don't understand the above error message.  Any idea what could issue it?
>
> Any clue, anyone?
>
> Cheers!
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Issue using the "gtk_widget_get_allocated_height" instruction

2018-11-23 Thread Sébastien Le Roux

Dear all, thanks for reading this,
I recently updated GTK from 3.22.24 to 3.22.30 (Fedora 27 to Fedora 28 
update),
doing so something changed in behaviour of the program I am working on 
(C code) at runtime.


In my program I create a GtkMenuBar widget, using the code:

GtkWidget * win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
GtkWidget * gl_vbox =  gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (win), gl_vbox);
GtkWidget * menu_bar = gtk_menu_bar_new ();
gtk_box_pack_start (GTK_BOX (gl_box), menu_bar, FALSE, FALSE, 0);
GtkWidget * gl_area = gtk_gl_area_new ();
gtk_widget_set_size_request (gl_area, 100, 100);
gtk_box_pack_start (GTK_BOX (gl_box), gl_area, FALSE, FALSE, 0);

Before my update I could get the height of the menu bar after drawing using:

int size = gtk_widget_get_allocated_height (menu_bar);

After my update the value of size is always 1, before the update it was 
around 15,
obviously this new 1 value is messing with my program, not to mention 
that it is not
what I see on the my computer screen, could anyone explain to me what to 
do the get
the proper size of the GtkMenuBar ? (the gtk_widget_get_size_request is 
useless).


Thanks for your help in the matter.

Best regards.

Sébastien Le Roux

--
===
Dr. Sébastien Le Roux
Ingénieur de Recherche CNRS
Institut de Physique et Chimie des Matériaux de Strasbourg
Département des Matériaux Organiques
23, rue du Loess
BP 43
F-67034 Strasbourg Cedex 2, France
E-mail: sebastien.ler...@ipcms.unistra.fr
Webpage: http://www-ipcms.u-strasbg.fr/spip.php?article1771
RINGS project: http://rings-code.sourceforge.net/
ISAACS project: http://isaacs.sourceforge.net/
Fax:   +33 3 88 10 72 46
Phone: +33 3 88 10 71 62
===

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list