My question was about weather it would be possible to embed the contents of a window (such as a terminal emulator, browser, game, or any other X org app) inside of a GTK3 application. This means that the user can still interact with the app and see contents of it. I am running Debian 11 64-bit and I want to make the app using C.
-
Do things like the `system()`, or `popen()` commands do what you are thinking? How about a session that is started up from a call to an exported function within shared library?. [More ideas here](https://stackoverflow.com/questions/5883462/linux-createprocess) – ryyker Dec 29 '21 at 22:07
-
@ryyker That would work for terminal applications, but my goal was embedding graphical applications inside other graphical applications. – person the human Dec 29 '21 at 23:33
-
[popen()](https://man7.org/linux/man-pages/man3/popen.3.html) is not limited to terminal applications. It is a library function that can be called from within a program whether its a terminal app, or one with windows/forms/panels. When called, it opens a pipe to the calling program, then creates a sub-process in which the string command argument is launched. The string command can be the path-name of any executable, whether it is native to the OS, or one that you have written, eg. `"./my_program.exe"`. Calls to `popen()` can also be made in such a way as to suppress console popups. – ryyker Dec 30 '21 at 14:35
-
@ryyker I know, but popen() will open another window. what I want to do is render the contents of a window inside a gtk widget. For example, the same way the ubuntu installer shows a small terminal while installing rather than a terminal popup. – person the human Dec 30 '21 at 15:39
-
There are ways to suppress the console from popping up. Nevertheless, take a look at this [question/answer](https://stackoverflow.com/questions/17248842/how-to-spawn-a-new-application-from-gnome-gtk-to-a-cli-application-and-read-its). – ryyker Dec 30 '21 at 15:46
-
@ryyker still not what I'm trying to do. I mean almost a virtual machine where the window is running inside of an element in another window. It moves with that window, and closes with that window as well. – person the human Dec 30 '21 at 18:04
1 Answers
The closest I have seen is using a GtkPlug
and a GtkSocket
:
Together with GtkSocket, GtkPlug 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 the ID of that widget’s window 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.
The communication between a GtkSocket and a GtkPlug follows the XEmbed Protocol. This protocol has also been implemented in other toolkits, e.g. Qt, allowing the same level of integration when embedding a Qt widget in GTK+ or vice versa.
An example of this is the xfce-settings-manager
, which you can study here (search for "socket-id" in the repo).
Notes:
GtkPlug
s andGtkSocket
s are X11 specific. If you are looking for something cross platform, this might not be it.- It seems both of these no longer exist in Gtk4.

- 3,870
- 3
- 20
- 42
-
Do you know what happened to the GtkPlug and the GtkSocket in GTK4? I can't find them. – Tommy Wolfheart Apr 03 '22 at 09:23
-
1It seems [they are gone](https://discourse.gnome.org/t/replacement-for-gtksocket/6268)... – BobMorane Apr 03 '22 at 11:35
-
Thanks. I've been looking at the [GdkX11](https://docs.gtk.org/gdk4-x11/class.X11Screen.html). Not sure what to make of it. – Tommy Wolfheart Apr 03 '22 at 11:38