diff options
-rw-r--r-- | sway/desktop/transaction.c | 55 | ||||
-rw-r--r-- | sway/tree/view.c | 10 | ||||
-rw-r--r-- | swaybar/status_line.c | 40 |
3 files changed, 50 insertions, 55 deletions
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 797f6b4c..34d99d52 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c | |||
@@ -31,14 +31,14 @@ struct sway_transaction_instruction { | |||
31 | struct sway_transaction *transaction; | 31 | struct sway_transaction *transaction; |
32 | struct sway_node *node; | 32 | struct sway_node *node; |
33 | union { | 33 | union { |
34 | struct sway_output_state *output_state; | 34 | struct sway_output_state output_state; |
35 | struct sway_workspace_state *workspace_state; | 35 | struct sway_workspace_state workspace_state; |
36 | struct sway_container_state *container_state; | 36 | struct sway_container_state container_state; |
37 | }; | 37 | }; |
38 | uint32_t serial; | 38 | uint32_t serial; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | static struct sway_transaction *transaction_create() { | 41 | static struct sway_transaction *transaction_create(void) { |
42 | struct sway_transaction *transaction = | 42 | struct sway_transaction *transaction = |
43 | calloc(1, sizeof(struct sway_transaction)); | 43 | calloc(1, sizeof(struct sway_transaction)); |
44 | if (!sway_assert(transaction, "Unable to allocate transaction")) { | 44 | if (!sway_assert(transaction, "Unable to allocate transaction")) { |
@@ -86,14 +86,7 @@ static void transaction_destroy(struct sway_transaction *transaction) { | |||
86 | 86 | ||
87 | static void copy_output_state(struct sway_output *output, | 87 | static void copy_output_state(struct sway_output *output, |
88 | struct sway_transaction_instruction *instruction) { | 88 | struct sway_transaction_instruction *instruction) { |
89 | struct sway_output_state *state = | 89 | struct sway_output_state *state = &instruction->output_state; |
90 | calloc(1, sizeof(struct sway_output_state)); | ||
91 | if (!state) { | ||
92 | wlr_log(WLR_ERROR, "Could not allocate output state"); | ||
93 | return; | ||
94 | } | ||
95 | instruction->output_state = state; | ||
96 | |||
97 | state->workspaces = create_list(); | 90 | state->workspaces = create_list(); |
98 | list_cat(state->workspaces, output->workspaces); | 91 | list_cat(state->workspaces, output->workspaces); |
99 | 92 | ||
@@ -102,13 +95,7 @@ static void copy_output_state(struct sway_output *output, | |||
102 | 95 | ||
103 | static void copy_workspace_state(struct sway_workspace *ws, | 96 | static void copy_workspace_state(struct sway_workspace *ws, |
104 | struct sway_transaction_instruction *instruction) { | 97 | struct sway_transaction_instruction *instruction) { |
105 | struct sway_workspace_state *state = | 98 | struct sway_workspace_state *state = &instruction->workspace_state; |
106 | calloc(1, sizeof(struct sway_workspace_state)); | ||
107 | if (!state) { | ||
108 | wlr_log(WLR_ERROR, "Could not allocate workspace state"); | ||
109 | return; | ||
110 | } | ||
111 | instruction->workspace_state = state; | ||
112 | 99 | ||
113 | state->fullscreen = ws->fullscreen; | 100 | state->fullscreen = ws->fullscreen; |
114 | state->x = ws->x; | 101 | state->x = ws->x; |
@@ -138,13 +125,7 @@ static void copy_workspace_state(struct sway_workspace *ws, | |||
138 | 125 | ||
139 | static void copy_container_state(struct sway_container *container, | 126 | static void copy_container_state(struct sway_container *container, |
140 | struct sway_transaction_instruction *instruction) { | 127 | struct sway_transaction_instruction *instruction) { |
141 | struct sway_container_state *state = | 128 | struct sway_container_state *state = &instruction->container_state; |
142 | calloc(1, sizeof(struct sway_container_state)); | ||
143 | if (!state) { | ||
144 | wlr_log(WLR_ERROR, "Could not allocate container state"); | ||
145 | return; | ||
146 | } | ||
147 | instruction->container_state = state; | ||
148 | 129 | ||
149 | state->layout = container->layout; | 130 | state->layout = container->layout; |
150 | state->con_x = container->x; | 131 | state->con_x = container->x; |
@@ -301,15 +282,15 @@ static void transaction_apply(struct sway_transaction *transaction) { | |||
301 | case N_ROOT: | 282 | case N_ROOT: |
302 | break; | 283 | break; |
303 | case N_OUTPUT: | 284 | case N_OUTPUT: |
304 | apply_output_state(node->sway_output, instruction->output_state); | 285 | apply_output_state(node->sway_output, &instruction->output_state); |
305 | break; | 286 | break; |
306 | case N_WORKSPACE: | 287 | case N_WORKSPACE: |
307 | apply_workspace_state(node->sway_workspace, | 288 | apply_workspace_state(node->sway_workspace, |
308 | instruction->workspace_state); | 289 | &instruction->workspace_state); |
309 | break; | 290 | break; |
310 | case N_CONTAINER: | 291 | case N_CONTAINER: |
311 | apply_container_state(node->sway_container, | 292 | apply_container_state(node->sway_container, |
312 | instruction->container_state); | 293 | &instruction->container_state); |
313 | break; | 294 | break; |
314 | } | 295 | } |
315 | 296 | ||
@@ -335,7 +316,7 @@ static bool transaction_same_nodes(struct sway_transaction *a, | |||
335 | return true; | 316 | return true; |
336 | } | 317 | } |
337 | 318 | ||
338 | static void transaction_progress_queue() { | 319 | static void transaction_progress_queue(void) { |
339 | if (!server.transactions->length) { | 320 | if (!server.transactions->length) { |
340 | return; | 321 | return; |
341 | } | 322 | } |
@@ -390,7 +371,7 @@ static bool should_configure(struct sway_node *node, | |||
390 | return false; | 371 | return false; |
391 | } | 372 | } |
392 | struct sway_container_state *cstate = &node->sway_container->current; | 373 | struct sway_container_state *cstate = &node->sway_container->current; |
393 | struct sway_container_state *istate = instruction->container_state; | 374 | struct sway_container_state *istate = &instruction->container_state; |
394 | #ifdef HAVE_XWAYLAND | 375 | #ifdef HAVE_XWAYLAND |
395 | // Xwayland views are position-aware and need to be reconfigured | 376 | // Xwayland views are position-aware and need to be reconfigured |
396 | // when their position changes. | 377 | // when their position changes. |
@@ -418,10 +399,10 @@ static void transaction_commit(struct sway_transaction *transaction) { | |||
418 | struct sway_node *node = instruction->node; | 399 | struct sway_node *node = instruction->node; |
419 | if (should_configure(node, instruction)) { | 400 | if (should_configure(node, instruction)) { |
420 | instruction->serial = view_configure(node->sway_container->view, | 401 | instruction->serial = view_configure(node->sway_container->view, |
421 | instruction->container_state->view_x, | 402 | instruction->container_state.view_x, |
422 | instruction->container_state->view_y, | 403 | instruction->container_state.view_y, |
423 | instruction->container_state->view_width, | 404 | instruction->container_state.view_width, |
424 | instruction->container_state->view_height); | 405 | instruction->container_state.view_height); |
425 | ++transaction->num_waiting; | 406 | ++transaction->num_waiting; |
426 | 407 | ||
427 | // From here on we are rendering a saved buffer of the view, which | 408 | // From here on we are rendering a saved buffer of the view, which |
@@ -513,8 +494,8 @@ void transaction_notify_view_ready_by_size(struct sway_view *view, | |||
513 | int width, int height) { | 494 | int width, int height) { |
514 | struct sway_transaction_instruction *instruction = | 495 | struct sway_transaction_instruction *instruction = |
515 | view->container->node.instruction; | 496 | view->container->node.instruction; |
516 | if (instruction->container_state->view_width == width && | 497 | if (instruction->container_state.view_width == width && |
517 | instruction->container_state->view_height == height) { | 498 | instruction->container_state.view_height == height) { |
518 | set_instruction_ready(instruction); | 499 | set_instruction_ready(instruction); |
519 | } | 500 | } |
520 | } | 501 | } |
diff --git a/sway/tree/view.c b/sway/tree/view.c index e370443c..a024f325 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -989,12 +989,16 @@ bool view_is_visible(struct sway_view *view) { | |||
989 | floater = floater->parent; | 989 | floater = floater->parent; |
990 | } | 990 | } |
991 | bool is_sticky = container_is_floating(floater) && floater->is_sticky; | 991 | bool is_sticky = container_is_floating(floater) && floater->is_sticky; |
992 | if (!is_sticky && !workspace_is_visible(workspace)) { | ||
993 | return false; | ||
994 | } | ||
992 | // Check view isn't in a tabbed or stacked container on an inactive tab | 995 | // Check view isn't in a tabbed or stacked container on an inactive tab |
993 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 996 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
994 | struct sway_container *con = view->container; | 997 | struct sway_container *con = view->container; |
995 | while (con) { | 998 | while (con) { |
996 | enum sway_container_layout layout = container_parent_layout(con); | 999 | enum sway_container_layout layout = container_parent_layout(con); |
997 | if (layout == L_TABBED || layout == L_STACKED) { | 1000 | if ((layout == L_TABBED || layout == L_STACKED) |
1001 | && !container_is_floating(con)) { | ||
998 | struct sway_node *parent = con->parent ? | 1002 | struct sway_node *parent = con->parent ? |
999 | &con->parent->node : &con->workspace->node; | 1003 | &con->parent->node : &con->workspace->node; |
1000 | if (seat_get_active_tiling_child(seat, parent) != &con->node) { | 1004 | if (seat_get_active_tiling_child(seat, parent) != &con->node) { |
@@ -1008,10 +1012,6 @@ bool view_is_visible(struct sway_view *view) { | |||
1008 | !container_is_fullscreen_or_child(view->container)) { | 1012 | !container_is_fullscreen_or_child(view->container)) { |
1009 | return false; | 1013 | return false; |
1010 | } | 1014 | } |
1011 | // Check the workspace is visible | ||
1012 | if (!is_sticky) { | ||
1013 | return workspace_is_visible(workspace); | ||
1014 | } | ||
1015 | return true; | 1015 | return true; |
1016 | } | 1016 | } |
1017 | 1017 | ||
diff --git a/swaybar/status_line.c b/swaybar/status_line.c index 48b43248..1442e1a0 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | #include <sys/ioctl.h> | ||
3 | #include <json-c/json.h> | 4 | #include <json-c/json.h> |
4 | #include <stdlib.h> | 5 | #include <stdlib.h> |
5 | #include <string.h> | 6 | #include <string.h> |
@@ -34,18 +35,35 @@ bool status_handle_readable(struct status_line *status) { | |||
34 | switch (status->protocol) { | 35 | switch (status->protocol) { |
35 | case PROTOCOL_UNDEF: | 36 | case PROTOCOL_UNDEF: |
36 | errno = 0; | 37 | errno = 0; |
37 | read_bytes = getline(&status->buffer, | 38 | int available_bytes; |
38 | &status->buffer_size, status->read); | 39 | if (ioctl(status->read_fd, FIONREAD, &available_bytes) == -1) { |
39 | if (errno == EAGAIN) { | 40 | wlr_log(WLR_ERROR, "Unable to read status command output size"); |
40 | clearerr(status->read); | ||
41 | } else if (errno) { | ||
42 | status_error(status, "[error reading from status command]"); | 41 | status_error(status, "[error reading from status command]"); |
43 | return true; | 42 | return true; |
44 | } | 43 | } |
45 | 44 | ||
45 | if ((size_t)available_bytes + 1 > status->buffer_size) { | ||
46 | // need room for leading '\0' too | ||
47 | status->buffer_size = available_bytes + 1; | ||
48 | status->buffer = realloc(status->buffer, status->buffer_size); | ||
49 | } | ||
50 | if (status->buffer == NULL) { | ||
51 | wlr_log_errno(WLR_ERROR, "Unable to read status line"); | ||
52 | status_error(status, "[error reading from status command]"); | ||
53 | return true; | ||
54 | } | ||
55 | |||
56 | read_bytes = read(status->read_fd, status->buffer, available_bytes); | ||
57 | if (read_bytes != available_bytes) { | ||
58 | status_error(status, "[error reading from status command]"); | ||
59 | return true; | ||
60 | } | ||
61 | status->buffer[available_bytes] = 0; | ||
62 | |||
46 | // the header must be sent completely the first time round | 63 | // the header must be sent completely the first time round |
64 | char *newline = strchr(status->buffer, '\n'); | ||
47 | json_object *header, *version; | 65 | json_object *header, *version; |
48 | if (status->buffer[read_bytes - 1] == '\n' | 66 | if (newline != NULL |
49 | && (header = json_tokener_parse(status->buffer)) | 67 | && (header = json_tokener_parse(status->buffer)) |
50 | && json_object_object_get_ex(header, "version", &version) | 68 | && json_object_object_get_ex(header, "version", &version) |
51 | && json_object_get_int(version) == 1) { | 69 | && json_object_get_int(version) == 1) { |
@@ -67,13 +85,9 @@ bool status_handle_readable(struct status_line *status) { | |||
67 | 85 | ||
68 | wl_list_init(&status->blocks); | 86 | wl_list_init(&status->blocks); |
69 | status->tokener = json_tokener_new(); | 87 | status->tokener = json_tokener_new(); |
70 | read_bytes = getdelim(&status->buffer, &status->buffer_size, EOF, status->read); | 88 | status->buffer_index = strlen(newline + 1); |
71 | if (read_bytes > 0) { | 89 | memmove(status->buffer, newline + 1, status->buffer_index + 1); |
72 | status->buffer_index = read_bytes; | 90 | return i3bar_handle_readable(status); |
73 | return i3bar_handle_readable(status); | ||
74 | } else { | ||
75 | return false; | ||
76 | } | ||
77 | } | 91 | } |
78 | 92 | ||
79 | wlr_log(WLR_DEBUG, "Using text protocol."); | 93 | wlr_log(WLR_DEBUG, "Using text protocol."); |