aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/pointer.c26
-rw-r--r--example/shared.c14
-rw-r--r--example/shared.h5
3 files changed, 41 insertions, 4 deletions
diff --git a/example/pointer.c b/example/pointer.c
index 969fb721..42ac85fd 100644
--- a/example/pointer.c
+++ b/example/pointer.c
@@ -23,6 +23,7 @@ struct sample_state {
struct wlr_renderer *renderer;
struct wlr_surface *cat_texture;
int cur_x, cur_y;
+ float clear_color[4];
};
static void handle_output_frame(struct output_state *output, struct timespec *ts) {
@@ -31,6 +32,9 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
struct wlr_output *wlr_output = output->output;
wlr_renderer_begin(sample->renderer, wlr_output);
+ glClearColor(sample->clear_color[0], sample->clear_color[1],
+ sample->clear_color[2], sample->clear_color[3]);
+ glClear(GL_COLOR_BUFFER_BIT);
float matrix[16];
wlr_surface_get_matrix(sample->cat_texture, &matrix,
@@ -55,14 +59,32 @@ static void handle_pointer_motion(struct pointer_state *pstate,
state->cur_y += d_y;
}
+static void handle_pointer_button(struct pointer_state *pstate,
+ uint32_t button, enum wlr_button_state state) {
+ struct sample_state *sample = pstate->compositor->data;
+ float (*color)[4];
+ if (state == WLR_BUTTON_RELEASED) {
+ float _default[4] = { 0.25f, 0.25f, 0.25f, 1 };
+ color = &_default;
+ } else {
+ float red[4] = { 0.25f, 0.25f, 0.25f, 1 };
+ red[button % 3] = 1;
+ color = &red;
+ }
+ memcpy(&sample->clear_color, color, sizeof(*color));
+}
+
int main(int argc, char *argv[]) {
- struct sample_state state = { 0 };
+ struct sample_state state = {
+ .clear_color = { 0.25f, 0.25f, 0.25f, 1 }
+ };
struct compositor_state compositor;
compositor_init(&compositor);
compositor.output_frame_cb = handle_output_frame;
- compositor.pointer_motion_cb = handle_pointer_motion;
compositor.keyboard_key_cb = handle_keyboard_key;
+ compositor.pointer_motion_cb = handle_pointer_motion;
+ compositor.pointer_button_cb = handle_pointer_button;
state.renderer = wlr_gles3_renderer_init();
state.cat_texture = wlr_render_surface_init(state.renderer);
diff --git a/example/shared.c b/example/shared.c
index 4657b7fe..6a676343 100644
--- a/example/shared.c
+++ b/example/shared.c
@@ -74,7 +74,17 @@ static void pointer_motion_notify(struct wl_listener *listener, void *data) {
struct wlr_pointer_motion *event = data;
struct pointer_state *pstate = wl_container_of(listener, pstate, motion);
if (pstate->compositor->pointer_motion_cb) {
- pstate->compositor->pointer_motion_cb(pstate, event->delta_x, event->delta_y);
+ pstate->compositor->pointer_motion_cb(pstate,
+ event->delta_x, event->delta_y);
+ }
+}
+
+static void pointer_button_notify(struct wl_listener *listener, void *data) {
+ struct wlr_pointer_button *event = data;
+ struct pointer_state *pstate = wl_container_of(listener, pstate, button);
+ if (pstate->compositor->pointer_button_cb) {
+ pstate->compositor->pointer_button_cb(pstate,
+ event->button, event->state);
}
}
@@ -87,7 +97,9 @@ static void pointer_add(struct wlr_input_device *device, struct compositor_state
wl_list_init(&pstate->button.link);
wl_list_init(&pstate->axis.link);
pstate->motion.notify = pointer_motion_notify;
+ pstate->button.notify = pointer_button_notify;
wl_signal_add(&device->pointer->events.motion, &pstate->motion);
+ wl_signal_add(&device->pointer->events.button, &pstate->button);
wl_list_insert(&state->pointers, &pstate->link);
}
diff --git a/example/shared.h b/example/shared.h
index 2c093414..ca558f1c 100644
--- a/example/shared.h
+++ b/example/shared.h
@@ -47,7 +47,10 @@ struct compositor_state {
void (*keyboard_remove_cb)(struct keyboard_state *s);
void (*keyboard_key_cb)(struct keyboard_state *s, xkb_keysym_t sym,
enum wlr_key_state key_state);
- void (*pointer_motion_cb)(struct pointer_state *s, double d_x, double d_y);
+ void (*pointer_motion_cb)(struct pointer_state *s,
+ double d_x, double d_y);
+ void (*pointer_button_cb)(struct pointer_state *s,
+ uint32_t button, enum wlr_button_state state);
struct wl_display *display;
struct wl_event_loop *event_loop;