Merge branch 'refactor-subsurface-creation'

This commit is contained in:
Daniel Eklöf 2021-02-17 21:51:31 +01:00
commit 34f89fbe72
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 144 additions and 190 deletions

View file

@ -52,7 +52,7 @@ quirk_weston_csd_on(struct terminal *term)
return;
for (int i = 0; i < ALEN(term->window->csd.surface); i++)
quirk_weston_subsurface_desync_on(term->window->csd.sub_surface[i]);
quirk_weston_subsurface_desync_on(term->window->csd.surface[i].sub);
}
void
@ -64,7 +64,7 @@ quirk_weston_csd_off(struct terminal *term)
return;
for (int i = 0; i < ALEN(term->window->csd.surface); i++)
quirk_weston_subsurface_desync_off(term->window->csd.sub_surface[i]);
quirk_weston_subsurface_desync_off(term->window->csd.surface[i].sub);
}
void

View file

@ -1409,7 +1409,7 @@ render_csd_title(struct terminal *term)
xassert(term->window->use_csd == CSD_YES);
struct csd_data info = get_csd_data(term, CSD_SURF_TITLE);
struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE];
struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE].surf;
xassert(info.width > 0 && info.height > 0);
@ -1440,7 +1440,7 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx)
xassert(surf_idx >= CSD_SURF_LEFT && surf_idx <= CSD_SURF_BOTTOM);
struct csd_data info = get_csd_data(term, surf_idx);
struct wl_surface *surf = term->window->csd.surface[surf_idx];
struct wl_surface *surf = term->window->csd.surface[surf_idx].surf;
if (info.width == 0 || info.height == 0)
return;
@ -1609,7 +1609,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx)
xassert(surf_idx >= CSD_SURF_MINIMIZE && surf_idx <= CSD_SURF_CLOSE);
struct csd_data info = get_csd_data(term, surf_idx);
struct wl_surface *surf = term->window->csd.surface[surf_idx];
struct wl_surface *surf = term->window->csd.surface[surf_idx].surf;
if (info.width == 0 || info.height == 0)
return;
@ -1696,8 +1696,8 @@ render_csd(struct terminal *term)
const int width = info.width;
const int height = info.height;
struct wl_surface *surf = term->window->csd.surface[i];
struct wl_subsurface *sub = term->window->csd.sub_surface[i];
struct wl_surface *surf = term->window->csd.surface[i].surf;
struct wl_subsurface *sub = term->window->csd.surface[i].sub;
xassert(surf != NULL);
xassert(sub != NULL);
@ -1775,49 +1775,23 @@ render_scrollback_position(struct terminal *term)
if (term->conf->scrollback.indicator.position == SCROLLBACK_INDICATOR_POSITION_NONE)
return;
struct wayland *wayl = term->wl;
struct wl_window *win = term->window;
if (term->grid->view == term->grid->offset) {
if (win->scrollback_indicator_surface != NULL) {
wl_subsurface_destroy(win->scrollback_indicator_sub_surface);
wl_surface_destroy(win->scrollback_indicator_surface);
win->scrollback_indicator_surface = NULL;
win->scrollback_indicator_sub_surface = NULL;
}
if (win->scrollback_indicator.surf != NULL)
wayl_win_subsurface_destroy(&win->scrollback_indicator);
return;
}
if (win->scrollback_indicator_surface == NULL) {
win->scrollback_indicator_surface
= wl_compositor_create_surface(wayl->compositor);
if (win->scrollback_indicator_surface == NULL) {
if (win->scrollback_indicator.surf == NULL) {
if (!wayl_win_subsurface_new(win, &win->scrollback_indicator)) {
LOG_ERR("failed to create scrollback indicator surface");
return;
}
wl_surface_set_user_data(win->scrollback_indicator_surface, win);
term->window->scrollback_indicator_sub_surface
= wl_subcompositor_get_subsurface(
wayl->sub_compositor,
win->scrollback_indicator_surface,
win->surface);
if (win->scrollback_indicator_sub_surface == NULL) {
LOG_ERR("failed to create scrollback indicator sub-surface");
wl_surface_destroy(win->scrollback_indicator_surface);
win->scrollback_indicator_surface = NULL;
return;
}
wl_subsurface_set_sync(win->scrollback_indicator_sub_surface);
}
xassert(win->scrollback_indicator_surface != NULL);
xassert(win->scrollback_indicator_sub_surface != NULL);
xassert(win->scrollback_indicator.surf != NULL);
xassert(win->scrollback_indicator.sub != NULL);
/* Find absolute row number of the scrollback start */
int scrollback_start = term->grid->offset + term->rows;
@ -1905,13 +1879,14 @@ render_scrollback_position(struct terminal *term)
}
wl_subsurface_set_position(
win->scrollback_indicator_sub_surface,
win->scrollback_indicator.sub,
(term->width - margin - width) / scale,
(term->margins.top + surf_top) / scale);
render_osd(
term,
win->scrollback_indicator_surface, win->scrollback_indicator_sub_surface,
win->scrollback_indicator.surf,
win->scrollback_indicator.sub,
buf, text,
term->colors.table[0], term->colors.table[8 + 4],
width, height, width - margin - wcslen(text) * term->cell_width, margin);
@ -1937,13 +1912,14 @@ render_render_timer(struct terminal *term, struct timeval render_time)
term->wl->shm, width, height, cookie, false, 1);
wl_subsurface_set_position(
win->render_timer_sub_surface,
win->render_timer.sub,
margin / term->scale,
(term->margins.top + term->cell_height - margin) / term->scale);
render_osd(
term,
win->render_timer_surface, win->render_timer_sub_surface,
win->render_timer.surf,
win->render_timer.sub,
buf, text,
term->colors.table[0], term->colors.table[8 + 1],
width, height, margin, margin);
@ -2232,7 +2208,7 @@ grid_render(struct terminal *term)
static void
render_search_box(struct terminal *term)
{
xassert(term->window->search_sub_surface != NULL);
xassert(term->window->search.sub != NULL);
/*
* We treat the search box pretty much like a row of cells. That
@ -2505,27 +2481,27 @@ render_search_box(struct terminal *term)
term, WINDOW_X(x), WINDOW_Y(y), 1, term->cell_height);
}
quirk_weston_subsurface_desync_on(term->window->search_sub_surface);
quirk_weston_subsurface_desync_on(term->window->search.sub);
/* TODO: this is only necessary on a window resize */
wl_subsurface_set_position(
term->window->search_sub_surface,
term->window->search.sub,
margin / scale,
max(0, (int32_t)term->height - height - margin) / scale);
wl_surface_attach(term->window->search_surface, buf->wl_buf, 0, 0);
wl_surface_damage_buffer(term->window->search_surface, 0, 0, width, height);
wl_surface_set_buffer_scale(term->window->search_surface, scale);
wl_surface_attach(term->window->search.surf, buf->wl_buf, 0, 0);
wl_surface_damage_buffer(term->window->search.surf, 0, 0, width, height);
wl_surface_set_buffer_scale(term->window->search.surf, scale);
struct wl_region *region = wl_compositor_create_region(term->wl->compositor);
if (region != NULL) {
wl_region_add(region, width - visible_width, 0, visible_width, height);
wl_surface_set_opaque_region(term->window->search_surface, region);
wl_surface_set_opaque_region(term->window->search.surf, region);
wl_region_destroy(region);
}
wl_surface_commit(term->window->search_surface);
quirk_weston_subsurface_desync_off(term->window->search_sub_surface);
wl_surface_commit(term->window->search.surf);
quirk_weston_subsurface_desync_off(term->window->search.sub);
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
free(text);
@ -2555,8 +2531,8 @@ render_urls(struct terminal *term)
const wchar_t *key = url->key;
const size_t entered_key_len = wcslen(term->url_keys);
struct wl_surface *surf = it->item.surf;
struct wl_subsurface *sub_surf = it->item.sub_surf;
struct wl_surface *surf = it->item.surf.surf;
struct wl_subsurface *sub_surf = it->item.surf.sub;
if (surf == NULL || sub_surf == NULL)
continue;

View file

@ -81,13 +81,7 @@ static void
search_cancel_keep_selection(struct terminal *term)
{
struct wl_window *win = term->window;
if (win->search_sub_surface != NULL)
wl_subsurface_destroy(win->search_sub_surface);
if (win->search_surface != NULL)
wl_surface_destroy(win->search_surface);
win->search_surface = NULL;
win->search_sub_surface = NULL;
wayl_win_subsurface_destroy(&win->search);
free(term->search.buf);
term->search.buf = NULL;
@ -124,14 +118,8 @@ search_begin(struct terminal *term)
}
/* On-demand instantiate wayland surface */
struct wl_window *win = term->window;
struct wayland *wayl = term->wl;
win->search_surface = wl_compositor_create_surface(wayl->compositor);
wl_surface_set_user_data(win->search_surface, term->window);
win->search_sub_surface = wl_subcompositor_get_subsurface(
wayl->sub_compositor, win->search_surface, win->surface);
wl_subsurface_set_sync(win->search_sub_surface);
bool ret = wayl_win_subsurface_new(term->window, &term->window->search);
xassert(ret);
term->search.original_view = term->grid->view;
term->search.view_followed_offset = term->grid->view == term->grid->offset;

View file

@ -2821,31 +2821,31 @@ term_surface_kind(const struct terminal *term, const struct wl_surface *surface)
{
if (likely(surface == term->window->surface))
return TERM_SURF_GRID;
else if (surface == term->window->search_surface)
else if (surface == term->window->search.surf)
return TERM_SURF_SEARCH;
else if (surface == term->window->scrollback_indicator_surface)
else if (surface == term->window->scrollback_indicator.surf)
return TERM_SURF_SCROLLBACK_INDICATOR;
else if (surface == term->window->render_timer_surface)
else if (surface == term->window->render_timer.surf)
return TERM_SURF_RENDER_TIMER;
else if (surface == term->window->csd.surface[CSD_SURF_TITLE])
else if (surface == term->window->csd.surface[CSD_SURF_TITLE].surf)
return TERM_SURF_TITLE;
else if (surface == term->window->csd.surface[CSD_SURF_LEFT])
else if (surface == term->window->csd.surface[CSD_SURF_LEFT].surf)
return TERM_SURF_BORDER_LEFT;
else if (surface == term->window->csd.surface[CSD_SURF_RIGHT])
else if (surface == term->window->csd.surface[CSD_SURF_RIGHT].surf)
return TERM_SURF_BORDER_RIGHT;
else if (surface == term->window->csd.surface[CSD_SURF_TOP])
else if (surface == term->window->csd.surface[CSD_SURF_TOP].surf)
return TERM_SURF_BORDER_TOP;
else if (surface == term->window->csd.surface[CSD_SURF_BOTTOM])
else if (surface == term->window->csd.surface[CSD_SURF_BOTTOM].surf)
return TERM_SURF_BORDER_BOTTOM;
else if (surface == term->window->csd.surface[CSD_SURF_MINIMIZE])
else if (surface == term->window->csd.surface[CSD_SURF_MINIMIZE].surf)
return TERM_SURF_BUTTON_MINIMIZE;
else if (surface == term->window->csd.surface[CSD_SURF_MAXIMIZE])
else if (surface == term->window->csd.surface[CSD_SURF_MAXIMIZE].surf)
return TERM_SURF_BUTTON_MAXIMIZE;
else if (surface == term->window->csd.surface[CSD_SURF_CLOSE])
else if (surface == term->window->csd.surface[CSD_SURF_CLOSE].surf)
return TERM_SURF_BUTTON_CLOSE;
else {
tll_foreach(term->window->urls, it) {
if (surface == it->item.surf)
if (surface == it->item.surf.surf)
return TERM_SURF_JUMP_LABEL;
}
return TERM_SURF_NONE;

View file

@ -472,45 +472,14 @@ void
urls_render(struct terminal *term)
{
struct wl_window *win = term->window;
struct wayland *wayl = term->wl;
if (tll_length(win->term->urls) == 0)
return;
xassert(tll_length(win->urls) == 0);
tll_foreach(win->term->urls, it) {
struct wl_surface *surf = wl_compositor_create_surface(wayl->compositor);
wl_surface_set_user_data(surf, win);
struct wl_subsurface *sub_surf = NULL;
if (surf != NULL) {
sub_surf = wl_subcompositor_get_subsurface(
wayl->sub_compositor, surf, win->surface);
if (sub_surf != NULL)
wl_subsurface_set_sync(sub_surf);
}
if (surf == NULL || sub_surf == NULL) {
LOG_WARN("failed to create URL (sub)-surface");
if (surf != NULL) {
wl_surface_destroy(surf);
surf = NULL;
}
if (sub_surf != NULL) {
wl_subsurface_destroy(sub_surf);
sub_surf = NULL;
}
}
struct wl_url url = {
.url = &it->item,
.surf = surf,
.sub_surf = sub_surf,
};
struct wl_url url = {.url = &it->item};
wayl_win_subsurface_new(win, &url.surf);
tll_push_back(win->urls, url);
tag_cells_for_url(term, &it->item, true);
@ -536,10 +505,7 @@ urls_reset(struct terminal *term)
if (term->window != NULL) {
tll_foreach(term->window->urls, it) {
if (it->item.sub_surf != NULL)
wl_subsurface_destroy(it->item.sub_surf);
if (it->item.surf != NULL)
wl_surface_destroy(it->item.surf);
wayl_win_subsurface_destroy(&it->item.surf);
tll_remove(term->window->urls, it);
}
}

136
wayland.c
View file

@ -39,36 +39,23 @@ csd_instantiate(struct wl_window *win)
struct wayland *wayl = win->term->wl;
xassert(wayl != NULL);
for (size_t i = 0; i < ALEN(win->csd.surface); i++) {
xassert(win->csd.surface[i] == NULL);
xassert(win->csd.sub_surface[i] == NULL);
for (size_t i = 0; i < CSD_SURF_MINIMIZE; i++) {
bool ret = wayl_win_subsurface_new(win, &win->csd.surface[i]);
xassert(ret);
}
win->csd.surface[i] = wl_compositor_create_surface(wayl->compositor);
struct wl_surface *parent = i < CSD_SURF_MINIMIZE
? win->surface : win->csd.surface[CSD_SURF_TITLE];
win->csd.sub_surface[i] = wl_subcompositor_get_subsurface(
wayl->sub_compositor, win->csd.surface[i], parent);
wl_subsurface_set_sync(win->csd.sub_surface[i]);
wl_surface_set_user_data(win->csd.surface[i], win);
wl_surface_commit(win->csd.surface[i]);
for (size_t i = CSD_SURF_MINIMIZE; i < CSD_SURF_COUNT; i++) {
bool ret = wayl_win_subsurface_new_with_custom_parent(
win, win->csd.surface[CSD_SURF_TITLE].surf, &win->csd.surface[i]);
xassert(ret);
}
}
static void
csd_destroy(struct wl_window *win)
{
for (size_t i = 0; i < ALEN(win->csd.surface); i++) {
if (win->csd.sub_surface[i] != NULL)
wl_subsurface_destroy(win->csd.sub_surface[i]);
if (win->csd.surface[i] != NULL)
wl_surface_destroy(win->csd.surface[i]);
win->csd.surface[i] = NULL;
win->csd.sub_surface[i] = NULL;
}
for (size_t i = 0; i < ALEN(win->csd.surface); i++)
wayl_win_subsurface_destroy(&win->csd.surface[i]);
}
static void
@ -1359,16 +1346,10 @@ wayl_win_init(struct terminal *term)
wl_surface_commit(win->surface);
if (conf->tweak.render_timer_osd) {
win->render_timer_surface = wl_compositor_create_surface(wayl->compositor);
if (win->render_timer_surface == NULL) {
if (!wayl_win_subsurface_new(win, &win->render_timer)) {
LOG_ERR("failed to create render timer surface");
goto out;
}
win->render_timer_sub_surface = wl_subcompositor_get_subsurface(
wayl->sub_compositor, win->render_timer_surface, win->surface);
wl_subsurface_set_sync(win->render_timer_sub_surface);
wl_surface_set_user_data(win->render_timer_surface, win);
wl_surface_commit(win->render_timer_surface);
}
return win;
@ -1396,27 +1377,27 @@ wayl_win_destroy(struct wl_window *win)
* nor mouse focus).
*/
if (win->render_timer_surface != NULL) {
wl_surface_attach(win->render_timer_surface, NULL, 0, 0);
wl_surface_commit(win->render_timer_surface);
if (win->render_timer.surf != NULL) {
wl_surface_attach(win->render_timer.surf, NULL, 0, 0);
wl_surface_commit(win->render_timer.surf);
}
if (win->scrollback_indicator_surface != NULL) {
wl_surface_attach(win->scrollback_indicator_surface, NULL, 0, 0);
wl_surface_commit(win->scrollback_indicator_surface);
if (win->scrollback_indicator.surf != NULL) {
wl_surface_attach(win->scrollback_indicator.surf, NULL, 0, 0);
wl_surface_commit(win->scrollback_indicator.surf);
}
/* Scrollback search */
if (win->search_surface != NULL) {
wl_surface_attach(win->search_surface, NULL, 0, 0);
wl_surface_commit(win->search_surface);
if (win->search.surf != NULL) {
wl_surface_attach(win->search.surf, NULL, 0, 0);
wl_surface_commit(win->search.surf);
}
/* CSD */
for (size_t i = 0; i < ALEN(win->csd.surface); i++) {
if (win->csd.surface[i] != NULL) {
wl_surface_attach(win->csd.surface[i], NULL, 0, 0);
wl_surface_commit(win->csd.surface[i]);
if (win->csd.surface[i].surf != NULL) {
wl_surface_attach(win->csd.surface[i].surf, NULL, 0, 0);
wl_surface_commit(win->csd.surface[i].surf);
}
}
@ -1430,26 +1411,15 @@ wayl_win_destroy(struct wl_window *win)
tll_free(win->on_outputs);
tll_foreach(win->urls, it) {
if (it->item.sub_surf != NULL)
wl_subsurface_destroy(it->item.sub_surf);
if (it->item.surf != NULL)
wl_surface_destroy(it->item.surf);
wayl_win_subsurface_destroy(&it->item.surf);
tll_remove(win->urls, it);
}
csd_destroy(win);
if (win->render_timer_sub_surface != NULL)
wl_subsurface_destroy(win->render_timer_sub_surface);
if (win->render_timer_surface != NULL)
wl_surface_destroy(win->render_timer_surface);
if (win->scrollback_indicator_sub_surface != NULL)
wl_subsurface_destroy(win->scrollback_indicator_sub_surface);
if (win->scrollback_indicator_surface != NULL)
wl_surface_destroy(win->scrollback_indicator_surface);
if (win->search_sub_surface != NULL)
wl_subsurface_destroy(win->search_sub_surface);
if (win->search_surface != NULL)
wl_surface_destroy(win->search_surface);
wayl_win_subsurface_destroy(&win->search);
wayl_win_subsurface_destroy(&win->scrollback_indicator);
wayl_win_subsurface_destroy(&win->render_timer);
if (win->frame_callback != NULL)
wl_callback_destroy(win->frame_callback);
if (win->xdg_toplevel_decoration != NULL)
@ -1570,3 +1540,53 @@ wayl_roundtrip(struct wayland *wayl)
wl_display_dispatch_pending(wayl->display);
wayl_flush(wayl);
}
bool
wayl_win_subsurface_new_with_custom_parent(
struct wl_window *win, struct wl_surface *parent,
struct wl_surf_subsurf *surf)
{
struct wayland *wayl = win->term->wl;
surf->surf = NULL;
surf->sub = NULL;
struct wl_surface *main = wl_compositor_create_surface(wayl->compositor);
if (main == NULL)
return false;
struct wl_subsurface *sub = wl_subcompositor_get_subsurface(
wayl->sub_compositor, main, parent);
if (sub == NULL) {
wl_surface_destroy(main);
return false;
}
wl_surface_set_user_data(main, win);
wl_subsurface_set_sync(sub);
surf->surf = main;
surf->sub = sub;
return true;
}
bool
wayl_win_subsurface_new(struct wl_window *win, struct wl_surf_subsurf *surf)
{
return wayl_win_subsurface_new_with_custom_parent(win, win->surface, surf);
}
void
wayl_win_subsurface_destroy(struct wl_surf_subsurf *surf)
{
if (surf == NULL)
return;
if (surf->sub != NULL)
wl_subsurface_destroy(surf->sub);
if (surf->surf != NULL)
wl_surface_destroy(surf->surf);
surf->surf = NULL;
surf->sub = NULL;
}

View file

@ -350,10 +350,14 @@ struct monitor {
bool use_output_release;
};
struct wl_surf_subsurf {
struct wl_surface *surf;
struct wl_subsurface *sub;
};
struct wl_url {
const struct url *url;
struct wl_surface *surf;
struct wl_subsurface *sub_surf;
struct wl_surf_subsurf surf;
};
struct wayland;
@ -368,21 +372,14 @@ struct wl_window {
enum {CSD_UNKNOWN, CSD_NO, CSD_YES } use_csd;
struct {
struct wl_surface *surface[CSD_SURF_COUNT];
struct wl_subsurface *sub_surface[CSD_SURF_COUNT];
struct wl_surf_subsurf surface[CSD_SURF_COUNT];
int move_timeout_fd;
uint32_t serial;
} csd;
/* Scrollback search */
struct wl_surface *search_surface;
struct wl_subsurface *search_sub_surface;
struct wl_surface *scrollback_indicator_surface;
struct wl_subsurface *scrollback_indicator_sub_surface;
struct wl_surface *render_timer_surface;
struct wl_subsurface *render_timer_sub_surface;
struct wl_surf_subsurf search;
struct wl_surf_subsurf scrollback_indicator;
struct wl_surf_subsurf render_timer;
struct wl_callback *frame_callback;
@ -453,10 +450,17 @@ struct wayland {
struct wayland *wayl_init(const struct config *conf, struct fdm *fdm);
void wayl_destroy(struct wayland *wayl);
bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale);
void wayl_flush(struct wayland *wayl);
void wayl_roundtrip(struct wayland *wayl);
struct wl_window *wayl_win_init(struct terminal *term);
void wayl_win_destroy(struct wl_window *win);
bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale);
bool wayl_win_subsurface_new(
struct wl_window *win, struct wl_surf_subsurf *surf);
bool wayl_win_subsurface_new_with_custom_parent(
struct wl_window *win, struct wl_surface *parent,
struct wl_surf_subsurf *surf);
void wayl_win_subsurface_destroy(struct wl_surf_subsurf *surf);