Casilda.Compositor¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (18), Gtk.Buildable (1), Gtk.Scrollable (9)
- Structs:
class |
|
|
|
|
Virtual Methods¶
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/co |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Casilda.Compositor(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
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.Compositorwidget 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
Noneas 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.Objectfrom ‘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:
- Returns:
a new
CasildaCompositorwidget- Return type:
Create a new
CasildaCompositorwidget 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:
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.
- spawn_async(working_directory, argv, envp, flags, child_setup, *user_data)¶
- Parameters:
working_directory (
strorNone) – child’s current working directory, orNoneto inherit parent’sargv ([
str]) – child’s argument vectorenvp ([
str] orNone) – child’s environment, orNoneto inherit parent’sflags (
GLib.SpawnFlags) – flags fromGLib.SpawnFlagschild_setup (
GLib.SpawnChildSetupFuncorNone) – function to run in the child just beforeexec()
- Raises:
- Returns:
Trueon success,Falseif error is set.- child_pid:
return location for child process reference, or
None
- Return type:
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::socketor a fd already connected to the compositor and set to WAYLAND_SOCKET if itsNone.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:
- Default Value:
- Flags:
Wayland socket the compositor will listen on.
If
Noneyou can still use WAYLAND_SOCKET with an fd returned byCasilda.Compositor.get_client_socket_fd() instead of setting up WAYLAND_DISPLAY.