Skip to content

Commit

Permalink
Merge branch 'swaywm:master' into move_to_container
Browse files Browse the repository at this point in the history
  • Loading branch information
ccdunder authored Nov 14, 2024
2 parents 392fca7 + fdc4318 commit 8973c2e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 28 deletions.
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh -eu

prev=$(git describe --tags --abbrev=0)
next=$(meson rewrite kwargs info project / 2>&1 >/dev/null | jq -r '.kwargs["project#/"].version')
next=$(meson rewrite kwargs info project / | jq -r '.kwargs["project#/"].version')

case "$next" in
*-dev)
Expand Down
24 changes: 16 additions & 8 deletions sway/config/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,6 @@ static bool finalize_output_config(struct output_config *oc, struct sway_output
wlr_output_layout_add_auto(root->output_layout, wlr_output);
}

// Update output->{lx, ly, width, height}
struct wlr_box output_box;
wlr_output_layout_get_box(root->output_layout, wlr_output, &output_box);
output->lx = output_box.x;
output->ly = output_box.y;
output->width = output_box.width;
output->height = output_box.height;

if (!output->enabled) {
output_enable(output);
}
Expand All @@ -562,6 +554,15 @@ static bool finalize_output_config(struct output_config *oc, struct sway_output
return true;
}

static void output_update_position(struct sway_output *output) {
struct wlr_box output_box;
wlr_output_layout_get_box(root->output_layout, output->wlr_output, &output_box);
output->lx = output_box.x;
output->ly = output_box.y;
output->width = output_box.width;
output->height = output_box.height;
}

// find_output_config_from_list returns a merged output_config containing all
// stored configuration that applies to the specified output.
static struct output_config *find_output_config_from_list(
Expand Down Expand Up @@ -933,6 +934,13 @@ static bool apply_resolved_output_configs(struct matched_output_config *configs,
sway_log(SWAY_DEBUG, "Finalizing config for %s",
cfg->output->wlr_output->name);
finalize_output_config(cfg->config, cfg->output);
}

// Output layout being applied in finalize_output_config can shift outputs
// around, so we do a second pass to update positions and arrange.
for (size_t idx = 0; idx < configs_len; idx++) {
struct matched_output_config *cfg = &configs[idx];
output_update_position(cfg->output);
arrange_layers(cfg->output);
}

Expand Down
72 changes: 58 additions & 14 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,11 @@ static bool output_can_tear(struct sway_output *output) {
static int output_repaint_timer_handler(void *data) {
struct sway_output *output = data;

output->wlr_output->frame_pending = false;
if (!output->enabled) {
return 0;
}

output->wlr_output->frame_pending = false;

output_configure_scene(output, &root->root_scene->tree.node, 1.0f);

struct wlr_scene_output_state_options opts = {
Expand All @@ -282,6 +281,7 @@ static int output_repaint_timer_handler(void *data) {
struct wlr_output_state pending;
wlr_output_state_init(&pending);
if (!wlr_scene_output_build_state(output->scene_output, &pending, &opts)) {
wlr_output_state_finish(&pending);
return 0;
}

Expand Down Expand Up @@ -457,19 +457,47 @@ static void handle_request_state(struct wl_listener *listener, void *data) {
struct sway_output *output =
wl_container_of(listener, output, request_state);
const struct wlr_output_event_request_state *event = data;
const struct wlr_output_state *state = event->state;

uint32_t committed = event->state->committed;
wlr_output_commit_state(output->wlr_output, event->state);
// Store the requested changes so that the active configuration is
// consistent with the current state, and to avoid duplicate logic to apply
// the changes.
struct output_config *oc = new_output_config(output->wlr_output->name);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
return;
}

int committed = state->committed;
if (committed & WLR_OUTPUT_STATE_MODE) {
if (state->mode != NULL) {
oc->width = state->mode->width;
oc->height = state->mode->height;
oc->refresh_rate = state->mode->refresh / 1000.f;
} else {
oc->width = state->custom_mode.width;
oc->height = state->custom_mode.height;
oc->refresh_rate = state->custom_mode.refresh / 1000.f;
}
committed &= ~WLR_OUTPUT_STATE_MODE;
}
if (committed & WLR_OUTPUT_STATE_SCALE) {
oc->scale = state->scale;
committed &= ~WLR_OUTPUT_STATE_SCALE;
}
if (committed & WLR_OUTPUT_STATE_TRANSFORM) {
oc->transform = state->transform;
committed &= ~WLR_OUTPUT_STATE_TRANSFORM;
}

if (committed & (
WLR_OUTPUT_STATE_MODE |
WLR_OUTPUT_STATE_TRANSFORM |
WLR_OUTPUT_STATE_SCALE)) {
arrange_layers(output);
arrange_output(output);
transaction_commit_dirty();
// We do not expect or support any other changes here
assert(committed == 0);
store_output_config(oc);
apply_stored_output_configs();

update_output_manager_config(output->server);
if (server.delayed_modeset != NULL) {
wl_event_source_remove(server.delayed_modeset);
server.delayed_modeset = NULL;
}
}

Expand Down Expand Up @@ -554,6 +582,10 @@ void handle_new_output(struct wl_listener *listener, void *data) {
static struct output_config *output_config_for_config_head(
struct wlr_output_configuration_head_v1 *config_head) {
struct output_config *oc = new_output_config(config_head->state.output->name);
if (!oc) {
return NULL;
}

oc->enabled = config_head->state.enabled;
if (!oc->enabled) {
return oc;
Expand Down Expand Up @@ -584,7 +616,8 @@ static void output_manager_apply(struct sway_server *server,
size_t configs_len = config->output_configs->length + wl_list_length(&cfg->heads);
struct output_config **configs = calloc(configs_len, sizeof(*configs));
if (!configs) {
goto done;
sway_log(SWAY_ERROR, "Allocation failed");
goto error;
}
size_t start_new_configs = config->output_configs->length;
for (size_t idx = 0; idx < start_new_configs; idx++) {
Expand All @@ -597,13 +630,19 @@ static void output_manager_apply(struct sway_server *server,
// Generate the configuration and store it as a temporary
// config. We keep a record of it so we can remove it later.
struct output_config *oc = output_config_for_config_head(config_head);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
goto error_config;
}
configs[config_idx++] = oc;
}

// Try to commit without degrade to off enabled. Note that this will fail
// if any output configured for enablement fails to be enabled, even if it
// was not part of the config heads we were asked to configure.
ok = apply_output_configs(configs, configs_len, test_only, false);

error_config:
for (size_t idx = start_new_configs; idx < configs_len; idx++) {
struct output_config *cfg = configs[idx];
if (!test_only && ok) {
Expand All @@ -614,7 +653,7 @@ static void output_manager_apply(struct sway_server *server,
}
free(configs);

done:
error:
if (ok) {
wlr_output_configuration_v1_send_succeeded(cfg);
if (server->delayed_modeset != NULL) {
Expand Down Expand Up @@ -649,6 +688,11 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
struct sway_output *output = event->output->data;

struct output_config *oc = new_output_config(output->wlr_output->name);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
return;
}

switch (event->mode) {
case ZWLR_OUTPUT_POWER_V1_MODE_OFF:
oc->power = 0;
Expand Down
5 changes: 3 additions & 2 deletions sway/desktop/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,14 @@ static void arrange_container(struct sway_container *con,
int border_bottom = con->current.border_bottom ? border_width : 0;
int border_left = con->current.border_left ? border_width : 0;
int border_right = con->current.border_right ? border_width : 0;
int vert_border_height = MAX(0, height - border_top - border_bottom);

wlr_scene_rect_set_size(con->border.top, width, border_top);
wlr_scene_rect_set_size(con->border.bottom, width, border_bottom);
wlr_scene_rect_set_size(con->border.left,
border_left, height - border_top - border_bottom);
border_left, vert_border_height);
wlr_scene_rect_set_size(con->border.right,
border_right, height - border_top - border_bottom);
border_right, vert_border_height);

wlr_scene_node_set_position(&con->border.top->node, 0, 0);
wlr_scene_node_set_position(&con->border.bottom->node,
Expand Down
4 changes: 2 additions & 2 deletions sway/tree/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void container_arrange_title_bar(struct sway_container *con) {
h_padding = width - config->titlebar_h_padding - marks_buffer_width;
}

h_padding = MAX(h_padding, 0);
h_padding = MAX(h_padding, config->titlebar_h_padding);

int alloc_width = MIN((int)node->width,
width - h_padding - config->titlebar_h_padding);
Expand All @@ -375,7 +375,7 @@ void container_arrange_title_bar(struct sway_container *con) {
h_padding = config->titlebar_h_padding;
}

h_padding = MAX(h_padding, 0);
h_padding = MAX(h_padding, config->titlebar_h_padding);

int alloc_width = MIN((int) node->width,
width - h_padding - config->titlebar_h_padding);
Expand Down
12 changes: 12 additions & 0 deletions swaybar/tray/watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static int handle_lost_service(sd_bus_message *msg,
list_del(watcher->items, idx--);
sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
"StatusNotifierItemUnregistered", "s", id);
sd_bus_emit_properties_changed(watcher->bus, obj_path, watcher->interface,
"RegisteredStatusNotifierItems", NULL);
free(id);
if (using_standard_protocol(watcher)) {
break;
Expand All @@ -50,6 +52,10 @@ static int handle_lost_service(sd_bus_message *msg,
sway_log(SWAY_DEBUG, "Unregistering Status Notifier Host '%s'", service);
free(watcher->hosts->items[idx]);
list_del(watcher->hosts, idx);
if (watcher->hosts->length == 0) {
sd_bus_emit_properties_changed(watcher->bus, obj_path, watcher->interface,
"IsStatusNotifierHostRegistered", NULL);
}
}
}

Expand Down Expand Up @@ -82,6 +88,8 @@ static int register_sni(sd_bus_message *msg, void *data, sd_bus_error *error) {
if (list_seq_find(watcher->items, cmp_id, id) == -1) {
sway_log(SWAY_DEBUG, "Registering Status Notifier Item '%s'", id);
list_add(watcher->items, id);
sd_bus_emit_properties_changed(watcher->bus, obj_path, watcher->interface,
"RegisteredStatusNotifierItems", NULL);
sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
"StatusNotifierItemRegistered", "s", id);
} else {
Expand All @@ -104,6 +112,10 @@ static int register_host(sd_bus_message *msg, void *data, sd_bus_error *error) {
if (list_seq_find(watcher->hosts, cmp_id, service) == -1) {
sway_log(SWAY_DEBUG, "Registering Status Notifier Host '%s'", service);
list_add(watcher->hosts, strdup(service));
if (watcher->hosts->length == 1) {
sd_bus_emit_properties_changed(watcher->bus, obj_path, watcher->interface,
"IsStatusNotifierHostRegistered", NULL);
}
sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
"StatusNotifierHostRegistered", "");
} else {
Expand Down
4 changes: 3 additions & 1 deletion swaynag/swaynag.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ static void output_scale(void *data, struct wl_output *output,
swaynag_output->scale = factor;
if (swaynag_output->swaynag->output == swaynag_output) {
swaynag_output->swaynag->scale = swaynag_output->scale;
update_all_cursors(swaynag_output->swaynag);
if (!swaynag_output->swaynag->cursor_shape_manager) {
update_all_cursors(swaynag_output->swaynag);
}
render_frame(swaynag_output->swaynag);
}
}
Expand Down

0 comments on commit 8973c2e

Please sign in to comment.