A simple Wayland compositor widget for Gtk 4.
It was originally created for Cambalache's workspace using (wlroots)[https://gitlab.freedesktop.org/wlroots/wlroots], a modular library
to create Wayland compositors.
Following Wayland tradition, this library is named after my hometown in Santa Fe, Argentina.
To embed another process window in your Gtk 4 application all you have to do is create a CasildaCompositor widget and add it in the
hierarchy just like any other widget.
You can specify which UNIX socket the compositor will listen for clients connections or use [
method@Casilda.Compositor.get_client_socket_fd] to get a already connected socket to the compositor.
```c compositor = casilda_compositor_new ("/tmp/casilda-example.sock"); gtk_window_set_child (GTK_WINDOW (window), GTK_WIDGET (compositor
)); ```
Once the compositor is running you can connect to it by specifying the socket in WAYLAND_DISPLAY environment variable.
```bash export GDK_BACKEND=wayland export WAYLAND_DISPLAY=/tmp/casilda-example.sock gtk4-demo ```
If you do not want any client being able to connect to the compositor you can pass NULL as socket and spawn the client with [
method@Casilda.Compositor.spawn_async] or get an already connected socket with [method@Casilda.Compositor.get_client_socket_fd] and pass
it to the client on WAYLAND_SOCKET env variable.
```c compositor = casilda_compositor_new (NULL); gtk_window_set_child (GTK_WINDOW (window), GTK_WIDGET (compositor)); gtk_window_present
(GTK_WINDOW (window));
gchar *argv[] = { "/usr/bin/gtk4-demo", NULL }; casilda_compositor_spawn_async (compositor, NULL, argv, NULL, G_SPAWN_DEFAULT, NULL,
NULL, NULL, NULL); ```
Python example running gtk4-demo with [method@Casilda.Compositor.spawn_async]
```python import gi import sys
gi.require_version("Gtk", "4.0") gi.require_version("Casilda", "1.0") from gi.repository import GLib, Gtk, Casilda
class CasildaApplication(Gtk.Application): def __init__(self): super.__init__(
application_id="ar.xjuan.casilda.PyGObject.Example")
def do_activate(self): compositor = Casilda.Compositor()
window = Gtk.ApplicationWindow( application=self, title="Casilda Compositor", default_width=800, default_height=600,
child=compositor )
compositor.spawn_async ( None, ["/usr/bin/gtk4-demo"], None, GLib.SpawnFlags.DEFAULT )
window.present()
if __name__ == "__main__": app = CasildaApplication sys.exit(app.run(sys.argv)) ```
and the same in Javascript:
```javascript import System from 'system'; import GLib from 'gi://GLib'; import GObject from 'gi://GObject'; import Gtk from
'gi://Gtk?version=4.0'; import Casilda from 'gi://Casilda?version=1.0';
let CasildaApplication = GObject.registerClass({}, class CasildaApplication extends Gtk.Application { constructor { super
({ application_id: 'ar.xjuan.casilda.Gjs.Example' }); }
vfunc_activate { let compositor = new Casilda.Compositor();
let window = new Gtk.ApplicationWindow({ application: this, title: 'Casilda Compositor', default_width: 800, default_height: 600,
child: compositor });
window.connect('close-request', () => { this.quit(); });
compositor.spawn_async ( null, ["/usr/bin/gtk4-demo"], null, GLib.SpawnFlags.DEFAULT, null );
window.present(); } });
let app = new CasildaApplication; app.run([System.programInvocationName].concat(ARGV)); ```