wayland: refactor: wrap wl_surface pointers in a wayl_surface struct

And add a viewport object to accompany the surface (to be used when
scaling the surface).

Also rename the wl_surf_subsurf struct to wayl_sub_surface, and add a
wayl_surface object to it, rather than a plain wl_surface pointer (to
also get the viewport pointer).
This commit is contained in:
Daniel Eklöf 2023-06-26 16:10:40 +02:00
parent c5d533ec71
commit ba46a039ac
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 149 additions and 139 deletions

View file

@ -89,5 +89,5 @@ quirk_sway_subsurface_unmap(struct terminal *term)
if (!is_sway()) if (!is_sway())
return; return;
wl_surface_damage_buffer(term->window->surface, 0, 0, INT32_MAX, INT32_MAX); wl_surface_damage_buffer(term->window->surface.surf, 0, 0, INT32_MAX, INT32_MAX);
} }

100
render.c
View file

@ -905,21 +905,21 @@ render_margin(struct terminal *term, struct buffer *buf,
if (apply_damage) { if (apply_damage) {
/* Top */ /* Top */
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, 0, 0, term->width, term->margins.top); term->window->surface.surf, 0, 0, term->width, term->margins.top);
/* Bottom */ /* Bottom */
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, 0, bmargin, term->width, term->margins.bottom); term->window->surface.surf, 0, bmargin, term->width, term->margins.bottom);
/* Left */ /* Left */
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, term->window->surface.surf,
0, term->margins.top + start_line * term->cell_height, 0, term->margins.top + start_line * term->cell_height,
term->margins.left, line_count * term->cell_height); term->margins.left, line_count * term->cell_height);
/* Right */ /* Right */
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, term->window->surface.surf,
rmargin, term->margins.top + start_line * term->cell_height, rmargin, term->margins.top + start_line * term->cell_height,
term->margins.right, line_count * term->cell_height); term->margins.right, line_count * term->cell_height);
} }
@ -1027,7 +1027,7 @@ grid_render_scroll(struct terminal *term, struct buffer *buf,
#endif #endif
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, term->margins.left, dst_y, term->window->surface.surf, term->margins.left, dst_y,
term->width - term->margins.left - term->margins.right, height); term->width - term->margins.left - term->margins.right, height);
/* /*
@ -1104,7 +1104,7 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
#endif #endif
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, term->margins.left, dst_y, term->window->surface.surf, term->margins.left, dst_y,
term->width - term->margins.left - term->margins.right, height); term->width - term->margins.left - term->margins.right, height);
/* /*
@ -1153,7 +1153,7 @@ render_sixel_chunk(struct terminal *term, pixman_image_t *pix, const struct sixe
x, y, x, y,
width, height); width, height);
wl_surface_damage_buffer(term->window->surface, x, y, width, height); wl_surface_damage_buffer(term->window->surface.surf, x, y, width, height);
} }
static void static void
@ -1480,7 +1480,7 @@ render_ime_preedit_for_seat(struct terminal *term, struct seat *seat,
free(real_cells); free(real_cells);
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, term->window->surface.surf,
term->margins.left, term->margins.left,
term->margins.top + row_idx * term->cell_height, term->margins.top + row_idx * term->cell_height,
term->width - term->margins.left - term->margins.right, term->width - term->margins.left - term->margins.right,
@ -1502,7 +1502,7 @@ render_ime_preedit(struct terminal *term, struct buffer *buf)
static void static void
render_overlay(struct terminal *term) render_overlay(struct terminal *term)
{ {
struct wl_surf_subsurf *overlay = &term->window->overlay; struct wayl_sub_surface *overlay = &term->window->overlay;
bool unicode_mode_active = false; bool unicode_mode_active = false;
/* Check if unicode mode is active on at least one seat focusing /* Check if unicode mode is active on at least one seat focusing
@ -1523,8 +1523,8 @@ render_overlay(struct terminal *term)
if (likely(style == OVERLAY_NONE)) { if (likely(style == OVERLAY_NONE)) {
if (term->render.last_overlay_style != OVERLAY_NONE) { if (term->render.last_overlay_style != OVERLAY_NONE) {
/* Unmap overlay sub-surface */ /* Unmap overlay sub-surface */
wl_surface_attach(overlay->surf, NULL, 0, 0); wl_surface_attach(overlay->surface.surf, NULL, 0, 0);
wl_surface_commit(overlay->surf); wl_surface_commit(overlay->surface.surf);
term->render.last_overlay_style = OVERLAY_NONE; term->render.last_overlay_style = OVERLAY_NONE;
term->render.last_overlay_buf = NULL; term->render.last_overlay_buf = NULL;
@ -1691,17 +1691,17 @@ render_overlay(struct terminal *term)
&(pixman_rectangle16_t){0, 0, term->width, term->height}); &(pixman_rectangle16_t){0, 0, term->width, term->height});
quirk_weston_subsurface_desync_on(overlay->sub); quirk_weston_subsurface_desync_on(overlay->sub);
wayl_surface_scale(term->wl, overlay->surf, term->scale); wayl_surface_scale(term->wl, overlay->surface.surf, term->scale);
wl_subsurface_set_position(overlay->sub, 0, 0); wl_subsurface_set_position(overlay->sub, 0, 0);
wl_surface_attach(overlay->surf, buf->wl_buf, 0, 0); wl_surface_attach(overlay->surface.surf, buf->wl_buf, 0, 0);
wl_surface_damage_buffer( wl_surface_damage_buffer(
overlay->surf, overlay->surface.surf,
damage_bounds.x1, damage_bounds.y1, damage_bounds.x1, damage_bounds.y1,
damage_bounds.x2 - damage_bounds.x1, damage_bounds.x2 - damage_bounds.x1,
damage_bounds.y2 - damage_bounds.y1); damage_bounds.y2 - damage_bounds.y1);
wl_surface_commit(overlay->surf); wl_surface_commit(overlay->surface.surf);
quirk_weston_subsurface_desync_off(overlay->sub); quirk_weston_subsurface_desync_off(overlay->sub);
buf->age = 0; buf->age = 0;
@ -1945,7 +1945,7 @@ render_csd_title(struct terminal *term, const struct csd_data *info,
{ {
xassert(term->window->csd_mode == CSD_YES); xassert(term->window->csd_mode == CSD_YES);
struct wl_surf_subsurf *surf = &term->window->csd.surface[CSD_SURF_TITLE]; struct wayl_sub_surface *surf = &term->window->csd.surface[CSD_SURF_TITLE];
if (info->width == 0 || info->height == 0) if (info->width == 0 || info->height == 0)
return; return;
@ -1971,11 +1971,11 @@ render_csd_title(struct terminal *term, const struct csd_data *info,
const int margin = M != NULL ? M->advance.x : win->csd.font->max_advance.x; const int margin = M != NULL ? M->advance.x : win->csd.font->max_advance.x;
render_osd(term, surf->surf, surf->sub, win->csd.font, render_osd(term, surf->surface.surf, surf->sub, win->csd.font,
buf, title_text, fg, bg, margin, buf, title_text, fg, bg, margin,
(buf->height - win->csd.font->height) / 2); (buf->height - win->csd.font->height) / 2);
csd_commit(term, surf->surf, buf); csd_commit(term, surf->surface.surf, buf);
free(_title_text); free(_title_text);
} }
@ -1986,7 +1986,7 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx,
xassert(term->window->csd_mode == CSD_YES); xassert(term->window->csd_mode == CSD_YES);
xassert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM); xassert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM);
struct wl_surface *surf = term->window->csd.surface[surf_idx].surf; struct wl_surface *surf = term->window->csd.surface[surf_idx].surface.surf;
if (info->width == 0 || info->height == 0) if (info->width == 0 || info->height == 0)
return; return;
@ -2271,7 +2271,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx,
xassert(term->window->csd_mode == CSD_YES); xassert(term->window->csd_mode == CSD_YES);
xassert(surf_idx >= CSD_SURF_MINIMIZE && surf_idx <= CSD_SURF_CLOSE); xassert(surf_idx >= CSD_SURF_MINIMIZE && surf_idx <= CSD_SURF_CLOSE);
struct wl_surface *surf = term->window->csd.surface[surf_idx].surf; struct wl_surface *surf = term->window->csd.surface[surf_idx].surface.surf;
if (info->width == 0 || info->height == 0) if (info->width == 0 || info->height == 0)
return; return;
@ -2358,7 +2358,7 @@ render_csd(struct terminal *term)
const int width = infos[i].width; const int width = infos[i].width;
const int height = infos[i].height; const int height = infos[i].height;
struct wl_surface *surf = term->window->csd.surface[i].surf; struct wl_surface *surf = term->window->csd.surface[i].surface.surf;
struct wl_subsurface *sub = term->window->csd.surface[i].sub; struct wl_subsurface *sub = term->window->csd.surface[i].sub;
xassert(surf != NULL); xassert(surf != NULL);
@ -2397,7 +2397,7 @@ render_scrollback_position(struct terminal *term)
struct wl_window *win = term->window; struct wl_window *win = term->window;
if (term->grid->view == term->grid->offset) { if (term->grid->view == term->grid->offset) {
if (win->scrollback_indicator.surf != NULL) { if (win->scrollback_indicator.surface.surf != NULL) {
wayl_win_subsurface_destroy(&win->scrollback_indicator); wayl_win_subsurface_destroy(&win->scrollback_indicator);
/* Work around Sway bug - unmapping a sub-surface does not damage /* Work around Sway bug - unmapping a sub-surface does not damage
@ -2407,7 +2407,7 @@ render_scrollback_position(struct terminal *term)
return; return;
} }
if (win->scrollback_indicator.surf == NULL) { if (win->scrollback_indicator.surface.surf == NULL) {
if (!wayl_win_subsurface_new( if (!wayl_win_subsurface_new(
win, &win->scrollback_indicator, false)) win, &win->scrollback_indicator, false))
{ {
@ -2416,7 +2416,7 @@ render_scrollback_position(struct terminal *term)
} }
} }
xassert(win->scrollback_indicator.surf != NULL); xassert(win->scrollback_indicator.surface.surf != NULL);
xassert(win->scrollback_indicator.sub != NULL); xassert(win->scrollback_indicator.sub != NULL);
/* Find absolute row number of the scrollback start */ /* Find absolute row number of the scrollback start */
@ -2514,8 +2514,8 @@ render_scrollback_position(struct terminal *term)
const int y = (term->margins.top + surf_top) / scale * scale; const int y = (term->margins.top + surf_top) / scale * scale;
if (y + height > term->height) { if (y + height > term->height) {
wl_surface_attach(win->scrollback_indicator.surf, NULL, 0, 0); wl_surface_attach(win->scrollback_indicator.surface.surf, NULL, 0, 0);
wl_surface_commit(win->scrollback_indicator.surf); wl_surface_commit(win->scrollback_indicator.surface.surf);
return; return;
} }
@ -2534,7 +2534,7 @@ render_scrollback_position(struct terminal *term)
render_osd( render_osd(
term, term,
win->scrollback_indicator.surf, win->scrollback_indicator.surface.surf,
win->scrollback_indicator.sub, win->scrollback_indicator.sub,
term->fonts[0], buf, text, term->fonts[0], buf, text,
fg, 0xffu << 24 | bg, fg, 0xffu << 24 | bg,
@ -2571,7 +2571,7 @@ render_render_timer(struct terminal *term, struct timespec render_time)
render_osd( render_osd(
term, term,
win->render_timer.surf, win->render_timer.surface.surf,
win->render_timer.sub, win->render_timer.sub,
term->fonts[0], buf, text, term->fonts[0], buf, text,
term->colors.table[0], 0xffu << 24 | term->colors.table[8 + 1], term->colors.table[0], 0xffu << 24 | term->colors.table[8 + 1],
@ -2919,7 +2919,7 @@ grid_render(struct terminal *term)
int height = (r - first_dirty_row) * term->cell_height; int height = (r - first_dirty_row) * term->cell_height;
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, x, y, width, height); term->window->surface.surf, x, y, width, height);
pixman_region32_union_rect( pixman_region32_union_rect(
&buf->dirty, &buf->dirty, 0, y, buf->width, height); &buf->dirty, &buf->dirty, 0, y, buf->width, height);
} }
@ -2947,7 +2947,7 @@ grid_render(struct terminal *term)
int width = term->width - term->margins.left - term->margins.right; int width = term->width - term->margins.left - term->margins.right;
int height = (term->rows - first_dirty_row) * term->cell_height; int height = (term->rows - first_dirty_row) * term->cell_height;
wl_surface_damage_buffer(term->window->surface, x, y, width, height); wl_surface_damage_buffer(term->window->surface.surf, x, y, width, height);
pixman_region32_union_rect(&buf->dirty, &buf->dirty, 0, y, buf->width, height); pixman_region32_union_rect(&buf->dirty, &buf->dirty, 0, y, buf->width, height);
} }
@ -3014,7 +3014,7 @@ grid_render(struct terminal *term)
xassert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows); xassert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows);
xassert(term->window->frame_callback == NULL); xassert(term->window->frame_callback == NULL);
term->window->frame_callback = wl_surface_frame(term->window->surface); term->window->frame_callback = wl_surface_frame(term->window->surface.surf);
wl_callback_add_listener(term->window->frame_callback, &frame_listener, term); wl_callback_add_listener(term->window->frame_callback, &frame_listener, term);
wayl_win_scale(term->window); wayl_win_scale(term->window);
@ -3024,7 +3024,7 @@ grid_render(struct terminal *term)
clock_gettime(term->wl->presentation_clock_id, &commit_time); clock_gettime(term->wl->presentation_clock_id, &commit_time);
struct wp_presentation_feedback *feedback = wp_presentation_feedback( struct wp_presentation_feedback *feedback = wp_presentation_feedback(
term->wl->presentation, term->window->surface); term->wl->presentation, term->window->surface.surf);
if (feedback == NULL) { if (feedback == NULL) {
LOG_WARN("failed to create presentation feedback"); LOG_WARN("failed to create presentation feedback");
@ -3048,11 +3048,11 @@ grid_render(struct terminal *term)
if (term->conf->tweak.damage_whole_window) { if (term->conf->tweak.damage_whole_window) {
wl_surface_damage_buffer( wl_surface_damage_buffer(
term->window->surface, 0, 0, INT32_MAX, INT32_MAX); term->window->surface.surf, 0, 0, INT32_MAX, INT32_MAX);
} }
wl_surface_attach(term->window->surface, buf->wl_buf, 0, 0); wl_surface_attach(term->window->surface.surf, buf->wl_buf, 0, 0);
wl_surface_commit(term->window->surface); wl_surface_commit(term->window->surface.surf);
} }
static void static void
@ -3374,18 +3374,18 @@ render_search_box(struct terminal *term)
margin / term->scale, margin / term->scale,
max(0, (int32_t)term->height - height - margin) / term->scale); max(0, (int32_t)term->height - height - margin) / term->scale);
wayl_surface_scale(term->wl, term->window->search.surf, term->scale); wayl_surface_scale(term->wl, term->window->search.surface.surf, term->scale);
wl_surface_attach(term->window->search.surf, buf->wl_buf, 0, 0); wl_surface_attach(term->window->search.surface.surf, buf->wl_buf, 0, 0);
wl_surface_damage_buffer(term->window->search.surf, 0, 0, width, height); wl_surface_damage_buffer(term->window->search.surface.surf, 0, 0, width, height);
struct wl_region *region = wl_compositor_create_region(term->wl->compositor); struct wl_region *region = wl_compositor_create_region(term->wl->compositor);
if (region != NULL) { if (region != NULL) {
wl_region_add(region, width - visible_width, 0, visible_width, height); wl_region_add(region, width - visible_width, 0, visible_width, height);
wl_surface_set_opaque_region(term->window->search.surf, region); wl_surface_set_opaque_region(term->window->search.surface.surf, region);
wl_region_destroy(region); wl_region_destroy(region);
} }
wl_surface_commit(term->window->search.surf); wl_surface_commit(term->window->search.surface.surf);
quirk_weston_subsurface_desync_off(term->window->search.sub); quirk_weston_subsurface_desync_off(term->window->search.sub);
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
@ -3466,7 +3466,7 @@ render_urls(struct terminal *term)
continue; continue;
} }
struct wl_surface *surf = it->item.surf.surf; struct wl_surface *surf = it->item.surf.surface.surf;
struct wl_subsurface *sub_surf = it->item.surf.sub; struct wl_subsurface *sub_surf = it->item.surf.sub;
if (surf == NULL || sub_surf == NULL) if (surf == NULL || sub_surf == NULL)
@ -3601,7 +3601,7 @@ render_urls(struct terminal *term)
: term->colors.table[3]; : term->colors.table[3];
for (size_t i = 0; i < render_count; i++) { for (size_t i = 0; i < render_count; i++) {
struct wl_surface *surf = info[i].url->surf.surf; struct wl_surface *surf = info[i].url->surf.surface.surf;
struct wl_subsurface *sub_surf = info[i].url->surf.sub; struct wl_subsurface *sub_surf = info[i].url->surf.sub;
const char32_t *label = info[i].text; const char32_t *label = info[i].text;
@ -4253,8 +4253,8 @@ render_xcursor_update(struct seat *seat)
if (seat->pointer.xcursor == XCURSOR_HIDDEN) { if (seat->pointer.xcursor == XCURSOR_HIDDEN) {
/* Hide cursor */ /* Hide cursor */
wl_surface_attach(seat->pointer.surface, NULL, 0, 0); wl_surface_attach(seat->pointer.surface.surf, NULL, 0, 0);
wl_surface_commit(seat->pointer.surface); wl_surface_commit(seat->pointer.surface.surf);
return; return;
} }
@ -4263,24 +4263,24 @@ render_xcursor_update(struct seat *seat)
const float scale = seat->pointer.scale; const float scale = seat->pointer.scale;
struct wl_cursor_image *image = seat->pointer.cursor->images[0]; struct wl_cursor_image *image = seat->pointer.cursor->images[0];
wayl_surface_scale(seat->wayl, seat->pointer.surface, scale); wayl_surface_scale(seat->wayl, seat->pointer.surface.surf, scale);
wl_surface_attach( wl_surface_attach(
seat->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0); seat->pointer.surface.surf, wl_cursor_image_get_buffer(image), 0, 0);
wl_pointer_set_cursor( wl_pointer_set_cursor(
seat->wl_pointer, seat->pointer.serial, seat->wl_pointer, seat->pointer.serial,
seat->pointer.surface, seat->pointer.surface.surf,
image->hotspot_x / scale, image->hotspot_y / scale); image->hotspot_x / scale, image->hotspot_y / scale);
wl_surface_damage_buffer( wl_surface_damage_buffer(
seat->pointer.surface, 0, 0, INT32_MAX, INT32_MAX); seat->pointer.surface.surf, 0, 0, INT32_MAX, INT32_MAX);
xassert(seat->pointer.xcursor_callback == NULL); xassert(seat->pointer.xcursor_callback == NULL);
seat->pointer.xcursor_callback = wl_surface_frame(seat->pointer.surface); seat->pointer.xcursor_callback = wl_surface_frame(seat->pointer.surface.surf);
wl_callback_add_listener(seat->pointer.xcursor_callback, &xcursor_listener, seat); wl_callback_add_listener(seat->pointer.xcursor_callback, &xcursor_listener, seat);
wl_surface_commit(seat->pointer.surface); wl_surface_commit(seat->pointer.surface.surf);
} }
static void static void

View file

@ -3589,23 +3589,23 @@ term_single_shift(struct terminal *term, enum charset_designator idx)
enum term_surface enum term_surface
term_surface_kind(const struct terminal *term, const struct wl_surface *surface) term_surface_kind(const struct terminal *term, const struct wl_surface *surface)
{ {
if (likely(surface == term->window->surface)) if (likely(surface == term->window->surface.surf))
return TERM_SURF_GRID; return TERM_SURF_GRID;
else if (surface == term->window->csd.surface[CSD_SURF_TITLE].surf) else if (surface == term->window->csd.surface[CSD_SURF_TITLE].surface.surf)
return TERM_SURF_TITLE; return TERM_SURF_TITLE;
else if (surface == term->window->csd.surface[CSD_SURF_LEFT].surf) else if (surface == term->window->csd.surface[CSD_SURF_LEFT].surface.surf)
return TERM_SURF_BORDER_LEFT; return TERM_SURF_BORDER_LEFT;
else if (surface == term->window->csd.surface[CSD_SURF_RIGHT].surf) else if (surface == term->window->csd.surface[CSD_SURF_RIGHT].surface.surf)
return TERM_SURF_BORDER_RIGHT; return TERM_SURF_BORDER_RIGHT;
else if (surface == term->window->csd.surface[CSD_SURF_TOP].surf) else if (surface == term->window->csd.surface[CSD_SURF_TOP].surface.surf)
return TERM_SURF_BORDER_TOP; return TERM_SURF_BORDER_TOP;
else if (surface == term->window->csd.surface[CSD_SURF_BOTTOM].surf) else if (surface == term->window->csd.surface[CSD_SURF_BOTTOM].surface.surf)
return TERM_SURF_BORDER_BOTTOM; return TERM_SURF_BORDER_BOTTOM;
else if (surface == term->window->csd.surface[CSD_SURF_MINIMIZE].surf) else if (surface == term->window->csd.surface[CSD_SURF_MINIMIZE].surface.surf)
return TERM_SURF_BUTTON_MINIMIZE; return TERM_SURF_BUTTON_MINIMIZE;
else if (surface == term->window->csd.surface[CSD_SURF_MAXIMIZE].surf) else if (surface == term->window->csd.surface[CSD_SURF_MAXIMIZE].surface.surf)
return TERM_SURF_BUTTON_MAXIMIZE; return TERM_SURF_BUTTON_MAXIMIZE;
else if (surface == term->window->csd.surface[CSD_SURF_CLOSE].surf) else if (surface == term->window->csd.surface[CSD_SURF_CLOSE].surface.surf)
return TERM_SURF_BUTTON_CLOSE; return TERM_SURF_BUTTON_CLOSE;
else else
return TERM_SURF_NONE; return TERM_SURF_NONE;

125
wayland.c
View file

@ -74,7 +74,7 @@ csd_instantiate(struct wl_window *win)
for (size_t i = CSD_SURF_MINIMIZE; i < CSD_SURF_COUNT; i++) { for (size_t i = CSD_SURF_MINIMIZE; i < CSD_SURF_COUNT; i++) {
bool ret = wayl_win_subsurface_new_with_custom_parent( bool ret = wayl_win_subsurface_new_with_custom_parent(
win, win->csd.surface[CSD_SURF_TITLE].surf, &win->csd.surface[i], win, win->csd.surface[CSD_SURF_TITLE].surface.surf, &win->csd.surface[i],
true); true);
xassert(ret); xassert(ret);
} }
@ -187,8 +187,12 @@ seat_destroy(struct seat *seat)
if (seat->pointer.theme != NULL) if (seat->pointer.theme != NULL)
wl_cursor_theme_destroy(seat->pointer.theme); wl_cursor_theme_destroy(seat->pointer.theme);
if (seat->pointer.surface != NULL) if (seat->pointer.surface.surf != NULL)
wl_surface_destroy(seat->pointer.surface); wl_surface_destroy(seat->pointer.surface.surf);
#if defined(HAVE_FRACTIONAL_SCALE)
if (seat->pointer.surface.viewport != NULL)
wp_viewport_destroy(seat->pointer.surface.viewport);
#endif
if (seat->pointer.xcursor_callback != NULL) if (seat->pointer.xcursor_callback != NULL)
wl_callback_destroy(seat->pointer.xcursor_callback); wl_callback_destroy(seat->pointer.xcursor_callback);
@ -288,10 +292,10 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
if (caps & WL_SEAT_CAPABILITY_POINTER) { if (caps & WL_SEAT_CAPABILITY_POINTER) {
if (seat->wl_pointer == NULL) { if (seat->wl_pointer == NULL) {
xassert(seat->pointer.surface == NULL); xassert(seat->pointer.surface.surf == NULL);
seat->pointer.surface = wl_compositor_create_surface(seat->wayl->compositor); seat->pointer.surface.surf = wl_compositor_create_surface(seat->wayl->compositor);
if (seat->pointer.surface == NULL) { if (seat->pointer.surface.surf == NULL) {
LOG_ERR("%s: failed to create pointer surface", seat->name); LOG_ERR("%s: failed to create pointer surface", seat->name);
return; return;
} }
@ -302,13 +306,13 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
} else { } else {
if (seat->wl_pointer != NULL) { if (seat->wl_pointer != NULL) {
wl_pointer_release(seat->wl_pointer); wl_pointer_release(seat->wl_pointer);
wl_surface_destroy(seat->pointer.surface); wl_surface_destroy(seat->pointer.surface.surf);
if (seat->pointer.theme != NULL) if (seat->pointer.theme != NULL)
wl_cursor_theme_destroy(seat->pointer.theme); wl_cursor_theme_destroy(seat->pointer.theme);
seat->wl_pointer = NULL; seat->wl_pointer = NULL;
seat->pointer.surface = NULL; seat->pointer.surface.surf = NULL;
seat->pointer.theme = NULL; seat->pointer.theme = NULL;
seat->pointer.cursor = NULL; seat->pointer.cursor = NULL;
} }
@ -848,7 +852,7 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface,
* anytime soon. Some compositors require a commit in * anytime soon. Some compositors require a commit in
* combination with an ack - make them happy. * combination with an ack - make them happy.
*/ */
wl_surface_commit(win->surface); wl_surface_commit(win->surface.surf);
} }
if (wasnt_configured) if (wasnt_configured)
@ -1225,7 +1229,7 @@ handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
if (seat->wl_keyboard != NULL) if (seat->wl_keyboard != NULL)
keyboard_listener.leave( keyboard_listener.leave(
seat, seat->wl_keyboard, -1, seat->kbd_focus->window->surface); seat, seat->wl_keyboard, -1, seat->kbd_focus->window->surface.surf);
} }
if (seat->mouse_focus != NULL) { if (seat->mouse_focus != NULL) {
@ -1235,7 +1239,7 @@ handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
if (seat->wl_pointer != NULL) if (seat->wl_pointer != NULL)
pointer_listener.leave( pointer_listener.leave(
seat, seat->wl_pointer, -1, seat->mouse_focus->window->surface); seat, seat->wl_pointer, -1, seat->mouse_focus->window->surface.surf);
} }
seat_destroy(seat); seat_destroy(seat);
@ -1531,29 +1535,29 @@ wayl_win_init(struct terminal *term, const char *token)
win->wm_capabilities.maximize = true; win->wm_capabilities.maximize = true;
win->wm_capabilities.minimize = true; win->wm_capabilities.minimize = true;
win->surface = wl_compositor_create_surface(wayl->compositor); win->surface.surf = wl_compositor_create_surface(wayl->compositor);
if (win->surface == NULL) { if (win->surface.surf == NULL) {
LOG_ERR("failed to create wayland surface"); LOG_ERR("failed to create wayland surface");
goto out; goto out;
} }
wayl_win_alpha_changed(win); wayl_win_alpha_changed(win);
wl_surface_add_listener(win->surface, &surface_listener, win); wl_surface_add_listener(win->surface.surf, &surface_listener, win);
#if defined(HAVE_FRACTIONAL_SCALE) #if defined(HAVE_FRACTIONAL_SCALE)
if (wayl->fractional_scale_manager != NULL && wayl->viewporter != NULL) { if (wayl->fractional_scale_manager != NULL && wayl->viewporter != NULL) {
win->viewport = wp_viewporter_get_viewport(wayl->viewporter, win->surface); win->surface.viewport = wp_viewporter_get_viewport(wayl->viewporter, win->surface.surf);
win->fractional_scale = win->fractional_scale =
wp_fractional_scale_manager_v1_get_fractional_scale( wp_fractional_scale_manager_v1_get_fractional_scale(
wayl->fractional_scale_manager, win->surface); wayl->fractional_scale_manager, win->surface.surf);
wp_fractional_scale_v1_add_listener( wp_fractional_scale_v1_add_listener(
win->fractional_scale, &fractional_scale_listener, win); win->fractional_scale, &fractional_scale_listener, win);
} }
#endif #endif
win->xdg_surface = xdg_wm_base_get_xdg_surface(wayl->shell, win->surface); win->xdg_surface = xdg_wm_base_get_xdg_surface(wayl->shell, win->surface.surf);
xdg_surface_add_listener(win->xdg_surface, &xdg_surface_listener, win); xdg_surface_add_listener(win->xdg_surface, &xdg_surface_listener, win);
win->xdg_toplevel = xdg_surface_get_toplevel(win->xdg_surface); win->xdg_toplevel = xdg_surface_get_toplevel(win->xdg_surface);
@ -1586,12 +1590,12 @@ wayl_win_init(struct terminal *term, const char *token)
LOG_WARN("no decoration manager available - using CSDs unconditionally"); LOG_WARN("no decoration manager available - using CSDs unconditionally");
} }
wl_surface_commit(win->surface); wl_surface_commit(win->surface.surf);
#if defined(HAVE_XDG_ACTIVATION) #if defined(HAVE_XDG_ACTIVATION)
/* Complete XDG startup notification */ /* Complete XDG startup notification */
if (token) if (token)
xdg_activation_v1_activate(wayl->xdg_activation, token, win->surface); xdg_activation_v1_activate(wayl->xdg_activation, token, win->surface.surf);
#endif #endif
if (!wayl_win_subsurface_new(win, &win->overlay, false)) { if (!wayl_win_subsurface_new(win, &win->overlay, false)) {
@ -1641,33 +1645,33 @@ wayl_win_destroy(struct wl_window *win)
* nor mouse focus). * nor mouse focus).
*/ */
if (win->render_timer.surf != NULL) { if (win->render_timer.surface.surf != NULL) {
wl_surface_attach(win->render_timer.surf, NULL, 0, 0); wl_surface_attach(win->render_timer.surface.surf, NULL, 0, 0);
wl_surface_commit(win->render_timer.surf); wl_surface_commit(win->render_timer.surface.surf);
} }
if (win->scrollback_indicator.surf != NULL) { if (win->scrollback_indicator.surface.surf != NULL) {
wl_surface_attach(win->scrollback_indicator.surf, NULL, 0, 0); wl_surface_attach(win->scrollback_indicator.surface.surf, NULL, 0, 0);
wl_surface_commit(win->scrollback_indicator.surf); wl_surface_commit(win->scrollback_indicator.surface.surf);
} }
/* Scrollback search */ /* Scrollback search */
if (win->search.surf != NULL) { if (win->search.surface.surf != NULL) {
wl_surface_attach(win->search.surf, NULL, 0, 0); wl_surface_attach(win->search.surface.surf, NULL, 0, 0);
wl_surface_commit(win->search.surf); wl_surface_commit(win->search.surface.surf);
} }
/* URLs */ /* URLs */
tll_foreach(win->urls, it) { tll_foreach(win->urls, it) {
wl_surface_attach(it->item.surf.surf, NULL, 0, 0); wl_surface_attach(it->item.surf.surface.surf, NULL, 0, 0);
wl_surface_commit(it->item.surf.surf); wl_surface_commit(it->item.surf.surface.surf);
} }
/* CSD */ /* CSD */
for (size_t i = 0; i < ALEN(win->csd.surface); i++) { for (size_t i = 0; i < ALEN(win->csd.surface); i++) {
if (win->csd.surface[i].surf != NULL) { if (win->csd.surface[i].surface.surf != NULL) {
wl_surface_attach(win->csd.surface[i].surf, NULL, 0, 0); wl_surface_attach(win->csd.surface[i].surface.surf, NULL, 0, 0);
wl_surface_commit(win->csd.surface[i].surf); wl_surface_commit(win->csd.surface[i].surface.surf);
} }
} }
@ -1675,8 +1679,8 @@ wayl_win_destroy(struct wl_window *win)
/* Main window */ /* Main window */
win->unmapped = true; win->unmapped = true;
wl_surface_attach(win->surface, NULL, 0, 0); wl_surface_attach(win->surface.surf, NULL, 0, 0);
wl_surface_commit(win->surface); wl_surface_commit(win->surface.surf);
wayl_roundtrip(win->term->wl); wayl_roundtrip(win->term->wl);
tll_free(win->on_outputs); tll_free(win->on_outputs);
@ -1710,8 +1714,8 @@ wayl_win_destroy(struct wl_window *win)
#if defined(HAVE_FRACTIONAL_SCALE) #if defined(HAVE_FRACTIONAL_SCALE)
if (win->fractional_scale != NULL) if (win->fractional_scale != NULL)
wp_fractional_scale_v1_destroy(win->fractional_scale); wp_fractional_scale_v1_destroy(win->fractional_scale);
if (win->viewport != NULL) if (win->surface.viewport != NULL)
wp_viewport_destroy(win->viewport); wp_viewport_destroy(win->surface.viewport);
#endif #endif
if (win->frame_callback != NULL) if (win->frame_callback != NULL)
wl_callback_destroy(win->frame_callback); wl_callback_destroy(win->frame_callback);
@ -1721,8 +1725,8 @@ wayl_win_destroy(struct wl_window *win)
xdg_toplevel_destroy(win->xdg_toplevel); xdg_toplevel_destroy(win->xdg_toplevel);
if (win->xdg_surface != NULL) if (win->xdg_surface != NULL)
xdg_surface_destroy(win->xdg_surface); xdg_surface_destroy(win->xdg_surface);
if (win->surface != NULL) if (win->surface.surf != NULL)
wl_surface_destroy(win->surface); wl_surface_destroy(win->surface.surf);
wayl_roundtrip(win->term->wl); wayl_roundtrip(win->term->wl);
@ -1880,7 +1884,7 @@ wayl_win_scale(struct wl_window *win)
const struct wayland *wayl = term->wl; const struct wayland *wayl = term->wl;
const float scale = term->scale; const float scale = term->scale;
wayl_surface_scale(wayl, win->surface, scale); wayl_surface_scale(wayl, win->surface.surf, scale);
} }
void void
@ -1894,11 +1898,11 @@ wayl_win_alpha_changed(struct wl_window *win)
if (region != NULL) { if (region != NULL) {
wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX); wl_region_add(region, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_set_opaque_region(win->surface, region); wl_surface_set_opaque_region(win->surface.surf, region);
wl_region_destroy(region); wl_region_destroy(region);
} }
} else } else
wl_surface_set_opaque_region(win->surface, NULL); wl_surface_set_opaque_region(win->surface.surf, NULL);
} }
#if defined(HAVE_XDG_ACTIVATION) #if defined(HAVE_XDG_ACTIVATION)
@ -1909,7 +1913,7 @@ activation_token_for_urgency_done(const char *token, void *data)
struct wayland *wayl = win->term->wl; struct wayland *wayl = win->term->wl;
win->urgency_token_is_pending = false; win->urgency_token_is_pending = false;
xdg_activation_v1_activate(wayl->xdg_activation, token, win->surface); xdg_activation_v1_activate(wayl->xdg_activation, token, win->surface.surf);
} }
#endif /* HAVE_XDG_ACTIVATION */ #endif /* HAVE_XDG_ACTIVATION */
@ -1954,11 +1958,11 @@ wayl_win_csd_borders_visible(const struct wl_window *win)
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,
struct wl_surf_subsurf *surf, bool allow_pointer_input) struct wayl_sub_surface *surf, bool allow_pointer_input)
{ {
struct wayland *wayl = win->term->wl; struct wayland *wayl = win->term->wl;
surf->surf = NULL; surf->surface.surf = NULL;
surf->sub = NULL; surf->sub = NULL;
struct wl_surface *main_surface struct wl_surface *main_surface
@ -2002,39 +2006,42 @@ wayl_win_subsurface_new_with_custom_parent(
wl_region_destroy(empty); wl_region_destroy(empty);
} }
surf->surf = main_surface; surf->surface.surf = main_surface;
surf->sub = sub; surf->sub = sub;
#if defined(HAVE_FRACTIONAL_SCALE) #if defined(HAVE_FRACTIONAL_SCALE)
surf->viewport = viewport; surf->surface.viewport = viewport;
#endif #endif
return true; return true;
} }
bool bool
wayl_win_subsurface_new(struct wl_window *win, struct wl_surf_subsurf *surf, wayl_win_subsurface_new(struct wl_window *win, struct wayl_sub_surface *surf,
bool allow_pointer_input) bool allow_pointer_input)
{ {
return wayl_win_subsurface_new_with_custom_parent( return wayl_win_subsurface_new_with_custom_parent(
win, win->surface, surf, allow_pointer_input); win, win->surface.surf, surf, allow_pointer_input);
} }
void void
wayl_win_subsurface_destroy(struct wl_surf_subsurf *surf) wayl_win_subsurface_destroy(struct wayl_sub_surface *surf)
{ {
if (surf == NULL) if (surf == NULL)
return; return;
#if defined(HAVE_FRACTIONAL_SCALE) #if defined(HAVE_FRACTIONAL_SCALE)
if (surf->viewport != NULL) if (surf->surface.viewport != NULL) {
wp_viewport_destroy(surf->viewport); wp_viewport_destroy(surf->surface.viewport);
surf->surface.viewport = NULL;
}
#endif #endif
if (surf->sub != NULL) if (surf->sub != NULL) {
wl_subsurface_destroy(surf->sub); wl_subsurface_destroy(surf->sub);
if (surf->surf != NULL) surf->sub = NULL;
wl_surface_destroy(surf->surf); }
if (surf->surface.surf != NULL) {
surf->surf = NULL; wl_surface_destroy(surf->surface.surf);
surf->sub = NULL; surf->surface.surf = NULL;
}
} }
#if defined(HAVE_XDG_ACTIVATION) #if defined(HAVE_XDG_ACTIVATION)
@ -2099,7 +2106,7 @@ wayl_get_activation_token(
if (seat != NULL && serial != 0) if (seat != NULL && serial != 0)
xdg_activation_token_v1_set_serial(token, serial, seat->wl_seat); xdg_activation_token_v1_set_serial(token, serial, seat->wl_seat);
xdg_activation_token_v1_set_surface(token, win->surface); xdg_activation_token_v1_set_surface(token, win->surface.surf);
xdg_activation_token_v1_add_listener(token, &activation_token_listener, ctx); xdg_activation_token_v1_add_listener(token, &activation_token_listener, ctx);
xdg_activation_token_v1_commit(token); xdg_activation_token_v1_commit(token);
return true; return true;

View file

@ -45,6 +45,18 @@ enum data_offer_mime_type {
DATA_OFFER_MIME_TEXT_UTF8_STRING, DATA_OFFER_MIME_TEXT_UTF8_STRING,
}; };
struct wayl_surface {
struct wl_surface *surf;
#if defined(HAVE_FRACTIONAL_SCALE)
struct wp_viewport *viewport;
#endif
};
struct wayl_sub_surface {
struct wayl_surface surface;
struct wl_subsurface *sub;
};
struct wl_window; struct wl_window;
struct wl_clipboard { struct wl_clipboard {
struct wl_window *window; /* For DnD */ struct wl_window *window; /* For DnD */
@ -132,7 +144,7 @@ struct seat {
struct { struct {
uint32_t serial; uint32_t serial;
struct wl_surface *surface; struct wayl_surface surface;
struct wl_cursor_theme *theme; struct wl_cursor_theme *theme;
struct wl_cursor *cursor; struct wl_cursor *cursor;
float scale; float scale;
@ -294,17 +306,9 @@ struct monitor {
bool use_output_release; bool use_output_release;
}; };
struct wl_surf_subsurf {
struct wl_surface *surf;
struct wl_subsurface *sub;
#if defined(HAVE_FRACTIONAL_SCALE)
struct wp_viewport *viewport;
#endif
};
struct wl_url { struct wl_url {
const struct url *url; const struct url *url;
struct wl_surf_subsurf surf; struct wayl_sub_surface surf;
}; };
enum csd_mode {CSD_UNKNOWN, CSD_NO, CSD_YES}; enum csd_mode {CSD_UNKNOWN, CSD_NO, CSD_YES};
@ -328,7 +332,7 @@ struct xdg_activation_token_context {
struct wayland; struct wayland;
struct wl_window { struct wl_window {
struct terminal *term; struct terminal *term;
struct wl_surface *surface; struct wayl_surface surface;
struct xdg_surface *xdg_surface; struct xdg_surface *xdg_surface;
struct xdg_toplevel *xdg_toplevel; struct xdg_toplevel *xdg_toplevel;
#if defined(HAVE_XDG_ACTIVATION) #if defined(HAVE_XDG_ACTIVATION)
@ -336,7 +340,6 @@ struct wl_window {
bool urgency_token_is_pending; bool urgency_token_is_pending;
#endif #endif
#if defined(HAVE_FRACTIONAL_SCALE) #if defined(HAVE_FRACTIONAL_SCALE)
struct wp_viewport *viewport;
struct wp_fractional_scale_v1 *fractional_scale; struct wp_fractional_scale_v1 *fractional_scale;
#endif #endif
bool unmapped; bool unmapped;
@ -348,7 +351,7 @@ struct wl_window {
enum csd_mode csd_mode; enum csd_mode csd_mode;
struct { struct {
struct wl_surf_subsurf surface[CSD_SURF_COUNT]; struct wayl_sub_surface surface[CSD_SURF_COUNT];
struct fcft_font *font; struct fcft_font *font;
int move_timeout_fd; int move_timeout_fd;
uint32_t serial; uint32_t serial;
@ -359,10 +362,10 @@ struct wl_window {
bool minimize:1; bool minimize:1;
} wm_capabilities; } wm_capabilities;
struct wl_surf_subsurf search; struct wayl_sub_surface search;
struct wl_surf_subsurf scrollback_indicator; struct wayl_sub_surface scrollback_indicator;
struct wl_surf_subsurf render_timer; struct wayl_sub_surface render_timer;
struct wl_surf_subsurf overlay; struct wayl_sub_surface overlay;
struct wl_callback *frame_callback; struct wl_callback *frame_callback;
@ -465,12 +468,12 @@ 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_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 wayl_sub_surface *surf,
bool allow_pointer_input); bool allow_pointer_input);
bool wayl_win_subsurface_new_with_custom_parent( bool wayl_win_subsurface_new_with_custom_parent(
struct wl_window *win, struct wl_surface *parent, struct wl_window *win, struct wl_surface *parent,
struct wl_surf_subsurf *surf, bool allow_pointer_input); struct wayl_sub_surface *surf, bool allow_pointer_input);
void wayl_win_subsurface_destroy(struct wl_surf_subsurf *surf); void wayl_win_subsurface_destroy(struct wayl_sub_surface *surf);
#if defined(HAVE_XDG_ACTIVATION) #if defined(HAVE_XDG_ACTIVATION)
bool wayl_get_activation_token( bool wayl_get_activation_token(