aboutsummaryrefslogtreecommitdiff
path: root/selection.c (unfollow)
Commit message (Collapse)AuthorLines
2021-02-12selection: don’t strip formatting C0 control characters in bracketed paste modeDaniel Eklöf-18/+25
It’s ok to let the receiving end handle formatting C0 control characters in bracketed paste mode. In fact, we *must* let them through. Otherwise it is impossible to paste e.g. tabs into editors and similar applications.
2021-02-12selection: don’t strip formatting C0 control characters in bracketed paste modeDaniel Eklöf-18/+25
It’s ok to let the receiving end handle formatting C0 control characters in bracketed paste mode. In fact, we *must* let them through. Otherwise it is impossible to paste e.g. tabs into editors and similar applications.
2021-02-12config: add ‘none’ as a possible value for ‘selection-target’Daniel Eklöf-0/+3
When ‘selection-target’ is set to ‘none’, selecting text does not copy the text to _any_ clipboard. This patch also refactors the value parsing to be data driven.
2021-02-12selection: copy selected text to the target configured by ‘selection-target’Daniel Eklöf-1/+14
Closes #288
2021-02-10Convert all but 2 remaining uses of xassert(false) to BUG("...")Craig Barnes-7/+6
2021-02-02selection: remove selection_enabled()Daniel Eklöf-10/+0
Its name did not reflect its semantics. Since it was only used in a single place, “inline” it there, and get rid of it.
2021-01-27selection: don’t replace \r\n and \n with \r in bracketed paste modeDaniel Eklöf-3/+14
2021-01-27selection: don’t replace \r\n and \n with \r in bracketed paste modeDaniel Eklöf-3/+14
2021-01-26selection: no xassert() in the releases/1.6 branchDaniel Eklöf-1/+1
2021-01-26selection: remove duplicate ‘ESC’ in switch caseDaniel Eklöf-4/+0
2021-01-26selection: DEL is 0x7f, not 0x1fDaniel Eklöf-1/+1
2021-01-26selection: codespell: stript -> stripDaniel Eklöf-1/+1
2021-01-26selection: strip non-formatting C0, BS, HT and DEL from pasted textDaniel Eklöf-0/+17
2021-01-26selection: unbreak text/uri-list decoding: we’re not using \r, not \nDaniel Eklöf-1/+1
Before passing the pasted text to the decoder, we now replace \r\n, and \n, with \r. The URI decoder was looking for a \n, which meant we failed to split up the list and instead pasted a single “multi-line” URI.
2021-01-26selection: replace \r\n and \n with \r, and strip \e from pasted textDaniel Eklöf-3/+27
Closes #305 Closes #306
2021-01-26selection: remove duplicate ‘ESC’ in switch caseDaniel Eklöf-4/+0
2021-01-26selection: DEL is 0x7f, not 0x1fDaniel Eklöf-1/+1
2021-01-26selection: codespell: stript -> stripDaniel Eklöf-1/+1
2021-01-26selection: strip non-formatting C0, BS, HT and DEL from pasted textDaniel Eklöf-0/+17
2021-01-26selection: unbreak text/uri-list decoding: we’re not using \r, not \nDaniel Eklöf-1/+1
Before passing the pasted text to the decoder, we now replace \r\n, and \n, with \r. The URI decoder was looking for a \n, which meant we failed to split up the list and instead pasted a single “multi-line” URI.
2021-01-26selection: replace \r\n and \n with \r, and strip \e from pasted textDaniel Eklöf-3/+27
Closes #305 Closes #306
2021-01-23config: add ‘none’ as a possible value for ‘selection-target’Daniel Eklöf-0/+3
When ‘selection-target’ is set to ‘none’, selecting text does not copy the text to _any_ clipboard. This patch also refactors the value parsing to be data driven.
2021-01-23selection: copy selected text to the target configured by ‘selection-target’Daniel Eklöf-1/+14
Closes #288
2021-01-21selection: uri decode: move zero-length check into decode_one_uri()Daniel Eklöf-2/+4
2021-01-21selection: add a ‘finish’ function, called at the end of receiving clipboard dataDaniel Eklöf-0/+24
This is necessary to decode the final URI in a text/uri-list offer if it hasn’t been newline terminated.
2021-01-21selection: URI decoder: break out decoding of a single URIDaniel Eklöf-27/+29
2021-01-16debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes-47/+47
2021-01-14config: add ‘select-extend-character-wise’ bind actionDaniel Eklöf-5/+17
This forces the (new) selection mode to be character-wise when extending a word- or line-wise selection. Default key binding is ctrl+RMB.
2021-01-12selection: uri decode: move zero-length check into decode_one_uri()Daniel Eklöf-2/+4
2021-01-12selection: add a ‘finish’ function, called at the end of receiving clipboard dataDaniel Eklöf-0/+24
This is necessary to decode the final URI in a text/uri-list offer if it hasn’t been newline terminated.
2021-01-12selection: URI decoder: break out decoding of a single URIDaniel Eklöf-27/+29
2021-01-06selection: extend-block: update pivot point and selection directionDaniel Eklöf-0/+6
2021-01-06selection: extend: don’t copy to primary - it is done when RMB is releasedDaniel Eklöf-2/+0
2021-01-06selection: extend: re-calculate pivot pointDaniel Eklöf-0/+30
2021-01-06selection: break out pivot point adjustment for character-wise selectionsDaniel Eklöf-80/+111
2021-01-06selection: combine enum selection_kind with selection_semanticDaniel Eklöf-15/+29
2021-01-04selection: update: line-wraps are ok while moving pivot start/end pointDaniel Eklöf-8/+14
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-04selection: update: get start-row pointer *after* modifying the start row indexDaniel Eklöf-5/+6
2021-01-04selection: update: simplify: multi-column chars don’t span line-wrapsDaniel Eklöf-14/+8
2021-01-04selection: wrap pivot_{start,end}->row before accessing grid row arrayDaniel Eklöf-5/+7
2021-01-04selection: cancel: reset pivot coordinatesDaniel Eklöf-0/+2
2021-01-04selection: update: find_word_boundary_{left,right}: coordinates are screen localDaniel Eklöf-4/+10
2021-01-04selection: find_word_boundary_{left,right}: try to make the code more readableDaniel Eklöf-24/+24
2021-01-04selection: find_word_boundary_{left,right}: handle multi-column charactersDaniel Eklöf-8/+40
2021-01-04selection: find_word_boundary{left,right}: what we match depends on initial characterDaniel Eklöf-50/+66
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-04selection: allow selections to pivot around a range instead of a pointDaniel Eklöf-26/+78
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-04selection: find_word_boundary{left,right}: handle composed charactersDaniel Eklöf-0/+24
2021-01-04selection: find_word_boundary_{left,right}: treat spacers as word charsDaniel Eklöf-4/+16
2021-01-04selection: use selection_start() to initialize word/row-based selectionDaniel Eklöf-92/+91
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-04selection: don’t finalize selection when starting a word/row-based selectionDaniel Eklöf-2/+0
2021-01-04selection: remember whether word-wise selection uses spaces only for delimitersDaniel Eklöf-2/+4
2021-01-04selection: wip: update selection row-wise when initial selection was by rowDaniel Eklöf-2/+23
2021-01-04selection: wip: update selection word-wise when initial selection was by wordDaniel Eklöf-54/+85
2020-12-12input: rework mouse button/motion handlingDaniel Eklöf-0/+2
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-11-30selection: do not try to paste un-handled mime typesDaniel Eklöf-2/+6
Closes #230
2020-11-30selection: offer clipboard content in more mime typesDaniel Eklöf-0/+10
2020-11-06selection: fix enum typeDaniel Eklöf-1/+1
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-06selection: fix enum typeDaniel Eklöf-1/+1
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-06selection: explicitly set direction when right-click extendingDaniel Eklöf-0/+6
Fixes an issue where right-click-and-dragging to extend a selection caused one cell being removed from the selection. Closes #180
2020-11-04selection: explicitly set direction when right-click extendingDaniel Eklöf-0/+6
Fixes an issue where right-click-and-dragging to extend a selection caused one cell being removed from the selection. Closes #180
2020-11-01selection: do mime-type based decoding before passing data to callbackDaniel Eklöf-119/+104
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-10-31selection: dnd: fix wl_data_offer_destroy() raceDaniel Eklöf-0/+5
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-28codespell: fix misspelled wordsDaniel Eklöf-2/+2
2020-10-28selection: add support for different mime-typesDaniel Eklöf-83/+315
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-26selection: debug log of data offer mime-types and actionsDaniel Eklöf-5/+5
2020-10-26selection: implement support for drag-and-dropDaniel Eklöf-5/+91
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-13selection: re-factor: break out code shared between clipboard/primary sendDaniel Eklöf-59/+21
The send functions are called by the compositor when another application wants to paste data *from* foot.
2020-10-11selection: use appropriate check for PRIMARY pasteSergey Nazaryev-2/+2
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-11selection: auto-scroll: call cmd_scrollback_{up,down}() with number of rowsDaniel Eklöf-4/+2
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-11selection: cancel: call selection_stop_scroll_timer()Daniel Eklöf-4/+1
Instead of re-implementing the same logic, simply call selection_stop_scroll_timer().
2020-10-11selection: auto-scroll: add SELECTION_SCROLL_NOT as a scroll ‘direction’Daniel Eklöf-2/+9
2020-10-11selection: auto-scroll: selection keeps scrolling while mouse is outside gridDaniel Eklöf-0/+103
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-10selection: use appropriate check for PRIMARY pasteSergey Nazaryev-1036/+262
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-09config: add ‘[default].word-delimiters’Daniel Eklöf-4/+5
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-09-17selection: reset clipboard/primary->text after free:ing itDaniel Eklöf-0/+2
2020-09-17selection: primary unset: don’t free text twiceDaniel Eklöf-1/+0
2020-09-09selection: add selection_<type>_has_data()Daniel Eklöf-0/+12
Returns true when there is data available for paste in the clipboard/primary selection.
2020-09-09selection: add selection_<type>_unset()Daniel Eklöf-0/+41
These functions clear the current selection.
2020-08-27codespell: selection: faild -> failedDaniel Eklöf-1/+1
2020-08-25selection: don't initiate a paste when we're already pastingDaniel Eklöf-0/+10
2020-08-25selection: must use term_paste_data_to_slave() for paste dataDaniel Eklöf-1/+1
2020-08-25selection: clipboard callback: assert we're in sending-paste-data modeDaniel Eklöf-0/+1
2020-08-25selection: block non-paste data from being sent to client while pastingDaniel Eklöf-3/+12
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-25selection: add a 2 second timeout when receiving clipboard dataDaniel Eklöf-11/+78
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-23selection: don't do "return function_returning_void()" in functions returning voidDaniel Eklöf-11/+22
2020-08-23don't use empty struct initializersDaniel Eklöf-3/+3
2020-08-18selection: don't highlight trailing empty cells in a selectionDaniel Eklöf-11/+55
This makes it clear which cells contain spaces (that will be copied) or are empty (will *not* be copied).
2020-08-14selection: extend: set ongoing to trueDaniel Eklöf-0/+2
2020-08-14selection: finalize: clear ongoing selectionDaniel Eklöf-3/+3
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-14selection: update: don't update if there's no ongoing selectionDaniel Eklöf-0/+3
2020-08-14config: add mouse specific bind actionsDaniel Eklöf-0/+7
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-13selection: improve handling of multi-column charactersDaniel Eklöf-13/+14
* Don't assume multi-column characters are exactly *two* columns * Check for CELL_MULT_COL_SPACER values instead of using wcwidth()
2020-08-13selection: handle multi-column characters when reversing selection directionDaniel Eklöf-16/+30
2020-08-12selection: adjust start point when the selection changes directionDaniel Eklöf-0/+37
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-08Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes-5/+6
2020-07-31config: add 'pipe-selected' key bindingDaniel Eklöf-4/+7
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-29input: margins are not selectableDaniel Eklöf-3/+4
* 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-27selection: extending a selection is now interactiveDaniel Eklöf-8/+8
That is, a selection extension can be resized just like an ordinary extension.
2020-07-26input: margins are not selectableDaniel Eklöf-3/+4
* 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-15selection: provide a const-wrapper for extract_one()Daniel Eklöf-1/+9
extract_one() takes const pointers, while the callback argument to foreach() expects non-const.