Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Comments

xdg-toplevel: refactor configure/state flow#3199

Merged
emersion merged 3 commits intoswaywm:masterfrom
vyivel:xdg-toplevel-refactor
Sep 21, 2021
Merged

xdg-toplevel: refactor configure/state flow#3199
emersion merged 3 commits intoswaywm:masterfrom
vyivel:xdg-toplevel-refactor

Conversation

@vyivel
Copy link
Member

@vyivel vyivel commented Sep 16, 2021

See individual commits.

Fixes #2330


Preliminary work for #3151.
If this is fine, I'll make a similar PR for wlr_layer_surface.

This is a breaking change: compositors that used to check wlr_xdg_toplevel.client_pending will now have to check wlr_xdg_toplevel.requested.

Copy link
Member

@ifreund ifreund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Splitting off the things not tied to the surface commit into a separate struct is a great idea and much cleaner. I'm also quite happy with the new names you've chosen, I find "scheduled" and "requested" much more clear.

@emersion emersion added the breaking Breaking change in public API label Sep 16, 2021
@vyivel vyivel force-pushed the xdg-toplevel-refactor branch from a9b9e23 to 114950e Compare September 16, 2021 14:00
@vyivel
Copy link
Member Author

vyivel commented Sep 18, 2021

Giving it some more thoughts, allowing requested to be accessed only on map event feels hacky. Also, considering that requested properties are double-buffered, I suppose they must a part of state.

Nevermind that. :P

@vyivel vyivel force-pushed the xdg-toplevel-refactor branch from 114950e to 309d6f8 Compare September 18, 2021 07:28
@vyivel vyivel changed the title xdg-toplevel: refactor states xdg-toplevel: refactor configure/state flow Sep 18, 2021
@vyivel
Copy link
Member Author

vyivel commented Sep 18, 2021

Technically scheduled isn't a state too, so wlr_xdg_toplevel_configure is added. This also avoids having useless size constraint fields in scheduled.

@vyivel vyivel requested a review from ifreund September 18, 2021 07:35
@vyivel vyivel force-pushed the xdg-toplevel-refactor branch from 8a83907 to 309d6f8 Compare September 18, 2021 08:31
Copy link
Member

@ifreund ifreund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating configure and state into different structs seems like a great idea to me!

@vyivel vyivel force-pushed the xdg-toplevel-refactor branch from 309d6f8 to a1c5055 Compare September 18, 2021 15:04
Copy link
Member

@ifreund ifreund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vyivel vyivel force-pushed the xdg-toplevel-refactor branch from a1c5055 to c6efee1 Compare September 18, 2021 15:40
Previously, `wlr_xdg_toplevel` didn't follow the usual "current state +
pending state" pattern and instead had confusingly named
`client_pending` and `server_pending`. This commit removes them, and
instead introduces `wlr_xdg_toplevel.scheduled` to store the properties
that are yet to be sent to a client, and `wlr_xdg_toplevel.requested`
to store the properties that a client has requested. They have different
types to emphasize that they aren't actual states.
@vyivel vyivel force-pushed the xdg-toplevel-refactor branch from 743ab8f to 2151257 Compare September 20, 2021 14:15
This commit removes any checks whether a configure will change anything
and makes configures be sent unconditionally. Additionally, configures
are scheduled on xdg_toplevel.{un,}set_{maximized,fullscreen} events.
@vyivel vyivel force-pushed the xdg-toplevel-refactor branch from 2151257 to e68d801 Compare September 20, 2021 14:18
@vyivel vyivel requested a review from ifreund September 20, 2021 14:46
Copy link
Member

@ifreund ifreund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest iteration looks great to me, it simplifies the code fixing #2330 and the problems discussed in #3206. It also makes subtle, hard to debug, bugs such as the one fixed by #2342 impossible.

wl_array_init(&states);
if (surface->toplevel->server_pending.maximized) {
if (surface->toplevel->scheduled.maximized) {
uint32_t *s = wl_array_add(&states, sizeof(uint32_t));
Copy link
Member

@emersion emersion Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated note: seems like this code could be cleaner by filling a uint32_t states[32], then creating a wl_array pointing to it. Something like:

uint32_t states[32];
size_t states_len = 0;

if (scheduled.maximized) {
    states[states_len++] = XDG_TOPLEVEL_STATE_MAXIMIZED;
}
…

assert(states_len < sizeof(states) / sizeof(states[0]));
struct wl_array states_arr = {
    .data = states,
    .size = states_len * sizeof(states[0]),
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a pretty unconventional way to create a wl_array, but sure, why not. Also avoids potential OOM errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah… Ideally wl_array could be marked const so that wayland-util functions like wl_array_add can't be called, but it's a bit too late. Here wl_array is just a read-only structure used by libwayland to send events.

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Thanks a bunch, and also thanks @ifreund for the review!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

breaking Breaking change in public API

Development

Successfully merging this pull request may close these issues.

Compositors may need to send no-op configure events

3 participants