From a26df747a2a08cefc18a5b321c210fb0256de96f Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Wed, 15 Jul 2020 18:27:11 +0900 Subject: [PATCH] samples: add exampleClient for testing exampleCompositor Change-Id: I08e17d9d09f2b176e5d985b8bd4752151b42460b Signed-off-by: Sung-Jin Park --- meson.build | 4 +-- packaging/libds.spec | 1 + samples/exampleClient.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ samples/meson.build | 11 ++++++- 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 samples/exampleClient.c diff --git a/meson.build b/meson.build index df7137c..1c0ab21 100644 --- a/meson.build +++ b/meson.build @@ -1,9 +1,9 @@ project( 'libds', - 'cpp', + ['c', 'cpp'], version : '0.0.1', license : 'MIT', - default_options : ['cpp_std=c++17'] + default_options : ['c_std=c11', 'cpp_std=c++17'] ) libds_version = meson.project_version().split('.') diff --git a/packaging/libds.spec b/packaging/libds.spec index 9f9e868..cd65568 100644 --- a/packaging/libds.spec +++ b/packaging/libds.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(libtdm) BuildRequires: pkgconfig(wayland-server) +BuildRequires: pkgconfig(wayland-client) BuildRequires: pkgconfig(tizen-extension-server) BuildRequires: pkgconfig(text-server) BuildRequires: pkgconfig(tizen-launch-server) diff --git a/samples/exampleClient.c b/samples/exampleClient.c new file mode 100644 index 0000000..0a9ef50 --- /dev/null +++ b/samples/exampleClient.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include + +struct wl_display *display = NULL; +struct wl_compositor *compositor = NULL; +struct wl_surface *surface; + +static void +global_registry_handler(void *data, struct wl_registry *registry, uint32_t id, + const char *interface, uint32_t version) +{ + printf("Got a registry event for %s id %d\n", interface, id); + + if (strcmp(interface, "wl_compositor") == 0) + { + compositor = wl_registry_bind(registry, id, &wl_compositor_interface, 1); + } +} + +static void +global_registry_remover(void *data, struct wl_registry *registry, uint32_t id) +{ + printf("Got a registry losing event for %d\n", id); +} + +static const struct wl_registry_listener registry_listener = { + global_registry_handler, + global_registry_remover +}; + + +int main(int argc, char **argv) { + + display = wl_display_connect(NULL); + + if (display == NULL) + { + fprintf(stderr, "Can't connect to display\n"); + exit(1); + } + + printf("connected to display\n"); + + struct wl_registry *registry = wl_display_get_registry(display); + wl_registry_add_listener(registry, ®istry_listener, NULL); + + wl_display_dispatch(display); + wl_display_roundtrip(display); + + if (compositor == NULL) + { + fprintf(stderr, "Can't find compositor\n"); + exit(1); + } + else + { + fprintf(stderr, "Found compositor\n"); + } + + surface = wl_compositor_create_surface(compositor); + + if (surface == NULL) + { + fprintf(stderr, "Can't create surface\n"); + exit(1); + } + else + { + fprintf(stderr, "Created surface\n"); + } + + wl_display_disconnect(display); + printf("disconnected from display\n"); + + exit(0); +} + diff --git a/samples/meson.build b/samples/meson.build index 4371026..1101dab 100644 --- a/samples/meson.build +++ b/samples/meson.build @@ -24,4 +24,13 @@ executable('exampleCompositor', dependencies : libds_declared_dep, install_dir : libds_prefix_bindir, install : true - ) \ No newline at end of file + ) + +# exampleClient written for testing exampleCompositor +wayland_client_dep = dependency('wayland-client') +executable('exampleClient', + 'exampleClient.c', + dependencies : [libds_declared_dep, wayland_client_dep], + install_dir : libds_prefix_bindir, + install : true + ) -- 2.7.4