aboutsummaryrefslogtreecommitdiff
path: root/examples/tablet.c
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-03-28 14:11:39 -0400
committerGitHub <noreply@github.com>2018-03-28 14:11:39 -0400
commit5dd022da1300185780ddf4b70014a6f8f306de85 (patch)
tree331f0e5f7b748387a338b678b625bf5a1ae7f693 /examples/tablet.c
parent52d621e0979c3b393753d1c67b2b0fd23212ca41 (diff)
parent3813121fefb1734ed2c2537759e6eead1c0d9a74 (diff)
Merge pull request #765 from swaywm/transformed-events
Use libinput transformed events instead of width_mm/height_mm
Diffstat (limited to 'examples/tablet.c')
-rw-r--r--examples/tablet.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/examples/tablet.c b/examples/tablet.c
index 9379fac3..be428f86 100644
--- a/examples/tablet.c
+++ b/examples/tablet.c
@@ -28,7 +28,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 +69,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 +94,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 +162,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,6 +187,8 @@ 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);