aboutsummaryrefslogtreecommitdiff
path: root/selection.c (follow)
Commit message (Collapse)AuthorAgeLines
* selection: send_clipboard_or_primary(): handle selection text being NULLDaniel Eklöf2023-07-22-3/+1
|
* selection: selection_on_rows(): typo: row_start -> row_endDaniel Eklöf2022-11-24-1/+1
| | | | | | | This fixes an issue where selections in the scroll margins were not detected correctly. This meant they weren’t canceled as they should have been, which in turn caused a visual glitch where text appeared to be selected, but were in fact not.
* selection: scroll down: handle non-full scrollback correctlyDaniel Eklöf2022-10-16-3/+8
| | | | | | | | | When determining whether or not to cancel a selection (due to it, or part of it, being "scrolled out"), we assumed the scrollback was full. This patch changes the implementation to compare the scrollback relative selection coordinates with the scrollback relative end-of-the-scrollback coordinates.
* selection: mark_selected_region(): use an enum to encode how the cells are to be updatedDaniel Eklöf2022-08-26-7/+20
|
* selection: restore <= 1.12 behavior in block selection wrt empty cellsDaniel Eklöf2022-08-26-1/+3
| | | | | That is, highlight empty cells, regardless of whether they’re trailing or not.
* selection: once again highlight non-trailing empty cellsDaniel Eklöf2022-08-22-6/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Foot 1.13.0 introduced a regression where non-trailing empty cells were highlighted inconsistently (cells that shouldn’t be highlighted, were, seemingly at random). 86663522d5915c0fdb2b8b132bacc247fcfd1fb8 “fixed” this by never highlighting *any* empty cells. This meant the behavior, compared to foot 1.12 and earlier, changed. In foot 1.12 and older versions, non-trailing empty cells were highlighted, as long as the selection covered at least one of the trailing non-empty cells. This patch restores that behavior. To understand how this works, lets first take a look at how selection works: When a selection is made, and updated (i.e. the mouse is dragged, or the selection is extended through RMB etc), we need to (un)tag and dirty the cells that are a) newly selected, or b) newly deselected. That is, we look at the diff between the “old” and the “new” selection, and only update those cells. This is for performance reasons: iterating the entire selection is not feasible with large selections. However, it also means we cannot reason about empty cells; we simply don’t know if an empty cells is a trailing empty cell, or a non-trailing one. Then, when we render a frame, we iterate all the *visible* and *selected* cells, once again tagging them as selected (this is needed since a selected cell might have lost its selected tag if the cell was written to, by the client application, after the selection was made). At this point, we *can* reason about empty cells. So, to restore the highlighting behavior to that of foot 1.12, we do this: When working with the selection diffs when a selection is updated, we don’t special case empty cells at all. Thus, all empty cells covered by the selection is highlighted, and dirtied. But, when rendering the frame, we _do_ special case them. The only difference (compared to foot 1.12) is that we *must* explicitly *clear* the selection tag, and dirty the empty cells. This is to ensure the empty cells that were incorrectly highlighted by the selection update algorithm, isn’t rendered as that. This does have a slight performance impact, as empty cells are now always re-rendered. The impact should however be small.
* selection: never highlight selected, empty cellsDaniel Eklöf2022-08-22-2/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a regression, where empty cells "between" non-empty cells (i.e. non-trailing empty cells) sometimes were incorrectly highlighted. The idea has always been to highlight exactly those cells that will get extracted when they’re copied. This means we’ve not highlighted trailing empty cells, but we _have_ highlighted other empty cells, since they are converted to spaces when copied (whereas trailing empty cells are skipped). fa2d9f86996467ba33cc381f810ea966a4323381 changed how a selection is updated. That is, which cells gets marked as selected, and which ones gets unmarked. Since we no longer walk all the cells, but instead work with pixman regions representing selection diffs, we can no longer determine (with certainty) which empty cells should be selected and which shouldn’t. Before this patch (but after fa2d9f86996467ba33cc381f810ea966a4323381), we sometimes incorrectly highlighted empty cells that should not have been highlighted. This happened when we’ve first (correctly) highlighted a region of empty cells, but then shrink the selection such that all those empty cells should be de-selected. This patch changes the selection behavior to *never* highlight empty cells. This fixes the regression, but also means slightly different behavior, compared to pre-fa2d9f86996467ba33cc381f810ea966a4323381. The other alternative is to always highlight all empty cells. But, since I personally like the fact that we’re skipping trailing empty cells, I prefer the approach taken by this patch.
* selection: rework how we update a selectionDaniel Eklöf2022-07-28-106/+190
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this patch, each selection update would result in grid covered by the selection being walked *three* times. First to “premark” the area that *will* be selected after the update, then again to unmark the previous selection (excluding the cells that were premarked - but the cells are still iterated), and then one more time to finalize the selection state in the grid. Furthermore, each time a frame is rendered, the entire selection were iterated again, to ensure all the cells have their ‘selected’ bit set. This quickly gets *very* slow. This patch takes a completely different approach. Instead of looking at the selection as a range of cells to iterate, we view it as an area, or region. Thus, on each update, we have to regions: the region representing the previous selection, and the region representing the to-be selection. By diffing these two regions, we get two new regions: one that represents the cells that were selected, but aren’t any more, and one that represents the cells that previously were not selected, but now will be. We implement the regions using pixman regions. By subtracting the current selection from the previous selection, we get the region representing the cells that are no longer selected, and that should be unmarked. By subtracting the previous selection from the current, we get the region representing the cells that was added to the selection in this update, and that should be marked. selection_dirty_cells() is rewritten in a similar manner. We create pixman regions for the selection, and the current scrollback view. The intersection represents the (selected) cells that are visible. These need to iterated and marked as being selected. Closes #1114
* selection: extend: use scrollback relative coordinatesDaniel Eklöf2022-07-28-15/+33
| | | | | | | | | | | | | When extending a selection, we determine *how* to extend it (which endpoint to move, and whether to grow or shrink the selection) by comparing the extension point with the old start and end coordinates. For this to work correctly, we need to use scrollback relative coordinates. This fixes an issue where extending a very large selection (covering many pages) sometimes shrunk the selection instead of growing it, or just misbehaving in general.
* selection: foreach_selected_*(): refactor: use grid_row_abs_to_sb()Daniel Eklöf2022-07-28-6/+5
|
* selection: selection_on_rows(): use scrollback relative coordsDaniel Eklöf2022-07-28-15/+59
| | | | | | | | | | | When checking if the current selection intersects with the region (passed as parameter to the function), use scrollback relative coordinates. This fixes an issue where selections crossing the scrollback wrap-around being misdetected, resulting in either the selection being canceled while scrolling, even though it wasn’t scrolled out, or the selection _not_ being canceled, when it _was_ scrolled out.
* selection: wl_data_offer_set_action: use enum values instead of magic integersDaniel Eklöf2022-06-21-1/+4
|
* selection: reject dnd offers with unsupported mime-typesDaniel Eklöf2022-06-20-0/+4
| | | | | | | We were already doing this, implicitly, *if* the offer was for the main grid. This patch makes it more clear that we do not accept the offer.
* selection: explicitly reject *all* dnd offers not targeting the gridDaniel Eklöf2022-06-20-0/+1
|
* selection: ignore drag-and-drops with unsupported mime-typesDaniel Eklöf2022-06-20-0/+6
| | | | | | | | Specifically, make sure we do *not* call wl_data_offer_receive() with a NULL mime-type, as this causes libwayland to error out, which in turn causes foot to exit. Closes #1092
* selection: allow HT, VT and FF, disallow NUL in non-bracketed paste modeDaniel Eklöf2022-06-15-3/+16
| | | | | | | | | | | | | | | | This syncs foot with more recent versions of XTerm, where it’s “disallowedPasteControls” resource has changed its default value to BS,DEL,ENQ,EOT,ESC,NULL Note that we’re already stripping out ENQ,EOT,ESC in all modes. What does it mean for foot: * HT, VT and FF are now allowed, regardless of paste mode * NUL is now stripped in non-bracketed paste mode Closes #1084
* selection: find_word_boundary_right: add “stop-on-space-to-word-boundary”Daniel Eklöf2022-04-27-8/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When true, selection_find_word_boundary_right() behaves as before - it stops as soon as it encounters a character that isn’t of the same *type* as the “initial” character (the last character in the selection). Take this, for example: The Quick Brown Fox The selection will first stop at the end of “the”, then just *before* “quick”, then at the end of “quick”. Then just *before* “brown”, and then at the end of “brown”, and so on. This suits mouse selections pretty good. But when selection_find_word_boundary_right() is used to extend a search match, it’s better to ignore space-to-word character transitions. That is, we want The Quick Brown Fox to first extend to the end of “the”, then immediately to the end of “quick”, then to the end of “brown”, and so on. Setting the ‘stop_to_space_to_word_boundary’ argument to false results in latter behavior. This is now done by search, when executing the “extend-to-word-boundary” and “extend-to-next-whitespace” key bindings.
* selection: add start/end coordinate gettersDaniel Eklöf2022-04-25-0/+24
| | | | | | | | Internally, selection coordinates are *unbounded* (that is, the row numbers may be larger than grid->num_rows) while a selection is ongoing. Only after it has been finalized are the coordinates bounded. This means it isn’t safe to use term->selection.coords.* directly.
* selection: assert serial is non-zero before copying data to the clipboardDaniel Eklöf2022-04-24-1/+4
|
* selection: find_word_boundary: assert ‘pos’ is validDaniel Eklöf2022-04-24-0/+10
|
* search: fix next/prev not updating selection correctly when matches overlapDaniel Eklöf2022-04-17-1/+1
| | | | | When the new match overlapped with the old match, the selection wasn’t updated correctly.
* refactor: add a ‘range’ struct, grouping a start and end coord togetherDaniel Eklöf2022-04-09-52/+52
|
* selection: don’t translate \r to \n when pastingDaniel Eklöf2022-03-19-7/+2
| | | | | | | | | | | | | | | | | In non-bracketed paste mode, we translate \n to \r, and \r\n to \r. The latter matches XTerm, urxvt, alacritty and kitty. The former matches alacritty and kitty (xterm and urxvt just blindly replaces all \n occurrences with \r, meaning \r\n is translated to \r\r. For some reason, we then unconditionally translated all \r back to \n, regardless of whether bracketed paste was enabled or not. Unsure why/where this comes from, but it doesn't match any of the other terminal emulators I tested. One example where this caused issues is in older versions of nano (at least up to 2.9). Closes #980
* selection: foreach: sort start/end based on their scrollback-start relative valuesDaniel Eklöf2022-02-07-20/+56
| | | | | | | | | | | | | | | | | | | | | When iterating the characters in a selection, we want to go from the “start” to the “end”, where start is the upper left-most character, and “end” is the lower right-most character. There are two things to consider: * The ‘start’ coordinate may actually sort after the ‘end’ coordinate (user selected from bottom of the window and upward) * The scrollback wraparound. What we do is calculate both the star and end coordinates’ scrollback-start relative row numbers. That is, the number of rows from the beginning of the scrollback. So if the very first row (i.e. the oldest) in the scrollback is selected, that has the scrollback-start relative number “0”. Then we loop from whichever (start or end coordinate) is highest up in the scrollback, to the “other” coordinate.
* selection: ensure start/end coordinates are bounded by the current gridDaniel Eklöf2022-02-07-10/+2
| | | | Closes #924
* fcft: adapt to API changes in fcft-3.xDaniel Eklöf2022-02-05-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fcft no longer uses wchar_t, but plain uint32_t to represent codepoints. Since we do a fair amount of string operations in foot, it still makes sense to use something that actually _is_ a string (or character), rather than an array of uint32_t. For this reason, we switch out all wchar_t usage in foot to char32_t. We also verify, at compile-time, that char32_t used UTF-32 (which is what fcft expects). Unfortunately, there are no string functions for char32_t. To avoid having to re-implement all wcs*() functions, we add a small wrapper layer of c32*() functions. These wrapper functions take char32_t arguments, but then simply call the corresponding wcs*() function. For this to work, wcs*() must _also_ be UTF-32 compatible. We can check for the presence of the __STDC_ISO_10646__ macro. If set, wchar_t is at least 4 bytes and its internal representation is UTF-32. FreeBSD does *not* define this macro, because its internal wchar_t representation depends on the current locale. It _does_ use UTF-32 _if_ the current locale is UTF-8. Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is defined. Other fcft API changes: * fcft_glyph_rasterize() -> fcft_codepoint_rasterize() * font.space_advance has been removed * ‘tags’ have been removed from fcft_grapheme_rasterize() * ‘fcft_log_init()’ removed * ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
* selection: don’t quote file URIs on the alt screenDaniel Eklöf2022-02-02-2/+9
| | | | Closes #379
* selection: convert \r -> \n when reading clipboard dataDaniel Eklöf2021-10-19-0/+5
| | | | | | | | This fixes an issue where pasting (using e.g. OSC-52) in client applications that doesn’t do this conversion themselves, like tmux, doesn’t work. Closes #752
* selection: line-wise selection now handles soft line-wrappingDaniel Eklöf2021-09-30-16/+83
| | | | | | | | | | | Previously, soft-wrapped lines were not selected correctly, as the selection logic was hardcoded to simply select everything between the first and last column on the current terminal row. Now, we scan backward and forward, looking for hard-wrapped lines. This is similar to how word-based selection works. Closes #726
* selection: modify: no need to check for NULL before calling free()Daniel Eklöf2021-08-16-4/+1
|
* selection: modify: convert ‘keep_selection’ bitmask from uint64_t to uint8_tDaniel Eklöf2021-08-16-11/+11
|
* selection: modify: replace reset_context() macro with a functionDaniel Eklöf2021-08-16-9/+9
|
* selection: don’t require two cell attr bits for selection updatingDaniel Eklöf2021-08-16-24/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When updating the selection (i.e when changing it - adding or removing cells to the selection), we need to do two things: * Unset the ‘selected’ bit on all cells that are no longer selected. * Set the ‘selected’ bit on all cells that *are* selected. Since it’s quite tricky to calculate the difference between the “old” and “new” selection, this is done by first un-selecting the old selection, and then selecting the new, updated selection. I.e. first we clear the ‘selected’ bit from *all* cells, and then we re-set it on those cells that are still selected. This process also dirties the cells, to make sure they are re-rendered (needed to reflect their new selected/un-selected status). To avoid dirtying *all* previously selected, and newly selected cells, we have used an algorithm that first runs a “pre-pass”, marking all cells that *will* be selected as such. The un-select pass would then skip (no dirty) cells that have been marked by the pre-pass. Finally, the select pass would only dirty cells that have *not* been marked by the pre-pass. In short, we only dirty cells whose selection state have *changed*. To do this, we used a second ‘selected’ bit in the cell attribute struct. Those bits are *scarce*. This patch implements an alternative algorithm, that frees up one of the two ‘selected’ bits. This is done by lazy allocating a bitmask for the entire grid. The pre-pass sets bits in the bitmask. Thus, after the pre-pass, the bitmask has set bits for all cells that *will* be selected. The un-select pass simply skips cells with a one-bit in the bitmask. Cells without a one-bit in the bitmask are dirtied, and their ‘selected’ bit is cleared. The select-pass doesn’t even have to look at the bitmask - if the cell already has its ‘selected’ bit set, it does nothing. Otherwise it sets it and dirties the cell. The bitmask is implemented as an array of arrays of 64-bit integers. Each outer element represents one row. These pointers are calloc():ed before starting the pre-pass. The pre-pass allocates the inner arrays on demand. The unselect pass is designed to handle both the complete absence of a bitmask, as well as row entries being NULL (both means the cell is *not* pre-marked, and will thus be dirtied).
* search: reset match state when selection is cancelledDaniel Eklöf2021-07-22-0/+3
| | | | | | | | | | | | While we’re in scrollback search mode, the selection may be cancelled (for example, if the application is scrolling out the selected text). Trying to e.g. extend the search selection after this has happened triggered a crash. This fixes it by simply resetting the search match state when the selection is cancelled. Closes #644
* csi: erase scrollback: cancel selection if it touches the scrollbackDaniel Eklöf2021-07-18-3/+1
| | | | | | | | | | | | | | | | | This breaks out the scrollback erasing logic for \E[3J from csi.c, and moves it to the new function term_erase_scrollback(), and changes the logic to calculate the start and end row (absolute) numbers of the scrollback, and only iterate those, instead of iterating *all* rows, filtering out those that are on-screen. It also adds an intersection range check of the selection range, and cancels the selection if it touches any of the deleted scrollback rows. This fixes a crash when trying to render the next frame, since the selection now references rows that have been freed. Closes #633
* composed: store compose chains in a binary search treeDaniel Eklöf2021-06-24-20/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation stored compose chains in a dynamically allocated array. Adding a chain was easy: resize the array and append the new chain at the end. Looking up a compose chain given a compose chain key/index was also easy: just index into the array. However, searching for a pre-existing chain given a codepoint sequence was very slow. Since the array wasn’t sorted, we typically had to scan through the entire array, just to realize that there is no pre-existing chain, and that we need to add a new one. Since this happens for *each* codepoint in a grapheme cluster, things quickly became really slow. Things were ok:ish as long as the compose chain struct was small, as that made it possible to hold all the chains in the cache. Once the number of chains reached a certain point, or when we were forced to bump maximum number of allowed codepoints in a chain, we started thrashing the cache and things got much much worse. So what can we do? We can’t sort the array, because a) that would invalidate all existing chain keys in the grid (and iterating the entire scrollback and updating compose keys is *not* an option). b) inserting a chain becomes slow as we need to first find _where_ to insert it, and then memmove() the rest of the array. This patch uses a binary search tree to store the chains instead of a simple array. The tree is sorted on a “key”, which is the XOR of all codepoints, truncated to the CELL_COMB_CHARS_HI-CELL_COMB_CHARS_LO range. The grid now stores CELL_COMB_CHARS_LO+key, instead of CELL_COMB_CHARS_LO+index. Since the key is truncated, collisions may occur. This is handled by incrementing the key by 1. Lookup is of course slower than before, O(log n) instead of O(1). Insertion is slightly slower as well: technically it’s O(log n) instead of O(1). However, we also need to take into account the re-allocating the array will occasionally force a full copy of the array when it cannot simply be growed. But finding a pre-existing chain is now *much* faster: O(log n) instead of O(n). In most cases, the first lookup will either succeed (return a true match), or fail (return NULL). However, since key collisions are possible, it may also return false matches. This means we need to verify the contents of the chain before deciding to use it instead of inserting a new chain. But remember that this comparison was being done for each and every chain in the previous implementation. With lookups being much faster, and in particular, no longer requiring us to check the chain contents for every singlec chain, we can now use a dynamically allocated ‘chars’ array in the chain. This was previously a hardcoded array of 10 chars. Using a dynamic allocated array means looking in the array is slower, since we now need two loads: one to load the pointer, and a second to load _from_ the pointer. As a result, the base size of a compose chain (i.e. an “empty” chain) has now been reduced from 48 bytes to 32. A chain with two codepoints is 40 bytes. This means we have up to 4 codepoints while still using less, or the same amount, of memory as before. Furthermore, the Unicode random test (i.e. write random “unicode” chars) is now **faster** than current master (i.e. before text-shaping support was added), **with** test-shaping enabled. With text-shaping disabled, we’re _even_ faster.
* wip: grapheme shapingDaniel Eklöf2021-06-24-4/+4
|
* selection: add support for TEXT/STRING/UTF8_STRING mime-types in incoming offersDaniel Eklöf2021-06-09-6/+15
| | | | | | | | | We were already offering these mime types for our own clipboard data, but ignored them in incoming offers. Fixes paste issues from Geany. Closes #583
* selection: reset ‘empty_count’ after we’ve emitted the empty cellsDaniel Eklöf2021-06-05-0/+2
| | | | | | | | | | | | | | When marking and unmarking cells, we don’t highlight trailing empty cells. We do however highlight empty cells if they are followed by non-empty cells. I think this was an intentional choice. If one row ended with trailing empty cells, but *no* hard linebreak, then we’d continue on the next row, and emit all the empty cells once we hit a non-emtpy cell on the second row. But this is something that shouldn’t happen in any real-world use cases.
* selection: fix bad assertionDaniel Eklöf2021-06-02-2/+2
| | | | | When there are multiple multi-column characters back-to-back, the cell before the pivot end point may in fact be a SPACER+1 cell.
* selection: pay attention to hard linebreaks when search for word boundariesDaniel Eklöf2021-05-31-4/+18
| | | | | | | | | | | | | | | | | | | Double-clicking on a word in the left or right margin, would line-wrap the selection if there was a non-empty cell in the corresponding right/left margin on the prev/next line. Regardless of whether there was a hard linebreak or not. Script to reprouce: !/bin/bash cols=$(tput cols) printf "%*coo\nbar\n" $((${cols} - 2)) f Run, then double click either “foo” or “bar”. Neither should select the other part. Closes #565
* extract: move ‘strip_trailing_empty’ parameter from extra_finish() to extract_begin()Daniel Eklöf2021-05-17-2/+2
|
* extract: add extract_finish_wide(), and optionally skip stripping trailing empty cellsDaniel Eklöf2021-05-17-1/+1
| | | | | | | | extract_finish() returns the extracted text in UTF-8, while extract_finish_wide() returns the extracted text in Unicode. This patch also adds a new argument to extract_finish{,_wide}, that when set to true, skips stripping trailing empty cells.
* selection: expose find_word_boundary_{left,right}()Daniel Eklöf2021-05-17-12/+16
|
* term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definitionDaniel Eklöf2021-05-14-13/+13
| | | | | | | | | | | | | | | | | | | | | Instead of using CELL_SPACER for *all* cells that previously used CELL_MULT_COL_SPACER, include the remaining number of spacers following, and including, itself. This is encoded by adding to the CELL_SPACER value. So, a double width character will now store the character itself in the first cell (just like before), and CELL_SPACER+1 in the second cell. A three-cell character would store the character itself, then CELL_SPACER+2, and finally CELL_SPACER+1. In other words, the last spacer is always CELL_SPACER+1. CELL_SPACER+0 is used when padding at the right margin. I.e. when writing e.g. a double width character in the last column, we insert a CELL_SPACER+0 pad character, and then write the double width character in the first column on the next row.
* selection: don’t strip formatting C0 control characters in bracketed paste modeDaniel Eklöf2021-02-12-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.
* Convert all but 2 remaining uses of xassert(false) to BUG("...")Craig Barnes2021-02-10-7/+6
|
* selection: remove selection_enabled()Daniel Eklöf2021-02-02-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.
* selection: don’t replace \r\n and \n with \r in bracketed paste modeDaniel Eklöf2021-01-27-3/+14
|
* selection: remove duplicate ‘ESC’ in switch caseDaniel Eklöf2021-01-26-4/+0
|
* selection: DEL is 0x7f, not 0x1fDaniel Eklöf2021-01-26-1/+1
|
* selection: codespell: stript -> stripDaniel Eklöf2021-01-26-1/+1
|
* selection: strip non-formatting C0, BS, HT and DEL from pasted textDaniel Eklöf2021-01-26-0/+17
|
* selection: unbreak text/uri-list decoding: we’re not using \r, not \nDaniel Eklöf2021-01-26-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.
* selection: replace \r\n and \n with \r, and strip \e from pasted textDaniel Eklöf2021-01-26-3/+27
| | | | | Closes #305 Closes #306
* config: add ‘none’ as a possible value for ‘selection-target’Daniel Eklöf2021-01-23-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.
* selection: copy selected text to the target configured by ‘selection-target’Daniel Eklöf2021-01-23-1/+14
| | | | Closes #288
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-47/+47
|
* config: add ‘select-extend-character-wise’ bind actionDaniel Eklöf2021-01-14-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.
* selection: uri decode: move zero-length check into decode_one_uri()Daniel Eklöf2021-01-12-2/+4
|
* selection: add a ‘finish’ function, called at the end of receiving clipboard dataDaniel Eklöf2021-01-12-0/+24
| | | | | This is necessary to decode the final URI in a text/uri-list offer if it hasn’t been newline terminated.
* selection: URI decoder: break out decoding of a single URIDaniel Eklöf2021-01-12-27/+29
|
* selection: extend-block: update pivot point and selection directionDaniel Eklöf2021-01-06-0/+6
|
* selection: extend: don’t copy to primary - it is done when RMB is releasedDaniel Eklöf2021-01-06-2/+0
|
* selection: extend: re-calculate pivot pointDaniel Eklöf2021-01-06-0/+30
|
* selection: break out pivot point adjustment for character-wise selectionsDaniel Eklöf2021-01-06-80/+111
|
* selection: combine enum selection_kind with selection_semanticDaniel Eklöf2021-01-06-15/+29
|
* selection: update: line-wraps are ok while moving pivot start/end pointDaniel Eklöf2021-01-04-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.
* selection: update: get start-row pointer *after* modifying the start row indexDaniel Eklöf2021-01-04-5/+6
|
* selection: update: simplify: multi-column chars don’t span line-wrapsDaniel Eklöf2021-01-04-14/+8
|
* selection: wrap pivot_{start,end}->row before accessing grid row arrayDaniel Eklöf2021-01-04-5/+7
|
* selection: cancel: reset pivot coordinatesDaniel Eklöf2021-01-04-0/+2
|
* selection: update: find_word_boundary_{left,right}: coordinates are screen localDaniel Eklöf2021-01-04-4/+10
|
* selection: find_word_boundary_{left,right}: try to make the code more readableDaniel Eklöf2021-01-04-24/+24
|
* selection: find_word_boundary_{left,right}: handle multi-column charactersDaniel Eklöf2021-01-04-8/+40
|
* selection: find_word_boundary{left,right}: what we match depends on initial characterDaniel Eklöf2021-01-04-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.
* selection: allow selections to pivot around a range instead of a pointDaniel Eklöf2021-01-04-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.
* selection: find_word_boundary{left,right}: handle composed charactersDaniel Eklöf2021-01-04-0/+24
|
* selection: find_word_boundary_{left,right}: treat spacers as word charsDaniel Eklöf2021-01-04-4/+16
|
* selection: use selection_start() to initialize word/row-based selectionDaniel Eklöf2021-01-04-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}
* selection: don’t finalize selection when starting a word/row-based selectionDaniel Eklöf2021-01-04-2/+0
|
* selection: remember whether word-wise selection uses spaces only for delimitersDaniel Eklöf2021-01-04-2/+4
|
* selection: wip: update selection row-wise when initial selection was by rowDaniel Eklöf2021-01-04-2/+23
|
* selection: wip: update selection word-wise when initial selection was by wordDaniel Eklöf2021-01-04-54/+85
|
* input: rework mouse button/motion handlingDaniel Eklöf2020-12-12-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.
* selection: do not try to paste un-handled mime typesDaniel Eklöf2020-11-30-2/+6
| | | | Closes #230
* selection: offer clipboard content in more mime typesDaniel Eklöf2020-11-30-0/+10
|
* selection: fix enum typeDaniel Eklöf2020-11-06-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.
* selection: explicitly set direction when right-click extendingDaniel Eklöf2020-11-04-0/+6
| | | | | | | Fixes an issue where right-click-and-dragging to extend a selection caused one cell being removed from the selection. Closes #180
* selection: do mime-type based decoding before passing data to callbackDaniel Eklöf2020-11-01-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.
* selection: dnd: fix wl_data_offer_destroy() raceDaniel Eklöf2020-10-31-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.
* codespell: fix misspelled wordsDaniel Eklöf2020-10-28-2/+2
|
* selection: add support for different mime-typesDaniel Eklöf2020-10-28-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.
* selection: debug log of data offer mime-types and actionsDaniel Eklöf2020-10-26-5/+5
|
* selection: implement support for drag-and-dropDaniel Eklöf2020-10-26-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
* selection: re-factor: break out code shared between clipboard/primary sendDaniel Eklöf2020-10-13-59/+21
| | | | | The send functions are called by the compositor when another application wants to paste data *from* foot.
* selection: auto-scroll: call cmd_scrollback_{up,down}() with number of rowsDaniel Eklöf2020-10-11-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.
* selection: cancel: call selection_stop_scroll_timer()Daniel Eklöf2020-10-11-4/+1
| | | | | Instead of re-implementing the same logic, simply call selection_stop_scroll_timer().
* selection: auto-scroll: add SELECTION_SCROLL_NOT as a scroll ‘direction’Daniel Eklöf2020-10-11-2/+9
|
* selection: auto-scroll: selection keeps scrolling while mouse is outside gridDaniel Eklöf2020-10-11-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.