Debian Codegraph @

src/wm/win.h

raw symbols SCIP
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2011-2013, Christopher Jeffrey
3 // Copyright (c) 2013 Richard Grenville <[email protected]>
4 // Copyright (c) 2018 Yuxuan Shui <[email protected]>
5
6 #pragma once
7 #include <stdbool.h>
8 #include <xcb/damage.h>
9 #include <xcb/render.h>
10 #include <xcb/xcb.h>
11
12 #include <picom/backend.h>
13 #include <picom/types.h>
14
15 #include "c2.h"
16 #include "compiler.h"
17 #include "config.h"
18 #include "defs.h"
19 #include "region.h"
20 #include "transition/script.h"
21 #include "utils/list.h"
22 #include "utils/misc.h"
23 #include "wm/wm.h"
24 #include "x.h"
25 #include "xcb/xproto.h"
26
27 struct backend_base;
28 typedef struct session session_t;
29 struct wm_cursor;
30
31 #define wm_stack_foreach(wm, i) \
32 for (struct wm_ref * (i) = wm_ref_topmost_child(wm_root_ref(wm)); (i); \
33 (i) = wm_ref_below(i))
34 #define wm_stack_foreach_rev(wm, i) \
35 for (struct wm_ref * (i) = wm_ref_bottommost_child(wm_root_ref(wm)); (i); \
36 (i) = wm_ref_above(i))
37
38 #define wm_stack_foreach_safe(wm, i, next_i) \
39 for (struct wm_ref * (i) = wm_ref_topmost_child(wm_root_ref(wm)), \
40 *(next_i) = (i) != NULL ? wm_ref_below(i) : NULL; \
41 (i); (i) = (next_i), (next_i) = (i) != NULL ? wm_ref_below(i) : NULL)
42
43 struct wm;
44 /// An entry in the window stack. May or may not correspond to a window we know about.
45 struct window_stack_entry {
46 struct list_node stack_neighbour;
47 /// The actual window correspond to this stack entry. NULL if we didn't know about
48 /// this window (e.g. an InputOnly window, or we haven't handled the window
49 /// creation yet)
50 struct win *win;
51 /// The window id. Might not be unique in the stack, because there might be
52 /// destroyed window still fading out in the stack.
53 xcb_window_t id;
54 };
55
56 /**
57 * About coordinate systems
58 *
59 * In general, X is the horizontal axis, Y is the vertical axis.
60 * X goes from left to right, Y goes downwards.
61 *
62 * Global: the origin is the top left corner of the Xorg screen.
63 * Local: the origin is the top left corner of the window, border is
64 * considered part of the window.
65 */
66
67 struct win_geometry {
68 int16_t x;
69 int16_t y;
70 uint16_t width;
71 uint16_t height;
72 uint16_t border_width;
73 };
74
75 /// These are changes of window state that might trigger an animation. We separate them
76 /// out and delay their application so determining which animation to run is easier.
77 ///
78 /// These values are only hold for an instant, and once the animation is started they are
79 /// updated to reflect the latest state.
80 struct win_state_change {
81 winstate_t state;
82 double opacity;
83 double blur_opacity;
84 struct win_geometry g;
85 struct color shadow_color;
86 };
87
88 struct win {
89 /// Reference back to the position of this window inside the window tree.
90 struct wm_ref *tree_ref;
91 /// backend data attached to this window. Only available when
92 /// `state` is not UNMAPPED
93 image_handle win_image;
94 /// The old window image before the window image is refreshed. This is used for
95 /// animation, and is only kept alive for the duration of the animation.
96 image_handle saved_win_image;
97 /// How much to scale the saved_win_image, so that it is the same size as the
98 /// current window image.
99 vec2 saved_win_image_scale;
100 /// A mask image for the shadow. This is usually a blurred `mask_image`, though
101 /// for some backends this can be generated on the CPU.
102 image_handle shadow_mask;
103 /// A mask image for the shape of the window.
104 image_handle mask_image;
105
106 // Core members
107 winstate_t state;
108 /// Window attributes.
109 xcb_get_window_attributes_reply_t a;
110 /// The geometry of the window body, excluding the window border region.
111 struct win_geometry g;
112 /// Updated geometry received in events
113 struct win_geometry pending_g;
114 /// Window visual pict format
115 const xcb_render_pictforminfo_t *pictfmt;
116 /// Client window visual pict format
117 const xcb_render_pictforminfo_t *client_pictfmt;
118 /// Window painting mode.
119 winmode_t mode; // TODO(yshui) only used by legacy backends, remove.
120 /// Whether the window has been damaged at least once since it
121 /// was mapped. Unmapped windows that were previously mapped
122 /// retain their `ever_damaged` state. Mapping a window resets
123 /// this.
124 bool ever_damaged;
125 /// Whether the window was damaged after last paint.
126 bool pixmap_damaged;
127 /// Damage of the window.
128 xcb_damage_damage_t damage;
129 /// bitmap for properties which needs to be updated
130 uint64_t *stale_props;
131 /// number of uint64_ts that has been allocated for stale_props
132 size_t stale_props_capacity;
133
134 /// Bounding shape of the window. In local coordinates.
135 /// See above about coordinate systems.
136 region_t bounding_shape;
137 /// Window flags. Definitions above.
138 uint64_t flags;
139 /// Cached width/height of the window including border.
140 int widthb, heightb;
141 /// Whether the window is bounding-shaped.
142 bool bounding_shaped;
143 /// Whether the window just have rounded corners.
144 bool rounded_corners;
145 /// Whether this window is to be painted.
146 bool to_paint;
147 /// Whether this window is in open/close state.
148 bool in_openclose;
149
150 // Client window related members
151 /// A bitflag of window types. According to ICCCM, a window can have more than one
152 /// type.
153 uint32_t window_types;
154
155 // Blacklist related members
156 /// Name of the window.
157 char *name;
158 /// Window instance class of the window.
159 char *class_instance;
160 /// Window general class of the window.
161 char *class_general;
162 /// <code>WM_WINDOW_ROLE</code> value of the window.
163 char *role;
164 /// Whether the window sets the EWMH fullscreen property.
165 bool is_ewmh_fullscreen;
166 /// Whether the window should be considered fullscreen. Based on
167 /// `is_ewmh_fullscreen`, or the windows spatial relation with the
168 /// root window. Which one is used is determined by user configuration.
169 bool is_fullscreen;
170 /// Whether the window is the active window.
171 bool is_focused;
172 /// Whether the window group this window belongs to is focused.
173 bool is_group_focused;
174
175 // Opacity-related members
176 /// The final window opacity if no animation is running
177 double opacity;
178 /// true if window (or client window, for broken window managers
179 /// not transferring client window's _NET_WM_WINDOW_OPACITY value) has opacity
180 /// prop
181 bool has_opacity_prop;
182 /// Cached value of opacity window attribute.
183 opacity_t opacity_prop;
184 /// Last window opacity value set by the rules.
185 double opacity_set;
186
187 float border_col[4];
188
189 // Frame-opacity-related members
190 /// Current window frame opacity. Affected by window opacity.
191 double frame_opacity;
192 /// Frame extents. Acquired from _NET_FRAME_EXTENTS.
193 margin_t frame_extents;
194
195 // Shadow-related members
196 /// Window specific shadow factor. The final shadow opacity is a combination of
197 /// this, the window opacity, and the window frame opacity.
198 double shadow_opacity;
199 /// X offset of shadow. Affected by command line argument.
200 int shadow_dx;
201 /// Y offset of shadow. Affected by command line argument.
202 int shadow_dy;
203 /// Width of shadow. Affected by window size and command line argument.
204 int shadow_width;
205 /// Height of shadow. Affected by window size and command line argument.
206 int shadow_height;
207 /// The value of _COMPTON_SHADOW attribute of the window. Below 0 for
208 /// none.
209 long long prop_shadow;
210
211 struct c2_window_state c2_state;
212
213 /// The damaged region of the window, in window local coordinates.
214 region_t damaged;
215
216 /// Per-window options coming from rules
217 struct window_maybe_options options;
218 /// Override of per-window options, used by dbus interface
219 struct window_maybe_options options_override;
220 /// Global per-window options default
221 const struct window_options *options_default;
222
223 /// Previous state of the window before state changed. This is used
224 /// by `win_process_animation_and_state_change` to trigger appropriate
225 /// animations.
226 struct win_state_change previous;
227 struct script_instance *running_animation_instance;
228 struct win_script running_animation;
229
230 /// Number of times each animation trigger is blocked
231 unsigned int animation_block[ANIMATION_TRIGGER_COUNT];
232 };
233
234 struct win_script_context {
235 double x, y, width, height;
236 double x_before, y_before, width_before, height_before;
237 double opacity_before, opacity;
238 double blur_opacity_before, blur_opacity;
239 double monitor_x, monitor_y;
240 double monitor_width, monitor_height;
241 struct color shadow_color, shadow_color_before;
242 };
243 // NOLINTNEXTLINE(bugprone-sizeof-expression)
244 static_assert(SCRIPT_CTX_PLACEHOLDER_BASE > sizeof(struct win_script_context),
245 "win_script_context too large");
246
247 #define X(name) offsetof(struct win_script_context, name)
248 static const struct script_context_info win_script_context_info[] = {
249 {"window-x", X(x)},
250 {"window-y", X(y)},
251 {"window-width", X(width)},
252 {"window-height", X(height)},
253 {"window-x-before", X(x_before)},
254 {"window-y-before", X(y_before)},
255 {"window-width-before", X(width_before)},
256 {"window-height-before", X(height_before)},
257 {"window-raw-opacity-before", X(opacity_before)},
258 {"window-raw-opacity", X(opacity)},
259 {"window-blur-opacity-before", X(blur_opacity_before)},
260 {"window-blur-opacity", X(blur_opacity)},
261 {"window-monitor-x", X(monitor_x)},
262 {"window-monitor-y", X(monitor_y)},
263 {"window-monitor-width", X(monitor_width)},
264 {"window-monitor-height", X(monitor_height)},
265 {"window-shadow-red", X(shadow_color.red)},
266 {"window-shadow-green", X(shadow_color.green)},
267 {"window-shadow-blue", X(shadow_color.blue)},
268 {"window-shadow-red-before", X(shadow_color_before.red)},
269 {"window-shadow-green-before", X(shadow_color_before.green)},
270 {"window-shadow-blue-before", X(shadow_color_before.blue)},
271 {NULL, 0} //
272 };
273 #undef X
274
275 static const struct script_output_info win_script_outputs[] = {
276 [WIN_SCRIPT_OFFSET_X] = {"offset-x"},
277 [WIN_SCRIPT_OFFSET_Y] = {"offset-y"},
278 [WIN_SCRIPT_SHADOW_OFFSET_X] = {"shadow-offset-x"},
279 [WIN_SCRIPT_SHADOW_OFFSET_Y] = {"shadow-offset-y"},
280 [WIN_SCRIPT_OPACITY] = {"opacity"},
281 [WIN_SCRIPT_BLUR_OPACITY] = {"blur-opacity"},
282 [WIN_SCRIPT_SHADOW_OPACITY] = {"shadow-opacity"},
283 [WIN_SCRIPT_SCALE_X] = {"scale-x"},
284 [WIN_SCRIPT_SCALE_Y] = {"scale-y"},
285 [WIN_SCRIPT_SHADOW_SCALE_X] = {"shadow-scale-x"},
286 [WIN_SCRIPT_SHADOW_SCALE_Y] = {"shadow-scale-y"},
287 [WIN_SCRIPT_CROP_X] = {"crop-x"},
288 [WIN_SCRIPT_CROP_Y] = {"crop-y"},
289 [WIN_SCRIPT_CROP_WIDTH] = {"crop-width"},
290 [WIN_SCRIPT_CROP_HEIGHT] = {"crop-height"},
291 [WIN_SCRIPT_SAVED_IMAGE_BLEND] = {"saved-image-blend"},
292 [WIN_SCRIPT_SHADOW_RED] = {"shadow-red"},
293 [WIN_SCRIPT_SHADOW_GREEN] = {"shadow-green"},
294 [WIN_SCRIPT_SHADOW_BLUE] = {"shadow-blue"},
295 [NUM_OF_WIN_SCRIPT_OUTPUTS] = {NULL},
296 };
297
298 static const struct window_maybe_options WIN_MAYBE_OPTIONS_DEFAULT = {
299 .blur_background = TRI_UNKNOWN,
300 .clip_shadow_above = TRI_UNKNOWN,
301 .shadow = TRI_UNKNOWN,
302 .fade = TRI_UNKNOWN,
303 .invert_color = TRI_UNKNOWN,
304 .paint = TRI_UNKNOWN,
305 .dim = NAN,
306 .opacity = NAN,
307 .blur_opacity = NAN,
308 .shader = NULL,
309 .corner_radius = -1,
310 .unredir = WINDOW_UNREDIR_INVALID,
311 };
312
313 static inline void win_script_fold(const struct win_script *upper,
314 const struct win_script *lower, struct win_script *output) {
315 for (size_t i = 0; i < ANIMATION_TRIGGER_COUNT; i++) {
316 output[i] = upper[i].script ? upper[i] : lower[i];
317 }
318 }
319
320 /// Return `a` if it's not NaN, otherwise return `def`.
321 static inline double __attribute__((always_inline, const)) number_or_d(double a, double def) {
322 return safe_isnan(a) ? def : a;
323 }
324
325 /// Combine two window options. The `upper` value has higher priority, the `lower` value
326 /// will only be used if the corresponding value in `upper` is not set (e.g. it is
327 /// TRI_UNKNOWN for tristate values, NaN for opacity, -1 for corner_radius).
328 static inline struct window_maybe_options __attribute__((always_inline, const))
329 win_maybe_options_fold(struct window_maybe_options upper, struct window_maybe_options lower) {
330 struct window_maybe_options ret = {
331 .unredir = upper.unredir == WINDOW_UNREDIR_INVALID ? lower.unredir : upper.unredir,
332 .blur_background = tri_or(upper.blur_background, lower.blur_background),
333 .clip_shadow_above = tri_or(upper.clip_shadow_above, lower.clip_shadow_above),
334 .full_shadow = tri_or(upper.full_shadow, lower.full_shadow),
335 .shadow = tri_or(upper.shadow, lower.shadow),
336 .fade = tri_or(upper.fade, lower.fade),
337 .invert_color = tri_or(upper.invert_color, lower.invert_color),
338 .paint = tri_or(upper.paint, lower.paint),
339 .transparent_clipping =
340 tri_or(upper.transparent_clipping, lower.transparent_clipping),
341 .opacity = number_or_d(upper.opacity, lower.opacity),
342 .blur_opacity = number_or_d(upper.blur_opacity, lower.blur_opacity),
343 .dim = number_or_d(upper.dim, lower.dim),
344 .shader = upper.shader ? upper.shader : lower.shader,
345 .corner_radius = upper.corner_radius >= 0 ? upper.corner_radius : lower.corner_radius,
346 .is_shadow_color_set = upper.is_shadow_color_set || lower.is_shadow_color_set,
347 .shadow_color = upper.is_shadow_color_set ? upper.shadow_color : lower.shadow_color,
348 };
349 win_script_fold(upper.animations, lower.animations, ret.animations);
350 return ret;
351 }
352
353 /// Unwrap a `window_maybe_options` to a `window_options`, using the default value for
354 /// values that are not set in the `window_maybe_options`.
355 static inline struct window_options __attribute__((always_inline, const))
356 win_maybe_options_or(struct window_maybe_options maybe, struct window_options def) {
357 assert(def.unredir != WINDOW_UNREDIR_INVALID);
358 struct window_options ret = {
359 .unredir = maybe.unredir == WINDOW_UNREDIR_INVALID ? def.unredir : maybe.unredir,
360 .blur_background = tri_or_bool(maybe.blur_background, def.blur_background),
361 .clip_shadow_above = tri_or_bool(maybe.clip_shadow_above, def.clip_shadow_above),
362 .full_shadow = tri_or_bool(maybe.full_shadow, def.full_shadow),
363 .shadow = tri_or_bool(maybe.shadow, def.shadow),
364 .corner_radius = maybe.corner_radius >= 0 ? (unsigned int)maybe.corner_radius
365 : def.corner_radius,
366 .fade = tri_or_bool(maybe.fade, def.fade),
367 .invert_color = tri_or_bool(maybe.invert_color, def.invert_color),
368 .paint = tri_or_bool(maybe.paint, def.paint),
369 .transparent_clipping =
370 tri_or_bool(maybe.transparent_clipping, def.transparent_clipping),
371 .opacity = number_or_d(maybe.opacity, def.opacity),
372 .blur_opacity = number_or_d(maybe.blur_opacity, def.blur_opacity),
373 .dim = number_or_d(maybe.dim, def.dim),
374 .shader = maybe.shader ? maybe.shader : def.shader,
375 .shadow_color = maybe.is_shadow_color_set ? maybe.shadow_color : def.shadow_color,
376 };
377 win_script_fold(maybe.animations, def.animations, ret.animations);
378 return ret;
379 }
380
381 static inline struct window_options __attribute__((always_inline, const))
382 win_options(const struct win *w) {
383 return win_maybe_options_or(
384 win_maybe_options_fold(w->options_override, w->options), *w->options_default);
385 }
386
387 /// Check if the window has changed in size. Border width is
388 /// not considered.
389 static inline bool win_size_changed(struct win_geometry a, struct win_geometry b) {
390 return a.width != b.width || a.height != b.height;
391 }
392
393 /// Check if the window position has changed.
394 static inline bool win_position_changed(struct win_geometry a, struct win_geometry b) {
395 return a.x != b.x || a.y != b.y;
396 }
397
398 /// Process pending updates/images flags on a window. Has to be called in X critical
399 /// section. Returns true if the window had an animation running and it has just finished,
400 /// or if the window's states just changed and there is no animation defined for this
401 /// state change.
402 bool win_process_animation_and_state_change(struct session *ps, struct win *w, double delta_t);
403 double win_animatable_get(const struct win *w, enum win_script_output output);
404 void win_process_primary_flags(session_t *ps, struct win *w);
405 void win_process_secondary_flags(session_t *ps, struct win *w);
406 void win_process_image_flags(session_t *ps, struct win *w);
407
408 /// Start the unmap of a window. We cannot unmap immediately since we might need to fade
409 /// the window out.
410 void unmap_win_start(struct win *);
411 void unmap_win_finish(session_t *ps, struct win *w);
412 /// Start the destroying of a window. Windows cannot always be destroyed immediately
413 /// because of fading and such.
414 void win_destroy_start(struct win *w);
415 void win_map_start(struct session *ps, struct win *w);
416 void win_release_saved_win_image(backend_t *base, struct win *w);
417 /// Release images bound with a window, set the *_NONE flags on the window. Only to be
418 /// used when de-initializing the backend outside of win.c
419 void win_release_images(struct backend_base *backend, struct win *w);
420 winmode_t attr_pure win_calc_mode_raw(const struct win *w);
421 // TODO(yshui) `win_calc_mode` is only used by legacy backends
422 winmode_t attr_pure win_calc_mode(const struct win *w);
423 /**
424 * Set real focused state of a window.
425 */
426 void win_set_focused(session_t *ps, struct win *w);
427 void win_on_factor_change(session_t *ps, struct win *w);
428 void win_on_client_update(session_t *ps, struct win *w);
429
430 int attr_pure win_find_monitor(const struct x_monitors *monitors, const struct win *mw);
431
432 /// Recheck if a window is fullscreen
433 void win_update_is_fullscreen(const session_t *ps, struct win *w);
434 /**
435 * Check if a window has BYPASS_COMPOSITOR property set
436 */
437 bool win_is_bypassing_compositor(const session_t *ps, const struct win *w);
438 /**
439 * Get a rectangular region in global coordinates a window (and possibly
440 * its shadow) occupies.
441 *
442 * Note w->shadow and shadow geometry must be correct before calling this
443 * function.
444 */
445 void win_extents(const struct win *w, region_t *res);
446 region_t win_extents_by_val(const struct win *w);
447
448 /// Get the region for the frame of the window
449 void win_get_region_frame_local(const struct win *w, region_t *res);
450 /// Get the region for the frame of the window, by value
451 region_t win_get_region_frame_local_by_val(const struct win *w);
452 /// Query the Xorg for information about window `win`
453 /// `win` pointer might become invalid after this function returns
454 struct win *win_maybe_allocate(session_t *ps, struct wm_ref *cursor,
455 const xcb_get_window_attributes_reply_t *attrs);
456
457 /**
458 * Release a destroyed window that is no longer needed.
459 */
460 void win_destroy_finish(session_t *ps, struct win *w);
461
462 /// Return whether the group a window belongs to is really focused.
463 ///
464 /// @param leader leader window ID
465 /// @return true if the window group is focused, false otherwise
466 bool win_is_group_focused(session_t *ps, struct win *w);
467
468 /// check if window has ARGB visual
469 bool attr_pure win_has_alpha(const struct win *w);
470
471 /// Whether it looks like a WM window. We consider a window WM window if
472 /// it does not have a decedent with WM_STATE and it is not override-
473 /// redirected itself.
474 static inline bool attr_pure win_is_wmwin(const struct win *w) {
475 return wm_ref_client_of(w->tree_ref) == NULL && !w->a.override_redirect;
476 }
477
478 static inline xcb_window_t win_id(const struct win *w) {
479 return wm_ref_win_id(w->tree_ref);
480 }
481
482 /// Returns the client window of a window. If a client window does not exist, returns the
483 /// window itself when `fallback_to_self` is true, otherwise returns XCB_NONE.
484 static inline xcb_window_t win_client_id(const struct win *w, bool fallback_to_self) {
485 auto client_win = wm_ref_client_of(w->tree_ref);
486 if (client_win == NULL) {
487 return fallback_to_self ? win_id(w) : XCB_NONE;
488 }
489 return wm_ref_win_id(client_win);
490 }
491
492 /// Whether a given window is mapped on the X server side
493 bool win_is_mapped_in_x(const struct win *w);
494 /// Set flags on a window. Some sanity checks are performed
495 void win_set_flags(struct win *w, uint64_t flags);
496 /// Clear flags on a window. Some sanity checks are performed
497 void win_clear_flags(struct win *w, uint64_t flags);
498 /// Returns true if any of the flags in `flags` is set
499 bool win_check_flags_any(struct win *w, uint64_t flags);
500 /// Returns true if all of the flags in `flags` are set
501 bool win_check_flags_all(struct win *w, uint64_t flags);
502 /// Mark properties as stale for a window
503 void win_set_properties_stale(struct win *w, const xcb_atom_t *prop, int nprops);
504
505 static inline struct win_geometry
506 win_geometry_from_configure_notify(const xcb_configure_notify_event_t *ce) {
507 return (struct win_geometry){
508 .x = ce->x,
509 .y = ce->y,
510 .width = ce->width,
511 .height = ce->height,
512 .border_width = ce->border_width,
513 };
514 }
515 static inline struct win_geometry
516 win_geometry_from_get_geometry(const xcb_get_geometry_reply_t *g) {
517 return (struct win_geometry){
518 .x = g->x,
519 .y = g->y,
520 .width = g->width,
521 .height = g->height,
522 .border_width = g->border_width,
523 };
524 }
525 /// Set the pending geometry of a window. And set appropriate flags when the geometry
526 /// changes.
527 /// Returns true if the geometry has changed, false otherwise.
528 bool win_set_pending_geometry(struct win *w, struct win_geometry g);
529 bool win_update_wintype(struct x_connection *c, struct atom *atoms, struct win *w);
530 /**
531 * Retrieve frame extents from a window.
532 */
533 void win_update_frame_extents(struct x_connection *c, struct atom *atoms, struct win *w,
534 xcb_window_t client);
535 /**
536 * Retrieve the <code>WM_CLASS</code> of a window and update its
537 * <code>win</code> structure.
538 */
539 bool win_update_class(struct x_connection *c, struct atom *atoms, struct win *w);
540 int win_update_role(struct x_connection *c, struct atom *atoms, struct win *w);
541 int win_update_name(struct x_connection *c, struct atom *atoms, struct win *w);
542 void win_on_win_size_change(struct win *w, int shadow_offset_x, int shadow_offset_y,
543 int shadow_radius);
544 void win_update_bounding_shape(struct x_connection *c, struct win *w,
545 bool detect_rounded_corners);
546 bool win_update_prop_fullscreen(struct x_connection *c, const struct atom *atoms,
547 struct win *w);
548
549 static inline attr_unused void win_set_property_stale(struct win *w, xcb_atom_t prop) {
550 return win_set_properties_stale(w, (xcb_atom_t[]){prop}, 1);
551 }
552
553 /// Free all resources in a struct win
554 void free_win_res(session_t *ps, struct win *w);
555
556 /// Remove the corners of a scaled, rounded rectangle from region `res`. `origin` is the
557 /// top-left corner of the rectangle in `res`'s coordinate system. `size` is the size of
558 /// the rectangle, `scale` is the scaling factor. `corner_radius` is the _unscaled_ radius
559 /// of the rounded corners. The top-left corner of the rectangle is the scaling origin.
560 static inline void win_remove_region_corners(ivec2 size, vec2 scale, int corner_radius,
561 ivec2 origin, region_t *res) {
562 static const struct {
563 int x, y;
564 } corner_index[] = {
565 {0, 0},
566 {0, 1},
567 {1, 0},
568 {1, 1},
569 };
570 rect_t rectangles[4];
571 for (size_t i = 0; i < ARR_SIZE(corner_index); i++) {
572 double x1 = origin.x +
573 corner_index[i].x * (size.width - corner_radius) * scale.x,
574 y1 = origin.y +
575 corner_index[i].y * (size.height - corner_radius) * scale.y,
576 x2 = x1 + corner_radius * scale.x, y2 = y1 + corner_radius * scale.y;
577 rectangles[i] = (rect_t){
578 .x1 = (int32_t)floor(x1),
579 .y1 = (int32_t)floor(y1),
580 .x2 = (int32_t)ceil(x2),
581 .y2 = (int32_t)ceil(y2),
582 };
583 }
584 region_t corners;
585 pixman_region32_init_rects(&corners, rectangles, 4);
586 pixman_region32_subtract(res, res, &corners);
587 pixman_region32_fini(&corners);
588 }
589
590 static inline region_t attr_unused win_get_bounding_shape_global_by_val(struct win *w) {
591 region_t ret;
592 pixman_region32_init(&ret);
593 pixman_region32_copy(&ret, &w->bounding_shape);
594 pixman_region32_translate(&ret, w->g.x, w->g.y);
595 return ret;
596 }
597
598 /**
599 * Calculate the extents of the frame of the given window based on EWMH
600 * _NET_FRAME_EXTENTS and the X window border width.
601 */
602 static inline margin_t attr_pure attr_unused win_calc_frame_extents(const struct win *w) {
603 margin_t result = w->frame_extents;
604 result.top = max2(result.top, w->g.border_width);
605 result.left = max2(result.left, w->g.border_width);
606 result.bottom = max2(result.bottom, w->g.border_width);
607 result.right = max2(result.right, w->g.border_width);
608 return result;
609 }
610
611 /**
612 * Check whether a window has WM frames.
613 */
614 static inline bool attr_pure attr_unused win_has_frame(const struct win *w) {
615 return w->g.border_width || w->frame_extents.top || w->frame_extents.left ||
616 w->frame_extents.right || w->frame_extents.bottom;
617 }
618
619 static inline const char *attr_pure attr_unused win_wm_ref_name(const struct wm_ref *ref) {
620 if (ref == NULL) {
621 return NULL;
622 }
623 auto win = wm_ref_deref(ref);
624 if (win == NULL) {
625 return NULL;
626 }
627 return win->name;
628 }