gVim in GNU Emacs
You can also embed gVim in GNU Emacs (GTK build with X11 backend). There are two things to take care of in this case - moving focus to the embedded widget and redirecting keyboard input to the widget.
A GTK widget can only have focus if it's set that way (remember there are multiple widgets in a window):
// Allow to receive keyboard input
gtk_widget_set_can_focus (widget, TRUE);
// Receive keyboard input
gtk_widget_grab_focus (widget);
gtk_widget_set_can_focus (widget, TRUE);
// Receive keyboard input
gtk_widget_grab_focus (widget);
Emacs filters keyboard events (KeyPress) before passing it to GTK. That's how C-g always works in Emacs. When Emacs receives XEMBED_REQUEST_FOCUS (event->type == ClientMessage && event->xclient.message_type == dpyinfo->Xatom_XEMBED && event->xclient.data.l[1] == XEMBED_REQUEST_FOCUS), we need to set input focus to the widget using XSetInputFocus() using the handle event->xclient.window . Additionally, we set a flag that a widget is active. Whenever this flag is active, we stop filtering keyboard events. This gets reset when user clicks (ButtonPress) in buffer window outside the widget.
It's useful to remember that an XEvent provides information about the source of event via different fields. Names in parentheses denotes event->type .
// Keyboard event (KeyPress, KeyRelease)
event->xkey.display
event->xkey.window
// Mouse event (ButtonPress, ButtonRelease)
event->xbutton.display
event->xbutton.window
// XEmbed (ClientMessage)
event->xclient.display
event->xclient.window
event->xkey.display
event->xkey.window
// Mouse event (ButtonPress, ButtonRelease)
event->xbutton.display
event->xbutton.window
// XEmbed (ClientMessage)
event->xclient.display
event->xclient.window
(require 'xwidget)
(insert " ")
(forward-char -1)
(setq w (xwidget-insert (point) 'socket "test" 400 400 '(:init "/usr/bin/gvim --servername emacs --socketid %lu")))
(insert " ")
(forward-char -1)
(setq w (xwidget-insert (point) 'socket "test" 400 400 '(:init "/usr/bin/gvim --servername emacs --socketid %lu")))
Code:
https://gitlab.com/atamariya/emacs/-/blob/dev/src/xwidget.chttps://gitlab.com/atamariya/emacs/-/blob/dev/src/xterm.h
https://gitlab.com/atamariya/emacs/-/blob/dev/src/xterm.c
https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/xwidget.el
https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/xwidget.el
Comments
Post a Comment