wayland: add helper functions wayl_win_csd_{titlebar,borders}_visible()

This commit is contained in:
Daniel Eklöf 2022-04-16 11:26:28 +02:00
parent 7a0e7c6c01
commit f9103d4381
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 36 additions and 20 deletions

View file

@ -1560,15 +1560,17 @@ get_csd_data(const struct terminal *term, enum csd_surface surf_idx)
{ {
xassert(term->window->csd_mode == CSD_YES); xassert(term->window->csd_mode == CSD_YES);
const bool borders_visible = wayl_win_csd_borders_visible(term->window);
const bool title_visible = wayl_win_csd_titlebar_visible(term->window);
/* Only title bar is rendered in maximized mode */ /* Only title bar is rendered in maximized mode */
const int border_width = !term->window->is_maximized const int border_width = borders_visible
? term->conf->csd.border_width * term->scale : 0; ? term->conf->csd.border_width * term->scale : 0;
const int title_height = term->window->is_fullscreen const int title_height = title_visible
? 0 ? term->conf->csd.title_height * term->scale : 0;
: term->conf->csd.title_height * term->scale;
const int button_width = !term->window->is_fullscreen const int button_width = title_visible
? term->conf->csd.button_width * term->scale : 0; ? term->conf->csd.button_width * term->scale : 0;
const int button_close_width = term->width >= 1 * button_width const int button_close_width = term->width >= 1 * button_width
@ -3575,11 +3577,9 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
width = term->conf->size.width; width = term->conf->size.width;
height = term->conf->size.height; height = term->conf->size.height;
if (term->window->csd_mode == CSD_YES) { /* Take CSDs into account */
/* Take CSD title bar into account */ if (wayl_win_csd_titlebar_visible(term->window))
xassert(!term->window->is_fullscreen);
height -= term->conf->csd.title_height; height -= term->conf->csd.title_height;
}
width *= scale; width *= scale;
height *= scale; height *= scale;
@ -3760,17 +3760,14 @@ damage_view:
#endif #endif
{ {
bool title_shown = const bool title_shown = wayl_win_csd_titlebar_visible(term->window);
!term->window->is_fullscreen && const bool border_shown = wayl_win_csd_borders_visible(term->window);
term->window->csd_mode == CSD_YES;
bool border_shown = const int title_height =
!term->window->is_fullscreen && title_shown ? term->conf->csd.title_height : 0;
!term->window->is_maximized && const int border_width =
term->window->csd_mode == CSD_YES; border_shown ? term->conf->csd.border_width_visible : 0;
int title_height = title_shown ? term->conf->csd.title_height : 0;
int border_width = border_shown ? term->conf->csd.border_width_visible : 0;
xdg_surface_set_window_geometry( xdg_surface_set_window_geometry(
term->window->xdg_surface, term->window->xdg_surface,
-border_width, -border_width,

View file

@ -747,9 +747,10 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface,
csd_destroy(win); csd_destroy(win);
if (enable_csd && new_width > 0 && new_height > 0) { if (enable_csd && new_width > 0 && new_height > 0) {
new_height -= win->term->conf->csd.title_height; if (wayl_win_csd_titlebar_visible(win))
new_height -= win->term->conf->csd.title_height;
if (!win->is_maximized) { if (wayl_win_csd_borders_visible(win)) {
new_height -= 2 * win->term->conf->csd.border_width_visible; new_height -= 2 * win->term->conf->csd.border_width_visible;
new_width -= 2 * win->term->conf->csd.border_width_visible; new_width -= 2 * win->term->conf->csd.border_width_visible;
} }
@ -1763,6 +1764,21 @@ wayl_win_set_urgent(struct wl_window *win)
#endif #endif
} }
bool
wayl_win_csd_titlebar_visible(const struct wl_window *win)
{
return win->csd_mode == CSD_YES &&
!win->is_fullscreen;
}
bool
wayl_win_csd_borders_visible(const struct wl_window *win)
{
return win->csd_mode == CSD_YES &&
!win->is_fullscreen &&
!win->is_maximized;
}
bool bool
wayl_win_subsurface_new_with_custom_parent( wayl_win_subsurface_new_with_custom_parent(
struct wl_window *win, struct wl_surface *parent, struct wl_window *win, struct wl_surface *parent,

View file

@ -511,6 +511,9 @@ void wayl_win_destroy(struct wl_window *win);
bool wayl_win_set_urgent(struct wl_window *win); bool wayl_win_set_urgent(struct wl_window *win);
bool wayl_win_csd_titlebar_visible(const struct wl_window *win);
bool wayl_win_csd_borders_visible(const struct wl_window *win);
bool wayl_win_subsurface_new( bool wayl_win_subsurface_new(
struct wl_window *win, struct wl_surf_subsurf *surf); struct wl_window *win, struct wl_surf_subsurf *surf);
bool wayl_win_subsurface_new_with_custom_parent( bool wayl_win_subsurface_new_with_custom_parent(