Commit graph

256 commits

Author SHA1 Message Date
Daniel Eklöf
b2a3cdb723
input: don’t enable keyboard repeat timer when repeat rate is zero
wayland-client-protocol.h:

  Negative values for either rate or delay are illegal. A rate of
  zero will disable any repeating (regardless of the value of
  delay).

This fixes a division-by-zero crash.
2021-01-21 11:58:07 +01:00
Craig Barnes
d2c00d73ec
Add xsnprintf() and remove some unnecessary strlen(3) calls 2021-01-21 11:57:46 +01:00
Daniel Eklöf
367faeb6ee
input: don’t try to close an invalid FD 2021-01-21 11:52:59 +01:00
Daniel Eklöf
43b8b5f779
input: don’t assert when receiving a button release without a press event 2021-01-21 11:52:55 +01:00
Daniel Eklöf
aeca6a8ea6
input: remove non-existing state from debug log 2021-01-21 11:43:46 +01:00
Daniel Eklöf
602dbdb9f6
input: make sure ‘surf_kind’ is not uninitialized 2020-12-12 21:10:28 +01:00
Daniel Eklöf
ff96ce1e91
input: rework mouse button/motion handling
Store a list of currently pressed buttons, and which surface they
belong to (i.e. which surface that received the press).

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

Also send release events to the originating surface.

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

Motion events with a button pressed will *always* use the *first*
button that was pressed. I.e. if you press a button, start dragging,
and then press another button, we keep generating motion events for
the *first* button.
2020-12-12 19:05:24 +01:00
Daniel Eklöf
a1a0b489ee
input: report mouse drag events also when the pointer is outside the grid
As long as the mouse button was *pressed* while the pointer was inside
the grid, we want to keep reporting motion events until the button is
released.

Even when the pointer moves outside the grid (but in this case, the
reported coordinates are bounded by the grid size).

This patch also tries to improve multi-button handling (i.e. multiple
buttons pressed at the same time), and the events we report to the
client for these, in the following ways:

* Motion events now report the *initial* button. That is, if you start
  a drag operation with the LEFT button, then press RIGHT (before
  releasing LEFT), keep reporting LEFT in the motion events.
* Mouse release events are reported for *any* button, as long as the
  pointer is *inside* the grid, *or*, the button released was the
  button used to start a drag operation.

The last point is important; if we have reported a button press
followed by motion events (i.e. a drag operation), we need to report
the button release, *even* if the pointer is outside the grid.

Note that the client may receive unbalanced button press/release
events in the following ways if the user pressed one, and then a
second button *inside* the grid, then releases the *first*
button (possibly outside the grid), and finally releases the *second*
button *outside* the grid.

In this case, both buttons will report press events. The first button
will report a release event since it is the initial button in the drag
operation.

However, we don’t track the fact that the second button is being
pressed, and thus if it is released outside the grid, it wont generate
a release event.
2020-12-11 21:01:00 +01:00
Daniel Eklöf
3e25faeae7
Merge branch 'remove-deprecated-things' 2020-12-09 20:53:05 +01:00
Daniel Eklöf
5020366bf5
config: remove support for scrollback-up and scrollback-down 2020-12-08 19:58:02 +01:00
Daniel Eklöf
8c3d48c5cd
ime: render pre-edit text
This is done by allocating cells for the pre-edit text when receiving
the text-input::done() call, and populating them by converting the
utf-8 formatted pre-edit text to wchars.

We also convert the pre-edit cursor position to cell positions (it can
cover multiple cells).

When rendering, we simply render the pre-edit cells on-top off the
regular grid. While doing so, we also mark the underlying, “real”,
cells as dirty, to ensure they are re-rendered when the pre-edit text
is modified or removed.
2020-12-07 20:44:10 +01:00
Daniel Eklöf
5745c610ac
ime: wip: commit all changes in ‘done()’ 2020-12-07 20:44:10 +01:00
Daniel Eklöf
c3201b9770
Merge branch 'modify-escape-key'
Closes #225
2020-12-01 18:31:25 +01:00
Daniel Eklöf
c44c7cc5be
input: relax requirements for overriding keypad application mode
Don’t require NumLock to be locked. Foot has no idea _which_ modifier
the user has mapped NumLock to, meaning we really cannot require it to
be locked.
2020-12-01 18:27:56 +01:00
Daniel Eklöf
09c88e6715
input: improved debug logging of pressed keys 2020-11-30 20:01:46 +01:00
Craig Barnes
31c73f0cf0 csi: add new private mode that makes the Escape key emit "\E[27;1;27~"
This mode can be set by client programs with the DECSET, DECRST,
XTSAVE and XTRESTORE sequences by using 27127 as the parameter.

The sequence "\E[27;1;27~" is encoded in the same way as is done by
xterm's "modifyOtherKeys" mode. Even though xterm itself never emits
such a sequence for the Escape key, many programs already have
support for parsing this style of key sequence.
2020-11-29 04:04:57 +00:00
Daniel Eklöf
121b488e74
keymap: use same lookup table for Tab and ISO_Left_Tab
With XKB, Shift+Tab maps to XKB_KEY_ISO_Left_Tab, not
XKB_Key_Tab. Previously, we had two different lookup tables for the
two.

The tab table was correctly populated, while the ISO-left tab
wasn’t. As a result, all Shift+Tab combos (except Shift+Tab itself)
was wrong, and resulted in the same escape sequence as Shift+Tab.

Fix by using the same table for both tab and ISO-left tab.

Closes #210
2020-11-19 19:22:48 +01:00
Daniel Eklöf
deb2c2db6d
input: enforce ‘numerical’ keypad mode when Num Lock override is enabled
When num lock override has been enabled via “CSI?1035h” (the default),
keypad is always considered to be in ‘numerical’ mode.

This affects how keypad keys are translated to escape sequences when
Num Lock is active.

The keypad has four modes:

* Num Lock off, numerical mode
* Num Lock off, application mode
* Num Lock on, numerical mode
* Num Lock on, application mode

The keymap is identical for numerical and application mode when Num
Lock is off, meaning the keypad effectively has three different modes.

In XTerm, numerical and application mode _can_ be the same, **if** the
‘numLock’ resource is set to true (the default). It is only when
‘numLock’ is false that the application mode is actually used.

This patch changes foot to do the same. We don’t expose an option, but
do implement “CSI ? 1035”.

Closes #194
2020-11-11 18:28:37 +01:00
Daniel Eklöf
bdaf20ba71
input: track num lock state 2020-11-11 18:28:13 +01:00
Daniel Eklöf
75bd780f02
input: use XKB_MOD_NAME_* macros instead of hard-coded strings 2020-11-11 18:25:54 +01:00
Daniel Eklöf
3fa3c58c8b
input: ignore keymap if we don’t recognize its format 2020-11-09 19:59:48 +01:00
Daniel Eklöf
9ce79e2ef0
config: add support for pipe-* actions in mouse bindings
Closes #183
2020-11-06 19:30:05 +01:00
Daniel Eklöf
9209adf6fa
input: don’t use seat->kbd_focus as terminal when processing a key press
When converting mouse scroll events to keyboard input (in alternate
scroll mode), we need to use seat->mouse_focus, not seat->kbd_focus.

To enable this, break out key press/release handling code to a
separate function that takes an explicit term argument. Call this
function from keyboard_key(), input_repeat() and in alternate scroll
mode.

Closes #179
2020-11-03 19:44:51 +01:00
Daniel Eklöf
0d319f8793
input: handle XKB errors
* Don’t de-reference the xkb context/keymap/state if we failed to
  instantiate them.
* Don’t try to send a translated utf8 key sequence if the translation
  failed.
* Handle xkb_compose_state_get_utf8() and xkb_state_key_get_utf8()
  returning more than 64 bytes.

This _may_ fix #171.
2020-10-20 21:01:33 +02:00
Daniel Eklöf
4c3d2cfc7d
input: don’t allow diagonal resize when tiled 2020-10-20 21:00:19 +02:00
Daniel Eklöf
0573c685c7
input: don’t crash if xkbcommon cannot find a compose file
Handle xkb_compose_table_new_from_locale() returning NULL. When this
happens, log a warning that “dead keys” will be disabled, and make
sure to never de-reference the compose table pointer.

Closes #170
2020-10-19 18:30:19 +02:00
Daniel Eklöf
8b06a55cb0
Merge branch 'releases/1.5' into master 2020-10-13 08:06:56 +02:00
Daniel Eklöf
fdb7e40355
input: regression: don’t pass on mouse click to application if we consumed it
When we ‘consume’ a mouse button event (i.e. when we have a shortcut
mapped to it), the event should *not* be passed on to the client
application.

In 5f64c5c335, button handling was
refactored and unfortunately introduced a regression where we once
again started passing consumed button presses to the client
application.

Fixes #168
2020-10-13 08:02:09 +02:00
Daniel Eklöf
8e04b08615
input: trackpad scroll: correctly convert pixel movements to line movements
Trackpad scroll movements are in pixels. Foot previously “translated”
these directly to line movements (i.e. a one pixel scroll event was
translated into a one line scroll).

Now we use the line height of the terminal and correctly convert
pixels to lines.

This makes the trackpad scroll speed in foot consistent with the
scroll speed in e.g. Alacritty and Kitty.
2020-10-11 19:23:25 +02:00
Daniel Eklöf
59ca98f989
input: mouse: match binding if binding’s click count is *less*
Allow a mouse binding to match even if its click count is less than
the actual click count.

If there are multiple bindings that match, use the one with the
highest click count (that less than, or equal to the actual click
count).

Closes #146
2020-10-11 19:22:47 +02:00
Daniel Eklöf
674e565b5a
input: comment: ‘measures’ -> ‘measured’ 2020-10-11 18:23:16 +02:00
Daniel Eklöf
0f67549e04
input: comment: ‘fast’ -> ‘faster’ 2020-10-11 18:22:29 +02:00
Daniel Eklöf
4ad7fdc19c
selection: auto-scroll: add SELECTION_SCROLL_NOT as a scroll ‘direction’ 2020-10-11 18:18:18 +02:00
Daniel Eklöf
dd14e0b3c3
input: auto-scroll: apply scrollback.multiplier to the interval divisor 2020-10-11 18:09:30 +02:00
Daniel Eklöf
7fedf2f801
selection: auto-scroll: selection keeps scrolling while mouse is outside grid
Moving the mouse outside the grid while we have an on-going selection
now starts a timer. The interval of this timer depends on the mouse’s
distance from the grid - the further away the mouse is, the shorter
interval.

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

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

The timer FD is created and destroyed on-demand.

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

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

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

The same applies to top and bottom margins, but since we already have
the scroll *direction*, which row value to use can be derived from this.
2020-10-11 15:44:20 +02:00
Daniel Eklöf
2303affc87
input: motion: scroll up/down while selecting
If the cursor moves above the grid top, or below the grid bottom,
while selecting text, scroll up/down the scrollback before updating
the selection.

TODO: this only scrolls when the mouse is *moved*. I.e. you can’t move
the cursor outside the grid once and for all, and then let foot
auto-scroll.
2020-10-11 12:03:20 +02:00
Daniel Eklöf
a0ce7e40af
input: trackpad scroll: correctly convert pixel movements to line movements
Trackpad scroll movements are in pixels. Foot previously “translated”
these directly to line movements (i.e. a one pixel scroll event was
translated into a one line scroll).

Now we use the line height of the terminal and correctly convert
pixels to lines.

This makes the trackpad scroll speed in foot consistent with the
scroll speed in e.g. Alacritty and Kitty.
2020-09-29 19:42:31 +02:00
Daniel Eklöf
6a089c92ca
input: mouse: match binding if binding’s click count is *less*
Allow a mouse binding to match even if its click count is less than
the actual click count.

If there are multiple bindings that match, use the one with the
highest click count (that less than, or equal to the actual click
count).

Closes #146
2020-09-27 14:31:39 +02:00
Daniel Eklöf
04c1bab7b0
input: mouse_scroll(): refactor 2020-09-15 18:57:00 +02:00
Daniel Eklöf
cb41db8596
input: don’t use stale keycodes for arrow-up/down
The keycodes will change if the seat’s keymap changes. Make sure we
only do alternate scrolling if the seat has a keyboard, and use
the *current* layout’s keycodes for arrow up/down (instead of
the *first* layout’s).
2020-09-15 18:44:54 +02:00
Daniel Eklöf
028bbd03a3
input: don’t do alternate mode scrolling if application is grabbing mouse 2020-09-15 18:40:51 +02:00
Daniel Eklöf
6ad90e6323
input: don’t do grid scrollback if mouse events are being captured 2020-09-15 18:33:58 +02:00
Daniel Eklöf
4d13429235
key-binding: deprecate scrollback-up/down, add scrollback-up/down-line
This deprecates/renames scrollback-up/down to scrollback-up/down-page.

It also renames scrollback-up/down-half to
scrollback-up/down-half-page, and adds the new bindings
scrollback-up/down-line.
2020-09-10 18:17:47 +02:00
Daniel Eklöf
2e3bd5e23c
config: add scrollback-{up,down}-half key bindings
These new bindings scroll up/down half a page in the
scrollback (instead of the full page scrolled by
‘scrollback-{up,down}’).

Closes #128.
2020-09-09 19:40:48 +02:00
Daniel Eklöf
5f64c5c335
input: fix assertion when pressing first one mouse button, then another 2020-09-07 19:35:25 +02:00
Daniel Eklöf
e32c0d9bf6
Cast printf formatter %p arguments to void* 2020-08-23 10:07:08 +02:00
Daniel Eklöf
dabdffafa5
don't use empty struct initializers 2020-08-23 10:07:00 +02:00
Daniel Eklöf
3ddc17937f
input: inhibit mouse events to client when a binding has consumed it
This introduces a new state to a seat's mouse struct, 'consumed'. It
is set on a mouse *press* event that is claimed by a mouse binding.

It is cleared after a mouse *release* event.

While set, *no* mouse motion or button events are sent to the client
application.
2020-08-22 13:35:36 +02:00
Craig Barnes
104fe2fa55 Fix some spelling mistakes 2020-08-15 19:39:00 +01:00
Daniel Eklöf
d29c4aed8a
input: mouse motion: don't update selection while scrollback searching
When we are doing a scrollback search, the selection *is* ongoing. We
still don't want to update the selection when the mouse moves.
2020-08-14 07:38:56 +02:00