aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-08 07:22:26 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-08 08:04:03 -0500
commitec7fc42a00db8c230ca1a050f0a1f7badc697fa5 (patch)
tree3e0614e8a497fbc12f2669945a43dcd310809c05
parentbasic input manager and seat (diff)
downloadsway-ec7fc42a00db8c230ca1a050f0a1f7badc697fa5.tar.gz
sway-ec7fc42a00db8c230ca1a050f0a1f7badc697fa5.tar.zst
sway-ec7fc42a00db8c230ca1a050f0a1f7badc697fa5.zip
sway cursor
-rw-r--r--include/sway/cursor.h26
-rw-r--r--include/sway/seat.h1
-rw-r--r--sway/input/cursor.c128
-rw-r--r--sway/input/seat.c52
-rw-r--r--sway/meson.build1
5 files changed, 208 insertions, 0 deletions
diff --git a/include/sway/cursor.h b/include/sway/cursor.h
new file mode 100644
index 00000000..647bc8f1
--- /dev/null
+++ b/include/sway/cursor.h
@@ -0,0 +1,26 @@
1#ifndef _SWAY_CURSOR_H
2#define _SWAY_CURSOR_H
3
4#include "sway/seat.h"
5
6struct sway_cursor {
7 struct wlr_cursor *cursor;
8
9 struct wl_listener motion;
10 struct wl_listener motion_absolute;
11 struct wl_listener button;
12 struct wl_listener axis;
13
14 struct wl_listener touch_down;
15 struct wl_listener touch_up;
16 struct wl_listener touch_motion;
17
18 struct wl_listener tool_axis;
19 struct wl_listener tool_tip;
20
21 struct wl_listener request_set_cursor;
22};
23
24struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
25
26#endif
diff --git a/include/sway/seat.h b/include/sway/seat.h
index a2b8fe51..2f8ca72e 100644
--- a/include/sway/seat.h
+++ b/include/sway/seat.h
@@ -6,6 +6,7 @@
6 6
7struct sway_seat { 7struct sway_seat {
8 struct wlr_seat *seat; 8 struct wlr_seat *seat;
9 struct sway_cursor *cursor;
9}; 10};
10 11
11struct sway_seat *sway_seat_create(struct wl_display *display, 12struct sway_seat *sway_seat_create(struct wl_display *display,
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
new file mode 100644
index 00000000..819007d5
--- /dev/null
+++ b/sway/input/cursor.c
@@ -0,0 +1,128 @@
1#define _XOPEN_SOURCE 700
2#include <wlr/types/wlr_cursor.h>
3#include "sway/cursor.h"
4#include "log.h"
5
6static void handle_cursor_motion(struct wl_listener *listener, void *data) {
7 struct sway_cursor *cursor =
8 wl_container_of(listener, cursor, motion);
9 struct wlr_event_pointer_motion *event = data;
10 sway_log(L_DEBUG, "TODO: handle event: %p", event);
11}
12
13static void handle_cursor_motion_absolute(struct wl_listener *listener,
14 void *data) {
15 struct sway_cursor *cursor =
16 wl_container_of(listener, cursor, motion_absolute);
17 struct wlr_event_pointer_motion_absolute *event = data;
18 sway_log(L_DEBUG, "TODO: handle event: %p", event);
19}
20
21static void handle_cursor_button(struct wl_listener *listener, void *data) {
22 struct sway_cursor *cursor =
23 wl_container_of(listener, cursor, button);
24 struct wlr_event_pointer_button *event = data;
25 sway_log(L_DEBUG, "TODO: handle event: %p", event);
26}
27
28static void handle_cursor_axis(struct wl_listener *listener, void *data) {
29 struct sway_cursor *cursor =
30 wl_container_of(listener, cursor, axis);
31 struct wlr_event_pointer_axis *event = data;
32 sway_log(L_DEBUG, "TODO: handle event: %p", event);
33}
34
35static void handle_touch_down(struct wl_listener *listener, void *data) {
36 struct sway_cursor *cursor =
37 wl_container_of(listener, cursor, touch_down);
38 struct wlr_event_touch_down *event = data;
39 sway_log(L_DEBUG, "TODO: handle event: %p", event);
40}
41
42static void handle_touch_up(struct wl_listener *listener, void *data) {
43 struct sway_cursor *cursor =
44 wl_container_of(listener, cursor, touch_up);
45 struct wlr_event_touch_up *event = data;
46 sway_log(L_DEBUG, "TODO: handle event: %p", event);
47}
48
49static void handle_touch_motion(struct wl_listener *listener, void *data) {
50 struct sway_cursor *cursor =
51 wl_container_of(listener, cursor, touch_motion);
52 struct wlr_event_touch_motion *event = data;
53 sway_log(L_DEBUG, "TODO: handle event: %p", event);
54}
55
56static void handle_tool_axis(struct wl_listener *listener, void *data) {
57 struct sway_cursor *cursor =
58 wl_container_of(listener, cursor, tool_axis);
59 struct wlr_event_tablet_tool_axis *event = data;
60 sway_log(L_DEBUG, "TODO: handle event: %p", event);
61}
62
63static void handle_tool_tip(struct wl_listener *listener, void *data) {
64 struct sway_cursor *cursor =
65 wl_container_of(listener, cursor, tool_tip);
66 struct wlr_event_tablet_tool_tip *event = data;
67 sway_log(L_DEBUG, "TODO: handle event: %p", event);
68}
69
70static void handle_request_set_cursor(struct wl_listener *listener,
71 void *data) {
72 struct sway_cursor *cursor =
73 wl_container_of(listener, cursor, request_set_cursor);
74 struct wlr_seat_pointer_request_set_cursor_event *event = data;
75 sway_log(L_DEBUG, "TODO: handle event: %p", event);
76}
77
78struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
79 struct sway_cursor *cursor = calloc(1, sizeof(struct sway_cursor));
80 if (!sway_assert(cursor, "could not allocate sway cursor")) {
81 return NULL;
82 }
83
84 struct wlr_cursor *wlr_cursor = wlr_cursor_create();
85 if (!sway_assert(wlr_cursor, "could not allocate wlr cursor")) {
86 free(cursor);
87 return NULL;
88 }
89
90 // input events
91 wl_signal_add(&wlr_cursor->events.motion, &cursor->motion);
92 cursor->motion.notify = handle_cursor_motion;
93
94 wl_signal_add(&wlr_cursor->events.motion_absolute,
95 &cursor->motion_absolute);
96 cursor->motion_absolute.notify = handle_cursor_motion_absolute;
97
98 wl_signal_add(&wlr_cursor->events.button, &cursor->button);
99 cursor->button.notify = handle_cursor_button;
100
101 wl_signal_add(&wlr_cursor->events.axis, &cursor->axis);
102 cursor->axis.notify = handle_cursor_axis;
103
104 wl_signal_add(&wlr_cursor->events.touch_down, &cursor->touch_down);
105 cursor->touch_down.notify = handle_touch_down;
106
107 wl_signal_add(&wlr_cursor->events.touch_up, &cursor->touch_up);
108 cursor->touch_up.notify = handle_touch_up;
109
110 wl_signal_add(&wlr_cursor->events.touch_motion,
111 &cursor->touch_motion);
112 cursor->touch_motion.notify = handle_touch_motion;
113
114 wl_signal_add(&wlr_cursor->events.tablet_tool_axis,
115 &cursor->tool_axis);
116 cursor->tool_axis.notify = handle_tool_axis;
117
118 wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip);
119 cursor->tool_tip.notify = handle_tool_tip;
120
121 wl_signal_add(&seat->seat->events.request_set_cursor,
122 &cursor->request_set_cursor);
123 cursor->request_set_cursor.notify = handle_request_set_cursor;
124
125 cursor->cursor = wlr_cursor;
126
127 return cursor;
128}
diff --git a/sway/input/seat.c b/sway/input/seat.c
index f41b6dba..459b2ee2 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -1,5 +1,7 @@
1#define _XOPEN_SOURCE 700 1#define _XOPEN_SOURCE 700
2#include <wlr/types/wlr_cursor.h>
2#include "sway/seat.h" 3#include "sway/seat.h"
4#include "sway/cursor.h"
3#include "sway/input-manager.h" 5#include "sway/input-manager.h"
4#include "log.h" 6#include "log.h"
5 7
@@ -9,16 +11,66 @@ struct sway_seat *sway_seat_create(struct wl_display *display,
9 if (!seat) { 11 if (!seat) {
10 return NULL; 12 return NULL;
11 } 13 }
14
12 seat->seat = wlr_seat_create(display, seat_name); 15 seat->seat = wlr_seat_create(display, seat_name);
16 if (!sway_assert(seat->seat, "could not allocate seat")) {
17 return NULL;
18 }
19
20 seat->cursor = sway_cursor_create(seat);
21 if (!seat->cursor) {
22 wlr_seat_destroy(seat->seat);
23 free(seat);
24 return NULL;
25 }
26
27 wlr_seat_set_capabilities(seat->seat,
28 WL_SEAT_CAPABILITY_KEYBOARD |
29 WL_SEAT_CAPABILITY_POINTER |
30 WL_SEAT_CAPABILITY_TOUCH);
31
13 return seat; 32 return seat;
14} 33}
15 34
35static void seat_add_pointer(struct sway_seat *seat,
36 struct wlr_input_device *device) {
37 // TODO pointer configuration
38 wlr_cursor_attach_input_device(seat->cursor->cursor, device);
39}
40
16void sway_seat_add_device(struct sway_seat *seat, 41void sway_seat_add_device(struct sway_seat *seat,
17 struct wlr_input_device *device) { 42 struct wlr_input_device *device) {
18 sway_log(L_DEBUG, "input add: %s", device->name); 43 sway_log(L_DEBUG, "input add: %s", device->name);
44 switch (device->type) {
45 case WLR_INPUT_DEVICE_POINTER:
46 seat_add_pointer(seat, device);
47 break;
48 case WLR_INPUT_DEVICE_KEYBOARD:
49 case WLR_INPUT_DEVICE_TOUCH:
50 case WLR_INPUT_DEVICE_TABLET_PAD:
51 case WLR_INPUT_DEVICE_TABLET_TOOL:
52 sway_log(L_DEBUG, "TODO: add other devices");
53 break;
54 }
55}
56
57static void seat_remove_pointer(struct sway_seat *seat,
58 struct wlr_input_device *device) {
59 // TODO
19} 60}
20 61
21void sway_seat_remove_device(struct sway_seat *seat, 62void sway_seat_remove_device(struct sway_seat *seat,
22 struct wlr_input_device *device) { 63 struct wlr_input_device *device) {
23 sway_log(L_DEBUG, "input remove: %s", device->name); 64 sway_log(L_DEBUG, "input remove: %s", device->name);
65 switch (device->type) {
66 case WLR_INPUT_DEVICE_POINTER:
67 seat_remove_pointer(seat, device);
68 break;
69 case WLR_INPUT_DEVICE_KEYBOARD:
70 case WLR_INPUT_DEVICE_TOUCH:
71 case WLR_INPUT_DEVICE_TABLET_PAD:
72 case WLR_INPUT_DEVICE_TABLET_TOOL:
73 sway_log(L_DEBUG, "TODO: remove other devices");
74 break;
75 }
24} 76}
diff --git a/sway/meson.build b/sway/meson.build
index cea565d6..059204b2 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -4,6 +4,7 @@ sway_sources = files(
4 'commands.c', 4 'commands.c',
5 'input/input-manager.c', 5 'input/input-manager.c',
6 'input/seat.c', 6 'input/seat.c',
7 'input/cursor.c',
7 'commands/exit.c', 8 'commands/exit.c',
8 'commands/exec.c', 9 'commands/exec.c',
9 'commands/exec_always.c', 10 'commands/exec_always.c',