foot/selection.h

82 lines
3 KiB
C
Raw Normal View History

2019-07-11 09:51:51 +02:00
#pragma once
#include <stdbool.h>
#include <wayland-client.h>
2019-07-11 09:51:51 +02:00
#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, struct seat *seat);
void selection_start(
struct terminal *term, int col, int row, enum selection_kind kind);
2019-07-11 09:51:51 +02:00
void selection_update(struct terminal *term, int col, int row);
void selection_finalize(
struct seat *seat, struct terminal *term, uint32_t serial);
void selection_dirty_cells(struct terminal *term);
2019-07-11 09:51:51 +02:00
void selection_cancel(struct terminal *term);
void selection_extend( struct seat *seat, struct terminal *term,
int col, int row, uint32_t serial);
term: scrolling: hopefully fix all selection/scrolling related crashes When scrolling, there are a couple of cases where an existing selection must be canceled because we cannot meaningfully represent it after scrolling. These are when the selection is (partly) inside: * The top scrolling region * The bottom scrolling region * The new lines scrolled in. I.e. re-used lines For the scrolling regions, the real problem is when the selection crosses the scrolling region boundary; a selection that is completely inside a scrolling regions _might_ be possible to keep, but we would need to translate the selection coordinates to the new scrolling region lines. For simplicity, we cancel the selection if it touches the scrolling region. Period. The last item, newly scrolled in lines is when the selection covers very old lines and we're now wrapping around the scrollback history. Then there's a fourth problem case: when the user has started a selection, but hasn't yet moved the cursor. In this case, we have no end point. What's more problematic is that when the user (after scrolling) moves the cursor, we try to create a huge selection that covers mostly empty (NULL) rows, causing us to crash. This can happen e.g. when reverse scrolling in such a way that we wrap around the scrollback history. The actual viewport in this case is something like `-n - m`. But the selection we'll end up trying to create will be `m - (rows - n)`. This range may very well contain NULL rows. To deal with this, we simply cancel the selection.
2020-05-17 15:34:49 +02:00
bool selection_on_rows(const struct terminal *term, int start, int end);
void selection_view_up(struct terminal *term, int new_view);
void selection_view_down(struct terminal *term, int new_view);
void selection_mark_word(
struct seat *seat, struct terminal *term, int col, int row,
bool spaces_only, uint32_t serial);
void selection_mark_row(
struct seat *seat, struct terminal *term, int row, uint32_t serial);
void selection_clipboard_unset(struct seat *seat);
void selection_primary_unset(struct seat *seat);
bool selection_clipboard_has_data(const struct seat *seat);
bool selection_primary_has_data(const struct seat *seat);
char *selection_to_text(const struct terminal *term);
void selection_to_clipboard(
struct seat *seat, struct terminal *term, uint32_t serial);
void selection_from_clipboard(
struct seat *seat, struct terminal *term, uint32_t serial);
void selection_to_primary(
struct seat *seat, struct terminal *term, uint32_t serial);
void selection_from_primary(struct seat *seat, struct terminal *term);
/* Copy text *to* primary/clipboard */
bool text_to_clipboard(
struct seat *seat, struct terminal *term, char *text, uint32_t serial);
bool text_to_primary(
struct seat *seat, 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 seat *seat, struct terminal *term,
void (*cb)(char *data, size_t size, void *user),
void (*done)(void *user), void *user);
void text_from_primary(
struct seat *seat, struct terminal *term,
void (*cb)(char *data, size_t size, void *user),
void (*dont)(void *user), void *user);
void selection_start_scroll_timer(
struct terminal *term, int interval_ns,
enum selection_scroll_direction direction, int col);
void selection_stop_scroll_timer(struct terminal *term);