summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-08 12:06:33 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-08 12:39:07 +0100
commit6f7cbf2eaca42c12af9bd4a8c3cc36dc6b180517 (patch)
tree6f0227ce0465b90443355672f9fabb58ccbe5ca8 /sway
parentSquash trailing whitespace (diff)
downloadsway-6f7cbf2eaca42c12af9bd4a8c3cc36dc6b180517.tar.gz
sway-6f7cbf2eaca42c12af9bd4a8c3cc36dc6b180517.tar.zst
sway-6f7cbf2eaca42c12af9bd4a8c3cc36dc6b180517.zip
Replace deprecated function wlc_output_get_pixels.
This makes IPC GET_PIXELS use the new `wlc_pixels_read` call instead of the deprecated `wlc_output_get_pixels`. The old version worked by passing a callback function to wlc which would grab the pixels and send them to the IPC client. The new version works by maintaining a list of clients who have requested the pixels of some output and then grap and send the pixels in the output_post_render hook of the `wlc_interface`.
Diffstat (limited to 'sway')
-rw-r--r--sway/handlers.c7
-rw-r--r--sway/ipc-server.c74
2 files changed, 63 insertions, 18 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index bb0c68e8..d3fbdc0f 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -150,6 +150,10 @@ static void handle_output_pre_render(wlc_handle output) {
150 } 150 }
151} 151}
152 152
153static void handle_output_post_render(wlc_handle output) {
154 ipc_get_pixels(output);
155}
156
153static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { 157static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) {
154 sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h); 158 sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h);
155 swayc_t *c = swayc_by_handle(output); 159 swayc_t *c = swayc_by_handle(output);
@@ -675,7 +679,8 @@ struct wlc_interface interface = {
675 .resolution = handle_output_resolution_change, 679 .resolution = handle_output_resolution_change,
676 .focus = handle_output_focused, 680 .focus = handle_output_focused,
677 .render = { 681 .render = {
678 .pre = handle_output_pre_render 682 .pre = handle_output_pre_render,
683 .post = handle_output_post_render
679 } 684 }
680 }, 685 },
681 .view = { 686 .view = {
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 63a6d703..a63026c6 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -5,7 +5,7 @@
5#include <sys/socket.h> 5#include <sys/socket.h>
6#include <sys/un.h> 6#include <sys/un.h>
7#include <stdbool.h> 7#include <stdbool.h>
8#include <wlc/wlc.h> 8#include <wlc/wlc-render.h>
9#include <unistd.h> 9#include <unistd.h>
10#include <stdlib.h> 10#include <stdlib.h>
11#include <sys/ioctl.h> 11#include <sys/ioctl.h>
@@ -38,6 +38,13 @@ struct ipc_client {
38 enum ipc_command_type subscribed_events; 38 enum ipc_command_type subscribed_events;
39}; 39};
40 40
41static list_t *ipc_get_pixel_requests = NULL;
42
43struct get_pixels_request {
44 struct ipc_client *client;
45 wlc_handle output;
46};
47
41struct sockaddr_un *ipc_user_sockaddr(void); 48struct sockaddr_un *ipc_user_sockaddr(void);
42int ipc_handle_connection(int fd, uint32_t mask, void *data); 49int ipc_handle_connection(int fd, uint32_t mask, void *data);
43int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data); 50int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data);
@@ -75,6 +82,7 @@ void ipc_init(void) {
75 setenv("SWAYSOCK", ipc_sockaddr->sun_path, 1); 82 setenv("SWAYSOCK", ipc_sockaddr->sun_path, 1);
76 83
77 ipc_client_list = create_list(); 84 ipc_client_list = create_list();
85 ipc_get_pixel_requests = create_list();
78 86
79 ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL); 87 ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
80} 88}
@@ -231,21 +239,49 @@ bool output_by_name_test(swayc_t *view, void *data) {
231 return !strcmp(name, view->name); 239 return !strcmp(name, view->name);
232} 240}
233 241
234bool get_pixels_callback(const struct wlc_size *size, uint8_t *rgba, void *arg) { 242void ipc_get_pixels(wlc_handle output) {
235 struct ipc_client *client = (struct ipc_client *)arg; 243 if (ipc_get_pixel_requests->length == 0) {
236 char response_header[9]; 244 return;
237 memset(response_header, 0, sizeof(response_header)); 245 }
238 response_header[0] = 1; 246
239 uint32_t *_size = (uint32_t *)(response_header + 1); 247 list_t *unhandled = create_list();
240 _size[0] = size->w; 248
241 _size[1] = size->h; 249 struct get_pixels_request *req;
242 size_t len = sizeof(response_header) + (size->w * size->h * 4); 250 int i;
243 char *payload = malloc(len); 251 for (i = 0; i < ipc_get_pixel_requests->length; ++i) {
244 memcpy(payload, response_header, sizeof(response_header)); 252 req = ipc_get_pixel_requests->items[i];
245 memcpy(payload + sizeof(response_header), rgba, len - sizeof(response_header)); 253 if (req->output != output) {
246 ipc_send_reply(client, payload, len); 254 list_add(unhandled, req);
247 free(payload); 255 continue;
248 return false; 256 }
257
258 const struct wlc_size *size = wlc_output_get_resolution(req->output);
259 struct wlc_geometry g = {
260 .size = *size,
261 .origin = { 0, 0 },
262 };
263 struct wlc_geometry g_out;
264 char response_header[9];
265 memset(response_header, 0, sizeof(response_header));
266 char *data = malloc(sizeof(response_header) + size->w * size->h * 4);
267 wlc_pixels_read(WLC_RGBA8888, &g, &g_out, data + sizeof(response_header));
268
269 response_header[0] = 1;
270 uint32_t *_size = (uint32_t *)(response_header + 1);
271 _size[0] = g_out.size.w;
272 _size[1] = g_out.size.h;
273 size_t len = sizeof(response_header) + (g_out.size.w * g_out.size.h * 4);
274 memcpy(data, response_header, sizeof(response_header));
275 ipc_send_reply(req->client, data, len);
276 free(data);
277 // free the request since it has been handled
278 free(req);
279 }
280
281 // free old list of pixel requests and set new list to all unhandled
282 // requests (request for another output).
283 list_free(ipc_get_pixel_requests);
284 ipc_get_pixel_requests = unhandled;
249} 285}
250 286
251void ipc_client_handle_command(struct ipc_client *client) { 287void ipc_client_handle_command(struct ipc_client *client) {
@@ -394,7 +430,11 @@ void ipc_client_handle_command(struct ipc_client *client) {
394 ipc_send_reply(client, response_header, sizeof(response_header)); 430 ipc_send_reply(client, response_header, sizeof(response_header));
395 break; 431 break;
396 } 432 }
397 wlc_output_get_pixels(output->handle, get_pixels_callback, client); 433 struct get_pixels_request *req = malloc(sizeof(struct get_pixels_request));
434 req->client = client;
435 req->output = output->handle;
436 list_add(ipc_get_pixel_requests, req);
437 wlc_output_schedule_render(output->handle);
398 break; 438 break;
399 } 439 }
400 case IPC_GET_BAR_CONFIG: 440 case IPC_GET_BAR_CONFIG: