aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMake/FindWayland.cmake11
-rw-r--r--include/client/client.h8
-rw-r--r--swaybg/CMakeLists.txt2
-rw-r--r--wayland/client.c43
4 files changed, 60 insertions, 4 deletions
diff --git a/CMake/FindWayland.cmake b/CMake/FindWayland.cmake
index 00c17a3c..69130fe0 100644
--- a/CMake/FindWayland.cmake
+++ b/CMake/FindWayland.cmake
@@ -12,6 +12,7 @@
12# WAYLAND_CLIENT_FOUND WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES 12# WAYLAND_CLIENT_FOUND WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES
13# WAYLAND_SERVER_FOUND WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES 13# WAYLAND_SERVER_FOUND WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES
14# WAYLAND_EGL_FOUND WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES 14# WAYLAND_EGL_FOUND WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES
15# WAYLAND_CURSOR_FOUND WAYLAND_CURSOR_INCLUDE_DIR WAYLAND_CURSOR_LIBRARIES
15# 16#
16# Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org> 17# Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org>
17# 18#
@@ -27,21 +28,23 @@ IF (NOT WIN32)
27 # Use pkg-config to get the directories and then use these values 28 # Use pkg-config to get the directories and then use these values
28 # in the FIND_PATH() and FIND_LIBRARY() calls 29 # in the FIND_PATH() and FIND_LIBRARY() calls
29 FIND_PACKAGE(PkgConfig) 30 FIND_PACKAGE(PkgConfig)
30 PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl) 31 PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor)
31 32
32 SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS}) 33 SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS})
33 34
34 FIND_PATH(WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 35 FIND_PATH(WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
35 FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 36 FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
36 FIND_PATH(WAYLAND_EGL_INCLUDE_DIR NAMES wayland-egl.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 37 FIND_PATH(WAYLAND_EGL_INCLUDE_DIR NAMES wayland-egl.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
38 FIND_PATH(WAYLAND_CURSOR_INCLUDE_DIR NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
37 39
38 FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 40 FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
39 FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 41 FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
40 FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 42 FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
43 FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
41 44
42 set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR}) 45 set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR})
43 46
44 set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES}) 47 set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES})
45 48
46 list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR) 49 list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR)
47 50
@@ -50,6 +53,7 @@ IF (NOT WIN32)
50 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT DEFAULT_MSG WAYLAND_CLIENT_LIBRARIES WAYLAND_CLIENT_INCLUDE_DIR) 53 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT DEFAULT_MSG WAYLAND_CLIENT_LIBRARIES WAYLAND_CLIENT_INCLUDE_DIR)
51 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER DEFAULT_MSG WAYLAND_SERVER_LIBRARIES WAYLAND_SERVER_INCLUDE_DIR) 54 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER DEFAULT_MSG WAYLAND_SERVER_LIBRARIES WAYLAND_SERVER_INCLUDE_DIR)
52 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL DEFAULT_MSG WAYLAND_EGL_LIBRARIES WAYLAND_EGL_INCLUDE_DIR) 55 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL DEFAULT_MSG WAYLAND_EGL_LIBRARIES WAYLAND_EGL_INCLUDE_DIR)
56 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CURSOR DEFAULT_MSG WAYLAND_CURSOR_LIBRARIES WAYLAND_CURSOR_INCLUDE_DIR)
53 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND DEFAULT_MSG WAYLAND_LIBRARIES WAYLAND_INCLUDE_DIR) 57 FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND DEFAULT_MSG WAYLAND_LIBRARIES WAYLAND_INCLUDE_DIR)
54 58
55 MARK_AS_ADVANCED( 59 MARK_AS_ADVANCED(
@@ -57,6 +61,7 @@ IF (NOT WIN32)
57 WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES 61 WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES
58 WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES 62 WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES
59 WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES 63 WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES
64 WAYLAND_CURSOR_INCLUDE_DIR WAYLAND_CURSOR_LIBRARIES
60 ) 65 )
61 66
62ENDIF () 67ENDIF ()
diff --git a/include/client/client.h b/include/client/client.h
index 5b24d315..b823235b 100644
--- a/include/client/client.h
+++ b/include/client/client.h
@@ -22,6 +22,13 @@ struct buffer {
22 bool busy; 22 bool busy;
23}; 23};
24 24
25struct cursor {
26 struct wl_surface *surface;
27 struct wl_cursor_theme *cursor_theme;
28 struct wl_cursor *cursor;
29 struct wl_poitner *pointer;
30};
31
25struct client_state { 32struct client_state {
26 struct wl_compositor *compositor; 33 struct wl_compositor *compositor;
27 struct wl_display *display; 34 struct wl_display *display;
@@ -34,6 +41,7 @@ struct client_state {
34 struct wl_surface *surface; 41 struct wl_surface *surface;
35 struct wl_shell_surface *shell_surface; 42 struct wl_shell_surface *shell_surface;
36 struct wl_callback *frame_cb; 43 struct wl_callback *frame_cb;
44 struct cursor cursor;
37 uint32_t width, height; 45 uint32_t width, height;
38 cairo_t *cairo; 46 cairo_t *cairo;
39 list_t *outputs; 47 list_t *outputs;
diff --git a/swaybg/CMakeLists.txt b/swaybg/CMakeLists.txt
index 5cf4ff05..7f0556df 100644
--- a/swaybg/CMakeLists.txt
+++ b/swaybg/CMakeLists.txt
@@ -26,7 +26,7 @@ add_executable(swaybg
26 ${proto-xdg-shell} 26 ${proto-xdg-shell}
27) 27)
28 28
29TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES} m) 29TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES} m)
30 30
31install( 31install(
32 TARGETS swaybg 32 TARGETS swaybg
diff --git a/wayland/client.c b/wayland/client.c
index 190d5ecb..be93709b 100644
--- a/wayland/client.c
+++ b/wayland/client.c
@@ -1,4 +1,5 @@
1#include <wayland-client.h> 1#include <wayland-client.h>
2#include <wayland-cursor.h>
2#include "wayland-xdg-shell-client-protocol.h" 3#include "wayland-xdg-shell-client-protocol.h"
3#include <cairo/cairo.h> 4#include <cairo/cairo.h>
4#include <pango/pangocairo.h> 5#include <pango/pangocairo.h>
@@ -44,6 +45,37 @@ static const struct wl_output_listener output_listener = {
44 .scale = display_handle_scale 45 .scale = display_handle_scale
45}; 46};
46 47
48static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
49 uint32_t serial, struct wl_surface *surface, wl_fixed_t sx_w, wl_fixed_t sy_w) {
50 struct client_state *state = data;
51 struct wl_cursor_image *image = state->cursor.cursor->images[0];
52 wl_pointer_set_cursor(pointer, serial, state->cursor.surface, image->hotspot_x, image->hotspot_y);
53}
54
55static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
56 uint32_t serial, struct wl_surface *surface) {
57}
58
59static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
60 uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) {
61}
62
63static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
64 uint32_t time, uint32_t button, uint32_t state_w) {
65}
66
67static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
68 uint32_t time, uint32_t axis, wl_fixed_t value) {
69}
70
71static const struct wl_pointer_listener pointer_listener = {
72 .enter = pointer_handle_enter,
73 .leave = pointer_handle_leave,
74 .motion = pointer_handle_motion,
75 .button = pointer_handle_button,
76 .axis = pointer_handle_axis
77};
78
47static void registry_global(void *data, struct wl_registry *registry, 79static void registry_global(void *data, struct wl_registry *registry,
48 uint32_t name, const char *interface, uint32_t version) { 80 uint32_t name, const char *interface, uint32_t version) {
49 struct client_state *state = data; 81 struct client_state *state = data;
@@ -57,6 +89,7 @@ static void registry_global(void *data, struct wl_registry *registry,
57 } else if (strcmp(interface, wl_seat_interface.name) == 0) { 89 } else if (strcmp(interface, wl_seat_interface.name) == 0) {
58 state->seat = wl_registry_bind(registry, name, &wl_seat_interface, version); 90 state->seat = wl_registry_bind(registry, name, &wl_seat_interface, version);
59 state->pointer = wl_seat_get_pointer(state->seat); 91 state->pointer = wl_seat_get_pointer(state->seat);
92 wl_pointer_add_listener(state->pointer, &pointer_listener, state);
60 } else if (strcmp(interface, wl_output_interface.name) == 0) { 93 } else if (strcmp(interface, wl_output_interface.name) == 0) {
61 struct wl_output *output = wl_registry_bind(registry, name, &wl_output_interface, version); 94 struct wl_output *output = wl_registry_bind(registry, name, &wl_output_interface, version);
62 struct output_state *ostate = malloc(sizeof(struct output_state)); 95 struct output_state *ostate = malloc(sizeof(struct output_state));
@@ -111,6 +144,16 @@ struct client_state *client_setup(uint32_t width, uint32_t height) {
111 wl_shell_surface_add_listener(state->shell_surface, &surface_listener, state); 144 wl_shell_surface_add_listener(state->shell_surface, &surface_listener, state);
112 wl_shell_surface_set_toplevel(state->shell_surface); 145 wl_shell_surface_set_toplevel(state->shell_surface);
113 146
147 state->cursor.cursor_theme = wl_cursor_theme_load("default", 32, state->shm); // TODO: let you customize this
148 state->cursor.cursor = wl_cursor_theme_get_cursor(state->cursor.cursor_theme, "left_ptr");
149 state->cursor.surface = wl_compositor_create_surface(state->compositor);
150
151 struct wl_cursor_image *image = state->cursor.cursor->images[0];
152 struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
153 wl_surface_attach(state->cursor.surface, cursor_buf, 0, 0);
154 wl_surface_damage(state->cursor.surface, 0, 0, image->width, image->height);
155 wl_surface_commit(state->cursor.surface);
156
114 return state; 157 return state;
115} 158}
116 159