mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
For performance reasons, we track whether a cell is selected or not using a bit in a cell's attributes. This makes it easy for the renderer to determine if the cells should be rendered as selected or not - it just have to look at the 'selected' bit instead of doing a complex range check against the current selection. This works nicely in most cases. But, if the cell is updated, the 'selected' bit is cleared. This results in the renderer rendering the cell normally, i.e. _not_ selected. Checking for this, and re-setting the 'selected' bit when the cell is updated (printed to) is way too expensive as it is in the hot path. Instead, sync the 'selected' bits just before rendering. This isn't so bad as it may sound; if there is no selection this is a no-op. Even if there is a selection, only those cells whose 'selected' bit have been cleared are dirtied (and thus re-rendered) - these cells would have been re-rendered anyway.
57 lines
2.2 KiB
C
57 lines
2.2 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <wayland-client.h>
|
|
|
|
#include "terminal.h"
|
|
|
|
extern const struct wl_data_device_listener data_device_listener;
|
|
extern const struct zwp_primary_selection_device_v1_listener primary_selection_device_listener;
|
|
|
|
bool selection_enabled(const struct terminal *term);
|
|
void selection_start(
|
|
struct terminal *term, int col, int row, enum selection_kind kind);
|
|
void selection_update(struct terminal *term, int col, int row);
|
|
void selection_finalize(struct terminal *term, uint32_t serial);
|
|
void selection_dirty_cells(struct terminal *term);
|
|
void selection_cancel(struct terminal *term);
|
|
void selection_extend(struct terminal *term, int col, int row, uint32_t serial);
|
|
|
|
bool selection_on_rows_in_view(const struct terminal *term, int start, int end);
|
|
|
|
void selection_mark_word(struct terminal *term, int col, int row,
|
|
bool spaces_only, uint32_t serial);
|
|
void selection_mark_row(struct terminal *term, int row, uint32_t serial);
|
|
|
|
void selection_to_clipboard(struct terminal *term, uint32_t serial);
|
|
void selection_from_clipboard(struct terminal *term, uint32_t serial);
|
|
void selection_to_primary(struct terminal *term, uint32_t serial);
|
|
void selection_from_primary(struct terminal *term);
|
|
|
|
/* Copy text *to* primary/clipboard */
|
|
bool text_to_clipboard(struct terminal *term, char *text, uint32_t serial);
|
|
bool text_to_primary(struct terminal *term, char *text, uint32_t serial);
|
|
|
|
/*
|
|
* Copy text *from* primary/clipboard
|
|
*
|
|
* Note that these are asynchronous; they *will* return
|
|
* immediately. The 'cb' callback will be called 0..n times with
|
|
* clipboard data. When done (or on error), the 'done' callback is
|
|
* called.
|
|
*
|
|
* As such, keep this in mind:
|
|
* - The 'user' context must not be stack allocated
|
|
* - Don't expect clipboard data to have been received when these
|
|
* functions return (it will *never* have been received at this
|
|
* point).
|
|
*/
|
|
void text_from_clipboard(
|
|
struct terminal *term, uint32_t serial,
|
|
void (*cb)(const char *data, size_t size, void *user),
|
|
void (*done)(void *user), void *user);
|
|
|
|
void text_from_primary(
|
|
struct terminal *term,
|
|
void (*cb)(const char *data, size_t size, void *user),
|
|
void (*dont)(void *user), void *user);
|