Skip to content

Commit

Permalink
win: expose information about monitors to animation script
Browse files Browse the repository at this point in the history
Define script context variables describing the monitor a window is on.

Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed May 19, 2024
1 parent 2899c78 commit 6624f09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -2190,13 +2190,22 @@ void unmap_win_start(struct managed_win *w) {

struct win_script_context
win_script_context_prepare(struct session *ps, struct managed_win *w) {
auto monitor =
(w->randr_monitor >= 0 && w->randr_monitor < ps->monitors.count)
? *pixman_region32_extents(&ps->monitors.regions[w->randr_monitor])

Check warning on line 2195 in src/win.c

View check run for this annotation

Codecov / codecov/patch

src/win.c#L2193-L2195

Added lines #L2193 - L2195 were not covered by tests
: (pixman_box32_t){
.x1 = 0, .y1 = 0, .x2 = ps->root_width, .y2 = ps->root_height};
struct win_script_context ret = {
.x = w->g.x,
.y = w->g.y,
.width = w->widthb,
.height = w->heightb,
.opacity = win_calc_opacity_target(ps, w),
.opacity_before = w->opacity,
.monitor_x = monitor.x1,
.monitor_y = monitor.y1,
.monitor_width = monitor.x2 - monitor.x1,
.monitor_height = monitor.y2 - monitor.y1,
};
return ret;
}
Expand Down
6 changes: 6 additions & 0 deletions src/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ struct managed_win {
struct win_script_context {
double x, y, width, height;
double opacity_before, opacity;
double monitor_x, monitor_y;
double monitor_width, monitor_height;
};

static const struct script_context_info win_script_context_info[] = {
Expand All @@ -326,6 +328,10 @@ static const struct script_context_info win_script_context_info[] = {
{"window-height", offsetof(struct win_script_context, height)},
{"window-raw-opacity-before", offsetof(struct win_script_context, opacity_before)},
{"window-raw-opacity", offsetof(struct win_script_context, opacity)},
{"window-monitor-x", offsetof(struct win_script_context, monitor_x)},
{"window-monitor-y", offsetof(struct win_script_context, monitor_y)},
{"window-monitor-width", offsetof(struct win_script_context, monitor_width)},
{"window-monitor-height", offsetof(struct win_script_context, monitor_height)},
{NULL, 0} //
};

Expand Down

0 comments on commit 6624f09

Please sign in to comment.