2

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.

person the human
  • 345
  • 4
  • 15
  • 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 Answers1

3

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:

  1. GtkPlugs and GtkSockets are X11 specific. If you are looking for something cross platform, this might not be it.
  2. It seems both of these no longer exist in Gtk4.
BobMorane
  • 3,870
  • 3
  • 20
  • 42