aboutsummaryrefslogtreecommitdiff
path: root/input.c (follow)
Commit message (Collapse)AuthorAgeLines
* term+input: refactor: move theme switching into term_theme_* functionsDaniel Eklöf2025-06-10-48/+3
|
* libxkbcommon: don't require 1.8.0Daniel Eklöf2025-05-18-0/+1
| | | | | | | | | | The version bump was done since we now use XKB_VMOD_NAME_*; macros added in libxkbcommon 1.8.0. Not all distros have updated libxkbcommon yet (read: Debian). Since it's fairly easy to work around, let's do that. Closes #2103
* csi: implement private mode 2031 (dark/light mode detection)Daniel Eklöf2025-04-26-0/+12
| | | | | | | | | | | | | | * Recognize 'CSI ? 996 n', and respond with - 'CSI ? 997 ; 1 n' if the primary theme is active - 'CSI ? 997 ; 2 n' if the alternative theme is actice * Implement private mode 2031, where changing the color theme (currently only possible via key bindings) causes the terminal to send the same CSI sequences as above. In this context, foot's primary theme is considered dark, and the alternative theme light (since the default theme is dark). Closes #2025
* key-bindings: add bindings to switch between color themesDaniel Eklöf2025-04-26-0/+45
| | | | | | * color-theme-switch-1: select the primary color theme * color-theme-switch-2: select the alternative color theme * color-theme-toggle: toggle between the primary and alternative color themes
* input: reset modifiers in keyboard_leave()Daniel Eklöf2025-04-19-0/+8
| | | | Closes #2034
* wayland+input: add support for toplevel edge constraintsDaniel Eklöf2025-04-07-20/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Edge constraints are new (not yet available in a wayland-protocols release) toplevel states, acting as a complement to the existing tiled states. Tiled tells us we shouldn't draw shadows etc *outside our window geometry*. Constrained tells us the window cannot be resized in the constrained direction. This patch does a couple of things: * Recognize the new states when debug logging * Change is_top_left() etc to look at the new constrained state instead of the tiled state. These functions are used when both choosing cursor shape, and when determining if/how to resize a window on a CSD edge click-and-drag. * Update cursor shape selection to use the default (left_ptr) shape when on a constrained edge (or corner). * Update CSD resize triggering, to not trigger a resize when attempted on a constrained edge (or corner). See https://gitlab.freedesktop.org/wayland/wayland-protocols/-/commit/86750c99ed062c306e837f11bb9492df572ad677: An edge constraint is an complementery state to the tiled state, meaning that it's not only tiled, but constrained in a way that it can't resize in that direction. This typically means that the constrained edge is tiled against a monitor edge. An example configuration is two windows tiled next to each other on a single monitor. Together they cover the whole work area. The left window would have the following tiled and edge constraint state: [ tiled_top, tiled_right, tiled_bottom, tiled_left, constrained_top, constrained_bottom, constrained_left ] while the right window would have the following: [ tiled_top, tiled_right, tiled_bottom, tiled_left, constrained_top, constrained_bottom, constrained_right ] This aims to replace and deprecate the `gtk_surface1.configure_edges` event and the `gtk_surface1.edge_constraint` enum.
* input: xkb: ignore virtual modifiersDaniel Eklöf2025-03-31-0/+52
| | | | | | | | | | | | | | | | | | | | | | | | Some compositors (mutter/GNOME is one) adds _virtual_ modifiers to the set of active modifiers when e.g. Alt, Meta, Super or Hyper is pressed. For example, pressing Alt+b would result in *both* the Alt *and* the Mod1 modifier being set. Since foot makes close to zero assumptions on how the modifiers should be interpreted, this causes various breakages. For example, a foot shortcut defined as Mod1+b will not match, since the Alt modifiers is also set. This has forced users to redefine/override some of the default key bindings to include the additional modifiers. It also causes issues with the kitty keyboard protocol, for some key combinations. Mainly whether or not to use unshifted key or not, resulting in incorrect escape sequences. Since all the "real" modifiers are always set as well, we can safely ignore the virtual modifiers. Closes #2009
* input: kitty: unittest: don't fail if system has no compose tablesDaniel Eklöf2025-03-11-2/+6
|
* input: kitty: send release events for composed keysDaniel Eklöf2025-03-11-3/+0
|
* input: kitty: regression test for #1987Daniel Eklöf2025-03-11-0/+97
|
* input: kitty: always use shifted key when it's the result of a composeDaniel Eklöf2025-03-10-1/+1
| | | | Closes #1987
* config+url: add support for user-defined regex patternsDaniel Eklöf2025-02-05-2/+38
| | | | | | | | | | | | | | | | | | | | | Users can now define their own regex patterns, and use them via key bindings: [regex:foo] regex=foo(bar)? launch=path-to-script-or-application {match} [key-bindings] regex-launch=[foo] Control+Shift+q regex-copy=[foo] Control+Mod1+Shift+q That is, add a section called 'regex:', followed by an identifier. Define a regex and a launcher command line. Add a key-binding, regex-launch and/or regex-copy (similar to show-urls-launch and show-urls-copy), and connect them to the regex with the "[regex-name]" syntax (similar to how the pipe-* bindings work).
* input: match unshifted key-bindings before shiftedDaniel Eklöf2025-01-31-12/+12
| | | | | | | | | | | | | | | | | | | | That is, try to match e.g. Control+shift+a, before trying to match Control+A. In most cases, order doesn't matter. There are however a couple of symbols where the layout consumes the shift-modifier, and the generated symbol is the same in both the shifted and unshifted form. One such example is backspace. Before this patch, key-bindings with shift-backspace would be ignored, if there were another key-binding with backspace. So, for example, if we had one key-binding with Control+Backspace, and another with Control+Shift+Backspace, the latter would never trigger, as we would always match the first one. By checking for unshifted matches first, we ensure Control+Shift+Backspace does match.
* input: ignore key-bindings without modifiers when matching untranslated/rawDaniel Eklöf2025-01-31-2/+2
| | | | | | | | | When matching the unshifted symbol, or the raw key code, ignore all key bindings that don't have any modifiers. This fixes an issue where it was impossible to enter (some of the) numbers on the keypad, **if** there was a key-binding for e.g. KP_Page_Up, or KP_Page_Down.
* input: close fd on no/unrecognized keymap formatAttila Fidan2025-01-30-0/+2
|
* key-bindings: try all bindings in translated mode before matching untranslated, and then finally rawDaniel Eklöf2025-01-27-3/+14
| | | | | | | | | | | | | | | | | | | When trying to match key bindings, we do three types of matching: * Match the _translated_ symbol (e.g. Control+C) * Match the _untranslated_ symbol (e.g. Control+Shift+c) * Match raw keyboard codes This was done for *each* key binding. This meant we sometimes matched a keybinding in raw mode, even though there was a translated/untranslated binding that would match it too. All depending on the internal order of the key binding list. This patch changes it, so that we first try all bindings in translated mode, then all bindings in untranslated mode, and finally all bindings in raw mode. Closes #1929
* input: kitty: refactor, try to simplify and be less confusingDaniel Eklöf2025-01-22-47/+60
| | | | | | | | | | Use better named variables while juggling the shifted vs. unshifted key codes. Switch to variable names appropriate for the kitty keyboard protocol once we have all the unshifted, shifted and base key codes done. It's not until then we can decide which key code to use as the main key, and whether or not to report the alternate key code.
* input: kitty: add more test casesDaniel Eklöf2025-01-22-0/+46
|
* input: kitty: only set 'alternate' if the "unshifted" code is printableDaniel Eklöf2025-01-22-19/+26
| | | | | Fixes a regression where alt+backspace was reported as ^[[8:127;3u instead of ^[[127;3u.
* input: codespell: indiciates -> indicatesDaniel Eklöf2025-01-22-2/+2
|
* input: kitty: add initial unit testDaniel Eklöf2025-01-22-0/+229
| | | | | | | | Test a couple of key combos from the se and de(neo) layouts. This unit test isn't intended to test _all_ key combinations, for all kitty flag combinations, but to be more of a regression test - whenever we discover a buggy, weird combo, add it here.
* input: kitty: improve handling of alternate+base keys even moreDaniel Eklöf2025-01-20-33/+41
| | | | | | | | | | | | | | | | * Always do a base key lookup. Before this, we didn't do that if we matched the XKB sym to a lookup table entry (i.e. keypads, cursor keys etc.) * Try to retrieve the unshifted symbol also when we matched the symbol to a lookup table entry. When successful, we now report an alternate key for keypad and cursor keys; before this patch, we only did that for keys that didn't have an entry in the lookup table (i.e. ASCII chars etc). This improves compatibility with kitty (and the kitty keyboard protocol) in more corner cases. One particular example is the neo keyboard layout, where part of the regular keys act as keypad keys when num-lock is active.
* input: kitty: fix alternate codepoint sometimes not being reportedDaniel Eklöf2025-01-20-23/+2
| | | | | | | | | | | | | | | | | | | | | When alternate key reporting is enabled (i.e. when we're supposed to report the shifted key along with the unshifted key), we try to figure out whether the key really is shifted or not (and thus which xkb keysym to use for the unshifted and shifted keys in the escape). This was done by getting the layout's *all* modifier combinations that produce the shifted keysym, and if any of of them contained a modifier that isn't supported by the kitty protocol, the shifted and unshifted keys are derived from the same keysym. This is to ensure we handle things like AltGr-combos correctly. The issue is, since there may be more than one modifier combination generating the shifted keysym, we may end up using the wrong keysym just because _another_ combination set contains modifiers not supported by the kitty protocol. What we're interrested in is whether the *pressed* set of modifiers contains such modifiers. Closes #1918
* kitty kbd: don't generate release events for plain Enter+Tab+BackspaceDaniel Eklöf2025-01-01-3/+14
| | | | | | | | | | | From the specification: The Enter, Tab and Backspace keys will not have release events unless Report all keys as escape codes is also set, so that the user can still type reset at a shell prompt when a program that sets this mode ends without resetting it. Closes #1892
* csd: track pointer when rendering and handling CSD button clicksDaniel Eklöf2024-08-09-9/+66
| | | | | | | | | | | | | | | | | | | | * Render button as highlighted only when pointer is above them * Releasing the mouse button while *not* on the button does *not* activate the button When pressing, and holding, a mouse button, the compositor keeps sending motion events for the surface where the button was pressed, even if the mouse has moved outside it. We also don't get any surface leave/enter events. This meant that the button was rendered as highlighted, and a click registered, if the user pressed the mouse button while on the button, and then moved the cursor away from the button before releasing the button. This patch fixes it, by checking if the current cursor coordinates fall within the button surface.
* input: CSD buttons are now triggered when releasing the mouse buttonDaniel Eklöf2024-08-09-3/+14
| | | | | | | | | | | | This is how most UIs work. Note that we (at least on River) don't get any surface enter/leave events while a button is held. This means we can't detect if the user pressed the mouse button while on a CSD button, but then moves the mouse outside. Releasing the mouse button will still activate the CSD button. Closes #1787
* spawn: add optional reaper callback, return pid_tDaniel Eklöf2024-07-23-2/+2
| | | | | This will allow spawn() callers to do things when the spawned process has terminated.
* input: allow mouse selections to start inside the marginsDaniel Eklöf2024-07-19-55/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this, margins were special cased: * The mouse cursor was always a pointer, and never an I-beam (thus signaling selections cannot be made). * The internal mouse coords where set to -1 when the cursor was inside the margins, causing: - text selections from being made - mouse events being passed to mouse grabbing applications In particular, even with a one-pixel margin, making selections was unnecessarily hard in e.g. fullscreen mode, where you'd expect to be able to throw the cursor into the corner of the screen and then start a selection. With this patch, the cursor is treated as if it was in the first/last column/row, when inside the margin(s). An unintended side-effect of this, initially, was that auto-scrolling selections where way too easy to trigger, since part of its logic is checking if the cursor is inside the margins. That problem has been reduced by two things: * auto-scrolling does not occur unless a selection has been started. That is, just holding down the mouse in the margins and moving up/down doesn't cause scrolling. You have to first select at least one cell in the visible viewport. * A selection isn't fully started (i.e. a cell is actually selected) unless the cursor is inside the actual grid, and *not* in the margins. What does the last point mean? We now allow a selection to be _started_ when clicking in the margin. What this means internally is we set a start coordinate for a selection, but *not* and end coordinate. At this point, we don't have an actual selection. Nothing is selected, and no cells are highlighted, graphically. This happens when we set an end coordinate. Without the last bullet point, that would happen as soon as the cursor was _moved_, even if still inside the margins. Now, we require the cursor to leave the margins and touch an actual cell before we set an end coordinate. Closes #1702
* input: don't map wheel events to BTN_{BACK,FORWARD}Daniel Eklöf2024-07-13-1/+1
| | | | | | | | | | | | | | | | | | | | BTN_BACK and BTN_FORWARD are separate buttons. The scroll wheel don't have any button mappings in libinput/wayland, so make up our own defines. This allows us to map them in mouse bindings. Also expose BTN_WHEEL_{LEFT,RIGHT}. These were already defined, and used, internally, to handle wheel tilt events. With this, they can also be used in mouse bindings. Finally, fix encoding used for BTN_{BACK,FORWARD} when sending mouse button events to the client application. Before this, they were mapped to buttons 4/5. But, button 4/5 are for the scroll wheel, and as mentioned above, BTN_{BACK,FORWARD} are not the same as scroll wheel "buttons". Closes #1763
* input: don't reset the XKB compose state in keymap()Daniel Eklöf2024-06-22-24/+0
| | | | | | | | | | | | | When the compositor sends a new keymap, don't reset the XKB compose state. This is done by initializing the XKB context, along with the compose state, when binding the seat, instead of in keymap(). Then, in keymap(), simply stop destroying the old xkb state. Only destroy, and re-create the keymap state. Closes #1744
* input: implement wl_pointer::axis_value120()Daniel Eklöf2024-06-18-12/+59
| | | | | | | | | | | | | | | | | | | This implements high resolution mouse wheel scroll events. A "normal" scroll step corresponds to the value 120. Anything less than that is a partial scroll step. This event replaces axis_discrete(), when we bind wl_seat v8 (which we now do, when available). We calculate the number of degrees that is required to scroll a single line, based off of the scrollback.multiplier value. Each high-res event accumulates, until we have at least the number of degress required to scroll one, or more lines. The remaining degrees are kept, and added to in the next scroll event. Closes #1738
* unicode-mode: move state from seat to termDaniel Eklöf2024-05-21-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes an issue where entering unicode-mode in one foot client, also enabled unicode-mode on other foot clients. Both visually (although glitchy), and in effect. The reason the state was originally in the seat objects, was to fully support multi-seat. That is, one seat/keyboard entering unicode-mode should not affect other seats/keyboards. The issue with this is that seat objects are Wayland global. Thus, in server mode, all seat objects are shared between the foot clients. There is a similarity with IME, which also keeps state in the seat. There's one big difference, however, and that is IME has Wayland native enter/leave events, that the compositor emits when windows are focused/unfocused. These events allow us to reset IME state. For our own Unicode mode, there is nothing similar. This patch moves the Unicode state from seats, to the terminal struct. This does mean that if one seat/keyboard enters Unicode mode, then *all* seats/keyboards will affect the unicode state. This potential downside is outweighed by the fact that different foot clients no longer affect each other. Closes #1717
* config: add new key-binding 'quit', unbound by defaultDaniel Eklöf2024-04-11-0/+4
| | | | Closes #1475
* kitty kbd: update handling of locked modifiersDaniel Eklöf2024-03-06-10/+28
| | | | | | | | | | | | | | | | The kitty keyboard specification has been updated/clarified yet again. Locked modifiers are to be ignored if the key event would result in plain text without the locked modifier being enabled. In short, locked modifiers are included in the set of modifiers reported in a key event. But having a locked modifier enabled doesn't turn all key events into CSIu sequences. For example, with only the disambiguate mode enabled, pressing 'a', or 'shift+a' results in a/A regardless of the state of Caps- or NumLock. But 'ctrl+a', which always results in a CSIu, will have a different modifier list, depending on whether Caps- or NumLock are enabled.
* kitty kbd: switch from GTK to XKB mode for 'consumed' modifiersDaniel Eklöf2024-03-02-14/+8
| | | | | | | | | | | This fixes an issue where some key combinations resulted in different output (e.g. escape code vs. plain text) depending on the state of e.g. the NumLock key. One such example is Shift+space. Another example is Shift+BackSpace. This patch also removes the hardcoded CapsLock filter, when determining whether a key combo produces text or not, and instead uses the locked modifiers as reported by XKB.
* input: don't clear text selection on modifier keypressesTim Culverhouse2024-02-22-2/+2
| | | | | | | | | When kitty keyboard is enabled, pressing a modifier key will clear the text selection. This makes it difficult to copy text because the selection clears as soon as the user presses "ctrl". Tested-by: Robin Jarry <robin@jarry.cc> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
* input: improved debug logging of key press/releaseDaniel Eklöf2024-02-20-16/+63
| | | | | | * Log which it is: press or release * Include locked modifiers * Include human-readable names of the modifiers
* input: remove debug loggingDaniel Eklöf2024-02-06-3/+0
|
* Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf2024-02-06-31/+31
|
* config: add pipe-command-output key-bindingDaniel Eklöf2024-02-06-1/+6
|
* term: move row->prompt_marker into new struct, row->shell_integrationDaniel Eklöf2024-02-06-2/+2
|
* input: remove the concept of "significant" modifiersDaniel Eklöf2024-02-06-31/+21
| | | | | | | | | | | | | | | | | | | For the purpose of matching key bindings, "significant" modifiers are no more. We're really only interested in filtering out "locked" modifiers. We're already doing this, so there's no need to *also* match against a set of "significant" modifiers. Furthermore, we *never* want to consider locked keys (e.g. when emitting escapes to the client application), thus we can filter those out already when retrieving the set of active modifiers. The exception is the kitty keyboard protocol, which has support for CapsLock and NumLock. Since we're already re-retrieving the "consumed" modifiers (using the GTK style, rather than normal "XKB" style, to better match the kitty terminal), we might as well re-retrieve the effective modifiers as well.
* input/config: support *all* modifier namesDaniel Eklöf2024-02-06-10/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | That is, allow custom modifiers (i.e. other than ctrl/shift/alt etc) in key bindings. This is done by no longer validating/translating modifier names to booleans for a pre-configured set of modifiers (ctrl, shift, alt, super). Instead, we keep the modifier *names* in a list, in the key binding struct. When a keymap is loaded, and we "convert" the key binding, _then_ we do modifier translation. For invalid modifier names, we print an error, and then ignore it. I.e. we no longer fail to load a config due to invalid modifier names. We also need to update how we determine the set of significant modifiers. Any modifier not in this list will be ignored when matching key bindings. Before this patch, we hardcoded this to shift/alt/ctrl/super. Now, to handle custom modifiers as well, we simply treat *all* modifiers defined by the current layout as significant. Typically, the only unwanted modifiers are "locked" modifiers. We are already filtering these out.
* util: add streq() function and use in place of strcmp(...) == 0Craig Barnes2024-02-05-3/+3
|
* input: kitty: update to latest version of the specDaniel Eklöf2024-01-24-14/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting with kitty 0.32.0, the modifier bits during modifier key events behave differently, compared to before. Or, rather, they have now been spec:ed; before, behavior was different on e.g. MacOS, and Linux. The new behavior is this: On key press, the modifier bits in the kitty key event *includes* the pressed modifier key. On key release, the modifier bits in the kitty key event does *not* include the released modifier key. In other words, The modifier bits reflects the state *after* the key event. This is the exact opposite of what foot did before this patch. The patch is really pretty small: in order to include the key in the modifier set, we simulate a key press to update the XKB state, using xkb_state_uppate_key(). For key pressed, we simulate an XKB_KEY_DOWN event, and for key releases we simulate an XKB_KEY_UP event. Then we re-retrieve the modifers, both the full set, and the consumed set. Closes #1561
* selection: add support for selecting the contents of a quoteDaniel Eklöf2023-09-19-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch changes the default of triple clicking, from selecting the current logical row, to first trying to select the contents of the quote under the cursor, and if failing to find a quote, selecting the current row (like before). This is implemented by adding a new key binding, 'select-quote'. It will search for surrounding quote characters, and if one is found on each side of the cursor, the quote is selected. If not, the entire row is selected instead. Subsequent selection operations will behave as if the selection is either a word selection (a quote was found), or a row selection (no quote found). Escaped quote characters are not supported: "foo \" bar" will match 'foo \', and not 'foo " bar'. Mismatched quotes are not custom handled. They will simply not match. Nested quotes ("123 'abc def' 456") are supported. Closes #1364
* input: make wheel events mappableDaniel Eklöf2023-09-18-102/+123
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Un-grabbed wheel events are now passed through the mouse binding matching logic, instead of being hardcoded to scrolling the terminal contents. They are mappable through the BTN_BACK and BTN_FORWARD buttons. Since they're not actually button *presses*, they never generate a click count other than 1. This limitation is documented, but not checked in the config. This means it's possible to create bindings like "BTN_BACK+3" (i.e. triple "click"). They will however never trigger. The old, hardcoded logic is now accessible through the new scrollback-up-mouse and scrollback-down-mouse mouse bindings. They (obiously) default to BTN_BACK and BTN_FORWARD, respectively. Example usage: keep the default of scrolling terminal contents with the wheel, when used without modifiers, but map Control+wheel to font zoom in/out: [mouse-bindings] font-increase=Control+BTN_FORWARD font-decrease=Control+BTN_BACK (this also keeps the default key bindings to zoom in/out; ctrl-+ and ctrl+-) Closes #1077
* input: improve touch handling on pointer presenseCismonX2023-08-23-32/+66
| | | | | | | | | | | No longer inhibits touch event handling when terminal window has pointer focus. Instead, inhibit touch event when at least one pointer button is held down. This change improves user experience when using foot with both a mouse and a touchscreen. Closes #1428.
* input: do not ignore touch events on the CSDsCismonX2023-07-16-3/+2
|
* config: add csd.double-click-to-maximize=no|yes optionDaniel Eklöf2023-07-14-1/+4
| | | | | | | | | When enabled, double-clicking the CSD titlebar will (un)maximize the window. Defaults to ‘yes’ (since this is the old hard-coded behavior). Closes #1293
* input: add basic support for touchscreen inputCismonX2023-07-05-20/+246
| | | | Closes #517
* refactor: track current xcursor using an enum, instead of a char pointerDaniel Eklöf2023-07-03-11/+11
|
* input: kitty: don’t treat zero-length utf8/utf32 strings as textDaniel Eklöf2023-03-31-1/+1
| | | | | | This is a regression introduced in 3215d54f31c9e339598a34c9fa43f3dc3c5d1e42 Symptoms: e.g. arrow keys not working in vim/neovim
* input: (kitty kbd): the resulting UTF-8 string may translate to multiple UTF-32 codepointsDaniel Eklöf2023-03-30-12/+29
| | | | | | | | | | | | | | | | | | | | | | | | When this happened (for example, by specifying a custom compose sequence), the kitty keyboard protocol didn’t emit any text at all. This was caused by the utf32 codepoint being -1. This in turned was caused by us trying to convert the utf8 sequence to a *single* utf32 codepoint. This patch replaces the use of mbrtoc32() with a call to ambstoc32(), and the utf32 codepoint with an utf32 string. The kitty keyboard protocol is updated: * When determining if we’re dealing with text, check *all* codepoints in the utf32 string. * Add support for multiple codepoints when reporting "associated text". The first codepoint is the actual parameter in the emitted sequence, and the remaining codepoints are sub-parameters. I.e. the codepoints are colon separated. Closes #1288
* input: pipe-*: set current CWD when spawning the sub-processDaniel Eklöf2022-09-10-1/+1
| | | | Closes #1166
* terminal: don’t unref a not-yet-referenced key-binding setDaniel Eklöf2022-09-06-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Key-binding sets are bound to a seat/configuration pair. The conf reference is done when a new terminal instance is created. When that same terminal instance is destroyed, the key binding set is unref:ed. If the terminal instance is destroyed *before* the key binding set has been referenced, we’ll still unref it. This creates an imbalance. In particular, when the there is exactly one other terminal instance referencing that same key binding set, that terminal instance will trigger a foot server crash as soon as it receives a key press/release event. This happens because the next-to-last terminal instance brought the reference count of the binding set down to 0, causing it to be free:d. Thus, we *must* reference the binding set *before* we can error out (when instantiating a new terminal instance). At this point, we don’t yet have a valid terminal instance. But, that’s ok, because all the key_binding_new_for_term() did with the terminal instance was get the "struct wayland" and "struct config" pointers. So, rename the function and simply pass these pointers explicitly. Similarly, change key_binding_for() to take a "struct config" pointer, rather than a "struct terminal" pointer. Also rename key_binding_unref_term() -> key_binding_unref().
* input: ignore pointer motion events on unknown surfacesDaniel Eklöf2022-08-12-4/+12
| | | | | | | | | | | | | | In some cases, the compositor sends a pointer enter event with a NULL surface. It’s unclear if this is a compositor bug, or a race (where the compositor sends an enter event on a CSD surface at the same time foot unmaps the CSDs). Regardless, this causes seat->mouse_focus to be unset, which triggers a crash in foot on the next pointer motion event. This patch does two things: a) log a warning when we receive a pointer event with a NULL surface b) ignore motion events where seat->mouse_focus is NULL
* unicode-input: move input (key press) handling to unicode_mode_input()Daniel Eklöf2022-07-29-58/+1
|
* input: add new Unicode input modeDaniel Eklöf2022-07-29-1/+68
| | | | | | | | | | | | | | This mode is activated through the new key-bindings.unicode-input and search-bindings.unicode-input key bindings. When active, the user can “build” a Unicode codepoint by typing its hexadecimal value. Note that there’s no visual feedback in this mode. This is intentional. This mode is intended to be a fallback for users that don’t use an IME. Closes #1116
* input: kitty: always treat composed characters as ‘printable’Daniel Eklöf2022-07-28-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Certain dead key combinations results different escape sequences in foot, compared to kitty, when the kitty keyboard protocol is used. if (composed && is_text) key = utf32; else { key = xkb_keysym_to_utf32(sym_to_use); if (key == 0) return false; /* The *shifted* key. May be the same as the unshifted * key - if so, this is filtered out below, when * emitting the CSI */ alternate = xkb_keysym_to_utf32(sym); } If is_text=false, we’ll fall through to the non-composed logic. is_text is set to true if the character is printable *and* there aren’t any non-consumed modifiers enabled. shift+space is one example where shift is *not* consumed (typically - may be layouts where it is). As a result, pressing ", followed by shift+space with the international english keyboard layout (where " is a dead key) results in different sequences in foot and kitty. This patch fixes this by always treating composed characters as printable. Closes #1120
* input: don’t ignore keyboard enter/leave events when there’s no keymapDaniel Eklöf2022-06-28-6/+0
| | | | | | | | | | | The compositor _usually_ sends the keymap event *before* the enter event. But not always. Not (yet) having a keymap is not a reason to ignore the enter event (now, on the other hand, getting a key press/release event without a keymap is a compositor bug). Closes #1097
* osc: add support for OSC 133;A (prompt markers)Daniel Eklöf2022-06-16-1/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds support for the OSC-133;A sequence, introduced by FinalTerm and implemented by iTerm2, Kitty and more. See https://iterm2.com/documentation-one-page.html#documentation-escape-codes.html. The shell emits the OSC just before printing the prompt. This lets the terminal know where, in the scrollback, there are prompts. We implement this using a simple boolean in the row struct ("this row has a prompt"). The prompt marker must be reflowed along with the text on window resizes. In an ideal world, erasing, or overwriting the cell where the OSC was emitted, would remove the prompt mark. Since we don't store this information in the cell struct, we can't do that. The best we can do is reset it in erase_line(). This works well enough in the "normal" screen, when used with a "normal" shell. It doesn't really work in fullscreen apps, on the alt screen. But that doesn't matter since we don't support jumping between prompts on the alt screen anyway. To be able to jump between prompts, two new key bindings have been added: prompt-prev and prompt-next, bound to ctrl+shift+z and ctrl+shift+x respectively. prompt-prev will jump to the previous, not currently visible, prompt, by moving the viewport, ensuring the prompt is at the top of the screen. prompt-next jumps to the next prompt, visible or not. Again, by moving the viewport to ensure the prompt is at the top of the screen. If we're at the bottom of the scrollback, the viewport is instead moved as far down as possible. Closes #30
* url-mode: add support for XDG activation when opening URLsDaniel Eklöf2022-05-05-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | First, add a ‘token’ argument to spawn(). When non-NULL, spawn() will set the ‘XDG_ACTIVATION_TOKEN’ environment variable in the forked process. If DISPLAY is non-NULL, we also set DESKTOP_STARTUP_ID, for compatibility with X11 applications. Note that failing to set either of these environment variables are considered non-fatal - i.e. we ignore failures. Next, add a helper function, wayl_get_activation_token(), to generate an XDG activation token, and call a user-provided callback when it’s ‘done (since token generation is asynchronous). This function takes an optional ‘seat’ and ‘serial’ arguments - when both are non-NULL/zero, we set the serial on the token. ‘win’ is a required argument, used to set the surface on the token. Re-write wayl_win_set_urgent() to use the new helper function. Finally, rewrite activate_url() to first try to get an activation token (and spawn the URL launcher in the token callback). If that fails, or if we don’t have XDG activation support, spawn the URL launcher immediately (like before this patch). Closes #1058
* input: assert serial received from compositor is non-zeroDaniel Eklöf2022-04-24-0/+6
|
* input: codespellDaniel Eklöf2022-04-20-1/+1
|
* input: copy libxkbcommon’s keysym_is_modifier()Daniel Eklöf2022-04-20-11/+13
| | | | | | | | | When determining whether a keysym is a modifier (to skip hiding the pointer when [mouse].hide-when-typing=yes), use the same matching logic xkbcommon does. This function, xkb_keysym_is_modifier() is unfortunately not part of the public API, which is why we copy it instead.
* wayland: refactor: remove ‘struct config’ pointer from wayland structDaniel Eklöf2022-04-17-11/+8
| | | | | | | | | | | | | | The global config doesn’t necessarily reflect the correct configuration to use - we should *always* use the current terminal instance’s conf pointer. * Move selection override modifier mask to the key_binding_set struct * Always warn if XDG activation is unavailable, not just if bell.urgent is set (we no longer have access to this information) * Pass ‘bool presentation_timings’ as a parameter to wayl_init() * Remove ‘presentation_timings’ member from the ‘terminal’ struct Closes #932
* key-binding: new API, for handling sets of key bindingsDaniel Eklöf2022-04-17-240/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, our Wayland seats have been tracking key bindings. This makes sense, since the seat’s keymap determines how the key bindings are resolved. However, tying bindings to the seat/keymap alone isn’t enough, since we also depend on the current configuration (i.e. user settings) when resolving a key binding. This means configurations that doesn’t match the wayland object’s configuration, currently don’t resolve key bindings correctly. This applies to footclients where the user has overridden key bindings on the command line (e.g. --override key-bindings.foo=bar). Thus, to correctly resolve key bindings, each set of key bindings must be tied *both* to a seat/keymap, *and* a configuration. This patch introduces a key-binding manager, with an API to add/remove/lookup, and load/unload keymaps from sets of key bindings. In the API, sets are tied to a seat and terminal instance, since this makes the most sense (we need to instantiate, or incref a set whenever a new terminal instance is created). Internally, the set is tied to a seat and the terminal’s configuration. Sets are *added* when a new seat is added, and when a new terminal instance is created. Since there can only be one instance of each seat, sets are always removed when a seat is removed. Terminals on the other hand can re-use the same configuration (and typically do). Thus, sets ref-count the configuration. In other words, when instantiating a new terminal, we may not have to instantiate a new set of key bindings, but can often be incref:ed instead. Whenever the keymap changes on a seat, all key bindings sets associated with that seat reloads (re-resolves) their key bindings. Closes #931
* url-mode: add a key binding that enables “persistent” URL modeDaniel Eklöf2022-04-17-4/+6
| | | | | | | This is an alternative to ‘show-urls-launch’, where we stay in URL mode after activating an URL. Closes #964
* wayland: optionally disable pointer input on subsurfacesDaniel Eklöf2022-04-16-18/+0
| | | | | | | | | | | | | | | | We have a number of sub-surfaces for which we are *not* interrested in pointer (or touch) input. Up until now, we’ve manually dealt with these, by recognizing these surfaces in all pointer events, and ignoring them. But, lo and behold, there are better ways of doing this. By clearing the subsurface’s input region, the compositor will do this for us - when a pointer is outside a surface’s input region, the event is passed to the next surface underneath it. This is exactly what we want! Do this for all subsurfaces, *except* the CSDs.
* input: improve XTerm compatibility when modifyOtherKeys=2Daniel Eklöf2022-04-10-1/+50
| | | | | | | | | | | | | | | | | | | Before this, foot always emitted a CSI if _any_ modifier was active. XTerm doesn’t behave quite like this. Instead, it appears to special-case shift somewhat: If the generated symbol (e.g ‘A’) is the upper case version of the pressed key’s base symbol (‘a’), and is in the range a-z, emit a CSI. If not emit a plain symbol: Examples (Swedish layout): * shift-a (generated symbol is ‘A’) emits a CSI * shift-, (generated symbol is ‘;’) emits ‘;’ * shift-alt-, (generated symbol is ‘;’) emits a CSI Closes #1009
* refactor: add a ‘range’ struct, grouping a start and end coord togetherDaniel Eklöf2022-04-09-2/+3
|
* input: don’t allow non-significant modifiers when matching untranslated symbolsDaniel Eklöf2022-03-20-5/+14
| | | | | | | | | | | | | | | | | | When matching “untranslated” bindings (by matching the base symbol of the key, e.g. ctrl+shift+2 in US layout), require that no non-significant modifiers are active. This fixes an issue where AltGr was “ignored”, and would cause certain combinations to match a key binding. Example: ctrl+altgr+0, on many European layouts matched against the default ctrl+0 (reset the font size), instead of emitting ^] To make this work, we now need to filter out “locked” modifiers (e.g. NumLock and CapsLock). Otherwise having e.g. NumLock active would prevent *all* untranslated matching to fail. Closes #983
* input: get_current_modifiers(): don’t crash if seat has no keyboardDaniel Eklöf2022-03-04-6/+15
| | | | Closes #963
* config/input: add scrollback-home|end key bindings (unbound by default)Daniel Eklöf2022-02-23-0/+14
|
* wip: map key combos to custom text strings (including escapes)Daniel Eklöf2022-02-16-0/+5
| | | | | | | | | | | | | With this, it is now possible to map key combos to custom escapes. The new bindings are defined in a new section, “text-bindings”, on the form “string=key combo”. The string can consist of printable characters, or \xNN style hex digits: [text-bindings] abcd = Control+a \x1b[A = Control+b Control+c Control+d # map ctrl+b/c/d to UP
* csi/input: remove private mode 27127Craig Barnes2022-02-09-7/+1
| | | | This effectively reverts commit 31c73f0cf01e1d0bdcd1435136b010c1c1ab442c.
* input/search/url: pass pointer-to key-binding struct to execute()Daniel Eklöf2022-02-09-17/+17
|
* config: ‘pipe’ is now optional ‘aux’ data in the key-binding structDaniel Eklöf2022-02-09-7/+7
| | | | | This allows us to add helper functions that e.g. compare bindings’ aux data in a generic way.
* input: call wayl_bindings_reset() when receiving a new keymapDaniel Eklöf2022-02-09-9/+1
|
* wayland: unify key- and mouse-binding structsDaniel Eklöf2022-02-09-17/+23
|
* fcft: adapt to API changes in fcft-3.xDaniel Eklöf2022-02-05-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* replace gettimeofday with clock_gettimePranjal Kole2022-01-15-5/+4
| | | | | | | | | | | | | POSIX.1-2008 has marked gettimeofday(2) as obsolete, recommending the use of clock_gettime(2) instead. CLOCK_MONOTONIC has been used instead of CLOCK_REALTIME because it is unaffected by manual changes in the system clock. This makes it better for our purposes, namely, measuring the difference between two points in time. tv_sec has been casted to long in most places since POSIX does not define the actual type of time_t.
* input: reset mouse button click counter when mouse movesDaniel Eklöf2022-01-13-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As described in #883, creating a block selection (with ctrl+BTN_LEFT), then *quickly* (within 300ms from) creating a new one, will, in fact, _not_ create a new block selection, but a ‘select-word-whitespace’ selection (ctrl+BTN_LEFT-2). A similar effect can be seen with plain selections (BTN_LEFT). Click and drag to make a selection, but *release*, and make a new selection within 300ms from the initial button press, and the new selection is suddenly a word-based selection. This happens because triggering a binding does *not* reset the button click counter. So, shouldn’t we just do that? No, because we rely on this behavior to handle single-, double- and triple-click actions. If we were to reset the button click handler, then we’d have to instead delay triggering the first action with 300ms, which would make things appear laggy. If we don’t do this, it would be impossible to double- and triple-click, since the single-click action would keep resetting the click counter. This patch takes a slightly different approach; we reset the click counter when the mouse has moved “too much”. For now, “too much” is when the cursor has moved to a different cell. This way, single-, double- and triple-clicks continue to work as before. But, creating actual selections, and then quickly releasing and starting a new selection produces the expected results. Closes #883
* input: reset view when pasting from primaryDaniel Eklöf2022-01-11-0/+1
| | | | | We’re already doing this for keyboard input, and regular clipboard pastes.
* SGR-Pixels mouse mode, closes #762Autumn Lamonte2022-01-01-1/+12
|
* input: apply scrollback.multplier in alterate scroll modeDaniel Eklöf2021-12-28-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | Before this patch, foot only applied [scrollback].multiplier on the normal screen, never the alt screen. However, scrolling can be done in two ways on the alt screen: If the application has enabled mouse support, we simply pass on the mouse scroll events to the application. Here, it makes sense to not apply the multiplier, and instead let the application choose how much to scroll for each scroll event. But, if the application has not enabled mouse support, we can still scroll by simulating the arrow keys being pressed - alternate scrolling (private mode 1007). This is enabled by default in foot (but can be disabled in foot.ini with the [mouse].alternate-scroll-mode setting). In this mode, it makes more sense to apply the multiplier. And that’s what this patch changes - the multiplier is now applied, on the alt screen, when the application has not enabled mouse support, and alternate scrolling has been enabled in foot. Closes #859
* input: kitty: don’t fallback to the XKB symbolDaniel Eklöf2021-12-16-4/+4
| | | | | | | | | | | When handling “generic” keys (i.e. keys not in the Kitty keymap), we use the pressed key’s Unicode codepoint as “key” in the kitty CSI. If we failed to convert the XKB symbol to a Unicode codepoint, we used to (before this patch), fallback to using the XKB symbol as is. This can never be correct... and it caused us to emit a meaningless CSI for XKB_KEY_ISO_Next_Group, which confused e.g. Kakoune.
* input: kitty: return the result of term_to_slave()Daniel Eklöf2021-12-12-2/+1
| | | | If term_to_slave() fails, then the key wasn’t ‘handled’...
* kitty: replace switch with a static keysym tableDaniel Eklöf2021-12-11-142/+36
|
* config: unify key- and mouse bindingsDaniel Eklöf2021-12-11-12/+10
| | | | | | | | | | | | | | With this patch, key- and mouse-bindings structs (the non-layout specific ones) are unified into a single struct. The logic that parses, and manages, the key- and mouse binding lists are almost identical. The *only* difference between a key- and a mouse binding is that key bindings have an XKB symbol, and mouse bindings a button and click-count. The new, unified, struct uses a union around these, and all functions that need to know which members to use/operate on now takes a ‘type’ parameter.
* config: do mouse binding collision detection after loading the confDaniel Eklöf2021-12-11-1/+1
|
* kitty: simplify: always calculate alternate/base keysDaniel Eklöf2021-12-08-14/+9
| | | | But only _emit_ them if report alternate has been enabled.
* kitty: when emitting associated text, don’t report mods/events unless necessaryDaniel Eklöf2021-12-08-6/+8
|
* kitty: report-alternate: apply base-layout key to composed charactersDaniel Eklöf2021-12-08-13/+15
|
* kitty: implement “base layout key” in “report alternate key”Daniel Eklöf2021-12-08-5/+31
|
* kitty: initial support for “report alternate key”Daniel Eklöf2021-12-08-1/+9
| | | | | | | | | | | | | | In this mode, the “shifted” and “base layout” keys are added to the CSIs, as sub-parameters to the “key” parameter. Note that this PR only implements the “shifted” key, not the “base layout key”. This is done by converting the original XKB symbol to it’s corresponding UTF-32 codepoint. If this codepoint is different from the one we use as “key” in the CSI, we add it as a sub-parameter. Related to #319
* kitty: only emit plain text on key press- and repeat eventsDaniel Eklöf2021-12-08-1/+1
| | | | That is, release events always generate CSIs
* kitty: add ISO_Level{3,5}_Shift keysDaniel Eklöf2021-12-08-0/+4
|
* kitty: composed characters with “report associated text”Daniel Eklöf2021-12-08-18/+20
| | | | | | | | | | The generic input handler now converts the composed character to it’s UTF-32 equivalent. This means we now provide a valid UTF-32 codepoint for both composed characters, and non-composed (plain-text) characters. Use this in the kitty protocol to simplify the logic around composed characters, by simply treating them as plain text.