aboutsummaryrefslogtreecommitdiff
path: root/example/pointer.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-13 12:31:24 -0400
committerDrew DeVault <sir@cmpwn.com>2017-06-13 12:31:24 -0400
commit8f284ec0b23953ccc274291eeb612d782d391b07 (patch)
tree63fa9bc4f7136bb7b95c1658fd42506467221313 /example/pointer.c
parent2f9fd72fdcf9249ed16bcc029a86e734ae1487a1 (diff)
Demonstrate pointer button event in example
Diffstat (limited to 'example/pointer.c')
-rw-r--r--example/pointer.c26
1 files changed, 24 insertions, 2 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);