diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 1ce4278..4838aee 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -100,20 +100,20 @@ pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, seat->pointer_y = wl_fixed_to_int(y); seat->serial = serial; seat->pointer_focus = surface; + ctx.active = component_slot_from_wl_surface(surface); if (own_proxy(surface)){ - ctx.active = component_slot_from_wl_surface(surface); if (ctx.active != 0){ draw_decoration(); wl_surface_commit(ctx.wl_surface); } - update_local_cursor(seat); + seat->current_cursor = wl_cursor_from_pos(seat->pointer_x, seat->pointer_y); if (seat->current_cursor != 0){ struct wl_cursor_image *image = seat->current_cursor->images[0]; struct wl_buffer *buffer = wl_cursor_image_get_buffer(image); - wl_surface_attach(seat->cursor_surface, buffer, 0, 0); wl_surface_set_buffer_scale(seat->cursor_surface, 1); + wl_surface_attach(seat->cursor_surface, buffer, 0, 0); wl_surface_damage_buffer(seat->cursor_surface, 0, 0, image->width, image->height); wl_surface_commit(seat->cursor_surface); wl_pointer_set_cursor(seat->wl_pointer, seat->serial, seat->cursor_surface, image->hotspot_x, image->hotspot_y); @@ -136,7 +136,7 @@ pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct ctx.hdr_focus.type = HEADER_NONE; draw_decoration(); wl_surface_commit(ctx.wl_surface); - update_local_cursor(seat); + seat->current_cursor = wl_cursor_from_pos(seat->pointer_x, seat->pointer_y); } } @@ -146,19 +146,18 @@ pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, struct seat *seat = data; struct header_element_data new_focus; - if (seat->pointer_focus != 0 && own_proxy(seat->pointer_focus)){ + if (own_proxy(seat->pointer_focus)){ seat->pointer_x = wl_fixed_to_int(surface_x); seat->pointer_y = wl_fixed_to_int(surface_y); - if (update_local_cursor(seat)){ - if (seat->current_cursor != 0){ - struct wl_cursor_image *image = seat->current_cursor->images[0]; - struct wl_buffer *buffer = wl_cursor_image_get_buffer(image); - wl_surface_attach(seat->cursor_surface, buffer, 0, 0); - wl_surface_set_buffer_scale(seat->cursor_surface, 1); - wl_surface_damage_buffer(seat->cursor_surface, 0, 0, image->width, image->height); - wl_surface_commit(seat->cursor_surface); - wl_pointer_set_cursor(seat->wl_pointer, seat->serial, seat->cursor_surface, image->hotspot_x, image->hotspot_y); - } + seat->current_cursor = wl_cursor_from_pos(seat->pointer_x, seat->pointer_y); + if (seat->current_cursor != 0){ + struct wl_cursor_image *image = seat->current_cursor->images[0]; + struct wl_buffer *buffer = wl_cursor_image_get_buffer(image); + wl_surface_attach(seat->cursor_surface, buffer, 0, 0); + wl_surface_set_buffer_scale(seat->cursor_surface, 1); + wl_surface_damage_buffer(seat->cursor_surface, 0, 0, image->width, image->height); + wl_surface_commit(seat->cursor_surface); + wl_pointer_set_cursor(seat->wl_pointer, seat->serial, seat->cursor_surface, image->hotspot_x, image->hotspot_y); } /* avoid warnings after decoration has been turned off */ @@ -193,7 +192,7 @@ static void pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state){ struct seat *seat = data; - if (seat->pointer_focus && own_proxy(seat->pointer_focus)){ + if (own_proxy(seat->pointer_focus)){ switch (ctx.active){ case COMPONENT_SLOT_SHADOW: { enum libdecor_resize_edge edge = edge_from_pos(seat->pointer_x, seat->pointer_y); @@ -2500,28 +2499,17 @@ edge_from_pos(int x, int y){ return(result); } -static bool -update_local_cursor(struct seat *seat){ - struct wl_cursor *wl_cursor = ctx.cursor_left_ptr; - if (own_proxy(seat->pointer_focus)){ - if (ctx.active != 0){ - if (ctx.active == COMPONENT_SLOT_SHADOW && - (ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){ - enum libdecor_resize_edge edge = edge_from_pos(seat->pointer_x, seat->pointer_y); - if (edge != LIBDECOR_RESIZE_EDGE_NONE){ - wl_cursor = ctx.cursors[edge - 1]; - } - } +static struct wl_cursor * +wl_cursor_from_pos(int x, int y){ + struct wl_cursor *result = ctx.cursor_left_ptr; + if (ctx.active == COMPONENT_SLOT_SHADOW && + (ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){ + enum libdecor_resize_edge edge = edge_from_pos(x, y); + if (edge != LIBDECOR_RESIZE_EDGE_NONE){ + result = ctx.cursors[edge - 1]; } } - - bool cursor_updated = false; - if (seat->current_cursor != wl_cursor) { - seat->current_cursor = wl_cursor; - cursor_updated = true; - } - - return(cursor_updated); + return(result); } diff --git a/digesting_libdecor.h b/digesting_libdecor.h index c858402..45033b3 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -298,7 +298,7 @@ static void libdecor_plugin_gtk_frame_free(void); static void libdecor_plugin_gtk_frame_commit(void); static Bounds2D border_size_from_window_state(enum libdecor_window_state window_state); -static bool update_local_cursor(struct seat *seat); +static struct wl_cursor* wl_cursor_from_pos(int x, int y); static void draw_decoration(void); static void draw_header_button(cairo_t *cr, cairo_surface_t *surface, enum header_element button_type); static void buffer_free(struct buffer *buffer);