From 61cabdac13986e6cb2ba69e81d5934f55d92a1a9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 27 Aug 2019 17:23:28 +0200 Subject: search: wip: re-direct input while searching, and build a search buffer This adds a new state, 'is_searching'. While active, input is re-directed, and stored in a search buffer. In the future, we'll use this buffer and search for its content in the scrollback buffer, and move the view and create a selection on matches. When rendering in 'is_searching', everything is dimmed. In the future, we'll render the current search buffer on-top of the dimmed "regular" terminal output. --- terminal.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'terminal.h') diff --git a/terminal.h b/terminal.h index 6f373a14..fbd734bc 100644 --- a/terminal.h +++ b/terminal.h @@ -331,6 +331,13 @@ struct terminal { struct primary primary; } selection; + bool is_searching; + struct { + wchar_t *buf; + size_t len; + size_t sz; + } search; + struct grid normal; struct grid alt; struct grid *grid; @@ -368,6 +375,7 @@ struct terminal { struct buffer *last_buf; /* Buffer we rendered to last time */ bool was_flashing; /* Flash was active last time we rendered */ + bool was_searching; } render; }; -- cgit v1.3 From aee5045395ca2393b60d962e6e9440a59edbfd6e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 27 Aug 2019 19:33:19 +0200 Subject: search: wip: initial search matching * match search buffer against scrollback content * adjust view to ensure matched content is visible * create selection on a successful match * finalize selection when user presses enter (to "commit" the search) * ctrl+r searches for the next match. Needs more work though. --- grid.h | 16 +++++- search.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- terminal.h | 5 ++ 3 files changed, 187 insertions(+), 3 deletions(-) (limited to 'terminal.h') diff --git a/grid.h b/grid.h index a421a5c0..96ef4181 100644 --- a/grid.h +++ b/grid.h @@ -7,12 +7,24 @@ void grid_swap_row(struct grid *grid, int row_a, int row_b, bool initialize); struct row *grid_row_alloc(int cols, bool initialize); void grid_row_free(struct row *row); +static inline int +grid_row_absolute(const struct grid *grid, int row_no) +{ + return (grid->offset + row_no) & (grid->num_rows - 1); +} + +static inline int +grid_row_absolute_in_view(const struct grid *grid, int row_no) +{ + return (grid->view + row_no) & (grid->num_rows - 1); +} + static inline struct row * _grid_row_maybe_alloc(struct grid *grid, int row_no, bool alloc_if_null) { assert(grid->offset >= 0); - int real_row = (grid->offset + row_no) & (grid->num_rows - 1); + int real_row = grid_row_absolute(grid, row_no); struct row *row = grid->rows[real_row]; if (row == NULL && alloc_if_null) { @@ -41,7 +53,7 @@ grid_row_in_view(struct grid *grid, int row_no) { assert(grid->view >= 0); - int real_row = (grid->view + row_no) & (grid->num_rows - 1); + int real_row = grid_row_absolute_in_view(grid, row_no); struct row *row = grid->rows[real_row]; assert(row != NULL); diff --git a/search.c b/search.c index 55c67bb0..cdc7ccf5 100644 --- a/search.c +++ b/search.c @@ -7,6 +7,8 @@ #define LOG_ENABLE_DBG 1 #include "log.h" #include "render.h" +#include "selection.h" +#include "grid.h" void search_begin(struct terminal *term) @@ -17,6 +19,10 @@ search_begin(struct terminal *term) term->search.buf = NULL; term->search.len = 0; term->search.sz = 0; + term->search.match = (struct coord){-1, -1}; + term->search.match_len = 0; + term->search.original_view = term->grid->view; + term->search.view_followed_offset = term->grid->view == term->grid->offset; term->is_searching = true; render_refresh(term); @@ -36,6 +42,133 @@ search_cancel(struct terminal *term) render_refresh(term); } +static void +search_update(struct terminal *term) +{ + if (term->search.len == 0) { + term->search.match = (struct coord){-1, -1}; + term->search.match_len = 0; + selection_cancel(term); + return; + } + + int start_row = term->search.match.row; + int start_col = term->search.match.col; + size_t len = term->search.match_len; + + assert((len == 0 && start_row == -1 && start_col == -1) || + (len > 0 && start_row >= 0 && start_col >= 0)); + + if (len == 0) { + start_row = grid_row_absolute(term->grid, term->rows - 1); + start_col = term->cols - 1; + } + + LOG_DBG("search: update: starting at row=%d col=%d", start_row, start_col); + + /* Scan backward from current end-of-output */ + for (; start_row >= 0; start_row--) { + const struct row *row = term->grid->rows[start_row]; + if (row == NULL) + break; + + for (; start_col >= 0; start_col--) { + if (row->cells[start_col].wc != term->search.buf[0]) + continue; + + /* + * Got a match on the first letter. Now we'll see if the + * rest of the search buffer matches. + */ + + LOG_DBG("search: initial match at row=%d, col=%d", start_row, start_col); + + int end_row = start_row; + int end_col = start_col; + size_t match_len = 0; + + for (size_t i = 0; i < term->search.len; i++, match_len++) { + if (row->cells[end_col].wc != term->search.buf[i]) + break; + + if (++end_col >= term->cols) { + if (end_row + 1 > grid_row_absolute(term->grid, term->grid->offset + term->rows - 1)) { + /* Don't continue past end of the world */ + break; + } + + end_row++; + end_col = 0; + row = term->grid->rows[end_row]; + } + } + + if (match_len != term->search.len) { + /* Didn't match (completely) */ + continue; + } + + /* + * We matched the entire buffer. Move view to ensure the + * match is visible, create a selection and return. + */ + + int old_view = term->grid->view; + int new_view = start_row; + + /* Prevent scrolling in uninitialized rows */ + bool all_initialized = false; + do { + all_initialized = true; + + for (int i = 0; i < term->rows; i++) { + int row_no = (new_view + i) % term->grid->num_rows; + if (term->grid->rows[row_no] == NULL) { + all_initialized = false; + new_view--; + break; + } + } + } while (!all_initialized); + + /* Don't scroll past scrollback history */ + int end = (term->grid->offset + term->rows - 1) % term->grid->num_rows; + if (end >= term->grid->offset) { + /* Not wrapped */ + if (new_view >= term->grid->offset && new_view <= end) + new_view = term->grid->offset; + } else { + if (new_view >= term->grid->offset || new_view <= end) + new_view = term->grid->offset; + } + + /* Update view */ + term->grid->view = new_view; + if (new_view != old_view) + term_damage_view(term); + + /* Selection endpoint is inclusive */ + if (--end_col < 0) { + end_col = term->cols - 1; + start_row--; + } + + /* Begin a selection (it's finalized when "committing" the search) */ + selection_start(term, start_col, start_row - term->grid->view); + selection_update(term, end_col, end_row - term->grid->view); + + /* Update match state */ + term->search.match.row = start_row; + term->search.match.col = start_col; + term->search.match_len = match_len; + + return; + } + + start_col = term->cols - 1; + } +} + void search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask_t mods) { @@ -49,8 +182,41 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask enum xkb_compose_status compose_status = xkb_compose_state_get_status( term->kbd.xkb_compose_state); - if ((mods == 0 && sym == XKB_KEY_Escape) || (mods == ctrl && sym == XKB_KEY_g)) + /* Cancel search */ + if ((mods == 0 && sym == XKB_KEY_Escape) || + (mods == ctrl && sym == XKB_KEY_g)) + { + if (term->search.view_followed_offset) + term->grid->view = term->grid->offset; + else + term->grid->view = term->search.original_view; + term_damage_view(term); search_cancel(term); + } + + /* "Commit" search - copy selection to primary and cancel search */ + else if (mods == 0 && sym == XKB_KEY_Return) { + selection_finalize(term, term->input_serial); + search_cancel(term); + } + + else if (mods == ctrl && sym == XKB_KEY_r) { + if (term->search.match_len > 0) { + int new_col = term->search.match.col - 1; + int new_row = term->search.match.row; + + if (new_col < 0) { + new_col = term->cols - 1; + new_row--; + } + + if (new_row >= 0) { + term->search.match.col = new_col; + term->search.match.row = new_row; + search_update(term); + } + } + } else if (mods == 0 && sym == XKB_KEY_BackSpace) { if (term->search.len > 0) @@ -103,5 +269,6 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask } LOG_DBG("search: buffer: %S", term->search.buf); + search_update(term); render_refresh(term); } diff --git a/terminal.h b/terminal.h index fbd734bc..5989788a 100644 --- a/terminal.h +++ b/terminal.h @@ -336,6 +336,11 @@ struct terminal { wchar_t *buf; size_t len; size_t sz; + + int original_view; + bool view_followed_offset; + struct coord match; + size_t match_len; } search; struct grid normal; -- cgit v1.3 From 777863ac3e27464175699921fceb2c1fab163d0e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 28 Aug 2019 17:25:42 +0200 Subject: term: add term_reset_view() - make view follow end-of-output again --- terminal.c | 10 ++++++++++ terminal.h | 2 ++ 2 files changed, 12 insertions(+) (limited to 'terminal.h') diff --git a/terminal.c b/terminal.c index b9d2f0f3..95a60682 100644 --- a/terminal.c +++ b/terminal.c @@ -362,6 +362,16 @@ term_reverse_index(struct terminal *term) term_cursor_up(term, 1); } +void +term_reset_view(struct terminal *term) +{ + if (term->grid->view == term->grid->offset) + return; + + term->grid->view = term->grid->offset; + term_damage_view(term); +} + void term_restore_cursor(struct terminal *term) { diff --git a/terminal.h b/terminal.h index 5989788a..18130392 100644 --- a/terminal.h +++ b/terminal.h @@ -392,6 +392,8 @@ void term_damage_rows_in_view(struct terminal *term, int start, int end); void term_damage_all(struct terminal *term); void term_damage_view(struct terminal *term); +void term_reset_view(struct terminal *term); + void term_damage_scroll( struct terminal *term, enum damage_type damage_type, struct scroll_region region, int lines); -- cgit v1.3 From 66912cbfb5e44d44670582fad932932f9de6794b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 29 Aug 2019 19:34:41 +0200 Subject: search: use a sub-surface to render the search buffer --- main.c | 5 +++ search.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------ terminal.h | 1 + 3 files changed, 141 insertions(+), 14 deletions(-) (limited to 'terminal.h') diff --git a/main.c b/main.c index 60d041f1..b78305f7 100644 --- a/main.c +++ b/main.c @@ -197,6 +197,11 @@ handle_global(void *data, struct wl_registry *registry, term->wl.registry, name, &wl_compositor_interface, 4); } + else if (strcmp(interface, wl_subcompositor_interface.name) == 0) { + term->wl.sub_compositor = wl_registry_bind( + term->wl.registry, name, &wl_subcompositor_interface, 1); + } + else if (strcmp(interface, wl_shm_interface.name) == 0) { term->wl.shm = wl_registry_bind( term->wl.registry, name, &wl_shm_interface, 1); diff --git a/search.c b/search.c index 6aa6be5c..558f98c7 100644 --- a/search.c +++ b/search.c @@ -1,6 +1,8 @@ #include "search.h" #include + +#include #include #define LOG_MODULE "search" @@ -9,11 +11,98 @@ #include "grid.h" #include "render.h" #include "selection.h" +#include "shm.h" -void -search_begin(struct terminal *term) +#define max(x, y) ((x) > (y) ? (x) : (y)) + +static struct wl_surface *wl_surf; +static struct wl_subsurface *sub_surf; + + +static inline pixman_color_t +color_hex_to_pixman_with_alpha(uint32_t color, uint16_t alpha) { - LOG_DBG("search: begin"); + int alpha_div = 0xffff / alpha; + return (pixman_color_t){ + .red = ((color >> 16 & 0xff) | (color >> 8 & 0xff00)) / alpha_div, + .green = ((color >> 8 & 0xff) | (color >> 0 & 0xff00)) / alpha_div, + .blue = ((color >> 0 & 0xff) | (color << 8 & 0xff00)) / alpha_div, + .alpha = alpha, + }; +} + +static inline pixman_color_t +color_hex_to_pixman(uint32_t color) +{ + /* Count on the compiler optimizing this */ + return color_hex_to_pixman_with_alpha(color, 0xffff); +} + +/* TODO: move to render.c? */ +static void +render(struct terminal *term) +{ + assert(sub_surf != NULL); + + /* TODO: at least sway allows the subsurface to extend outside the + * main window. Do we want that? */ + const int scale = term->scale >= 1 ? term->scale : 1; + const int margin = scale * 3; + const int width = 2 * margin + max(20, term->search.len) * term->cell_width; + const int height = 2 * margin + 1 * term->cell_height; + + struct buffer *buf = shm_get_buffer(term->wl.shm, width, height, 1); + + /* Background - yellow on empty/match, red on mismatch */ + pixman_color_t color = color_hex_to_pixman( + term->search.match_len == term->search.len ? 0xffff00 : 0xff0000); + + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix, &color, + 1, &(pixman_rectangle16_t){0, 0, width, height}); + + int x = margin; + int y = margin; + pixman_color_t fg = color_hex_to_pixman(0x000000); + + /* Text (what the user entered - *not* match(es)) */ + for (size_t i = 0; i < term->search.len; i++) { + const struct glyph *glyph = font_glyph_for_wc(&term->fonts[0], term->search.buf[i]); + if (glyph == NULL) + continue; + + pixman_image_t *src = pixman_image_create_solid_fill(&fg); + pixman_image_composite32( + PIXMAN_OP_OVER, src, glyph->pix, buf->pix, 0, 0, 0, 0, + x + glyph->x, y + term->fextents.ascent - glyph->y, + glyph->width, glyph->height); + pixman_image_unref(src); + + x += glyph->width; + } + + LOG_INFO("match length: %zu", term->search.match_len); + + wl_subsurface_set_position( + sub_surf, term->width - width - margin, term->height - height - margin); + + wl_surface_damage_buffer(wl_surf, 0, 0, width, height); + wl_surface_attach(wl_surf, buf->wl_buf, 0, 0); + wl_surface_set_buffer_scale(wl_surf, scale); + wl_surface_commit(wl_surf); +} + +static void +search_cancel_keep_selection(struct terminal *term) +{ + if (sub_surf != NULL) { + wl_subsurface_destroy(sub_surf); + sub_surf = NULL; + } + if (wl_surf != NULL) { + wl_surface_destroy(wl_surf); + wl_surf = NULL; + } free(term->search.buf); term->search.buf = NULL; @@ -21,35 +110,65 @@ search_begin(struct terminal *term) term->search.sz = 0; term->search.match = (struct coord){-1, -1}; term->search.match_len = 0; + term->is_searching = false; + + render_refresh(term); +} + +void +search_begin(struct terminal *term) +{ + LOG_DBG("search: begin"); + + search_cancel_keep_selection(term); + selection_cancel(term); + term->search.original_view = term->grid->view; term->search.view_followed_offset = term->grid->view == term->grid->offset; term->is_searching = true; - selection_cancel(term); + wl_surf = wl_compositor_create_surface(term->wl.compositor); + if (wl_surf != NULL) { + sub_surf = wl_subcompositor_get_subsurface( + term->wl.sub_compositor, wl_surf, term->wl.surface); + + if (sub_surf != NULL) { + /* Sub-surface updates may occur without updating the main + * window */ + wl_subsurface_set_desync(sub_surf); + } + } + + if (wl_surf == NULL || sub_surf == NULL) { + LOG_ERR("failed to create sub-surface for search box"); + if (wl_surf != NULL) + wl_surface_destroy(wl_surf); + assert(sub_surf == NULL); + } + + render(term); render_refresh(term); } void search_cancel(struct terminal *term) { - LOG_DBG("search: cancel"); - - free(term->search.buf); - term->search.buf = NULL; - term->search.len = 0; - term->search.sz = 0; - term->is_searching = false; + if (!term->is_searching) + return; - render_refresh(term); + search_cancel_keep_selection(term); + selection_cancel(term); } static void search_update(struct terminal *term) { if (term->search.len == 0) { + LOG_INFO("len == 0"); term->search.match = (struct coord){-1, -1}; term->search.match_len = 0; selection_cancel(term); + render(term); return; } @@ -187,6 +306,7 @@ search_update(struct terminal *term) term->search.match.col = start_col; term->search.match_len = match_len; + render(term); return; } @@ -198,7 +318,7 @@ search_update(struct terminal *term) term->search.match = (struct coord){-1, -1}; term->search.match_len = 0; selection_cancel(term); - + render(term); #undef ROW_DEC } @@ -225,12 +345,13 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask term->grid->view = term->search.original_view; term_damage_view(term); search_cancel(term); + return; } /* "Commit" search - copy selection to primary and cancel search */ else if (mods == 0 && sym == XKB_KEY_Return) { selection_finalize(term, term->input_serial); - search_cancel(term); + search_cancel_keep_selection(term); return; } diff --git a/terminal.h b/terminal.h index 18130392..755c7b4a 100644 --- a/terminal.h +++ b/terminal.h @@ -41,6 +41,7 @@ struct wayland { struct wl_display *display; struct wl_registry *registry; struct wl_compositor *compositor; + struct wl_subcompositor *sub_compositor; struct wl_surface *surface; struct wl_shm *shm; struct wl_seat *seat; -- cgit v1.3 From 44a353a7f74b562cb057c23760013a12becbecf3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 29 Aug 2019 20:15:33 +0200 Subject: search: move wayland surface variables into the term struct --- main.c | 20 ++++++++++++-------- search.c | 47 +++++++++++++++++++++++------------------------ terminal.h | 16 ++++++++++++++-- 3 files changed, 49 insertions(+), 34 deletions(-) (limited to 'terminal.h') diff --git a/main.c b/main.c index b78305f7..e92996ef 100644 --- a/main.c +++ b/main.c @@ -1019,12 +1019,6 @@ out: if (term.wl.xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(term.wl.xdg_output_manager); - if (term.render.frame_callback != NULL) - wl_callback_destroy(term.render.frame_callback); - 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); free(term.wl.pointer.theme_name); if (term.wl.pointer.theme != NULL) wl_cursor_theme_destroy(term.wl.pointer.theme); @@ -1054,10 +1048,20 @@ 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.surface != NULL) - wl_surface_destroy(term.wl.surface); + 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.render.frame_callback != NULL) + wl_callback_destroy(term.render.frame_callback); + 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.wl.shm != NULL) wl_shm_destroy(term.wl.shm); if (term.wl.compositor != NULL) diff --git a/search.c b/search.c index 558f98c7..150bd050 100644 --- a/search.c +++ b/search.c @@ -15,8 +15,6 @@ #define max(x, y) ((x) > (y) ? (x) : (y)) -static struct wl_surface *wl_surf; -static struct wl_subsurface *sub_surf; static inline pixman_color_t @@ -42,7 +40,7 @@ color_hex_to_pixman(uint32_t color) static void render(struct terminal *term) { - assert(sub_surf != NULL); + assert(term->wl.search_sub_surface != NULL); /* TODO: at least sway allows the subsurface to extend outside the * main window. Do we want that? */ @@ -84,24 +82,25 @@ render(struct terminal *term) LOG_INFO("match length: %zu", term->search.match_len); wl_subsurface_set_position( - sub_surf, term->width - width - margin, term->height - height - margin); + term->wl.search_sub_surface, + term->width - width - margin, term->height - height - margin); - wl_surface_damage_buffer(wl_surf, 0, 0, width, height); - wl_surface_attach(wl_surf, buf->wl_buf, 0, 0); - wl_surface_set_buffer_scale(wl_surf, scale); - wl_surface_commit(wl_surf); + 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); } static void search_cancel_keep_selection(struct terminal *term) { - if (sub_surf != NULL) { - wl_subsurface_destroy(sub_surf); - sub_surf = NULL; + if (term->wl.search_sub_surface != NULL) { + wl_subsurface_destroy(term->wl.search_sub_surface); + term->wl.search_sub_surface = NULL; } - if (wl_surf != NULL) { - wl_surface_destroy(wl_surf); - wl_surf = NULL; + if (term->wl.search_surface != NULL) { + wl_surface_destroy(term->wl.search_surface); + term->wl.search_surface = NULL; } free(term->search.buf); @@ -127,23 +126,23 @@ search_begin(struct terminal *term) term->search.view_followed_offset = term->grid->view == term->grid->offset; term->is_searching = true; - wl_surf = wl_compositor_create_surface(term->wl.compositor); - if (wl_surf != NULL) { - sub_surf = wl_subcompositor_get_subsurface( - term->wl.sub_compositor, wl_surf, term->wl.surface); + term->wl.search_surface = wl_compositor_create_surface(term->wl.compositor); + if (term->wl.search_surface != NULL) { + term->wl.search_sub_surface = wl_subcompositor_get_subsurface( + term->wl.sub_compositor, term->wl.search_surface, term->wl.surface); - if (sub_surf != NULL) { + if (term->wl.search_sub_surface != NULL) { /* Sub-surface updates may occur without updating the main * window */ - wl_subsurface_set_desync(sub_surf); + wl_subsurface_set_desync(term->wl.search_sub_surface); } } - if (wl_surf == NULL || sub_surf == NULL) { + if (term->wl.search_surface == NULL || term->wl.search_sub_surface == NULL) { LOG_ERR("failed to create sub-surface for search box"); - if (wl_surf != NULL) - wl_surface_destroy(wl_surf); - assert(sub_surf == NULL); + if (term->wl.search_surface != NULL) + wl_surface_destroy(term->wl.search_surface); + assert(term->wl.search_sub_surface == NULL); } render(term); diff --git a/terminal.h b/terminal.h index 755c7b4a..948a8f11 100644 --- a/terminal.h +++ b/terminal.h @@ -42,15 +42,19 @@ struct wayland { struct wl_registry *registry; struct wl_compositor *compositor; struct wl_subcompositor *sub_compositor; - struct wl_surface *surface; struct wl_shm *shm; + struct wl_seat *seat; + struct wl_keyboard *keyboard; struct zxdg_output_manager_v1 *xdg_output_manager; + + /* Clipboard */ struct wl_data_device_manager *data_device_manager; struct wl_data_device *data_device; struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; struct zwp_primary_selection_device_v1 *primary_selection_device; - struct wl_keyboard *keyboard; + + /* Cursor */ struct { struct wl_pointer *pointer; uint32_t serial; @@ -61,9 +65,17 @@ struct wayland { int size; 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; + + /* 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 */ -- cgit v1.3 From 27da0d7f287f49a477e5901e979230a2858689ec Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 29 Aug 2019 21:02:35 +0200 Subject: term: add a 'cursor' (position) to the search state --- terminal.h | 1 + 1 file changed, 1 insertion(+) (limited to 'terminal.h') diff --git a/terminal.h b/terminal.h index 948a8f11..d81ff76d 100644 --- a/terminal.h +++ b/terminal.h @@ -349,6 +349,7 @@ struct terminal { wchar_t *buf; size_t len; size_t sz; + size_t cursor; int original_view; bool view_followed_offset; -- cgit v1.3 From 47da5b4086d2081737ec2264f7b5b754c0166a3a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 30 Aug 2019 17:55:45 +0200 Subject: main: request server-side decorations --- main.c | 41 +++++++++++++++++++++++++++++++++++++++++ meson.build | 1 + terminal.h | 3 +++ 3 files changed, 45 insertions(+) (limited to 'terminal.h') diff --git a/main.c b/main.c index a076fb24..c9a7b64c 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #include #include +#include #define LOG_MODULE "main" #define LOG_ENABLE_DBG 0 @@ -215,6 +216,10 @@ handle_global(void *data, struct wl_registry *registry, xdg_wm_base_add_listener(term->wl.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->wl.registry, name, &zxdg_decoration_manager_v1_interface, 1); + else if (strcmp(interface, wl_seat_interface.name) == 0) { term->wl.seat = wl_registry_bind( term->wl.registry, name, &wl_seat_interface, 5); @@ -340,6 +345,30 @@ static const struct xdg_surface_listener xdg_surface_listener = { .configure = &xdg_surface_configure, }; +static void +xdg_toplevel_decoration_configure(void *data, + struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, + uint32_t mode) +{ + switch (mode) { + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: + LOG_ERR("unimplemented: client-side decorations"); + break; + + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: + LOG_DBG("using server-side decorations"); + break; + + default: + LOG_ERR("unimplemented: unknown XDG toplevel decoration mode: %u", mode); + break; + } +} + +static const struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = { + .configure = &xdg_toplevel_decoration_configure, +}; + static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { @@ -741,6 +770,14 @@ main(int argc, char *const *argv) xdg_toplevel_set_app_id(term.wl.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); + zxdg_toplevel_decoration_v1_set_mode( + term.wl.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); + /* Scrollback search box */ term.wl.search_surface = wl_compositor_create_surface(term.wl.compositor); term.wl.search_sub_surface = wl_subcompositor_get_subsurface( @@ -1061,6 +1098,10 @@ out: wl_surface_destroy(term.wl.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) diff --git a/meson.build b/meson.build index 01a85cc8..632da62d 100644 --- a/meson.build +++ b/meson.build @@ -60,6 +60,7 @@ wl_proto_headers = [] wl_proto_src = [] foreach prot : [ wayland_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml', + wayland_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml', wayland_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml', wayland_protocols_datadir + '/unstable/primary-selection/primary-selection-unstable-v1.xml', ] diff --git a/terminal.h b/terminal.h index d81ff76d..f5eabad1 100644 --- a/terminal.h +++ b/terminal.h @@ -72,6 +72,9 @@ struct wayland { 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; -- cgit v1.3 From 556bf95b2802fba5bc4e204a27ae9283d0cfcba5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 30 Aug 2019 20:15:12 +0200 Subject: search: make search-direction configurable --- search.c | 30 +++++++++++++++++++++++------- terminal.h | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'terminal.h') diff --git a/search.c b/search.c index 4bb9223d..21059f41 100644 --- a/search.c +++ b/search.c @@ -63,6 +63,9 @@ search_cancel(struct terminal *term) static void search_update(struct terminal *term) { + bool backward = term->search.direction == SEARCH_BACKWARD; + term->search.direction = SEARCH_BACKWARD; + if (term->search.len == 0) { term->search.match = (struct coord){-1, -1}; term->search.match_len = 0; @@ -78,23 +81,36 @@ search_update(struct terminal *term) (len > 0 && start_row >= 0 && start_col >= 0)); if (len == 0) { - start_row = grid_row_absolute_in_view(term->grid, term->rows - 1); - start_col = term->cols - 1; + if (backward) { + start_row = grid_row_absolute_in_view(term->grid, term->rows - 1); + start_col = term->cols - 1; + } else { + start_row = grid_row_absolute_in_view(term->grid, 0); + start_col = 0; + } } - LOG_DBG("search: update: starting at row=%d col=%d (offset = %d, view = %d)", - start_row, start_col, term->grid->offset, term->grid->view); + LOG_DBG("search: update: %s: starting at row=%d col=%d (offset = %d, view = %d)", + backward ? "backward" : "forward", start_row, start_col, + term->grid->offset, term->grid->view); #define ROW_DEC(_r) ((_r) = ((_r) - 1 + term->grid->num_rows) % term->grid->num_rows) +#define ROW_INC(_r) ((_r) = ((_r) + 1) % term->grid->num_rows) /* Scan backward from current end-of-output */ /* TODO: don't search "scrollback" in alt screen? */ - for (size_t r = 0; r < term->grid->num_rows; ROW_DEC(start_row), r++) { + for (size_t r = 0; + r < term->grid->num_rows; + backward ? ROW_DEC(start_row) : ROW_INC(start_row), r++) + { const struct row *row = term->grid->rows[start_row]; if (row == NULL) continue; - for (; start_col >= 0; start_col--) { + for (; + backward ? start_col >= 0 : start_col < term->cols; + backward ? start_col-- : start_col++) + { if (wcsncasecmp(&row->cells[start_col].wc, term->search.buf, 1) != 0) continue; @@ -207,7 +223,7 @@ search_update(struct terminal *term) return; } - start_col = term->cols - 1; + start_col = backward ? term->cols - 1 : 0; } /* No match */ diff --git a/terminal.h b/terminal.h index f5eabad1..f435ab3b 100644 --- a/terminal.h +++ b/terminal.h @@ -353,6 +353,7 @@ struct terminal { size_t len; size_t sz; size_t cursor; + enum { SEARCH_BACKWARD, SEARCH_FORWARD} direction; int original_view; bool view_followed_offset; -- cgit v1.3