I have embedded gvim inside a Gtk::Socket which is placed in a Gtk::Box, how can I grab focus to the embedded gvim window so that I achieve the same as actually pointing and clicking in the embedded window?
Using ->grab_focus()
on the Gtk::Socket widget does not have any effect.
According to the XEMBED spec (http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html#idm139742761059984) it seems that the embedder (Gtk::Socket) should send either a XEMBED_FOCUS_IN
or a XEMBED_WINDOW_ACTIVATE
signal to the child, but there does not seem to be an interface for this in Gtk::Socket.
An simple example of what I am trying to do based on the Gtk::Plug and Gtk::Socket example can be found here: https://github.com/gauteh/plug-socket-grab-focus .
In case this is a bug, it has been reported here: https://bugzilla.gnome.org/show_bug.cgi?id=729248
There are now two ways to achieve this, one is by using the patch as provided in: https://bugzilla.gnome.org/show_bug.cgi?id=729248 which adds an gtk_socket_focus_forward ()
method to GtkSocket
. Calling this will focus the first widget inside the Gtk::Plug
window.
An example of using gtk_socket_focus_forward
can be found in the focus_forward branch of an example adapted from the standard example.
The second way to achieve this is to send the Gtk::DIR_TAB_FORWARD
signal as described on the mailing list, a similar example can be found in the tab_forward branch.
This involves the following:
socket->set_can_focus (true);
socket->child_focus (Gtk::DIR_TAB_FORWARD);
The method does diverge slightly from what is possible with gtk_socket_focus_forward
, but appears to do the trick.