From 91ffbb4fdf9517f7a0065413d65db4bb110e68d7 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 19 May 2024 08:48:44 +0100 Subject: [PATCH] win: expose information about monitors to animation script Define script context variables describing the monitor a window is on. Signed-off-by: Yuxuan Shui --- src/win.c | 9 +++++++++ src/win.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/win.c b/src/win.c index a25d7c5f1d..b0ed94df61 100644 --- a/src/win.c +++ b/src/win.c @@ -2190,6 +2190,11 @@ 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]) + : (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, @@ -2197,6 +2202,10 @@ win_script_context_prepare(struct session *ps, struct managed_win *w) { .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; } diff --git a/src/win.h b/src/win.h index 231efed1a3..73d22ea301 100644 --- a/src/win.h +++ b/src/win.h @@ -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[] = { @@ -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} // };