Wrap xdg in IVI shell

Stuvart S lovelinuxdeeply at gmail.com
Wed Feb 21 04:30:19 UTC 2018


Hi team,

I wrote a user app which is capable of displaying a surface. It works
perfectly on xdg shell ,but when switching to ivi shell it doesn,t. I could
know that there are differences in protocols,thats why it happens and there
is one way that we can wrap xdg in ivi shell.But I am not aware of doing
that.

Following are the code snipet that works for me in xdg..(tested in
raspberry pi )
Does anybody have any clue ? Any help is appreciated..
Thanks in advance.


#include <stdio.h>
#include <string.h>

#include <syscall.h>
#include <unistd.h>
#include <sys/mman.h>

#include <wayland-client.h>
#include <wayland-client-core.h>


struct wl_compositor *compositor;
struct wl_shm *shm;
struct wl_shell *shell;

void registry_global_handler
(
    void *data,
    struct wl_registry *registry,
    uint32_t name,
    const char *interface,
    uint32_t version
) {
    if (strcmp(interface, "wl_compositor") == 0) {
        compositor = wl_registry_bind(registry, name,
            &wl_compositor_interface, 3);
    } else if (strcmp(interface, "wl_shm") == 0) {
        shm = wl_registry_bind(registry, name,
            &wl_shm_interface, 1);
    } else if (strcmp(interface, "wl_shell") == 0) {
        shell = wl_registry_bind(registry, name,
            &wl_shell_interface, 1);
    }
}

void registry_global_remove_handler
(
    void *data,
    struct wl_registry *registry,
    uint32_t name
) {}

const struct wl_registry_listener registry_listener = {
    .global = registry_global_handler,
    .global_remove = registry_global_remove_handler
};

int main(void)
{
    struct wl_display *display = wl_display_connect(NULL);
    struct wl_registry *registry = wl_display_get_registry(display);
    wl_registry_add_listener(registry, &registry_listener, NULL);

    // wait for the "initial" set of globals to appear
    wl_display_roundtrip(display);

    struct wl_surface *surface = wl_compositor_create_surface(compositor);
    struct wl_shell_surface *shell_surface =
wl_shell_get_shell_surface(shell, surface);
    wl_shell_surface_set_toplevel(shell_surface);

    int width = 108;
    int height = 192;
    int stride = width * 4;
    int size = stride * height;  // bytes

    // open an anonymous file and write some zero bytes to it
    int fd = syscall(SYS_memfd_create, "buffer", 0);
    ftruncate(fd, size);

    // map it to the memory
    unsigned char *data = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
   int temp=0;

struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);

    // allocate the buffer in that pool
    struct wl_buffer *buffer = wl_shm_pool_create_buffer(pool,
        0, width, height, stride, WL_SHM_FORMAT_ARGB8888);

    wl_surface_attach(surface, buffer, 0, 0);



while(1){
printf("%d\n",temp);
temp++;
for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {

        struct pixel {
            // little-endian ARGB
            unsigned char blue;
            unsigned char green;
            unsigned char red;
            unsigned char alpha;
        } *px = (struct pixel *) (data + y * stride + x * 4);

        // yellow
        px->alpha = 255;
                  if(temp >100)
    {
     px->red = 100;
        px->green = 0;
         px->blue = 0;

    }
    else
    {

        px->red = 0;
        px->green = 100;
        px->blue = 0;
        //if(y==(height/2))
        //break;
        }
    }
}


usleep(50*1000);
    // turn it into a shared memory pool
 wl_surface_commit(surface);
     wl_display_flush(display);
/* wl_display_destroy(display);*/



    }
}

Cheers,
Stuvart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20180221/b3398bc5/attachment-0001.html>


More information about the wayland-devel mailing list