diff --git a/main.c b/main.c index 92104e6e..78a70fe4 100644 --- a/main.c +++ b/main.c @@ -221,13 +221,13 @@ handle_global(void *data, struct wl_registry *registry, } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { - term->wl.shell = wl_registry_bind( + term->window.shell = wl_registry_bind( term->wl.registry, name, &xdg_wm_base_interface, 1); - xdg_wm_base_add_listener(term->wl.shell, &xdg_wm_base_listener, term); + xdg_wm_base_add_listener(term->window.shell, &xdg_wm_base_listener, term); } else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) - term->wl.xdg_decoration_manager = wl_registry_bind( + term->window.xdg_decoration_manager = wl_registry_bind( term->wl.registry, name, &zxdg_decoration_manager_v1_interface, 1); else if (strcmp(interface, wl_seat_interface.name) == 0) { @@ -278,7 +278,7 @@ surface_enter(void *data, struct wl_surface *wl_surface, tll_foreach(term->wl.monitors, it) { if (it->item.output == wl_output) { LOG_DBG("mapped on %s", it->item.name); - tll_push_back(term->wl.on_outputs, &it->item); + tll_push_back(term->window.on_outputs, &it->item); /* Resize, since scale-to-use may have changed */ render_resize(term, term->width / term->scale, term->height / term->scale); @@ -295,12 +295,12 @@ surface_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output) { struct terminal *term = data; - tll_foreach(term->wl.on_outputs, it) { + tll_foreach(term->window.on_outputs, it) { if (it->item->output != wl_output) continue; LOG_DBG("unmapped from %s", it->item->name); - tll_remove(term->wl.on_outputs, it); + tll_remove(term->window.on_outputs, it); /* Resize, since scale-to-use may have changed */ render_resize(term, term->width / term->scale, term->height / term->scale); @@ -909,7 +909,7 @@ main(int argc, char *const *argv) LOG_ERR("no shared memory buffers interface"); goto out; } - if (term.wl.shell == NULL) { + if (term.window.shell == NULL) { LOG_ERR("no XDG shell interface"); goto out; } @@ -973,38 +973,38 @@ main(int argc, char *const *argv) } /* Main window */ - term.wl.surface = wl_compositor_create_surface(term.wl.compositor); - if (term.wl.surface == NULL) { + term.window.surface = wl_compositor_create_surface(term.wl.compositor); + if (term.window.surface == NULL) { LOG_ERR("failed to create wayland surface"); goto out; } - wl_surface_add_listener(term.wl.surface, &surface_listener, &term); + wl_surface_add_listener(term.window.surface, &surface_listener, &term); - term.wl.xdg_surface = xdg_wm_base_get_xdg_surface(term.wl.shell, term.wl.surface); - xdg_surface_add_listener(term.wl.xdg_surface, &xdg_surface_listener, &term); + term.window.xdg_surface = xdg_wm_base_get_xdg_surface(term.window.shell, term.window.surface); + xdg_surface_add_listener(term.window.xdg_surface, &xdg_surface_listener, &term); - term.wl.xdg_toplevel = xdg_surface_get_toplevel(term.wl.xdg_surface); - xdg_toplevel_add_listener(term.wl.xdg_toplevel, &xdg_toplevel_listener, &term); + term.window.xdg_toplevel = xdg_surface_get_toplevel(term.window.xdg_surface); + xdg_toplevel_add_listener(term.window.xdg_toplevel, &xdg_toplevel_listener, &term); - xdg_toplevel_set_app_id(term.wl.xdg_toplevel, "foot"); + xdg_toplevel_set_app_id(term.window.xdg_toplevel, "foot"); term_set_window_title(&term, "foot"); /* Request server-side decorations */ - term.wl.xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( - term.wl.xdg_decoration_manager, term.wl.xdg_toplevel); + term.window.xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( + term.window.xdg_decoration_manager, term.window.xdg_toplevel); zxdg_toplevel_decoration_v1_set_mode( - term.wl.xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + term.window.xdg_toplevel_decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); zxdg_toplevel_decoration_v1_add_listener( - term.wl.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, &term); + term.window.xdg_toplevel_decoration, &xdg_toplevel_decoration_listener, &term); /* Scrollback search box */ - term.wl.search_surface = wl_compositor_create_surface(term.wl.compositor); - term.wl.search_sub_surface = wl_subcompositor_get_subsurface( - term.wl.sub_compositor, term.wl.search_surface, term.wl.surface); - wl_subsurface_set_desync(term.wl.search_sub_surface); + term.window.search_surface = wl_compositor_create_surface(term.wl.compositor); + term.window.search_sub_surface = wl_subcompositor_get_subsurface( + term.wl.sub_compositor, term.window.search_surface, term.window.surface); + wl_subsurface_set_desync(term.window.search_sub_surface); - wl_surface_commit(term.wl.surface); + wl_surface_commit(term.window.surface); wl_display_roundtrip(term.wl.display); if (conf.width == -1) { @@ -1151,7 +1151,7 @@ out: shm_fini(); - tll_free(term.wl.on_outputs); + tll_free(term.window.on_outputs); tll_foreach(term.wl.monitors, it) { free(it->item.name); if (it->item.xdg != NULL) @@ -1193,24 +1193,24 @@ out: zwp_primary_selection_device_manager_v1_destroy(term.wl.primary_selection_device_manager); if (term.wl.seat != NULL) wl_seat_destroy(term.wl.seat); - if (term.wl.search_sub_surface != NULL) - wl_subsurface_destroy(term.wl.search_sub_surface); - if (term.wl.search_surface != NULL) - wl_surface_destroy(term.wl.search_surface); + if (term.window.search_sub_surface != NULL) + wl_subsurface_destroy(term.window.search_sub_surface); + if (term.window.search_surface != NULL) + wl_surface_destroy(term.window.search_surface); if (term.render.frame_callback != NULL) wl_callback_destroy(term.render.frame_callback); - if (term.wl.xdg_toplevel_decoration != NULL) - zxdg_toplevel_decoration_v1_destroy(term.wl.xdg_toplevel_decoration); - if (term.wl.xdg_decoration_manager != NULL) - zxdg_decoration_manager_v1_destroy(term.wl.xdg_decoration_manager); - if (term.wl.xdg_toplevel != NULL) - xdg_toplevel_destroy(term.wl.xdg_toplevel); - if (term.wl.xdg_surface != NULL) - xdg_surface_destroy(term.wl.xdg_surface); - if (term.wl.shell != NULL) - xdg_wm_base_destroy(term.wl.shell); - if (term.wl.surface != NULL) - wl_surface_destroy(term.wl.surface); + if (term.window.xdg_toplevel_decoration != NULL) + zxdg_toplevel_decoration_v1_destroy(term.window.xdg_toplevel_decoration); + if (term.window.xdg_decoration_manager != NULL) + zxdg_decoration_manager_v1_destroy(term.window.xdg_decoration_manager); + if (term.window.xdg_toplevel != NULL) + xdg_toplevel_destroy(term.window.xdg_toplevel); + if (term.window.xdg_surface != NULL) + xdg_surface_destroy(term.window.xdg_surface); + if (term.window.shell != NULL) + xdg_wm_base_destroy(term.window.shell); + if (term.window.surface != NULL) + wl_surface_destroy(term.window.surface); if (term.wl.shm != NULL) wl_shm_destroy(term.wl.shm); if (term.wl.sub_compositor != NULL) diff --git a/render.c b/render.c index ff05d501..9f9d720c 100644 --- a/render.c +++ b/render.c @@ -330,7 +330,8 @@ grid_render_scroll(struct terminal *term, struct buffer *buf, raw + src_y * buf->stride, height * buf->stride); - wl_surface_damage_buffer(term->wl.surface, term->x_margin, dst_y, term->width - term->x_margin, height); + wl_surface_damage_buffer( + term->window.surface, term->x_margin, dst_y, term->width - term->x_margin, height); } } @@ -355,7 +356,8 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf, raw + src_y * buf->stride, height * buf->stride); - wl_surface_damage_buffer(term->wl.surface, term->x_margin, dst_y, term->width - term->x_margin, height); + wl_surface_damage_buffer( + term->window.surface, term->x_margin, dst_y, term->width - term->x_margin, height); } } @@ -439,7 +441,7 @@ grid_render(struct terminal *term) assert(term->height > 0); struct buffer *buf = shm_get_buffer(term->wl.shm, term->width, term->height, 1 + term->render.workers.count); - wl_surface_attach(term->wl.surface, buf->wl_buf, 0, 0); + wl_surface_attach(term->window.surface, buf->wl_buf, 0, 0); pixman_image_t *pix = buf->pix; bool all_clean = tll_length(term->grid->scroll_damage) == 0; @@ -487,13 +489,13 @@ grid_render(struct terminal *term) {0, bmargin, term->width, bmargin_height}}); /* Bottom */ wl_surface_damage_buffer( - term->wl.surface, 0, 0, term->width, term->y_margin); + term->window.surface, 0, 0, term->width, term->y_margin); wl_surface_damage_buffer( - term->wl.surface, 0, 0, term->x_margin, term->height); + term->window.surface, 0, 0, term->x_margin, term->height); wl_surface_damage_buffer( - term->wl.surface, rmargin, 0, rmargin_width, term->height); + term->window.surface, rmargin, 0, rmargin_width, term->height); wl_surface_damage_buffer( - term->wl.surface, 0, bmargin, term->width, bmargin_height); + term->window.surface, 0, bmargin, term->width, bmargin_height); /* Force a full grid refresh */ term_damage_view(term); @@ -514,7 +516,7 @@ grid_render(struct terminal *term) render_cell(term, pix, cell, at.col, at.row, false); wl_surface_damage_buffer( - term->wl.surface, + term->window.surface, term->x_margin + at.col * term->cell_width, term->y_margin + at.row * term->cell_height, term->cell_width, term->cell_height); @@ -567,7 +569,7 @@ grid_render(struct terminal *term) all_clean = false; wl_surface_damage_buffer( - term->wl.surface, + term->window.surface, term->x_margin, term->y_margin + r * term->cell_height, term->width - term->x_margin, term->cell_height); } @@ -590,7 +592,7 @@ grid_render(struct terminal *term) all_clean = false; wl_surface_damage_buffer( - term->wl.surface, + term->window.surface, term->x_margin, term->y_margin + r * term->cell_height, term->width - term->x_margin, term->cell_height); } @@ -672,7 +674,7 @@ grid_render(struct terminal *term) term, pix, cell, term->cursor.col, view_aligned_row, true); wl_surface_damage_buffer( - term->wl.surface, + term->window.surface, term->x_margin + term->cursor.col * term->cell_width, term->y_margin + view_aligned_row * term->cell_height, cols_updated * term->cell_width, term->cell_height); @@ -692,18 +694,18 @@ grid_render(struct terminal *term) 1, &(pixman_rectangle16_t){0, 0, term->width, term->height}); wl_surface_damage_buffer( - term->wl.surface, 0, 0, term->width, term->height); + term->window.surface, 0, 0, term->width, term->height); } assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows); assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows); assert(term->render.frame_callback == NULL); - term->render.frame_callback = wl_surface_frame(term->wl.surface); + term->render.frame_callback = wl_surface_frame(term->window.surface); wl_callback_add_listener(term->render.frame_callback, &frame_listener, term); - wl_surface_set_buffer_scale(term->wl.surface, term->scale); - wl_surface_commit(term->wl.surface); + wl_surface_set_buffer_scale(term->window.surface, term->scale); + wl_surface_commit(term->window.surface); #if TIME_FRAME_RENDERING struct timeval end_time; @@ -730,7 +732,7 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da void render_search_box(struct terminal *term) { - assert(term->wl.search_sub_surface != NULL); + assert(term->window.search_sub_surface != NULL); /* TODO: at least sway allows the subsurface to extend outside the * main window. Do we want that? */ @@ -778,13 +780,13 @@ render_search_box(struct terminal *term) draw_bar(term, buf->pix, font, &fg, x, y); wl_subsurface_set_position( - term->wl.search_sub_surface, + term->window.search_sub_surface, term->width - width - margin, term->height - height - margin); - wl_surface_damage_buffer(term->wl.search_surface, 0, 0, width, height); - wl_surface_attach(term->wl.search_surface, buf->wl_buf, 0, 0); - wl_surface_set_buffer_scale(term->wl.search_surface, scale); - wl_surface_commit(term->wl.search_surface); + wl_surface_damage_buffer(term->window.search_surface, 0, 0, width, height); + wl_surface_attach(term->window.search_surface, buf->wl_buf, 0, 0); + wl_surface_set_buffer_scale(term->window.search_surface, scale); + wl_surface_commit(term->window.search_surface); } static void @@ -816,7 +818,7 @@ void render_resize(struct terminal *term, int width, int height) { int scale = -1; - tll_foreach(term->wl.on_outputs, it) { + tll_foreach(term->window.on_outputs, it) { if (it->item->scale > scale) scale = it->item->scale; } @@ -937,7 +939,7 @@ render_resize(struct terminal *term, int width, int height) void render_set_title(struct terminal *term, const char *title) { - xdg_toplevel_set_title(term->wl.xdg_toplevel, title); + xdg_toplevel_set_title(term->window.xdg_toplevel, title); } bool diff --git a/search.c b/search.c index 45ca675e..59ac0152 100644 --- a/search.c +++ b/search.c @@ -19,8 +19,8 @@ static void search_cancel_keep_selection(struct terminal *term) { - wl_surface_attach(term->wl.search_surface, NULL, 0, 0); - wl_surface_commit(term->wl.search_surface); + wl_surface_attach(term->window.search_surface, NULL, 0, 0); + wl_surface_commit(term->window.search_surface); free(term->search.buf); term->search.buf = NULL; diff --git a/terminal.h b/terminal.h index a10e1928..643eaa65 100644 --- a/terminal.h +++ b/terminal.h @@ -67,22 +67,8 @@ struct wayland { char *theme_name; } pointer; - /* Main window */ - struct wl_surface *surface; - struct xdg_wm_base *shell; - struct xdg_surface *xdg_surface; - struct xdg_toplevel *xdg_toplevel; - - struct zxdg_decoration_manager_v1 *xdg_decoration_manager; - struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; - - /* Scrollback search */ - struct wl_surface *search_surface; - struct wl_subsurface *search_sub_surface; - bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ - tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */ }; struct rgb { float r, g, b; }; @@ -375,6 +361,22 @@ struct terminal { } fextents; struct wayland wl; + struct { + struct wl_surface *surface; + struct xdg_wm_base *shell; + struct xdg_surface *xdg_surface; + struct xdg_toplevel *xdg_toplevel; + + struct zxdg_decoration_manager_v1 *xdg_decoration_manager; + struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; + + /* Scrollback search */ + struct wl_surface *search_surface; + struct wl_subsurface *search_sub_surface; + + tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */ + } window; + struct { int scrollback_lines; struct wl_callback *frame_callback;