aboutsummaryrefslogtreecommitdiffstats
path: root/wayland/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'wayland/window.c')
-rw-r--r--wayland/window.c177
1 files changed, 0 insertions, 177 deletions
diff --git a/wayland/window.c b/wayland/window.c
deleted file mode 100644
index 8a506656..00000000
--- a/wayland/window.c
+++ /dev/null
@@ -1,177 +0,0 @@
1#include <wayland-client.h>
2#include <wayland-cursor.h>
3#include "wayland-xdg-shell-client-protocol.h"
4#include "wayland-desktop-shell-client-protocol.h"
5#include <cairo/cairo.h>
6#include <pango/pangocairo.h>
7#include <stdlib.h>
8#include <string.h>
9#include <stdio.h>
10#include <unistd.h>
11#include <errno.h>
12#include <sys/mman.h>
13#include "client/window.h"
14#include "client/buffer.h"
15#include "list.h"
16#include "log.h"
17
18static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
19 uint32_t serial, struct wl_surface *surface, wl_fixed_t sx_w, wl_fixed_t sy_w) {
20 struct window *window = data;
21 if (window->registry->pointer) {
22 struct wl_cursor_image *image = window->cursor.cursor->images[0];
23 wl_pointer_set_cursor(pointer, serial, window->cursor.surface, image->hotspot_x, image->hotspot_y);
24 }
25}
26
27static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
28 uint32_t serial, struct wl_surface *surface) {
29}
30
31static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
32 uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) {
33 struct window *window = data;
34
35 window->pointer_input.last_x = wl_fixed_to_int(sx_w);
36 window->pointer_input.last_y = wl_fixed_to_int(sy_w);
37}
38
39static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
40 uint32_t time, uint32_t button, uint32_t state_w) {
41 struct window *window = data;
42 struct pointer_input *input = &window->pointer_input;
43
44 if (window->pointer_input.notify_button) {
45 window->pointer_input.notify_button(window, input->last_x, input->last_y, button, state_w);
46 }
47}
48
49static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
50 uint32_t time, uint32_t axis, wl_fixed_t value) {
51 struct window *window = data;
52 enum scroll_direction direction;
53
54 switch (axis) {
55 case 0:
56 direction = wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN;
57 break;
58 case 1:
59 direction = wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT;
60 break;
61 default:
62 sway_log(L_DEBUG, "Unexpected axis value on mouse scroll");
63 return;
64 }
65
66 if (window->pointer_input.notify_scroll) {
67 window->pointer_input.notify_scroll(window, direction);
68 }
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
79void shell_surface_configure(void *data, struct wl_shell_surface *wl_shell_surface,
80 uint32_t edges, int32_t width, int32_t height) {
81 struct window *window = data;
82 window->width = width;
83 window->height = height;
84}
85
86static const struct wl_shell_surface_listener surface_listener = {
87 .configure = shell_surface_configure
88};
89
90void window_make_shell(struct window *window) {
91 window->shell_surface = wl_shell_get_shell_surface(window->registry->shell, window->surface);
92 wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window);
93 wl_shell_surface_set_toplevel(window->shell_surface);
94}
95
96struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height,
97 int32_t scale, bool shell_surface) {
98 struct window *window = malloc(sizeof(struct window));
99 memset(window, 0, sizeof(struct window));
100 window->width = width;
101 window->height = height;
102 window->scale = scale;
103 window->registry = registry;
104 window->font = "monospace 10";
105
106 window->surface = wl_compositor_create_surface(registry->compositor);
107 if (shell_surface) {
108 window_make_shell(window);
109 }
110 if (registry->pointer) {
111 wl_pointer_add_listener(registry->pointer, &pointer_listener, window);
112 }
113
114 get_next_buffer(window);
115
116 if (registry->pointer) {
117 char *cursor_theme = getenv("SWAY_CURSOR_THEME");
118 if (!cursor_theme) {
119 cursor_theme = "default";
120 }
121 char *cursor_size = getenv("SWAY_CURSOR_SIZE");
122 if (!cursor_size) {
123 cursor_size = "16";
124 }
125
126 sway_log(L_DEBUG, "Cursor scale: %d", scale);
127 window->cursor.cursor_theme = wl_cursor_theme_load(cursor_theme,
128 atoi(cursor_size) * scale, registry->shm);
129 window->cursor.cursor = wl_cursor_theme_get_cursor(window->cursor.cursor_theme, "left_ptr");
130 window->cursor.surface = wl_compositor_create_surface(registry->compositor);
131
132 struct wl_cursor_image *image = window->cursor.cursor->images[0];
133 struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
134 wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0);
135 wl_surface_set_buffer_scale(window->cursor.surface, scale);
136 wl_surface_damage(window->cursor.surface, 0, 0,
137 image->width, image->height);
138 wl_surface_commit(window->cursor.surface);
139 }
140
141 return window;
142}
143
144static void frame_callback(void *data, struct wl_callback *callback, uint32_t time) {
145 struct window *window = data;
146 wl_callback_destroy(callback);
147 window->frame_cb = NULL;
148}
149
150static const struct wl_callback_listener listener = {
151 frame_callback
152};
153
154int window_prerender(struct window *window) {
155 if (window->frame_cb) {
156 return 0;
157 }
158
159 get_next_buffer(window);
160 return 1;
161}
162
163int window_render(struct window *window) {
164 window->frame_cb = wl_surface_frame(window->surface);
165 wl_callback_add_listener(window->frame_cb, &listener, window);
166
167 wl_surface_attach(window->surface, window->buffer->buffer, 0, 0);
168 wl_surface_set_buffer_scale(window->surface, window->scale);
169 wl_surface_damage(window->surface, 0, 0, window->width, window->height);
170 wl_surface_commit(window->surface);
171
172 return 1;
173}
174
175void window_teardown(struct window *window) {
176 // TODO
177}