aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-03-07 20:57:55 -0500
committerDrew DeVault <sir@cmpwn.com>2018-03-07 20:57:55 -0500
commitbfc0e95d2cfeab96d771cb34e78ca92afee4464c (patch)
treea5f5d132cba797f8f169781a482e9e995df14332 /examples
parent36dcad13d09d63bd321958ed79d479687479f852 (diff)
Add mode support to libinput backend
And extend tablet example with tilt and ring support
Diffstat (limited to 'examples')
-rw-r--r--examples/support/shared.c10
-rw-r--r--examples/support/shared.h3
-rw-r--r--examples/tablet.c59
3 files changed, 56 insertions, 16 deletions
diff --git a/examples/support/shared.c b/examples/support/shared.c
index c4f9288d..e6233206 100644
--- a/examples/support/shared.c
+++ b/examples/support/shared.c
@@ -294,6 +294,14 @@ static void tablet_pad_button_notify(struct wl_listener *listener, void *data) {
}
}
+static void tablet_pad_ring_notify(struct wl_listener *listener, void *data) {
+ struct wlr_event_tablet_pad_ring *event = data;
+ struct tablet_pad_state *pstate = wl_container_of(listener, pstate, ring);
+ if (pstate->compositor->pad_ring_cb) {
+ pstate->compositor->pad_ring_cb(pstate, event->ring, event->position);
+ }
+}
+
static void tablet_pad_destroy_notify(struct wl_listener *listener, void *data) {
struct tablet_pad_state *pstate = wl_container_of(listener, pstate, destroy);
struct compositor_state *state = pstate->compositor;
@@ -315,6 +323,8 @@ static void tablet_pad_add(struct wlr_input_device *device,
wl_signal_add(&device->events.destroy, &pstate->destroy);
pstate->button.notify = tablet_pad_button_notify;
wl_signal_add(&device->tablet_pad->events.button, &pstate->button);
+ pstate->ring.notify = tablet_pad_ring_notify;
+ wl_signal_add(&device->tablet_pad->events.ring, &pstate->ring);
wl_list_insert(&state->tablet_pads, &pstate->link);
}
diff --git a/examples/support/shared.h b/examples/support/shared.h
index 8cdea301..d00e75b3 100644
--- a/examples/support/shared.h
+++ b/examples/support/shared.h
@@ -73,6 +73,7 @@ struct tablet_pad_state {
struct wlr_input_device *device;
struct wl_listener destroy;
struct wl_listener button;
+ struct wl_listener ring;
struct wl_list link;
void *data;
};
@@ -117,6 +118,8 @@ struct compositor_state {
uint32_t button, enum wlr_button_state state);
void (*pad_button_cb)(struct tablet_pad_state *s,
uint32_t button, enum wlr_button_state state);
+ void (*pad_ring_cb)(struct tablet_pad_state *s,
+ uint32_t ring, double position);
struct wl_display *display;
struct wl_event_loop *event_loop;
diff --git a/examples/tablet.c b/examples/tablet.c
index ca76ec5a..5bfa1271 100644
--- a/examples/tablet.c
+++ b/examples/tablet.c
@@ -14,6 +14,7 @@
#include <wlr/render.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
+#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/types/wlr_tablet_pad.h>
@@ -28,7 +29,9 @@ struct sample_state {
double distance;
double pressure;
double x_mm, y_mm;
+ double x_tilt, y_tilt;
double width_mm, height_mm;
+ double ring;
struct wl_list link;
float tool_color[4];
float pad_color[4];
@@ -46,7 +49,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
wlr_renderer_begin(sample->renderer, wlr_output);
wlr_renderer_clear(sample->renderer, &(float[]){0.25f, 0.25f, 0.25f, 1});
- float matrix[16], view[16];
+ float matrix[16];
float distance = 0.8f * (1 - sample->distance);
float tool_color[4] = { distance, distance, distance, 1 };
for (size_t i = 0; sample->button && i < 4; ++i) {
@@ -58,22 +61,31 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
float pad_height = sample->height_mm * scale;
float left = width / 2.0f - pad_width / 2.0f;
float top = height / 2.0f - pad_height / 2.0f;
- wlr_matrix_translate(&matrix, left, top, 0);
- wlr_matrix_scale(&view, pad_width, pad_height, 1);
- wlr_matrix_mul(&matrix, &view, &view);
- wlr_matrix_mul(&wlr_output->transform_matrix, &view, &matrix);
+ struct wlr_box box = {
+ .x = left, .y = top,
+ .width = pad_width, .height = pad_height,
+ };
+ wlr_matrix_project_box(&matrix, &box, 0, 0,
+ &wlr_output->transform_matrix);
wlr_render_colored_quad(sample->renderer, &sample->pad_color, &matrix);
if (sample->proximity) {
- wlr_matrix_translate(&matrix,
- sample->x_mm * scale - 8 * (sample->pressure + 1) + left,
- sample->y_mm * scale - 8 * (sample->pressure + 1) + top, 0);
- wlr_matrix_scale(&view,
- 16 * (sample->pressure + 1),
- 16 * (sample->pressure + 1), 1);
- wlr_matrix_mul(&matrix, &view, &view);
- wlr_matrix_mul(&wlr_output->transform_matrix, &view, &matrix);
- wlr_render_colored_ellipse(sample->renderer, &tool_color, &matrix);
+ struct wlr_box box = {
+ .x = sample->x_mm * scale - 8 * (sample->pressure + 1) + left,
+ .y = sample->y_mm * scale - 8 * (sample->pressure + 1) + top,
+ .width = 16 * (sample->pressure + 1),
+ .height = 16 * (sample->pressure + 1),
+ };
+ wlr_matrix_project_box(&matrix, &box, 0, sample->ring,
+ &wlr_output->transform_matrix);
+ wlr_render_colored_quad(sample->renderer, &tool_color, &matrix);
+ box.x += sample->x_tilt;
+ box.y += sample->y_tilt;
+ box.width /= 2;
+ box.height /= 2;
+ wlr_matrix_project_box(&matrix, &box, 0, 0,
+ &wlr_output->transform_matrix);
+ wlr_render_colored_quad(sample->renderer, &tool_color, &matrix);
}
wlr_renderer_end(sample->renderer);
@@ -97,6 +109,12 @@ static void handle_tool_axis(struct tablet_tool_state *tstate,
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE)) {
sample->pressure = event->pressure;
}
+ if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_X)) {
+ sample->x_tilt = event->tilt_x;
+ }
+ if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_Y)) {
+ sample->y_tilt = event->tilt_y;
+ }
}
static void handle_tool_proximity(struct tablet_tool_state *tstate,
@@ -125,7 +143,7 @@ static void handle_tool_button(struct tablet_tool_state *tstate,
static void handle_pad_button(struct tablet_pad_state *pstate,
uint32_t button, enum wlr_button_state state) {
struct sample_state *sample = pstate->compositor->data;
- float default_color[4] = { 0.75, 0.75, 0.75, 1.0 };
+ float default_color[4] = { 0.5, 0.5, 0.5, 1.0 };
if (state == WLR_BUTTON_RELEASED) {
memcpy(sample->pad_color, default_color, sizeof(default_color));
} else {
@@ -139,11 +157,19 @@ static void handle_pad_button(struct tablet_pad_state *pstate,
}
}
+static void handle_pad_ring(struct tablet_pad_state *pstate,
+ uint32_t ring, double position) {
+ struct sample_state *sample = pstate->compositor->data;
+ if (position != -1) {
+ sample->ring = -(position * (M_PI / 180.0));
+ }
+}
+
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.75, 0.75, 0.75, 1.0 }
+ .pad_color = { 0.5, 0.5, 0.5, 1.0 }
};
struct compositor_state compositor = { 0,
.data = &state,
@@ -152,6 +178,7 @@ int main(int argc, char *argv[]) {
.tool_proximity_cb = handle_tool_proximity,
.tool_button_cb = handle_tool_button,
.pad_button_cb = handle_pad_button,
+ .pad_ring_cb = handle_pad_ring,
};
compositor_init(&compositor);