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 { struct sway_transaction *transaction; struct sway_node *node; union { - struct sway_output_state *output_state; - struct sway_workspace_state *workspace_state; - struct sway_container_state *container_state; + struct sway_output_state output_state; + struct sway_workspace_state workspace_state; + struct sway_container_state container_state; }; uint32_t serial; }; -static struct sway_transaction *transaction_create() { +static struct sway_transaction *transaction_create(void) { struct sway_transaction *transaction = calloc(1, sizeof(struct sway_transaction)); if (!sway_assert(transaction, "Unable to allocate transaction")) { @@ -86,14 +86,7 @@ static void transaction_destroy(struct sway_transaction *transaction) { static void copy_output_state(struct sway_output *output, struct sway_transaction_instruction *instruction) { - struct sway_output_state *state = - calloc(1, sizeof(struct sway_output_state)); - if (!state) { - wlr_log(WLR_ERROR, "Could not allocate output state"); - return; - } - instruction->output_state = state; - + struct sway_output_state *state = &instruction->output_state; state->workspaces = create_list(); list_cat(state->workspaces, output->workspaces); @@ -102,13 +95,7 @@ static void copy_output_state(struct sway_output *output, static void copy_workspace_state(struct sway_workspace *ws, struct sway_transaction_instruction *instruction) { - struct sway_workspace_state *state = - calloc(1, sizeof(struct sway_workspace_state)); - if (!state) { - wlr_log(WLR_ERROR, "Could not allocate workspace state"); - return; - } - instruction->workspace_state = state; + struct sway_workspace_state *state = &instruction->workspace_state; state->fullscreen = ws->fullscreen; state->x = ws->x; @@ -138,13 +125,7 @@ static void copy_workspace_state(struct sway_workspace *ws, static void copy_container_state(struct sway_container *container, struct sway_transaction_instruction *instruction) { - struct sway_container_state *state = - calloc(1, sizeof(struct sway_container_state)); - if (!state) { - wlr_log(WLR_ERROR, "Could not allocate container state"); - return; - } - instruction->container_state = state; + struct sway_container_state *state = &instruction->container_state; state->layout = container->layout; state->con_x = container->x; @@ -301,15 +282,15 @@ static void transaction_apply(struct sway_transaction *transaction) { case N_ROOT: break; case N_OUTPUT: - apply_output_state(node->sway_output, instruction->output_state); + apply_output_state(node->sway_output, &instruction->output_state); break; case N_WORKSPACE: apply_workspace_state(node->sway_workspace, - instruction->workspace_state); + &instruction->workspace_state); break; case N_CONTAINER: apply_container_state(node->sway_container, - instruction->container_state); + &instruction->container_state); break; } @@ -335,7 +316,7 @@ static bool transaction_same_nodes(struct sway_transaction *a, return true; } -static void transaction_progress_queue() { +static void transaction_progress_queue(void) { if (!server.transactions->length) { return; } @@ -390,7 +371,7 @@ static bool should_configure(struct sway_node *node, return false; } struct sway_container_state *cstate = &node->sway_container->current; - struct sway_container_state *istate = instruction->container_state; + struct sway_container_state *istate = &instruction->container_state; #ifdef HAVE_XWAYLAND // Xwayland views are position-aware and need to be reconfigured // when their position changes. @@ -418,10 +399,10 @@ static void transaction_commit(struct sway_transaction *transaction) { struct sway_node *node = instruction->node; if (should_configure(node, instruction)) { instruction->serial = view_configure(node->sway_container->view, - instruction->container_state->view_x, - instruction->container_state->view_y, - instruction->container_state->view_width, - instruction->container_state->view_height); + instruction->container_state.view_x, + instruction->container_state.view_y, + instruction->container_state.view_width, + instruction->container_state.view_height); ++transaction->num_waiting; // 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, int width, int height) { struct sway_transaction_instruction *instruction = view->container->node.instruction; - if (instruction->container_state->view_width == width && - instruction->container_state->view_height == height) { + if (instruction->container_state.view_width == width && + instruction->container_state.view_height == height) { set_instruction_ready(instruction); } } 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) { floater = floater->parent; } bool is_sticky = container_is_floating(floater) && floater->is_sticky; + if (!is_sticky && !workspace_is_visible(workspace)) { + return false; + } // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *con = view->container; while (con) { enum sway_container_layout layout = container_parent_layout(con); - if (layout == L_TABBED || layout == L_STACKED) { + if ((layout == L_TABBED || layout == L_STACKED) + && !container_is_floating(con)) { struct sway_node *parent = con->parent ? &con->parent->node : &con->workspace->node; if (seat_get_active_tiling_child(seat, parent) != &con->node) { @@ -1008,10 +1012,6 @@ bool view_is_visible(struct sway_view *view) { !container_is_fullscreen_or_child(view->container)) { return false; } - // Check the workspace is visible - if (!is_sticky) { - return workspace_is_visible(workspace); - } return true; } 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 @@ #define _POSIX_C_SOURCE 200809L #include <fcntl.h> +#include <sys/ioctl.h> #include <json-c/json.h> #include <stdlib.h> #include <string.h> @@ -34,18 +35,35 @@ bool status_handle_readable(struct status_line *status) { switch (status->protocol) { case PROTOCOL_UNDEF: errno = 0; - read_bytes = getline(&status->buffer, - &status->buffer_size, status->read); - if (errno == EAGAIN) { - clearerr(status->read); - } else if (errno) { + int available_bytes; + if (ioctl(status->read_fd, FIONREAD, &available_bytes) == -1) { + wlr_log(WLR_ERROR, "Unable to read status command output size"); status_error(status, "[error reading from status command]"); return true; } + if ((size_t)available_bytes + 1 > status->buffer_size) { + // need room for leading '\0' too + status->buffer_size = available_bytes + 1; + status->buffer = realloc(status->buffer, status->buffer_size); + } + if (status->buffer == NULL) { + wlr_log_errno(WLR_ERROR, "Unable to read status line"); + status_error(status, "[error reading from status command]"); + return true; + } + + read_bytes = read(status->read_fd, status->buffer, available_bytes); + if (read_bytes != available_bytes) { + status_error(status, "[error reading from status command]"); + return true; + } + status->buffer[available_bytes] = 0; + // the header must be sent completely the first time round + char *newline = strchr(status->buffer, '\n'); json_object *header, *version; - if (status->buffer[read_bytes - 1] == '\n' + if (newline != NULL && (header = json_tokener_parse(status->buffer)) && json_object_object_get_ex(header, "version", &version) && json_object_get_int(version) == 1) { @@ -67,13 +85,9 @@ bool status_handle_readable(struct status_line *status) { wl_list_init(&status->blocks); status->tokener = json_tokener_new(); - read_bytes = getdelim(&status->buffer, &status->buffer_size, EOF, status->read); - if (read_bytes > 0) { - status->buffer_index = read_bytes; - return i3bar_handle_readable(status); - } else { - return false; - } + status->buffer_index = strlen(newline + 1); + memmove(status->buffer, newline + 1, status->buffer_index + 1); + return i3bar_handle_readable(status); } wlr_log(WLR_DEBUG, "Using text protocol."); |