Commit graph

353 commits

Author SHA1 Message Date
Daniel Eklöf
4c5f53878e
input: kitty: don’t fallback to the XKB symbol
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.
2021-12-16 12:49:41 +01:00
Daniel Eklöf
fe851a6936
input: kitty: return the result of term_to_slave()
If term_to_slave() fails, then the key wasn’t ‘handled’...
2021-12-12 15:08:46 +01:00
Daniel Eklöf
53fc9ca3b2
kitty: replace switch with a static keysym table 2021-12-11 21:04:58 +01:00
Daniel Eklöf
f6a591b80a
config: unify key- and mouse bindings
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.
2021-12-11 20:19:11 +01:00
Daniel Eklöf
4c50c44cf7
config: do mouse binding collision detection after loading the conf 2021-12-11 20:19:11 +01:00
Daniel Eklöf
34ce9f97bb
kitty: simplify: always calculate alternate/base keys
But only _emit_ them if report alternate has been enabled.
2021-12-08 17:54:37 +01:00
Daniel Eklöf
52eee4482b
kitty: when emitting associated text, don’t report mods/events unless necessary 2021-12-08 17:54:37 +01:00
Daniel Eklöf
c0cfec89e0
kitty: report-alternate: apply base-layout key to composed characters 2021-12-08 17:54:37 +01:00
Daniel Eklöf
9b57ef07f1
kitty: implement “base layout key” in “report alternate key” 2021-12-08 17:54:37 +01:00
Daniel Eklöf
9d5ab91b6a
kitty: initial support for “report alternate key”
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
2021-12-08 17:54:37 +01:00
Daniel Eklöf
21fe01099c
kitty: only emit plain text on key press- and repeat events
That is, release events always generate CSIs
2021-12-08 17:53:01 +01:00
Daniel Eklöf
e9a762f8a1
kitty: add ISO_Level{3,5}_Shift keys 2021-12-08 17:53:00 +01:00
Daniel Eklöf
69f97446fa
kitty: composed characters with “report associated text”
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.
2021-12-08 17:53:00 +01:00
Daniel Eklöf
78666d248a
kitty: implement “report associated text”
In this mode, key events that generate text now add a third CSI
parameter, indicating the actual codepoint.

Remember that we always use the *unshifted* key in the CSI
escapes. With this mode, those CSI escapes now also included the text
codepoint. I.e. what would have been emitted, had we not generated a
CSI escape.

As far as I can tell, this mode has no effect unless “report all keys
as escape sequences” is enabled (reason being, without that, there
aren’t any text events that generate CSIs - they’re always emitted
as-is).

Note that Kitty itself seems to be somewhat buggy in this mode. At
least on Wayland, with my Swedish layout. For example ‘a’ and ‘A’ does
generate the expected CSIs, but ‘å’ and ‘Å’ appears to be treated as
non-text input.

Furthermore, Kitty optimizes away the modifier parameter, if no
modifiers are pressed (e.g. CSI 97;;97u), while we always emit the
modifier (CSI 97;1;97u).

Related to #319
2021-12-08 17:53:00 +01:00
Daniel Eklöf
0e2d8429c0
input: kitty: add support for “report all keys as escape codes” 2021-12-06 19:49:52 +01:00
Daniel Eklöf
93a8f51b75
input: kitty: merge handling of plain-text and composed characters
All plain-text and composed characters are now printed as-is, in a
single place.

Also fix handling of “generic” keys when emitted as escapes; don’t use
the raw XKB symbol as key in the escape, convert it to a unicode code
point first. For many symbols, these are the same. But not
all.

For now, we fallback to using the symbol as is if XKB fails to convert
it to a codepoint. Not sure if we should simply drop the key press
instead.

Composed characters also need special treatment; we can’t use the
symbol as is, since it typically refers to the last key
pressed (i.e. not the composed character). And, that key is
also (usually) a special “dead” key, which cannot be converted to a
unicode codepoint.

So, what we do is convert the generated utf8 string, and (try to)
convert it to a wchar. If it succeeds, use that. If not, fallback to
using the XKB symbol (as above).
2021-12-04 18:32:07 +01:00
Daniel Eklöf
660626118a
input: reset compose state on key *releases*, not presses 2021-12-04 18:32:07 +01:00
Daniel Eklöf
6b9b03b8dd
input: kitty: treat repeating == pressed when report-events is off 2021-12-04 18:32:06 +01:00
Daniel Eklöf
1df94f1468
input: kitty: add support for the “report event” mode (0b10) 2021-12-04 18:32:06 +01:00
Daniel Eklöf
0193f5bd9b
input: don’t ignore key release events
Before this, key release events stopped the repeat timer, and then
returned.

Now, we run through the entire function. Most things are still only
done on key press events. But, the goal here is to get to the keyboard
protocol functions (and the kitty protocol in particular), and call
them on release events too.

This is in preparation for the kitty protocol mode 0b10, report event
types.
2021-12-04 18:32:06 +01:00
feeptr@codeberg.org
a4d53bdf88 config, input: allow configuring select-override modifiers 2021-12-02 18:44:08 -05:00
Daniel Eklöf
1619e83c13
input: always update the xcursor shape in pointer enter/motion events
Now that term_xcursor_update_for_seat() takes the current surface into
account (i.e. doesn’t assume the cursor is over the main grid),
there’s no longer any need to call render_xcursor_set() directly.

Thus, we can simply call term_xcursor_update_for_seat() on **all**
pointer enter and motion events. As long as we take care to update the
internal state to reflect the, possibly new, current surface before
doing so.

Also make sure to **always** reset the seat’s “current” xcursor
pointer on pointer leave events. This is done without actually sending
anything to the compositor, but is necessary to ensure that we *do*
send a request to update the xcursor on the next pointer enter event.
2021-12-01 20:04:01 +01:00
Daniel Eklöf
63e8b1b292
input: fix debug log format specifier; ‘count’ is a size_t 2021-12-01 20:03:18 +01:00
Daniel Eklöf
fce13c4106
input: make csd_data variable ‘const’ 2021-11-30 22:15:13 +01:00
Daniel Eklöf
90cfdcf1a5
Merge branch 'window-menu' 2021-11-30 22:10:27 +01:00
Daniel Eklöf
73a048f9d3
input: regression: reset view (and cancel selection) on “handled” input
This fixes a regression, where the view (and selection) was only reset
if the keyboard input resulted in plain text. That is, key presses
like enter, arrows etc did not.
2021-11-29 19:31:48 +01:00
Jonas Ådahl
38741baf9a input: Add support for xdg_toplevl.show_window_menu()
This makes, if the compositor supports it, the window menu appear when
right clicking on the title bar.
2021-11-29 16:26:40 +01:00
Jonas Ådahl
c0ce131f1a input: Update mouse x/y coordinates on wl_pointer_enter
Otherwise if you don't receive motion event before e.g. button pressed,
the coordinates will be incorrect. This happens when e.g. you get
alt-tabbed so that the mouse cursor ends up on top of the terminal
window, but the mouse never actually moved.
2021-11-29 16:26:40 +01:00
Jonas Ådahl
5c2557b421 terminal: Make seat xcursor update focus aware
When term_xcursor_update_for_seat() was called on e.g. keyboard focus
loss, it'd update the curret xcursor to 'text' even if it was e.g. on
top of the window title, or resize areas. This makes the function a bit
more focus aware, and will not be so eager to set the text xcursor.
2021-11-29 16:26:40 +01:00
Daniel Eklöf
a55a3daae7
input: regression: special keys don’t reset view and cancel selection
This fixes an issue where e.g. holding down ctrl would cancel the
selection, thus making it impossible to copy text to the clipboard.
2021-11-28 16:48:30 +01:00
Daniel Eklöf
8f41a8dc94
input: kitty: use XKB_CONSUMED_MODE_GTK when retrieving consumed mods 2021-11-28 15:14:56 +01:00
Daniel Eklöf
913dd8b4a6
input: get_current_modifiers(): use xkb_state_key_get_consumed_mods2()
Explicitly request consumed modifiers using the `XKB` mode.
2021-11-28 15:14:56 +01:00
Daniel Eklöf
546bcd66b7
input: legacy: use ALEN(mod_param_map) 2021-11-28 15:14:55 +01:00
Daniel Eklöf
42d1fcb484
input: grammar: “an UTF-8” -> “a UTF-8” 2021-11-28 15:14:55 +01:00
Daniel Eklöf
ce8ea2db66
input: legacy: reduce size of reply buffer
Its maximum size is known; the only two variables are two integers. We
know the maximum length of an integer converted to a string.
2021-11-28 15:14:55 +01:00
Daniel Eklöf
07068165ec
input: only report modifiers when “Report all keys as escape codes” is enabled 2021-11-28 15:14:55 +01:00
Daniel Eklöf
6930abe945
input: kitty: add shift/alt/ctrl/super/hyper/meta keys 2021-11-28 15:14:54 +01:00
Daniel Eklöf
9933284ab1
input: kitty: add ‘media’ keys 2021-11-28 15:14:54 +01:00
Daniel Eklöf
1ec218c3ac
input: kitty: map ISO_Left_Tab to Tab 2021-11-28 15:14:54 +01:00
Daniel Eklöf
66171f1045
input: rename ‘meta’ to ‘super’ 2021-11-28 15:14:54 +01:00
Daniel Eklöf
a08494a766
input: kitty: only emit CSIs for Caps- and Num-Lock when they aren’t modifiers 2021-11-28 15:14:54 +01:00
Daniel Eklöf
8fb641a7ed
input: handle “invalid” XKB modifiers
A modifier may not exist in a specific layout. This is indicated by
XKB returning XKB_MOD_INVALID from xkb_keymap_mod_get_index().
2021-11-28 15:14:54 +01:00
Daniel Eklöf
ebad4bba28
input: kitty: disable CSI for Caps- and Num-Lock
Not sure why these keys have CSIs in the kitty spec; they don’t emit
anything.

Could it be that they are used if the keys are *not* modifiers in the
current layout?
2021-11-28 15:14:53 +01:00
Daniel Eklöf
e744cee760
input: kitty: printables are emitted as text, even if Caps- or Num-Lock is in effect
Not sure if this is the best/correct way to do it. But kitty seems to
ignore at least Num-Lock for printables, while it _does_ affect other
keys. For example, Return, which usually emits ‘\r’, are affected by
Num-Lock and emit ‘CSI 13;129u’.

Note that as soon as some other modifier is in effect, the Num-Lock
modifier *is* encoded in the CSI, also for printables.
2021-11-28 15:14:53 +01:00
Daniel Eklöf
db746d72ed
input: get_current_modifiers() no longer strips insignificant mods
Our internal binding handling cares about a different set of
modifiers, compared to the kitty keyboard protocol.

To handle this, get_current_modifiers() has been modified, to no
longer strip the “unsignificant” modifiers. This is now up to the
caller to do.

To help, we keep two masks (for significant modifiers) in the seat
struct; one for our internal binding handling (and the legacy keyboard
protocol), and one for the kitty keyboard protocol. These two masks
are updated when the seat’s keymap is updated/changed.
2021-11-28 15:14:53 +01:00
Daniel Eklöf
b9d03c16a6
input: kitty: use base symbol instead of lowering the symbol
When emitting an escape sequence for a printable character, with
modifiers (e.g. ctrl+a), use the key’s base symbol instead of
“lowering” it.

This means we now handle e.g. ctrl+2 and ctrl+shift+2, with Swedish
layout.

There’s a twist however. We *only* use the base symbol if the
modifiers that is used to “generate” the symbol are “significant”.

Significant modifiers are, in this context, modifiers we can encode in
the kitty escape sequences.

In the Swedish layout, pressing AltGr+2 results in ‘@’. AltGr cannot
be encoded in the kitty protocol. If we were to use the base symbol,
AltGr+Alt+2 would result in exactly the same escape sequence as Alt+2.
2021-11-28 15:14:53 +01:00
Daniel Eklöf
ab5dfa3f3b
input: wip: add support for kitty kbd protocol “Disambiguate escape codes”
Most things appear to work as in kitty. There’s one known difference:
tri-state keys don’t generate the same unshifted symbol while holding
Shift (but e.g. Ctrl+a and Ctrl+Shift+a *does* generate the same base
symbol).

For example, the Swedish keyboard layout has double quote, ‘2’ and ‘@’
on the same key. ‘2’ is the base (unshifted) symbol. Double quote is
Shift+2. ‘@’ is AltGr+2.

Kitty generates the same base symbol for ‘2’ and double quote (the
base symbol is, as expected, ‘2’).

But, for ‘@’ kitty generates the base symbol ‘@’.

Currently, foot generates the base symbol by calling
xkb_keysym_to_lower().

I _think_ what we need to do is “consume” the shift modifier, and then
re-retrieve the symbol (given the current xkb state and key pressed).
2021-11-28 15:14:53 +01:00
Daniel Eklöf
2d85dbec6b
input: enable repeat while COMPOSING 2021-11-28 15:14:52 +01:00
Daniel Eklöf
9f3dba683e
input: refactor: new function: legacy_kbd_protocol()
This breaks out all handling of key escapes to-be-sent to the client,
to a separate function, legacy_kbd_protocol().

That is, the key press/release handler first handles key generic
handling, such as starting and stopping the repeat timer.

Then it checks for foot keyboard bindings. If not bindings match, we
need to pass the keyboard event to the client. This code has now been
separated out into a new function.
2021-11-28 15:14:52 +01:00
Daniel Eklöf
325ad6dd4e
input: finalize mouse selection on a pointer-leave event on the GRID surface
If a mouse selection was ongoing, and the user switched
workspace (probably using the keyboard...), and then back, the
selection was still treated as ongoing, while all other mouse state
has been reset.

This meant the user had to tap at least once to stop the selection.
2021-11-25 15:21:53 +01:00