Commit graph

173 commits

Author SHA1 Message Date
Daniel Eklöf
f236dc7701
selection: break out pivot point adjustment for character-wise selections 2021-01-06 10:54:53 +01:00
Daniel Eklöf
3a9172342f
selection: combine enum selection_kind with selection_semantic 2021-01-06 10:53:27 +01:00
Daniel Eklöf
4849e8f874
selection: update: line-wraps are ok while moving pivot start/end point
This fixes an assertion triggered when selecting the upper left cell
and dragging down.

We would end up trying to decrement the pivot end point, hitting an
assertion that only is valid while skipping spacers.

Remove the assertion, and allow pivot points to be moved across line
wraps, but take care not to move outside the visible screen area.
2021-01-04 19:48:44 +01:00
Daniel Eklöf
56f6e450b0
selection: update: get start-row pointer *after* modifying the start row index 2021-01-04 19:48:43 +01:00
Daniel Eklöf
fb9a95494d
selection: update: simplify: multi-column chars don’t span line-wraps 2021-01-04 19:48:43 +01:00
Daniel Eklöf
2b195d2cc3
selection: wrap pivot_{start,end}->row before accessing grid row array 2021-01-04 19:48:43 +01:00
Daniel Eklöf
8113d2205d
selection: cancel: reset pivot coordinates 2021-01-04 19:48:43 +01:00
Daniel Eklöf
683f63c929
selection: update: find_word_boundary_{left,right}: coordinates are screen local 2021-01-04 19:48:43 +01:00
Daniel Eklöf
c851aae9d6
selection: find_word_boundary_{left,right}: try to make the code more readable 2021-01-04 19:48:42 +01:00
Daniel Eklöf
3863a61ba6
selection: find_word_boundary_{left,right}: handle multi-column characters 2021-01-04 19:48:42 +01:00
Daniel Eklöf
b22091a8c9
selection: find_word_boundary{left,right}: what we match depends on initial character
If the initial character is a space, find the next non-space
character.

If the initial character is a delimiter, find the next non-delimiter
character (space, or word character).

If the initial character is neither (i.e, it is a word character),
find the next non-word character.
2021-01-04 19:48:42 +01:00
Daniel Eklöf
2fd7b2fbd4
selection: allow selections to pivot around a range instead of a point
Extend selection pivoting to allow selections to pivot around a
range.

Use this in word- and row-based selections to pivot around the initial
word/row that was selected.

This mimics the behavior of at least urxvt and xterm.
2021-01-04 19:48:42 +01:00
Daniel Eklöf
c821914e67
selection: find_word_boundary{left,right}: handle composed characters 2021-01-04 19:48:41 +01:00
Daniel Eklöf
736ff0421c
selection: find_word_boundary_{left,right}: treat spacers as word chars 2021-01-04 19:48:41 +01:00
Daniel Eklöf
3afc5a723e
selection: use selection_start() to initialize word/row-based selection
This removes the selection_mark_word() and selection_mark_row()
functions. To start a word/row-based selection, use selection_start()
with SELECTION_SEMANTIC_{WORD,ROW}
2021-01-04 19:48:41 +01:00
Daniel Eklöf
3dd6b7e4ef
selection: don’t finalize selection when starting a word/row-based selection 2021-01-04 19:48:41 +01:00
Daniel Eklöf
bef69cb961
selection: remember whether word-wise selection uses spaces only for delimiters 2021-01-04 19:48:41 +01:00
Daniel Eklöf
55ecf29a36
selection: wip: update selection row-wise when initial selection was by row 2021-01-04 19:48:40 +01:00
Daniel Eklöf
30de262d29
selection: wip: update selection word-wise when initial selection was by word 2021-01-04 19:48:26 +01:00
Daniel Eklöf
ff96ce1e91
input: rework mouse button/motion handling
Store a list of currently pressed buttons, and which surface they
belong to (i.e. which surface that received the press).

Then, in motion events (with a button pressed, aka drag operations),
send the event to the “original” surface (that received the press).

Also send release events to the originating surface.

This means a surface receiving a press will always receive a
corresponding release. And no one will receive a release event without
a corresponding press event.

Motion events with a button pressed will *always* use the *first*
button that was pressed. I.e. if you press a button, start dragging,
and then press another button, we keep generating motion events for
the *first* button.
2020-12-12 19:05:24 +01:00
Daniel Eklöf
9e1746cc29
selection: do not try to paste un-handled mime types
Closes #230
2020-11-30 20:04:17 +01:00
Daniel Eklöf
043b741008
selection: offer clipboard content in more mime types 2020-11-30 20:02:47 +01:00
Daniel Eklöf
2281ee852a
selection: fix enum type
enum selection_scroll_direction is used when extending a selection by
auto-scrolling the terminal content while the mouse is outside the
grid.

What we want is enum selection_direction.
2020-11-06 20:12:15 +01:00
Daniel Eklöf
a8fb51a34c
selection: explicitly set direction when right-click extending
Fixes an issue where right-click-and-dragging to extend a selection
caused one cell being removed from the selection.

Closes #180
2020-11-04 19:01:59 +01:00
Daniel Eklöf
43f293f22e
selection: do mime-type based decoding before passing data to callback
The intention here is to make *all* text_from_clipboard() and
text_from_primary() callers benefit from mime-type base
decoding (e.g. URI list decoding).

Previously, the decoding was done *in* the callback, which meant only
the “default” clipboard/primary selection paste functions, and DnD,
recognized URI lists.
2020-11-01 11:52:11 +01:00
Daniel Eklöf
102d4975a1
selection: dnd: fix wl_data_offer_destroy() race
At the end of a drag-and-drop operation, we need to call
`wl_data_offer_finish()`.

We *must* ensure the data offer hasn’t been destroyed before
that. This could previously happen if the compositor decided to send a
regular clipboard offer *after* we had started a drop operation,
but *before* it had finished. The dnd offer was then destroyed when
the clipboard offer was received, causing us to crash in
`wl_data_offer_finish()`.

To handle this, let the receive_offer_context take over ownership of
the data_offer pointer, and “manually” destroy it *after* calling
`wl_data_offer_finish()` in `receive_dnd_done()`.

Note: we should not, and can not, do the same thing for regular
clipboard and primary selection offers; such offers can be used
multiple times and should *not* be destroyed after a single copy
operation.
2020-10-31 10:36:11 +01:00
Daniel Eklöf
bb43695426
codespell: fix misspelled words 2020-10-28 19:34:49 +01:00
Daniel Eklöf
be22fefdc7
selection: add support for different mime-types
Add support for `text/plain`, `text/plain;charset=utf-8` and
`text/uri-list` to regular copy operations (both from clipboard and
primary selection) and drag-and-drop operations.
2020-10-28 19:16:04 +01:00
Daniel Eklöf
9580c04dd3
selection: debug log of data offer mime-types and actions 2020-10-26 21:19:07 +01:00
Daniel Eklöf
8e23b5b70d
selection: implement support for drag-and-drop
We accept COPY and MOVE actions, for text/plain;charset=utf-8
mime-types.

To implement DnD, we need to track the current DnD data offer *and*
the terminal instance it is (currently) targeting.

To do this, a seat has a new member, ‘dnd_term’. On a DnD enter event,
we lookup the corresponding terminal instance and point ‘dnd_term’ to
it.

On a DnD leave event, ‘dnd_term’ is reset.

The DnD data offer is tracked in the terminal’s wayland window
instance. It is reset, along with the seat’s ‘dnd_term’ on a DnD leave
event.

On a drop event, we immediately clear the seat’s ‘dnd_term’, to ensure
we don’t reset it, or destroy the offer before the drop has been
completed.

The drop’s ‘done()’ callback takes care of destroying and resetting
the DnD offer in the terminal’s wayland window instance.

Closes #175
2020-10-26 21:02:53 +01:00
Daniel Eklöf
033ff180af
selection: re-factor: break out code shared between clipboard/primary send
The send functions are called by the compositor when another
application wants to paste data *from* foot.
2020-10-13 18:38:49 +02:00
Daniel Eklöf
0d8344d3b9
selection: auto-scroll: call cmd_scrollback_{up,down}() with number of rows
No need to loop and call cmd_scrollback_{up,down}() with ‘1’ each loop
iteration; just call it with the total number of lines to scroll.
2020-10-11 18:26:24 +02:00
Daniel Eklöf
0cff7c7c4f
selection: cancel: call selection_stop_scroll_timer()
Instead of re-implementing the same logic, simply call
selection_stop_scroll_timer().
2020-10-11 18:24:47 +02:00
Daniel Eklöf
4ad7fdc19c
selection: auto-scroll: add SELECTION_SCROLL_NOT as a scroll ‘direction’ 2020-10-11 18:18:18 +02:00
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