Casilda.Compositor

g Casilda.Compositor Casilda.Compositor GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget Gtk.Scrollable Gtk.Scrollable GObject.GInterface->Gtk.Scrollable GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Scrollable->Casilda.Compositor Gtk.Widget->Casilda.Compositor

Subclasses:

None

Methods

Inherited:

Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (18), Gtk.Buildable (1), Gtk.Scrollable (9)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new (socket)

get_client_socket_fd ()

set_scrollable (scrollable)

spawn_async (working_directory, argv, envp, flags, child_setup, *user_data)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (7), Gtk.Buildable (9), Gtk.Scrollable (1)

Properties

Inherited:

Gtk.Widget (35), Gtk.Accessible (1), Gtk.Scrollable (4)

Name

Type

Flags

Short Description

socket

str

r/w/co

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Casilda.Compositor(**kwargs)
Bases:

Gtk.Widget, Gtk.Scrollable

Abstract:

No

Structure:

Casilda.CompositorClass

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 Casilda.Compositor 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 None 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 (None); Gtk.Window.set_child (GTK_WINDOW (window), GTK_WIDGET (compositor)); Gtk.Window.present (GTK_WINDOW (window));

str *argv[] = { “/usr/bin/gtk4-demo”, None }; Casilda.Compositor.spawn_async (compositor, None, argv, None, GLib.SpawnFlags.DEFAULT, None, None, None, None); ```

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.Object from ‘gi://GObject.Object'; import Gtk from ‘gi://Gtk?version=4.0’; import Casilda from ‘gi://Casilda?version=1.0’;

let CasildaApplication = GObject.Object.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)); ```

classmethod new(socket)
Parameters:

socket (str) – the named socket to use or None

Returns:

a new CasildaCompositor widget

Return type:

Casilda.Compositor

Create a new CasildaCompositor widget using socket as the name of the Wayland socket. Clients can connect to the compositor by setting WAYLAND_DISPLAY=`socket`

get_client_socket_fd()
Returns:

a socket FD connected to the compositor

Return type:

int

Create a client socket file descriptor connected to this compositor ready to use by passing it to a client with WAYLAND_SOCKET environment variable. Once the returned FD is passed to the client it must be closed on the parent otherwise the client windows wont get destroyed if the client looses the connection to the server.

set_scrollable(scrollable)
Parameters:

scrollable (bool) –

spawn_async(working_directory, argv, envp, flags, child_setup, *user_data)
Parameters:
Raises:

GLib.Error

Returns:

True on success, False if error is set.

child_pid:

return location for child process reference, or None

Return type:

(bool, child_pid: int)

Executes a child program asynchronously with the right environment to automatically connect to this compositor.

See [func`GLib`.spawn_async_with_pipes_and_fds] for a full description; this function simply calls [func`GLib`.spawn_async_with_pipes_and_fds] without any pipes and with WAYLAND_DISPLAY set to CasildaCompositor::socket or a fd already connected to the compositor and set to WAYLAND_SOCKET if its None.

Please note GDK_BACKEND, WAYLAND_DISPLAY and WAYLAND_SOCKET are set by this function they are ignored from %envp and DISPLAY is removed to avoid clients try to connect using X11

Property Details

Casilda.Compositor.props.socket
Name:

socket

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Wayland socket the compositor will listen on.

If None you can still use WAYLAND_SOCKET with an fd returned by Casilda.Compositor.get_client_socket_fd() instead of setting up WAYLAND_DISPLAY.