Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wm: split geometry trigger into geometry and position #1335

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ enum animation_trigger {
ANIMATION_TRIGGER_CLOSE,
/// When a window's geometry changes
ANIMATION_TRIGGER_GEOMETRY,
/// When a window's position changes
ANIMATION_TRIGGER_POSITION,

ANIMATION_TRIGGER_INVALID,
ANIMATION_TRIGGER_COUNT = ANIMATION_TRIGGER_INVALID,
Expand All @@ -97,6 +99,7 @@ static const char *animation_trigger_names[] attr_unused = {
[ANIMATION_TRIGGER_OPEN] = "open",
[ANIMATION_TRIGGER_CLOSE] = "close",
[ANIMATION_TRIGGER_GEOMETRY] = "geometry",
[ANIMATION_TRIGGER_POSITION] = "position",
};

struct script;
Expand Down
12 changes: 9 additions & 3 deletions src/wm/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,10 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d
bool will_never_render =
(!w->ever_damaged || w->win_image == NULL) && w->state != WSTATE_MAPPED;
auto win_ctx = win_script_context_prepare(ps, w);
bool geometry_changed = !win_geometry_eq(w->previous.g, w->g);

bool geometry_changed = win_geometry_changed(w->previous.g, w->g);
bool position_changed = win_position_changed(w->previous.g, w->g);

auto old_state = w->previous.state;

w->previous.state = w->state;
Expand All @@ -1834,7 +1837,7 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d
// This window won't be rendered, so we don't need to run the animations.
bool state_changed = old_state != w->state ||
win_ctx.opacity_before != win_ctx.opacity ||
geometry_changed;
geometry_changed || position_changed;
return state_changed || (w->running_animation_instance != NULL);
}

Expand Down Expand Up @@ -1894,6 +1897,9 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d
assert(false);
return true;
}
} else if (position_changed) {
assert(w->state == WSTATE_MAPPED);
trigger = ANIMATION_TRIGGER_POSITION;
} else if (geometry_changed) {
assert(w->state == WSTATE_MAPPED);
trigger = ANIMATION_TRIGGER_GEOMETRY;
Expand Down Expand Up @@ -1980,7 +1986,7 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d
memory[output_indices[WIN_SCRIPT_SAVED_IMAGE_BLEND]] =
1 - memory[output_indices[WIN_SCRIPT_SAVED_IMAGE_BLEND]];
}
if (geometry_changed) {
if (geometry_changed || position_changed) {
// If the window has moved, we need to adjust scripts
// outputs so that the window will stay in the same position and
// size after applying the animation. This way the window's size
Expand Down
15 changes: 12 additions & 3 deletions src/wm/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,19 @@ win_options(const struct win *w) {
win_maybe_options_fold(w->options_override, w->options), *w->options_default);
}

/// Check if win_geometry `a` and `b` have the same sizes and positions. Border width is
/// Check if the window has changed in size. Border width is
/// not considered.
static inline bool win_geometry_eq(struct win_geometry a, struct win_geometry b) {
return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
static inline bool win_geometry_changed(struct win_geometry a, struct win_geometry b) {
return a.width != b.width || a.height != b.height;
}

/// Check if the window position has changed.
static inline bool win_position_changed(struct win_geometry a, struct win_geometry b) {
if (win_geometry_changed(a, b)) {
return false;
}

return a.x != b.x || a.y != b.y;
}

/// Process pending updates/images flags on a window. Has to be called in X critical
Expand Down