From 86e09896730314864a6fbd779e27901c5d00ea1a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 7 Jul 2010 09:51:11 -0400 Subject: [PATCH] Hide wayland cursor when X11 compositor loses focus --- compositor-drm.c | 1 + compositor-x11.c | 15 ++++++++++++++- compositor.c | 7 ++++--- compositor.h | 5 +++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/compositor-drm.c b/compositor-drm.c index c45b1d8..38d04bf 100644 --- a/compositor-drm.c +++ b/compositor-drm.c @@ -678,6 +678,7 @@ drm_compositor_create(struct wl_display *display) WL_EVENT_READABLE, on_drm_input, ec); setup_tty(ec, loop); ec->base.present = drm_compositor_present; + ec->base.focus = 1; return &ec->base; } diff --git a/compositor-x11.c b/compositor-x11.c index 61369fd..2ecd2a2 100644 --- a/compositor-x11.c +++ b/compositor-x11.c @@ -346,7 +346,9 @@ x11_compositor_create_output(struct x11_compositor *c, int width, int height) XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE | - XCB_EVENT_MASK_STRUCTURE_NOTIFY, + XCB_EVENT_MASK_STRUCTURE_NOTIFY | + XCB_EVENT_MASK_ENTER_WINDOW | + XCB_EVENT_MASK_LEAVE_WINDOW, 0 }; @@ -559,6 +561,17 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data) r->width = expose->width; r->height = expose->height; break; + + case XCB_ENTER_NOTIFY: + c->base.focus = 1; + wlsc_compositor_schedule_repaint(&c->base); + break; + + case XCB_LEAVE_NOTIFY: + c->base.focus = 0; + wlsc_compositor_schedule_repaint(&c->base); + break; + case XCB_CLIENT_MESSAGE: client_message = (xcb_client_message_event_t *) event; atom = client_message->data.data32[0]; diff --git a/compositor.c b/compositor.c index 268c8e5..f3017ab 100644 --- a/compositor.c +++ b/compositor.c @@ -375,8 +375,9 @@ wlsc_output_repaint(struct wlsc_output *output) wl_list_for_each(es, &ec->surface_list, link) wlsc_surface_draw(es, output); - wl_list_for_each(eid, &ec->input_device_list, link) - wlsc_surface_draw(eid->sprite, output); + if (ec->focus) + wl_list_for_each(eid, &ec->input_device_list, link) + wlsc_surface_draw(eid->sprite, output); } static void @@ -398,7 +399,7 @@ repaint(void *data) ec->repaint_needed = 0; } -static void +void wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor) { compositor->repaint_needed = 1; diff --git a/compositor.h b/compositor.h index 99cce30..362a8c5 100644 --- a/compositor.h +++ b/compositor.h @@ -99,6 +99,7 @@ struct wlsc_compositor { uint32_t current_frame; uint32_t modifier_state; + uint32_t focus; void (*present)(struct wlsc_compositor *c); }; @@ -131,8 +132,8 @@ notify_key(struct wlsc_input_device *device, uint32_t key, uint32_t state); void wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs); -struct wlsc_input_device * -wlsc_input_device_create(struct wlsc_compositor *ec); +void +wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor); int wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display); -- 2.7.4