| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 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 |
|
| 45 |
struct window_stack_entry { |
| 46 |
struct list_node stack_neighbour; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
struct win *win; |
| 51 |
|
| 52 |
|
| 53 |
xcb_window_t id; |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 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 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 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 |
|
| 90 |
struct wm_ref *tree_ref; |
| 91 |
|
| 92 |
|
| 93 |
image_handle win_image; |
| 94 |
|
| 95 |
|
| 96 |
image_handle saved_win_image; |
| 97 |
|
| 98 |
|
| 99 |
vec2 saved_win_image_scale; |
| 100 |
|
| 101 |
|
| 102 |
image_handle shadow_mask; |
| 103 |
|
| 104 |
image_handle mask_image; |
| 105 |
|
| 106 |
|
| 107 |
winstate_t state; |
| 108 |
|
| 109 |
xcb_get_window_attributes_reply_t a; |
| 110 |
|
| 111 |
struct win_geometry g; |
| 112 |
|
| 113 |
struct win_geometry pending_g; |
| 114 |
|
| 115 |
const xcb_render_pictforminfo_t *pictfmt; |
| 116 |
|
| 117 |
const xcb_render_pictforminfo_t *client_pictfmt; |
| 118 |
|
| 119 |
winmode_t mode; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
bool ever_damaged; |
| 125 |
|
| 126 |
bool pixmap_damaged; |
| 127 |
|
| 128 |
xcb_damage_damage_t damage; |
| 129 |
|
| 130 |
uint64_t *stale_props; |
| 131 |
|
| 132 |
size_t stale_props_capacity; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
region_t bounding_shape; |
| 137 |
|
| 138 |
uint64_t flags; |
| 139 |
|
| 140 |
int widthb, heightb; |
| 141 |
|
| 142 |
bool bounding_shaped; |
| 143 |
|
| 144 |
bool rounded_corners; |
| 145 |
|
| 146 |
bool to_paint; |
| 147 |
|
| 148 |
bool in_openclose; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
uint32_t window_types; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
char *name; |
| 158 |
|
| 159 |
char *class_instance; |
| 160 |
|
| 161 |
char *class_general; |
| 162 |
|
| 163 |
char *role; |
| 164 |
|
| 165 |
bool is_ewmh_fullscreen; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
bool is_fullscreen; |
| 170 |
|
| 171 |
bool is_focused; |
| 172 |
|
| 173 |
bool is_group_focused; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
double opacity; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
bool has_opacity_prop; |
| 182 |
|
| 183 |
opacity_t opacity_prop; |
| 184 |
|
| 185 |
double opacity_set; |
| 186 |
|
| 187 |
float border_col[4]; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
double frame_opacity; |
| 192 |
|
| 193 |
margin_t frame_extents; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
double shadow_opacity; |
| 199 |
|
| 200 |
int shadow_dx; |
| 201 |
|
| 202 |
int shadow_dy; |
| 203 |
|
| 204 |
int shadow_width; |
| 205 |
|
| 206 |
int shadow_height; |
| 207 |
|
| 208 |
|
| 209 |
long long prop_shadow; |
| 210 |
|
| 211 |
struct c2_window_state c2_state; |
| 212 |
|
| 213 |
|
| 214 |
region_t damaged; |
| 215 |
|
| 216 |
|
| 217 |
struct window_maybe_options options; |
| 218 |
|
| 219 |
struct window_maybe_options options_override; |
| 220 |
|
| 221 |
const struct window_options *options_default; |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
struct win_state_change previous; |
| 227 |
struct script_instance *running_animation_instance; |
| 228 |
struct win_script running_animation; |
| 229 |
|
| 230 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 326 |
|
| 327 |
|
| 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 |
|
| 354 |
|
| 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 |
|
| 388 |
|
| 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 |
|
| 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 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 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 |
|
| 409 |
|
| 410 |
void unmap_win_start(struct win *); |
| 411 |
void unmap_win_finish(session_t *ps, struct win *w); |
| 412 |
|
| 413 |
|
| 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 |
|
| 418 |
|
| 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 |
|
| 422 |
winmode_t attr_pure win_calc_mode(const struct win *w); |
| 423 |
|
| 424 |
|
| 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 |
|
| 433 |
void win_update_is_fullscreen(const session_t *ps, struct win *w); |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
bool win_is_bypassing_compositor(const session_t *ps, const struct win *w); |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 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 |
|
| 449 |
void win_get_region_frame_local(const struct win *w, region_t *res); |
| 450 |
|
| 451 |
region_t win_get_region_frame_local_by_val(const struct win *w); |
| 452 |
|
| 453 |
|
| 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 |
|
| 459 |
|
| 460 |
void win_destroy_finish(session_t *ps, struct win *w); |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
bool win_is_group_focused(session_t *ps, struct win *w); |
| 467 |
|
| 468 |
|
| 469 |
bool attr_pure win_has_alpha(const struct win *w); |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 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 |
|
| 483 |
|
| 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 |
|
| 493 |
bool win_is_mapped_in_x(const struct win *w); |
| 494 |
|
| 495 |
void win_set_flags(struct win *w, uint64_t flags); |
| 496 |
|
| 497 |
void win_clear_flags(struct win *w, uint64_t flags); |
| 498 |
|
| 499 |
bool win_check_flags_any(struct win *w, uint64_t flags); |
| 500 |
|
| 501 |
bool win_check_flags_all(struct win *w, uint64_t flags); |
| 502 |
|
| 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 |
|
| 526 |
|
| 527 |
|
| 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 |
|
| 532 |
|
| 533 |
void win_update_frame_extents(struct x_connection *c, struct atom *atoms, struct win *w, |
| 534 |
xcb_window_t client); |
| 535 |
|
| 536 |
|
| 537 |
|
| 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 |
|
| 554 |
void free_win_res(session_t *ps, struct win *w); |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 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 |
|
| 600 |
|
| 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 |
|
| 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 |
} |