Commit graph

139 commits

Author SHA1 Message Date
Daniel Eklöf
7fedf2f801
selection: auto-scroll: selection keeps scrolling while mouse is outside grid
Moving the mouse outside the grid while we have an on-going selection
now starts a timer. The interval of this timer depends on the mouse’s
distance from the grid - the further away the mouse is, the shorter
interval.

On each timer timeout, we scroll one line, and update the
selection. Thus, the shorter the interval, the faster we scroll.

The timer is canceled as soon as the mouse enters the grid again, or
the selection is either canceled or finalized.

The timer FD is created and destroyed on-demand.

Most of the logic is now in selection.c. The exception is the
calculation of the timer interval, which depends on the mouse’s
position. Thus, this is done in input.c.

The scroll+selection update logic needs to know a) which direction
we’re scrolling in, and b) which *column* the selection should be
updated with.

If the mouse is outside the grid’s left or right margins, the stored
mouse column will be -1. I.e. we don’t know whether the mouse is on
the left or right side of the grid. This is why the caller, that
starts the timer, must provide this value.

The same applies to top and bottom margins, but since we already have
the scroll *direction*, which row value to use can be derived from this.
2020-10-11 15:44:20 +02:00
Sergey Nazaryev
d95dd062aa selection: use appropriate check for PRIMARY paste
Assume it could be a copy-paste typo. We should check PRIMARY, not
CLIPBOARD. Without this fix, we can't use PRIMARY until we copy anything
to CLIPBOARD.
2020-10-10 21:13:58 +03:00
Daniel Eklöf
49f4b3da64
config: add ‘[default].word-delimiters’
This option lets the user configure which characters act as word
delimiters when selecting text.

This affects both “double clicking”, and ‘ctrl-w’ in scrollback search
mode.

Closes #156
2020-10-09 19:44:23 +02:00
Daniel Eklöf
fcb2beebda
selection: reset clipboard/primary->text after free:ing it 2020-09-17 20:05:22 +02:00
Daniel Eklöf
dd18710bb7
selection: primary unset: don’t free text twice 2020-09-17 20:02:38 +02:00
Daniel Eklöf
dec6f963cb
selection: add selection_<type>_has_data()
Returns true when there is data available for paste in the
clipboard/primary selection.
2020-09-09 19:01:21 +02:00
Daniel Eklöf
c3cacb4704
selection: add selection_<type>_unset()
These functions clear the current selection.
2020-09-09 19:01:21 +02:00
Daniel Eklöf
44e7943fef
codespell: selection: faild -> failed 2020-08-27 19:55:27 +02:00
Daniel Eklöf
1707db1678
selection: don't initiate a paste when we're already pasting 2020-08-25 18:56:15 +02:00
Daniel Eklöf
9ec4c3fd94
selection: must use term_paste_data_to_slave() for paste data 2020-08-25 18:56:15 +02:00
Daniel Eklöf
efbc3431ed
selection: clipboard callback: assert we're in sending-paste-data mode 2020-08-25 18:56:15 +02:00
Daniel Eklöf
e570146c07
selection: block non-paste data from being sent to client while pasting
While pasting data from the clipboard, block *all* other data from
being sent to the client. This includes keyboard and mouse events, but
also replies for VT queries.

This is particularly important when bracketed paste has been enabled,
since then the client will interpret *everything* between the
bracketed paste start and end as paste data.
2020-08-25 18:56:15 +02:00
Daniel Eklöf
81222dac57
selection: add a 2 second timeout when receiving clipboard data
When reading clipboard data, a malicious clipboard provider could
stall us forever, by not sending any data, and not closing the pipe.

This commit adds a timer_fd based timeout of 2 seconds. If the timer
triggers, we abort the clipboard receive.
2020-08-25 18:56:13 +02:00
Daniel Eklöf
74cf8e0206
selection: don't do "return function_returning_void()" in functions returning void 2020-08-23 10:07:09 +02:00
Daniel Eklöf
dabdffafa5
don't use empty struct initializers 2020-08-23 10:07:00 +02:00
Daniel Eklöf
cb9626741a
selection: don't highlight trailing empty cells in a selection
This makes it clear which cells contain spaces (that will be copied)
or are empty (will *not* be copied).
2020-08-18 18:03:07 +02:00
Daniel Eklöf
f14b49068a
selection: extend: set ongoing to true 2020-08-14 07:38:56 +02:00
Daniel Eklöf
9517c6443c
selection: finalize: clear ongoing selection
Check for ongoing selection, and *clear* it before bailing out due to
the selection not having an end-point.

This fixes an issue where a selection was kept as ongoing, even though
the button had been released. Typically triggered by clicking without
moving the mouse; this started a new selection, then (tried to)
finalize it, but failed since the selection didn't have an end-point.
2020-08-14 07:38:55 +02:00
Daniel Eklöf
cddeaa2c1c
selection: update: don't update if there's no ongoing selection 2020-08-14 07:38:55 +02:00
Daniel Eklöf
20f0334e13
config: add mouse specific bind actions
This extends the "normal" bind action enum with mouse specific
actions.

When parsing key bindings, we only check up to the last valid keyboard
binding, while mouse bindings support *both* key actions and mouse
actions.

The new actions are:

* select-begin: starts an interactive selection
* select-extend: interactively extend an existing selection
* select-word: select word under cursor
* select-word-whitespace: select word under cursor, where the only
  word separating characters are whitespace characters.

The old hard-coded selection "bindings" have been converted to instead
use these actions, via default bindings added to the configuration.
2020-08-14 07:38:55 +02:00
Daniel Eklöf
1decd8e9de
selection: improve handling of multi-column characters
* Don't assume multi-column characters are exactly *two* columns
* Check for CELL_MULT_COL_SPACER values instead of using wcwidth()
2020-08-13 18:33:22 +02:00
Daniel Eklöf
3816a3b460
selection: handle multi-column characters when reversing selection direction 2020-08-13 18:32:56 +02:00
Daniel Eklöf
8808dd28f2
selection: adjust start point when the selection changes direction
Without this, the initial cell will always be selected, regardless of
how the selection is moved to the left or right.

With this patch, the initial cell will only be selected while the
selection is being made in the original direction. Changing direction
of the selection moves the start point to next/previous character.
2020-08-12 19:42:21 +02:00
Craig Barnes
7a77958ba2 Convert most dynamic allocations to use functions from xmalloc.h 2020-08-08 20:37:57 +01:00
Daniel Eklöf
639a61abd8
config: add 'pipe-selected' key binding
This works just like pipe-visible and pipe-scrollback, but pipes the
user-selected text, if any, to the external tool.

Closes #51
2020-07-31 17:04:30 +02:00
Daniel Eklöf
5c20069588
Merge branch 'master' into scrollback-position-indicator 2020-07-27 16:51:39 +02:00
Daniel Eklöf
7127a0a6c3
selection: extending a selection is now interactive
That is, a selection extension can be resized just like an ordinary
extension.
2020-07-27 16:44:41 +02:00
Daniel Eklöf
c1f35731e0
input: margins are not selectable
* Fix col/row calculation in pointer-enter event; we did not take the
  margins into account.
* seat->mouse.col,row are now set to -1 if the cursor is inside the
  margins. That is, col/row are only ever valid when the mouse is
  actually over the grid, and not in the margins.
* Use regular 'left-ptr' mouse cursor when mouse is inside the
  margins, to not make the user think he/she can start a selection.

Besides making things clearer, this also fixes a crash that occurred
if you started a selection in e.g. the right margin.
2020-07-26 12:37:02 +02:00
Daniel Eklöf
ffaa19ee22
selection: provide a const-wrapper for extract_one()
extract_one() takes const pointers, while the callback argument to
foreach() expects non-const.
2020-07-15 11:31:57 +02:00
Daniel Eklöf
aafa120f92
selection: refactor: break out text extraction to a separate file 2020-07-15 11:19:18 +02:00
Daniel Eklöf
bead6f36d6
selection: don't skip SPACER cells in the generic foreach()
As that breaks e.g. selection marking (SPACER cells didn't get
inverted when rendered).

Instead, skip them in extract_one() only. I.e. when copying text from
the grid.
2020-07-15 09:22:06 +02:00
Daniel Eklöf
540864521e
selection: row->dirty is a boolean 2020-07-15 09:21:39 +02:00
Daniel Eklöf
a2af13a126
selection: no need to try to detect multi-column chars at the end of the line
This is handled by the generic foreach() functions, which now simply
skips spacer cells.
2020-07-14 17:06:04 +02:00
Daniel Eklöf
df2927e088
term: print: write special value CELL_MULT_COL_SPACER to extra cells
When printing a multi-column character, write CELL_MULT_COL_SPACER
instead of '0' to both padding cells (when character doesn't fit at
the end of the line), and to the cells following the actual character.
2020-07-14 16:49:11 +02:00
Daniel Eklöf
5c99e8013b
term: rename COMB_CHARS_LO,HI -> CELL_COMB_CHARS_LO,HI 2020-07-14 16:41:57 +02:00
Daniel Eklöf
4cf7195695
selection: recognize empty padding cells in a forced linewrap
When printing a multi-column character at the end of the line, and it
doesn't fit, we currently insert a forced line-wrap. This means the
last character(s) on the previous line will be empty, followed by a
multi-column character in the first cell on the next line.

Without special code to handle this, the selection text extraction
code will insert a hard newline, since this is normally the correct
thing to do.

Add a TODO, to consider writing a special place holder value to these
padding cells.
2020-07-14 13:17:50 +02:00
Daniel Eklöf
3bc404b5a3
selection: foreach: don't call callback for trailing multi-character cells 2020-07-14 12:59:36 +02:00
Daniel Eklöf
71584aed38
seat: use separate 'enter' serials for keyboard and mouse 2020-07-09 11:20:46 +02:00
Daniel Eklöf
4e48d550ef
multi-seat: improve handling of multiple (mouse) pointers
* xcursor always set for all pointers
* xcursor sometimes not updated when it should be
* mouse grabbed state wasn't per seat, but global (i.e. "does at least
  one seat enable mouse grabbing")
* selection enabled state wasn't per seat
2020-07-09 09:52:11 +02:00
Daniel Eklöf
4c7d29f7eb
multi-seat: re-enable selection support (excluding OSC 52) 2020-07-08 18:41:09 +02:00
Daniel Eklöf
c470825067
wip: multi-seat support
Compiles and runs, but mouse, clipboard and other things have been
disabled.
2020-07-08 16:45:26 +02:00
Daniel Eklöf
159bfddb87
selection: fix typo when extending selection to cover double-width character 2020-06-03 17:31:41 +02:00
Daniel Eklöf
056fd4ffe0
selection: don't allow only half of double-width characters to be selected 2020-06-02 18:21:39 +02:00
Daniel Eklöf
8ad3b9c172
selection: performance: check for < 0 or >= 0 instead of == -1 2020-05-19 18:51:30 +02:00
Daniel Eklöf
08588cd0fc
selection: handle viewport wrap around correctly
When the viewport wraps around, the selection points may be
"incorrect".
2020-05-19 18:49:42 +02:00
Daniel Eklöf
96a4f1b993
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
Daniel Eklöf
5d643e63fe
selection: on_rows_in_view: fix range check 2020-05-17 12:04:08 +02:00
Daniel Eklöf
6902c22a77
selection: copy: insert line break if either cell is empty 2020-05-16 22:29:53 +02:00
Daniel Eklöf
1a8ccb0ffa
selection/render: sync cells' 'selected' bit before rendering
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.
2020-05-16 21:36:08 +02:00
Daniel Eklöf
e3992b8379
selection: update: don't assert on 'start' being set 2020-05-16 21:16:35 +02:00