swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 0d546e80c1431c1c8d603715865b0b7fd9836789
parent e7f24676fef7fb26093824a02ad0efc7e2a6cfbc
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 22 Jan 2014 16:26:06 -0800

pointer: Set left pointer cursor by default

Diffstat:
Mlibswc/local.mk | 1+
Mlibswc/pointer.c | 27+++++++++++++++++++++++++++
Mlibswc/pointer.h | 5+++++
3 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/libswc/local.mk b/libswc/local.mk @@ -85,6 +85,7 @@ SWC_SHARED_OBJECTS = $(SWC_SOURCES:%.c=%.lo) objects = $(foreach obj,$(1),$(dir)/$(obj).o $(dir)/$(obj).lo) $(call objects,drm drm_buffer): protocol/wayland-drm-server-protocol.h $(call objects,xserver): protocol/xserver-server-protocol.h +$(call objects,pointer): cursor/cursor_data.h $(dir)/libswc.a: $(SWC_STATIC_OBJECTS) $(call quiet,AR) cru $@ $^ diff --git a/libswc/pointer.c b/libswc/pointer.c @@ -4,6 +4,7 @@ #include "screen.h" #include "shm.h" #include "util.h" +#include "cursor/cursor_data.h" #include <stdio.h> #include <assert.h> @@ -158,6 +159,30 @@ static inline void update_cursor(struct swc_pointer * pointer) wl_fixed_to_int(pointer->y) - pointer->cursor.hotspot.y); } +void swc_pointer_set_cursor(struct swc_pointer * pointer, uint32_t id) +{ + struct cursor * cursor = &cursor_metadata[id]; + union wld_object object = { .ptr = &cursor_data[cursor->offset] }; + + if (pointer->cursor.internal_buffer.wld) + wld_destroy_buffer(pointer->cursor.internal_buffer.wld); + + pointer->cursor.internal_buffer.wld = wld_import_buffer + (swc.shm->context, WLD_OBJECT_DATA, object, + cursor->width, cursor->height, WLD_FORMAT_ARGB8888, cursor->width * 4); + + if (!pointer->cursor.internal_buffer.wld) + { + ERROR("Failed to create cursor buffer\n"); + return; + } + + pointer->cursor.hotspot.x = cursor->hotspot_x; + pointer->cursor.hotspot.y = cursor->hotspot_y; + swc_view_attach(&pointer->cursor.view, &pointer->cursor.internal_buffer); + update_cursor(pointer); +} + bool swc_pointer_initialize(struct swc_pointer * pointer) { struct wld_buffer * buffer; @@ -185,6 +210,8 @@ bool swc_pointer_initialize(struct swc_pointer * pointer) return false; swc_buffer_initialize(&pointer->cursor.buffer, buffer); + swc_buffer_initialize(&pointer->cursor.internal_buffer, NULL); + swc_pointer_set_cursor(pointer, cursor_left_ptr); swc_input_focus_initialize(&pointer->focus, &pointer->focus_handler); pixman_region32_init(&pointer->region); diff --git a/libswc/pointer.h b/libswc/pointer.h @@ -34,6 +34,9 @@ struct swc_pointer struct wl_listener destroy_listener; struct swc_buffer buffer; + /* Used for cursors set with swc_pointer_set_cursor */ + struct swc_buffer internal_buffer; + struct { int32_t x, y; @@ -52,6 +55,8 @@ void swc_pointer_set_focus(struct swc_pointer * pointer, struct swc_surface * surface); void swc_pointer_set_region(struct swc_pointer * pointer, pixman_region32_t * region); +void swc_pointer_set_cursor(struct swc_pointer * pointer, uint32_t id); + struct wl_resource * swc_pointer_bind(struct swc_pointer * pointer, struct wl_client * client, uint32_t id); void swc_pointer_handle_button(struct swc_pointer * pointer, uint32_t time,