Skip to content

Commit 6624f09

Browse files
committed
win: expose information about monitors to animation script
Define script context variables describing the monitor a window is on. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
1 parent 2899c78 commit 6624f09

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/win.c

+9
Original file line numberDiff line numberDiff line change
@@ -2190,13 +2190,22 @@ void unmap_win_start(struct managed_win *w) {
21902190

21912191
struct win_script_context
21922192
win_script_context_prepare(struct session *ps, struct managed_win *w) {
2193+
auto monitor =
2194+
(w->randr_monitor >= 0 && w->randr_monitor < ps->monitors.count)
2195+
? *pixman_region32_extents(&ps->monitors.regions[w->randr_monitor])
2196+
: (pixman_box32_t){
2197+
.x1 = 0, .y1 = 0, .x2 = ps->root_width, .y2 = ps->root_height};
21932198
struct win_script_context ret = {
21942199
.x = w->g.x,
21952200
.y = w->g.y,
21962201
.width = w->widthb,
21972202
.height = w->heightb,
21982203
.opacity = win_calc_opacity_target(ps, w),
21992204
.opacity_before = w->opacity,
2205+
.monitor_x = monitor.x1,
2206+
.monitor_y = monitor.y1,
2207+
.monitor_width = monitor.x2 - monitor.x1,
2208+
.monitor_height = monitor.y2 - monitor.y1,
22002209
};
22012210
return ret;
22022211
}

src/win.h

+6
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ struct managed_win {
317317
struct win_script_context {
318318
double x, y, width, height;
319319
double opacity_before, opacity;
320+
double monitor_x, monitor_y;
321+
double monitor_width, monitor_height;
320322
};
321323

322324
static const struct script_context_info win_script_context_info[] = {
@@ -326,6 +328,10 @@ static const struct script_context_info win_script_context_info[] = {
326328
{"window-height", offsetof(struct win_script_context, height)},
327329
{"window-raw-opacity-before", offsetof(struct win_script_context, opacity_before)},
328330
{"window-raw-opacity", offsetof(struct win_script_context, opacity)},
331+
{"window-monitor-x", offsetof(struct win_script_context, monitor_x)},
332+
{"window-monitor-y", offsetof(struct win_script_context, monitor_y)},
333+
{"window-monitor-width", offsetof(struct win_script_context, monitor_width)},
334+
{"window-monitor-height", offsetof(struct win_script_context, monitor_height)},
329335
{NULL, 0} //
330336
};
331337

0 commit comments

Comments
 (0)