diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-02-08 07:40:41 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-02-08 07:40:41 -0500 |
commit | 91d6113d4ad15e38308a795313da92b0ec249bcf (patch) | |
tree | 6f0227ce0465b90443355672f9fabb58ccbe5ca8 | |
parent | Squash trailing whitespace (diff) | |
parent | Replace deprecated function wlc_output_get_pixels. (diff) | |
download | sway-91d6113d4ad15e38308a795313da92b0ec249bcf.tar.gz sway-91d6113d4ad15e38308a795313da92b0ec249bcf.tar.zst sway-91d6113d4ad15e38308a795313da92b0ec249bcf.zip |
Merge pull request #488 from mikkeloscar/get-pixels
Replace deprecated function wlc_output_get_pixels.
-rw-r--r-- | include/ipc-server.h | 7 | ||||
-rw-r--r-- | sway/handlers.c | 7 | ||||
-rw-r--r-- | sway/ipc-server.c | 74 |
3 files changed, 70 insertions, 18 deletions
diff --git a/include/ipc-server.h b/include/ipc-server.h index 96b7902f..aef3aa07 100644 --- a/include/ipc-server.h +++ b/include/ipc-server.h | |||
@@ -1,6 +1,8 @@ | |||
1 | #ifndef _SWAY_IPC_SERVER_H | 1 | #ifndef _SWAY_IPC_SERVER_H |
2 | #define _SWAY_IPC_SERVER_H | 2 | #define _SWAY_IPC_SERVER_H |
3 | 3 | ||
4 | #include <wlc/wlc.h> | ||
5 | |||
4 | #include "container.h" | 6 | #include "container.h" |
5 | #include "config.h" | 7 | #include "config.h" |
6 | #include "ipc.h" | 8 | #include "ipc.h" |
@@ -27,4 +29,9 @@ void ipc_event_modifier(uint32_t modifier, const char *state); | |||
27 | void ipc_event_binding_keyboard(struct sway_binding *sb); | 29 | void ipc_event_binding_keyboard(struct sway_binding *sb); |
28 | const char *swayc_type_string(enum swayc_types type); | 30 | const char *swayc_type_string(enum swayc_types type); |
29 | 31 | ||
32 | /** | ||
33 | * Send pixel data to registered clients. | ||
34 | */ | ||
35 | void ipc_get_pixels(wlc_handle output); | ||
36 | |||
30 | #endif | 37 | #endif |
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 | ||
153 | static void handle_output_post_render(wlc_handle output) { | ||
154 | ipc_get_pixels(output); | ||
155 | } | ||
156 | |||
153 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { | 157 | static 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 | ||
41 | static list_t *ipc_get_pixel_requests = NULL; | ||
42 | |||
43 | struct get_pixels_request { | ||
44 | struct ipc_client *client; | ||
45 | wlc_handle output; | ||
46 | }; | ||
47 | |||
41 | struct sockaddr_un *ipc_user_sockaddr(void); | 48 | struct sockaddr_un *ipc_user_sockaddr(void); |
42 | int ipc_handle_connection(int fd, uint32_t mask, void *data); | 49 | int ipc_handle_connection(int fd, uint32_t mask, void *data); |
43 | int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data); | 50 | int 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 | ||
234 | bool get_pixels_callback(const struct wlc_size *size, uint8_t *rgba, void *arg) { | 242 | void 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 | ||
251 | void ipc_client_handle_command(struct ipc_client *client) { | 287 | void 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: |