aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-04-02 15:57:04 -0400
committeremersion <contact@emersion.fr>2018-04-02 15:57:04 -0400
commit8836b4f024f957971cae28a0fdc567ff16c8fbc8 (patch)
tree23be1fc669c4fc721a521691ce182041cc7c5237 /examples
parentcadfccf1fde164646b175401a3fb1d3108b4af9a (diff)
parentd466cc117f95d34e239049a5af701b7ba696d336 (diff)
Merge branch 'master' into xwayland-dnd
Diffstat (limited to 'examples')
-rw-r--r--examples/layer-shell.c430
-rw-r--r--examples/meson.build7
-rw-r--r--examples/multi-pointer.c5
-rw-r--r--examples/output-layout.c9
-rw-r--r--examples/pointer.c20
-rw-r--r--examples/rotation.c9
-rw-r--r--examples/support/shared.c12
-rw-r--r--examples/support/shared.h8
-rw-r--r--examples/tablet.c30
-rw-r--r--examples/touch.c32
10 files changed, 504 insertions, 58 deletions
diff --git a/examples/layer-shell.c b/examples/layer-shell.c
new file mode 100644
index 00000000..f084d10f
--- /dev/null
+++ b/examples/layer-shell.c
@@ -0,0 +1,430 @@
+#define _POSIX_C_SOURCE 199309L
+#include <assert.h>
+#include <GLES2/gl2.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <wayland-client.h>
+#include <wayland-cursor.h>
+#include <wayland-egl.h>
+#include <wlr/render/egl.h>
+#include <wlr/util/log.h>
+#include "wlr-layer-shell-unstable-v1-client-protocol.h"
+
+static struct wl_compositor *compositor = NULL;
+static struct wl_seat *seat = NULL;
+static struct wl_shm *shm = NULL;
+static struct wl_pointer *pointer = NULL;
+//static struct wl_keyboard *keyboard = NULL;
+static struct zwlr_layer_shell_v1 *layer_shell = NULL;
+struct zwlr_layer_surface_v1 *layer_surface;
+static struct wl_output *wl_output = NULL;
+
+struct wl_surface *wl_surface;
+struct wlr_egl egl;
+struct wl_egl_window *egl_window;
+struct wlr_egl_surface *egl_surface;
+struct wl_callback *frame_callback;
+
+static uint32_t output = 0;
+static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
+static uint32_t anchor = 0;
+static uint32_t width = 256, height = 256;
+static int32_t margin_top = 0;
+static double alpha = 1.0;
+static bool run_display = true;
+static bool animate = false;
+static double frame = 0;
+static int cur_x = -1, cur_y = -1;
+static int buttons = 0;
+
+struct wl_cursor_theme *cursor_theme;
+struct wl_cursor_image *cursor_image;
+struct wl_surface *cursor_surface;
+
+static struct {
+ struct timespec last_frame;
+ float color[3];
+ int dec;
+} demo;
+
+static void draw(void);
+
+static void surface_frame_callback(
+ void *data, struct wl_callback *cb, uint32_t time) {
+ wl_callback_destroy(cb);
+ frame_callback = NULL;
+ draw();
+}
+
+static struct wl_callback_listener frame_listener = {
+ .done = surface_frame_callback
+};
+
+static void draw(void) {
+ eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context);
+
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+
+ long ms = (ts.tv_sec - demo.last_frame.tv_sec) * 1000 +
+ (ts.tv_nsec - demo.last_frame.tv_nsec) / 1000000;
+ int inc = (demo.dec + 1) % 3;
+
+ if (!buttons) {
+ demo.color[inc] += ms / 2000.0f;
+ demo.color[demo.dec] -= ms / 2000.0f;
+
+ if (demo.color[demo.dec] < 0.0f) {
+ demo.color[inc] = 1.0f;
+ demo.color[demo.dec] = 0.0f;
+ demo.dec = inc;
+ }
+ }
+
+ if (animate) {
+ frame += ms / 50.0;
+ int32_t old_top = margin_top;
+ margin_top = -(20 - ((int)frame % 20));
+ if (old_top != margin_top) {
+ zwlr_layer_surface_v1_set_margin(layer_surface,
+ margin_top, 0, 0, 0);
+ wl_surface_commit(wl_surface);
+ }
+ }
+
+ glViewport(0, 0, width, height);
+ if (buttons) {
+ glClearColor(1, 1, 1, alpha);
+ } else {
+ glClearColor(demo.color[0], demo.color[1], demo.color[2], alpha);
+ }
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (cur_x != -1 && cur_y != -1) {
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(cur_x, height - cur_y, 5, 5);
+ glClearColor(0, 0, 0, 1);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glDisable(GL_SCISSOR_TEST);
+ }
+
+ frame_callback = wl_surface_frame(wl_surface);
+ wl_callback_add_listener(frame_callback, &frame_listener, NULL);
+
+ eglSwapBuffers(egl.display, egl_surface);
+
+ demo.last_frame = ts;
+}
+
+static void layer_surface_configure(void *data,
+ struct zwlr_layer_surface_v1 *surface,
+ uint32_t serial, uint32_t w, uint32_t h) {
+ width = w;
+ height = h;
+ if (egl_window) {
+ wl_egl_window_resize(egl_window, width, height, 0, 0);
+ }
+ zwlr_layer_surface_v1_ack_configure(surface, serial);
+}
+
+static void layer_surface_closed(void *data,
+ struct zwlr_layer_surface_v1 *surface) {
+ eglDestroySurface(egl.display, egl_surface);
+ wl_egl_window_destroy(egl_window);
+ zwlr_layer_surface_v1_destroy(surface);
+ wl_surface_destroy(wl_surface);
+ run_display = false;
+}
+
+struct zwlr_layer_surface_v1_listener layer_surface_listener = {
+ .configure = layer_surface_configure,
+ .closed = layer_surface_closed,
+};
+
+static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
+ uint32_t serial, struct wl_surface *surface,
+ wl_fixed_t surface_x, wl_fixed_t surface_y) {
+ wl_surface_attach(cursor_surface,
+ wl_cursor_image_get_buffer(cursor_image), 0, 0);
+ wl_pointer_set_cursor(wl_pointer, serial, cursor_surface,
+ cursor_image->hotspot_x, cursor_image->hotspot_y);
+ wl_surface_commit(cursor_surface);
+}
+
+static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
+ uint32_t serial, struct wl_surface *surface) {
+ cur_x = cur_y = -1;
+ buttons = 0;
+}
+
+static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
+ uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
+ cur_x = wl_fixed_to_int(surface_x);
+ cur_y = wl_fixed_to_int(surface_y);
+}
+
+static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
+ uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
+ if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
+ buttons++;
+ } else {
+ buttons--;
+ }
+}
+
+static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
+ uint32_t time, uint32_t axis, wl_fixed_t value) {
+ // Who cares
+}
+
+static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) {
+ // Who cares
+}
+
+static void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer,
+ uint32_t axis_source) {
+ // Who cares
+}
+
+static void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer,
+ uint32_t time, uint32_t axis) {
+ // Who cares
+}
+
+static void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
+ uint32_t axis, int32_t discrete) {
+ // Who cares
+}
+
+struct wl_pointer_listener pointer_listener = {
+ .enter = wl_pointer_enter,
+ .leave = wl_pointer_leave,
+ .motion = wl_pointer_motion,
+ .button = wl_pointer_button,
+ .axis = wl_pointer_axis,
+ .frame = wl_pointer_frame,
+ .axis_source = wl_pointer_axis_source,
+ .axis_stop = wl_pointer_axis_stop,
+ .axis_discrete = wl_pointer_axis_discrete,
+};
+
+static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
+ enum wl_seat_capability caps) {
+ if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
+ pointer = wl_seat_get_pointer(wl_seat);
+ wl_pointer_add_listener(pointer, &pointer_listener, NULL);
+ }
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
+ // TODO
+ }
+}
+
+static void seat_handle_name(void *data, struct wl_seat *wl_seat,
+ const char *name) {
+ // Who cares
+}
+
+const struct wl_seat_listener seat_listener = {
+ .capabilities = seat_handle_capabilities,
+ .name = seat_handle_name,
+};
+
+static void handle_global(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, 1);
+ } else if (strcmp(interface, wl_shm_interface.name) == 0) {
+ shm = wl_registry_bind(registry, name,
+ &wl_shm_interface, 1);
+ } else if (strcmp(interface, "wl_output") == 0) {
+ if (output == 0 && !wl_output) {
+ wl_output = wl_registry_bind(registry, name,
+ &wl_output_interface, 1);
+ } else {
+ output--;
+ }
+ } else if (strcmp(interface, wl_seat_interface.name) == 0) {
+ seat = wl_registry_bind(registry, name,
+ &wl_seat_interface, 1);
+ wl_seat_add_listener(seat, &seat_listener, NULL);
+ } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
+ layer_shell = wl_registry_bind(
+ registry, name, &zwlr_layer_shell_v1_interface, 1);
+ }
+}
+
+static void handle_global_remove(void *data, struct wl_registry *registry,
+ uint32_t name) {
+ // who cares
+}
+
+static const struct wl_registry_listener registry_listener = {
+ .global = handle_global,
+ .global_remove = handle_global_remove,
+};
+
+int main(int argc, char **argv) {
+ wlr_log_init(L_DEBUG, NULL);
+ char *namespace = "wlroots";
+ int exclusive_zone = 0;
+ int32_t margin_right = 0, margin_bottom = 0, margin_left = 0;
+ bool found;
+ int c;
+ while ((c = getopt(argc, argv, "nw:h:o:l:a:x:m:t:")) != -1) {
+ switch (c) {
+ case 'o':
+ output = atoi(optarg);
+ break;
+ case 'w':
+ width = atoi(optarg);
+ break;
+ case 'h':
+ height = atoi(optarg);
+ break;
+ case 'x':
+ exclusive_zone = atoi(optarg);
+ break;
+ case 'l': {
+ struct {
+ char *name;
+ enum zwlr_layer_shell_v1_layer value;
+ } layers[] = {
+ { "background", ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND },
+ { "bottom", ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM },
+ { "top", ZWLR_LAYER_SHELL_V1_LAYER_TOP },
+ { "overlay", ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY },
+ };
+ found = false;
+ for (size_t i = 0; i < sizeof(layers) / sizeof(layers[0]); ++i) {
+ if (strcmp(optarg, layers[i].name) == 0) {
+ layer = layers[i].value;
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ fprintf(stderr, "invalid layer %s\n", optarg);
+ return 1;
+ }
+ break;
+ }
+ case 'a': {
+ struct {
+ char *name;
+ uint32_t value;
+ } anchors[] = {
+ { "top", ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP },
+ { "bottom", ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM },
+ { "left", ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT },
+ { "right", ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT },
+ };
+ found = false;
+ for (size_t i = 0; i < sizeof(anchors) / sizeof(anchors[0]); ++i) {
+ if (strcmp(optarg, anchors[i].name) == 0) {
+ anchor |= anchors[i].value;
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ fprintf(stderr, "invalid anchor %s\n", optarg);
+ return 1;
+ }
+ break;
+ }
+ case 't':
+ alpha = atof(optarg);
+ break;
+ case 'm': {
+ char *endptr = optarg;
+ margin_top = strtol(endptr, &endptr, 10);
+ assert(*endptr == ',');
+ margin_right = strtol(endptr + 1, &endptr, 10);
+ assert(*endptr == ',');
+ margin_bottom = strtol(endptr + 1, &endptr, 10);
+ assert(*endptr == ',');
+ margin_left = strtol(endptr + 1, &endptr, 10);
+ assert(!*endptr);
+ break;
+ }
+ case 'n':
+ animate = true;
+ break;
+ default:
+ break;
+ }
+ }
+
+ struct wl_display *display = wl_display_connect(NULL);
+ if (display == NULL) {
+ fprintf(stderr, "Failed to create display\n");
+ return 1;
+ }
+
+ struct wl_registry *registry = wl_display_get_registry(display);
+ wl_registry_add_listener(registry, &registry_listener, NULL);
+ wl_display_roundtrip(display);
+
+ if (compositor == NULL) {
+ fprintf(stderr, "wl_compositor not available\n");
+ return 1;
+ }
+ if (shm == NULL) {
+ fprintf(stderr, "wl_shm not available\n");
+ return 1;
+ }
+ if (layer_shell == NULL) {
+ fprintf(stderr, "layer_shell not available\n");
+ return 1;
+ }
+ if (wl_output == NULL) {
+ fprintf(stderr, "wl_output not available\n");
+ return 1;
+ }
+
+ assert(cursor_theme = wl_cursor_theme_load(NULL, 16, shm));
+ struct wl_cursor *cursor;
+ assert(cursor = wl_cursor_theme_get_cursor(cursor_theme, "crosshair"));
+ cursor_image = cursor->images[0];
+ assert(cursor_surface = wl_compositor_create_surface(compositor));
+
+ EGLint attribs[] = { EGL_ALPHA_SIZE, 8, EGL_NONE };
+ wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display,
+ attribs, WL_SHM_FORMAT_ARGB8888);
+
+ wl_surface = wl_compositor_create_surface(compositor);
+ assert(wl_surface);
+
+ layer_surface = zwlr_layer_shell_v1_get_layer_surface(layer_shell,
+ wl_surface, wl_output, layer, namespace);
+ assert(layer_surface);
+ zwlr_layer_surface_v1_set_size(layer_surface, width, height);
+ zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
+ zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, exclusive_zone);
+ zwlr_layer_surface_v1_set_margin(layer_surface,
+ margin_top, margin_right, margin_bottom, margin_left);
+ zwlr_layer_surface_v1_add_listener(layer_surface,
+ &layer_surface_listener, layer_surface);
+ // TODO: interactivity
+ wl_surface_commit(wl_surface);
+ wl_display_roundtrip(display);
+
+ egl_window = wl_egl_window_create(wl_surface, width, height);
+ assert(egl_window);
+ egl_surface = wlr_egl_create_surface(&egl, egl_window);
+ assert(egl_surface);
+
+ wl_display_roundtrip(display);
+ draw();
+
+ while (wl_display_dispatch(display) != -1 && run_display) {
+ // This space intentionally left blank
+ }
+
+ wl_cursor_theme_destroy(cursor_theme);
+ return 0;
+}
diff --git a/examples/meson.build b/examples/meson.build
index a83def8f..9e60c37a 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -6,6 +6,7 @@ lib_shared = static_library(
)
threads = dependency('threads')
+wayland_cursor = dependency('wayland-cursor')
executable('simple', 'simple.c', dependencies: wlroots, link_with: lib_shared)
executable('pointer', 'pointer.c', dependencies: wlroots, link_with: lib_shared)
@@ -48,3 +49,9 @@ executable(
dependencies: [wayland_client, wlr_protos, wlroots, threads],
link_with: lib_shared,
)
+
+executable(
+ 'layer-shell',
+ 'layer-shell.c',
+ dependencies: [wayland_cursor, wayland_client, wlr_protos, wlroots]
+)
diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c
index 43ccdb66..46f0e78f 100644
--- a/examples/multi-pointer.c
+++ b/examples/multi-pointer.c
@@ -118,8 +118,7 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
struct sample_cursor *cursor =
wl_container_of(listener, cursor, cursor_motion_absolute);
struct wlr_event_pointer_motion_absolute *event = data;
- wlr_cursor_warp_absolute(cursor->cursor, event->device,
- event->x_mm / event->width_mm, event->y_mm / event->height_mm);
+ wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
}
static void handle_input_add(struct compositor_state *state,
@@ -149,7 +148,7 @@ static void handle_input_add(struct compositor_state *state,
sample->compositor);
struct wlr_xcursor_image *image = sample->xcursor->images[0];
- wlr_cursor_set_image(cursor->cursor, image->buffer, image->width,
+ wlr_cursor_set_image(cursor->cursor, image->buffer, image->width * 4,
image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
wl_list_insert(&sample->cursors, &cursor->link);
diff --git a/examples/output-layout.c b/examples/output-layout.c
index 45d896b0..b04e86b7 100644
--- a/examples/output-layout.c
+++ b/examples/output-layout.c
@@ -13,7 +13,6 @@
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
-#include <wlr/render/gles2.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h>
@@ -196,10 +195,10 @@ int main(int argc, char *argv[]) {
compositor.keyboard_key_cb = handle_keyboard_key;
compositor_init(&compositor);
- state.renderer = wlr_gles2_renderer_create(compositor.backend);
- state.cat_texture = wlr_render_texture_create(state.renderer);
- wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888,
- cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
+ state.renderer = wlr_backend_get_renderer(compositor.backend);
+ state.cat_texture = wlr_texture_from_pixels(state.renderer,
+ WL_SHM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
+ cat_tex.pixel_data);
if (!wlr_backend_start(compositor.backend)) {
wlr_log(L_ERROR, "Failed to start backend");
diff --git a/examples/pointer.c b/examples/pointer.c
index e8a0e892..aaaad841 100644
--- a/examples/pointer.c
+++ b/examples/pointer.c
@@ -112,7 +112,7 @@ static void handle_output_add(struct output_state *ostate) {
sample->compositor);
struct wlr_xcursor_image *image = sample->xcursor->images[0];
- wlr_cursor_set_image(sample->cursor, image->buffer, image->width,
+ wlr_cursor_set_image(sample->cursor, image->buffer, image->width * 4,
image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y);
@@ -154,8 +154,8 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
wl_container_of(listener, sample, cursor_motion_absolute);
struct wlr_event_pointer_motion_absolute *event = data;
- sample->cur_x = event->x_mm;
- sample->cur_y = event->y_mm;
+ sample->cur_x = event->x;
+ sample->cur_y = event->y;
wlr_cursor_warp_absolute(sample->cursor, event->device, sample->cur_x,
sample->cur_y);
@@ -217,8 +217,8 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
struct wlr_event_touch_down *event = data;
struct touch_point *point = calloc(1, sizeof(struct touch_point));
point->touch_id = event->touch_id;
- point->x = event->x_mm / event->width_mm;
- point->y = event->y_mm / event->height_mm;
+ point->x = event->x;
+ point->y = event->y;
wl_list_insert(&sample->touch_points, &point->link);
warp_to_touch(sample, event->device);
@@ -232,8 +232,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
struct touch_point *point;
wl_list_for_each(point, &sample->touch_points, link) {
if (point->touch_id == event->touch_id) {
- point->x = event->x_mm / event->width_mm;
- point->y = event->y_mm / event->height_mm;
+ point->x = event->x;
+ point->y = event->y;
break;
}
}
@@ -251,8 +251,8 @@ static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) {
struct wlr_event_tablet_tool_axis *event = data;
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
- wlr_cursor_warp_absolute(sample->cursor, event->device,
- event->x_mm / event->width_mm, event->y_mm / event->height_mm);
+ wlr_cursor_warp_absolute(sample->cursor,
+ event->device, event->x, event->y);
}
}
@@ -324,7 +324,7 @@ int main(int argc, char *argv[]) {
}
struct wlr_xcursor_image *image = state.xcursor->images[0];
- wlr_cursor_set_image(state.cursor, image->buffer, image->width,
+ wlr_cursor_set_image(state.cursor, image->buffer, image->width * 4,
image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
compositor_init(&compositor);
diff --git a/examples/rotation.c b/examples/rotation.c
index cbff09a1..c7bbc99a 100644
--- a/examples/rotation.c
+++ b/examples/rotation.c
@@ -13,7 +13,6 @@
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/wlr_renderer.h>
-#include <wlr/render/gles2.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/util/log.h>
@@ -137,18 +136,18 @@ int main(int argc, char *argv[]) {
compositor.keyboard_key_cb = handle_keyboard_key;
compositor_init(&compositor);
- state.renderer = wlr_gles2_renderer_create(compositor.backend);
+ state.renderer = wlr_backend_get_renderer(compositor.backend);
if (!state.renderer) {
wlr_log(L_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
}
- state.cat_texture = wlr_render_texture_create(state.renderer);
+ state.cat_texture = wlr_texture_from_pixels(state.renderer,
+ WL_SHM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
+ cat_tex.pixel_data);
if (!state.cat_texture) {
wlr_log(L_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
}
- wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888,
- cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
if (!wlr_backend_start(compositor.backend)) {
wlr_log(L_ERROR, "Failed to start backend");
diff --git a/examples/support/shared.c b/examples/support/shared.c
index e6233206..02b324f5 100644
--- a/examples/support/shared.c
+++ b/examples/support/shared.c
@@ -108,8 +108,8 @@ static void pointer_motion_absolute_notify(struct wl_listener *listener, void *d
struct wlr_event_pointer_motion_absolute *event = data;
struct pointer_state *pstate = wl_container_of(listener, pstate, motion_absolute);
if (pstate->compositor->pointer_motion_absolute_cb) {
- pstate->compositor->pointer_motion_absolute_cb(pstate,
- event->x_mm, event->y_mm);
+ pstate->compositor->pointer_motion_absolute_cb(
+ pstate, event->x, event->y);
}
}
@@ -167,8 +167,8 @@ static void touch_down_notify(struct wl_listener *listener, void *data) {
struct wlr_event_touch_down *event = data;
struct touch_state *tstate = wl_container_of(listener, tstate, down);
if (tstate->compositor->touch_down_cb) {
- tstate->compositor->touch_down_cb(tstate, event->touch_id,
- event->x_mm, event->y_mm, event->width_mm, event->height_mm);
+ tstate->compositor->touch_down_cb(tstate,
+ event->touch_id, event->x, event->y);
}
}
@@ -176,8 +176,8 @@ static void touch_motion_notify(struct wl_listener *listener, void *data) {
struct wlr_event_touch_motion *event = data;
struct touch_state *tstate = wl_container_of(listener, tstate, motion);
if (tstate->compositor->touch_motion_cb) {
- tstate->compositor->touch_motion_cb(tstate, event->touch_id,
- event->x_mm, event->y_mm, event->width_mm, event->height_mm);
+ tstate->compositor->touch_motion_cb(tstate,
+ event->touch_id, event->x, event->y);
}
}
diff --git a/examples/support/shared.h b/examples/support/shared.h
index d00e75b3..2079a9ef 100644
--- a/examples/support/shared.h
+++ b/examples/support/shared.h
@@ -102,10 +102,10 @@ struct compositor_state {
enum wlr_axis_source source,
enum wlr_axis_orientation orientation,
double delta);
- void (*touch_down_cb)(struct touch_state *s, int32_t touch_id,
- double x, double y, double width, double height);
- void (*touch_motion_cb)(struct touch_state *s, int32_t touch_id,
- double x, double y, double width, double height);
+ void (*touch_down_cb)(struct touch_state *s,
+ int32_t touch_id, double x, double y);
+ void (*touch_motion_cb)(struct touch_state *s,
+ int32_t touch_id, double x, double y);
void (*touch_up_cb)(struct touch_state *s, int32_t touch_id);
void (*touch_cancel_cb)(struct touch_state *s, int32_t touch_id);
void (*tool_axis_cb)(struct tablet_tool_state *s,
diff --git a/examples/tablet.c b/examples/tablet.c
index 9379fac3..ca9d782c 100644
--- a/examples/tablet.c
+++ b/examples/tablet.c
@@ -11,7 +11,6 @@
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
-#include <wlr/render/gles2.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_matrix.h>
@@ -28,7 +27,7 @@ struct sample_state {
bool proximity, tap, button;
double distance;
double pressure;
- double x_mm, y_mm;
+ double x, y;
double x_tilt, y_tilt;
double width_mm, height_mm;
double ring;
@@ -69,8 +68,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
if (sample->proximity) {
struct wlr_box box = {
- .x = sample->x_mm * scale - 8 * (sample->pressure + 1) + left,
- .y = sample->y_mm * scale - 8 * (sample->pressure + 1) + top,
+ .x = (sample->x * pad_width) - 8 * (sample->pressure + 1) + left,
+ .y = (sample->y * pad_height) - 8 * (sample->pressure + 1) + top,
.width = 16 * (sample->pressure + 1),
.height = 16 * (sample->pressure + 1),
};
@@ -94,13 +93,11 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
static void handle_tool_axis(struct tablet_tool_state *tstate,
struct wlr_event_tablet_tool_axis *event) {
struct sample_state *sample = tstate->compositor->data;
- sample->width_mm = event->width_mm;
- sample->height_mm = event->height_mm;
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
- sample->x_mm = event->x_mm;
+ sample->x = event->x;
}
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
- sample->y_mm = event->y_mm;
+ sample->y = event->y;
}
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE)) {
sample->distance = event->distance;
@@ -164,13 +161,24 @@ static void handle_pad_ring(struct tablet_pad_state *pstate,
}
}
+static void handle_input_add(struct compositor_state *cstate,
+ struct wlr_input_device *inputdev) {
+ struct sample_state *sample = cstate->data;
+ if (inputdev->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
+ sample->width_mm = inputdev->width_mm == 0 ?
+ 20 : inputdev->width_mm;
+ sample->height_mm = inputdev->height_mm == 0 ?
+ 10 : inputdev->height_mm;
+ }
+}
+
int main(int argc, char *argv[]) {
wlr_log_init(L_DEBUG, NULL);
struct sample_state state = {
.tool_color = { 1, 1, 1, 1 },
.pad_color = { 0.5, 0.5, 0.5, 1.0 }
};
- struct compositor_state compositor = { 0,
+ struct compositor_state compositor = {
.data = &state,
.output_frame_cb = handle_output_frame,
.tool_axis_cb = handle_tool_axis,
@@ -178,10 +186,12 @@ int main(int argc, char *argv[]) {
.tool_button_cb = handle_tool_button,
.pad_button_cb = handle_pad_button,
.pad_ring_cb = handle_pad_ring,
+ .input_add_cb = handle_input_add,
+ 0
};
compositor_init(&compositor);
- state.renderer = wlr_gles2_renderer_create(compositor.backend);
+ state.renderer = wlr_backend_get_renderer(compositor.backend);
if (!state.renderer) {
wlr_log(L_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
diff --git a/examples/touch.c b/examples/touch.c
index f9c496cf..949d209d 100644
--- a/examples/touch.c
+++ b/examples/touch.c
@@ -12,7 +12,6 @@
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
-#include <wlr/render/gles2.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_list.h>
#include <wlr/types/wlr_matrix.h>
@@ -45,10 +44,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
+ int tex_width, tex_height;
+ wlr_texture_get_size(sample->cat_texture, &tex_width, &tex_height);
+
struct touch_point *p;
wl_list_for_each(p, &sample->touch_points, link) {
- int x = (int)(p->x * width) - sample->cat_texture->width / 2;
- int y = (int)(p->y * height) - sample->cat_texture->height / 2;
+ int x = (int)(p->x * width) - tex_width / 2;
+ int y = (int)(p->y * height) - tex_height / 2;
wlr_render_texture(sample->renderer, sample->cat_texture,
wlr_output->transform_matrix, x, y, 1.0f);
}
@@ -57,13 +59,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
wlr_output_swap_buffers(wlr_output, NULL, NULL);
}
-static void handle_touch_down(struct touch_state *tstate, int32_t touch_id,
- double x, double y, double width, double height) {
+static void handle_touch_down(struct touch_state *tstate,
+ int32_t touch_id, double x, double y) {
struct sample_state *sample = tstate->compositor->data;
struct touch_point *point = calloc(1, sizeof(struct touch_point));
point->touch_id = touch_id;
- point->x = x / width;
- point->y = y / height;
+ point->x = x;
+ point->y = y;
wl_list_insert(&sample->touch_points, &point->link);
}
@@ -78,14 +80,14 @@ static void handle_touch_up(struct touch_state *tstate, int32_t touch_id) {
}
}
-static void handle_touch_motion(struct touch_state *tstate, int32_t touch_id,
- double x, double y, double width, double height) {
+static void handle_touch_motion(struct touch_state *tstate,
+ int32_t touch_id, double x, double y) {
struct sample_state *sample = tstate->compositor->data;
struct touch_point *point;
wl_list_for_each(point, &sample->touch_points, link) {
if (point->touch_id == touch_id) {
- point->x = x / width;
- point->y = y / height;
+ point->x = x;
+ point->y = y;
break;
}
}
@@ -105,18 +107,18 @@ int main(int argc, char *argv[]) {
};
compositor_init(&compositor);
- state.renderer = wlr_gles2_renderer_create(compositor.backend);
+ state.renderer = wlr_backend_get_renderer(compositor.backend);
if (!state.renderer) {
wlr_log(L_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
}
- state.cat_texture = wlr_render_texture_create(state.renderer);
+ state.cat_texture = wlr_texture_from_pixels(state.renderer,
+ WL_SHM_FORMAT_ARGB8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
+ cat_tex.pixel_data);
if (!state.cat_texture) {
wlr_log(L_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
}
- wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ARGB8888,
- cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
if (!wlr_backend_start(compositor.backend)) {
wlr_log(L_ERROR, "Failed to start backend");