<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Em 19-04-2013 01:52,
      <a class="moz-txt-link-abbreviated" href="mailto:darxus@chaosreigns.com">darxus@chaosreigns.com</a> escreveu:<br>
    </div>
    <blockquote cite="mid:20130419005229.GD27223@chaosreigns.com"
      type="cite">
      <pre wrap="">Might be useful to post the code.</pre>
    </blockquote>
    <br>
    Ok. I'll post it then.<br>
    I'm linking only the wayland libraries. One also needs to use the
    -std=gnu++11 flag.<br>
    <br>
    #include <cstdio>
    <br>
    #include <iostream>
    <br>
    #include <string>
    <br>
    #include <cstring>
    <br>
    #include <wayland-client.h>
    <br>
    #include <wayland-client-protocol.h>
    <br>
    #include <unistd.h>
    <br>
    #include <sys/mman.h>
    <br>
    #include <cstdlib>
    <br>
    #include <cerrno>
    <br>
    #include <fcntl.h>
    <br>
    #include <assert.h>
    <br>
    <br>
    #define SHM_FILENAME    "/tmp/shm.bufferXXXXXX"
    <br>
    #define SHM_SIZE        10*1024*1024
    <br>
    <br>
    using namespace std;
    <br>
    <br>
    struct display_data_s {
    <br>
        struct wl_compositor *compositor;
    <br>
        struct wl_shell     *shell;
    <br>
        struct wl_shm         *shm;
    <br>
        struct wl_seat         *seat;
    <br>
        struct wl_output     *output;
    <br>
    <br>
        struct wl_shm_pool *shm_pool;
    <br>
    } display_data;
    <br>
    <br>
    namespace registry_listeners {
    <br>
        void global(void *data,
    <br>
                       struct wl_registry *registry,
    <br>
                       uint32_t id,
    <br>
                       const char *interface,
    <br>
                       uint32_t version)
    <br>
        {
    <br>
            display_data_s <b class="moz-txt-star"><span
        class="moz-txt-tag">*</span>ddata = (display_data_s<span
        class="moz-txt-tag">*</span></b>)data;
    <br>
            printf("Wayland object reported: %-25s     %d;\n",
    interface, id);
    <br>
    <br>
            if (strcmp(interface, "wl_compositor") == 0) {
    <br>
                ddata->compositor = (struct
    wl_compositor*)wl_registry_bind(registry, id,
    <br>
                             &wl_compositor_interface, 1);
    <br>
            } else if (strcmp(interface, "wl_shell") == 0) {
    <br>
                ddata->shell = (struct
    wl_shell*)wl_registry_bind(registry, id, &wl_shell_interface,
    1);
    <br>
            } else if (strcmp(interface, "wl_seat") == 0) {
    <br>
                ddata->seat = (struct
    wl_seat*)wl_registry_bind(registry, id,
    <br>
                             &wl_seat_interface, 1);
    <br>
                //wl_seat_add_listener(input->wl_seat,
    &seat_listener, input);
    <br>
            } else if (strcmp(interface, "wl_shm") == 0) {
    <br>
                ddata->shm = (struct
    wl_shm*)wl_registry_bind(registry, id,
    <br>
                             &wl_shm_interface, 1);
    <br>
                //wl_shm_add_listener(client->wl_shm,
    &shm_listener, client);
    <br>
            } else if (strcmp(interface, "wl_output") == 0) {
    <br>
                ddata->output = (struct
    wl_output*)wl_registry_bind(registry, id,
    <br>
                             &wl_output_interface, 1);
    <br>
                //wl_output_add_listener(output->wl_output,
    &output_listener, output);
    <br>
            }
    <br>
        }
    <br>
    <br>
        void global_remove(void *data,
    <br>
                          struct wl_registry *wl_registry,
    <br>
                          uint32_t name)
    <br>
        {
    <br>
            return;
    <br>
        }
    <br>
    <br>
    }
    <br>
    <br>
    namespace surface_listeners {
    <br>
        void enter(void *data,
    <br>
                  struct wl_surface *wl_surface,
    <br>
                  struct wl_output *output)
    <br>
        {
    <br>
            cout << "surface enters an output" << endl;
    <br>
        }
    <br>
    <br>
        void leave(void *data,
    <br>
                  struct wl_surface *wl_surface,
    <br>
                  struct wl_output *output)
    <br>
        {
    <br>
            cout << "surface leaves an output" << endl;
    <br>
    <br>
        }
    <br>
    }
    <br>
    <br>
    int main()
    <br>
    {
    <br>
        try {
    <br>
            printf("Hello world!!!!! Example Wayland client...\n");
    <br>
    <br>
            // Connect
    <br>
            struct wl_display *display;
    <br>
            display = wl_display_connect(NULL);
    <br>
            if (!display) throw string("Could not connect to display");
    <br>
            cout << "Connect ok\n" << endl;
    <br>
    <br>
            // Registry... Listing objects
    <br>
            cout << "Listing globals:" << endl;
    <br>
            struct wl_registry *reg = wl_display_get_registry(display);
    <br>
            struct wl_registry_listener reg_listener;
    <br>
            reg_listener.global = registry_listeners::global;
    <br>
            reg_listener.global_remove =
    registry_listeners::global_remove;
    <br>
            wl_registry_add_listener(reg, &reg_listener,
    (void*)&display_data);
    <br>
    <br>
            wl_display_dispatch(display);
    <br>
            wl_display_roundtrip(display);
    <br>
            cout << "End of globals..." << endl <<
    endl;
    <br>
    <br>
            // Create surface
    <br>
            struct wl_surface *surface =
    wl_compositor_create_surface(display_data.compositor);
    <br>
            assert(surface);
    <br>
            struct wl_surface_listener surface_listener;
    <br>
            surface_listener.enter = surface_listeners::enter;
    <br>
            surface_listener.leave = surface_listeners::leave;
    <br>
            wl_surface_add_listener(surface, &surface_listener,
    NULL);
    <br>
            //wl_display_dispatch(display);
    <br>
    <br>
            // Shell surface... later.....
    <br>
            //struct wl_shell_surface *shell_surface;
    <br>
            //shell_surface =
    wl_shell_get_shell_surface(display_data.shell, surface);
    <br>
    <br>
            char shm_filename[] = SHM_FILENAME;
    <br>
            int shmfd = mkostemp(shm_filename, O_CLOEXEC);
    <br>
            if (shmfd == -1) throw (string("could not create shm buffer
    file... errno is ") + to_string(errno));
    <br>
            ftruncate(shmfd, SHM_SIZE);
    <br>
            uint32_t <b class="moz-txt-star"><span class="moz-txt-tag">*</span>buffer
      = (uint32_t<span class="moz-txt-tag">*</span></b>)mmap(NULL,
    SHM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
    <br>
            if (buffer == MAP_FAILED) throw (string("mmap failed...
    errno is ") + to_string(errno));
    <br>
            display_data.shm_pool = wl_shm_create_pool(display_data.shm,
    shmfd, SHM_SIZE);
    <br>
            struct wl_buffer *buffer_wl = (struct
    wl_buffer*)wl_shm_pool_create_buffer(display_data.shm_pool, 0,
    <br>
                                     100, 200,    // Largura, Altura
    <br>
                                     100*4 /<b class="moz-txt-star"><span
        class="moz-txt-tag">*</span>stride<span class="moz-txt-tag">*</span></b>/,
    WL_SHM_FORMAT_ARGB8888 /<b class="moz-txt-star"><span
        class="moz-txt-tag">*</span>format<span class="moz-txt-tag">*</span></b>/);
    <br>
            wl_display_dispatch(display);
    <br>
    <br>
            for (int i=0; i<100*200; ++i) {
    <br>
                buffer[i] = 0x40404040;
    <br>
            }
    <br>
    <br>
            wl_surface_attach(surface, buffer_wl, 0, 0);
    <br>
    <br>
            wl_surface_damage(surface, 0, 0, 100, 200);
    <br>
            wl_surface_commit(surface);
    <br>
    <br>
            for(;;);
    <br>
    <br>
            // Terminate connection
    <br>
            wl_display_disconnect(display);
    <br>
    <br>
            return 0;
    <br>
        }
    <br>
        catch(string &errstr) {
    <br>
            cout << "FATAL: " << errstr << endl;
    <br>
        }
    <br>
    }
    <br>
    <br>
    <br>
    João Jerónimo
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <blockquote cite="mid:20130419005229.GD27223@chaosreigns.com"
      type="cite">
      <pre wrap="">

On 04/19, João Jerónimo wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">Hello.

I was trying to understand what is the minimal code needed to get a
square painter on the screen. However, although I can make the
client talk to the Weston compositor, enumerate the global objects,
etc, I can't still see my surface drawn in the compositor scene.

The steps that my program makes so far are as follows:
 - call wl_display_connect(NULL)
 - call wl_display_get_registry(display)
 - Install listeners for the registry that wl_registry_bind() many
of the advertised objects. However, I'm not listening to the events
of the objects advertised by the registry. Is it needed?
 - call wl_display_dispatch()  and wl_display_roundtrip()
 - call wl_compositor_create_surface()
 - mkostemp() a file and ftruncate() it to some 10MB or so
 - mmap() the entire file created
 - call wl_shm_create_pool()
 - call wl_shm_pool_create_buffer()
 - call wl_display_dispatch()
 - Fill the buffer with some content. I filled it entirely with
pattern 0x40404040.
 - call wl_surface_attach(surface, buffer, 0, 0)
 - Then the program just sits in an infinite loop...

Am I missing anything?

Sorry for my poor English (assuming that you think it's poor)....
João Jerónimo

_______________________________________________
wayland-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a>

</pre>
      </blockquote>
      <pre wrap="">
</pre>
    </blockquote>
    <br>
  </body>
</html>