On Wed, 1 May 2019 03:24:04 +0100
adlo <adloco...@gmail.com> wrote:

> > On 29 Oct 2018, at 09:33, Pekka Paalanen <ppaala...@gmail.com> wrote:
> > 
> > the only opinionated advice I can give you is don't do it. Instead, put
> > the GTK stuff in a separate process, let your compositor fork & exec
> > it, and talk to it through your own private protocol extension for the
> > special bits you need.  
> 
> What are the basics for creating a private protocol extension, i.e. what's 
> the minimum boilerplate code needed? What's a simple example of how to 
> implement a request between the two processes? The Weston source code is 
> difficult to follow.
> 
> How do I allow the child process to call functions and pass data to the 
> parent and vice versa?

Hi adlo,

it is all just the normal Wayland protocol exchange but with a new
interface of your own design. I'm not sure if there is a really
minimal example, but I'll list at least some.

One example of such private protocol extension is
https://gitlab.freedesktop.org/wayland/weston/blob/master/protocol/weston-desktop-shell.xml

The server-side implementation of it is in shell.c and the
entrypoint to that is
https://gitlab.freedesktop.org/wayland/weston/blob/master/desktop-shell/shell.c#L5143

        wl_global_create(ec->wl_display,
                             &weston_desktop_shell_interface, 1,
                             shell, bind_desktop_shell)

which installs the protocol extension in the compositor. You can
see everything about the implementation by following all callbacks
that get registered, starting with bind_desktop_shell().

The privacy of the protocol extension, the installed wayland global
really, is achieved in
https://gitlab.freedesktop.org/wayland/weston/blob/master/desktop-shell/shell.c#L4366

        shell->child.client = weston_client_start(shell->compositor,
                                                  shell->client);

which creates the Wayland connection before forking the child
process and bind_desktop_shell() then verifying the client trying
to bind to the global is the client that was forked.


The client-side implementation is in desktop-shell.c with the entry
point at
https://gitlab.freedesktop.org/wayland/weston/blob/master/clients/desktop-shell.c#L1392

        if (!strcmp(interface, "weston_desktop_shell")) {
                desktop->shell = display_bind(desktop->display,
                                              id,
                                              &weston_desktop_shell_interface,
                                              1);
                weston_desktop_shell_add_listener(desktop->shell,
                                                  &listener,
                                                  desktop);


https://gitlab.freedesktop.org/wayland/weston/blob/master/protocol/weston-touch-calibration.xml
is another example of a custom protocol extension (not for a shell
helper client though), with implementations in
https://gitlab.freedesktop.org/wayland/weston/blob/master/libweston/touch-calibration.c
and
https://gitlab.freedesktop.org/wayland/weston/blob/master/clients/touch-calibrator.c
Again, you can find the entry points with wl_global_create() and
display_bind(), respectively.

There is also
https://gitlab.freedesktop.org/wayland/weston/blob/master/protocol/weston-test.xml
used by the test suite exclusively, implemented in
https://gitlab.freedesktop.org/wayland/weston/blob/master/tests/weston-test.c
and
https://gitlab.freedesktop.org/wayland/weston/blob/master/tests/weston-test-client-helper.c
this time using wl_global_create() and wl_registry_bind().


Yet another external example is
https://github.com/raspberrypi/maynard/ which contains its own
additional protocol extensions and both a weston plugin and a
GTK-based helper client. Unfortunately it hasn't been touched in a
few years, so it probably won't work with a recent Weston.

Hope this helps.


Thanks,
pq

Attachment: pgpT776R0dqa3.pgp
Description: OpenPGP digital signature

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to