Posts

Showing posts with the label xembed

gVim in GNU Emacs

Image
  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);   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. T...

Embedding GTK applications via XEmbed - 2

Image
In previous post , we learnt the basics of embedding a GTK application in another application. This works fine when the embedded application supports client server architecture like gVim. Note that in this case the client mode invocations are short lived processes while server process runs throughout the lifetime of the application. In contrast, an application like VLC provides a remote control interface to run  multiple operations in the same process. In this case, we need to obtain an input channel of the process and write our commands to the same. Here's an updated version of the code. Remember to update the two bold paths with appropriate video locations. The application starts with one video and then switches to the next one when the button is clicked. embed.c #include <gtk/gtkx.h> gchar *string; GMutex mutex; void send_hello(GtkButton *btn) {   /* Note the \n at the end */   string = g_strdup_printf("add /home/anand/Downloads/test.mp4 \n"); } static vo...

Embedding GTK applications via XEmbed

Image
Together with GtkPlug , GtkSocket provides the ability to embed widgets from one process into another process in a fashion that is transparent to the user. One process creates a GtkSocket widget and passes that widget’s window ID to the other process, which then creates a GtkPlug with that window ID . Any widgets contained in the GtkPlug then will appear inside the first application’s window. Here's an updated version of Embedding applications via XEmbed using GTK 3.0. Reference Here are commands for running some GTK applications in embedded mode: gvim --servername %d --socketid %d #GVim server gvim --servername %d --remote-send 'GoHello, World!<Esc><C-O>' #GVim client cvlc --drawable-xid %d out.mp4     #VLC xterm -into %lu    # Terminal emulator mpv --wid=%lu url     # mpv video player surf -e %lu   # Surf web browser from Suckless based on webkitgtk2 embed.c #include <gtk/gtkx.h> #define EXPR "'GoHel...