Commit Graph

924 Commits

Author SHA1 Message Date
Guido Cella da82c0428e input/cmd: increase the command length for --input-cmdlist
--input-cmdlist crops playlist-next-playlist, playlist-prev-playlist,
write-watch-later-config and delete-watch-later-config, so increase the
string length to that of the longest command.

Also stop specifying both the minimum and maximum length since they are
the same.
2024-11-16 16:58:38 +01:00
nanahi 1c9d066c9e input: fix memory leak with scalable input and nonscalable commands
With scalable input source, scale_units can be 0, and cmd is not
freed. Fix this by freeing cmd when scale_units is 0.

Fixes: 937128697f
2024-11-16 16:58:21 +01:00
nanahi 081fc7e317 input: fix style 2024-11-02 01:39:15 +01:00
nanahi 1b9d070786 command: fix keybind command with sequence keys
The command is documented to use the same syntax as input.conf, but
it doesn't work with sequence keys because it uses
mp_input_get_key_from_name for checking key names, when it should
use mp_input_get_keys_from_string instead.

Fix this by using the correct function.
2024-11-02 01:39:15 +01:00
nanahi 56e2689894 command: add the ability to set comment for keybind command
This allows the keybind to have a comment field which can be
read from input-bindings, and displayed by e.g. stats.lua.
2024-11-02 01:39:15 +01:00
nanahi d97ba359d2 input: deduplicate mp_input_bind_key
It's just a copypaste of bind_keys with some params set to
hard coded values, so use bind_keys instead.
2024-11-02 01:39:15 +01:00
nanahi 8c3fd2cd38 input: use stream_read_file2 for reading config
The existing logic already duplicates stream_read_file other than
the flags. With stream_read_file2, this duplication can be removed.
2024-10-20 19:31:49 +02:00
nanahi da0160b0ee input/cmd: add nonscalable prefix
Some keys like WHEEL_UP are "scaled" if the input source is high
resolution, like touchpad. However, sometimes it's desirable to
disable this scaling and only active the key binding in discrete
steps, such as relative keyframe seeking which interacts poorly
if the command is scaled.

This adds the nonscalable prefix to disable this scaling.
2024-10-14 01:55:49 +02:00
nanahi 3863221246 input: skip BOM properly
Key names are already required be UTF-8 like everything else
in mpv other than media file formats which support other encodings.
stream_skip_bom is the wrong function for this, since it also skips
UTF-16 BOM.
2024-09-24 19:22:47 +02:00
Kacper Michajłow 71f2220991 meson: use relative file paths for file2string
This fixes "Generated from" comments to not include local source path in
generated files.
2024-09-21 23:39:10 +02:00
Kacper Michajłow 5edc8973eb various: use talloc_replace 2024-09-08 17:33:27 +02:00
nanahi c4ff675198 input: add MP_KEY_STATE_SET_ONLY
Trivial.
2024-09-07 18:14:56 +00:00
nanahi 4295141703 input/keycodes: fix typo 2024-09-07 18:14:56 +00:00
Kacper Michajłow ad7976c33e input: fix use of bstr like null terminated one
It has been changed in one of the iterations of the patch during review,
but bstr doesn't have to be null terminated. Fix it by adding dedicated
node_map helper.

Fixes: 1a27f3c
2024-09-04 03:52:09 +02:00
nanahi ab0aaaad39 input/keycodes: add KP_ADD/SUBTRACT/MULTIPLY/DIVIDE keycodes
In general, mpv treats numpad keys as separate inputs. The +-*/ keys
however are exceptions so it's not possible to distinguish them from
non-numpad keys.

This adds keycodes corresponding to these keys so that they can be
handled differently.
2024-08-11 15:08:42 +02:00
llyyr 67bd00f163 input: fix inverted condition
I don't know if this broke anything but the the condition was inverted
as a result of the recent commit.

Fixes: 1a27f3caf7 ("input: use bstr for section name")
2024-08-06 20:26:49 +02:00
llyyr d766fc0914 input: don't mutate 'section' variable inside a loop
This fixes broken input-section parsing

Fixes: 1a27f3caf7 ("input: use bstr for section name")
2024-08-06 20:26:49 +02:00
Kacper Michajłow 1a27f3caf7 input: use bstr for section name
Resolves mixed use of bstr in internal processing and char* for storage.
Also makes faster comparision when searching for section and resolves
comparision when name contains null chars.
2024-08-04 21:33:36 +02:00
nanahi 40f1a89e40 input/ipc: use bstr for fd parsing
Also rejects the case of "fd://" without any number which was
silently accepted as 0.
2024-07-29 21:00:48 +02:00
nanahi bb0932a3ad input/ipc-win: support fd:// for --input-ipc-client
This makes --input-ipc-client work on Windows.

To use this feature, a parent process needs to create a connected named pipe,
wrap the server handle in a CRT fd, and then spawn mpv as a child process
with the fd as the --input-ipc-client parameter.
The process can then communicate through the client handle.

The named pipe must be created duplex with overlapped IO and inheritable
handles.
2024-07-29 21:00:48 +02:00
nanahi 7c70df0934 input/cmd: move m_option_type_cycle_dir to m_option.c
A relic when commands lived in input.c. Move them to where other option
types live. Also remove the redundant copy_opt.
2024-07-01 10:02:13 +02:00
Kacper Michajłow b4123826e5 input/keycodes: validate parsed value to avoid overflow 2024-06-23 02:33:04 +02:00
Kacper Michajłow b4bbc27d9c input: map Num 5 to distinct value when numlock is off
Until now both numlock on and off were mapped to KP5.
2024-06-13 20:42:24 +02:00
nanahi 65fef73c2b input: don't resolve double clicks on the active mouse section
Normally, key bindings are resolved in the input section stack order.
However, mouse key bindings have a special "active mouse section" feature
(which is a section with MOUSE_MOVE bound and mouse button is down in the
section) which lets the section to be selected instead, with a fallback
to the "default" section. The intention of the feature is for mouse
dragging which should "stick" to the section where the mouse is down.

This causes a problem with scripts which bind mouse double clicks:
since double clicks are triggered on mouse down, it's resolved with the
"active mouse section" feature instead of the section stack order.
If the section which has the double click bound doesn't also have
MOUSE_MOVE bound, the "default" section will be used instead.
If it's already bound there, it will be triggered.

Fix this by not resolving double clicks on the active mouse section, which
is not the intention of the feature.
2024-06-08 23:13:15 +02:00
nanahi de97cb0964 input: mark a command as canceled if it is explicitly dropped
In certain situations (including but not limited to begin window dragging),
it is desired to cancel the current command completely. However, commands
which have on_updown flag set require the command to be invoked in this
situation. There is currently no way to know if the command is triggered
normally or triggered because it is dropped.

This adds a canceled state to mp_cmd which indicates this.
2024-06-06 23:38:39 +03:00
nanahi 16612672fd input: fix grammar errors and typo 2024-06-05 13:35:33 +00:00
nanahi 0509e5b2ed input: only begin VO dragging if the section allows
Otherwise, on sections which don't allow VO dragging, the mouse button
is force released and dragging events won't be generated.

Fixes: 349aac462e
2024-06-05 11:11:00 +02:00
nanahi 7e82108bec input: reset doubleclick timer when dragging begins
This prevents doubleclick from activation if a second mouse click comes
quickly after a click which begins dragging.
2024-06-04 12:41:51 +02:00
nanahi 49b5e6d042 input: un-hardcode VO dragging
This adds the --input-builtin-dragging option, which allows the built-in
dragging behavior to be disabled. This allows scripts to implement custom
dragging behavior with left button down events and begin-vo-dragging
command, which could only be done for other mouse buttons before.
2024-06-04 12:41:51 +02:00
nanahi 349aac462e input: prevent MBTN_LEFT conflict with VO dragging
Currently, the built-in VO dragging conflicts with the MBTN_LEFT binding,
so the binding is activated even though the VO dragging begins. Fix this
by releasing the currently down command so that MBTN_LEFT can be bound to
a useful action (such as play/pause).
2024-06-04 12:41:51 +02:00
nanahi a6683ea3c9 input: implement VO dragging deadzone
This adds the --input-dragging-deadzone option, which adds a deadzone
for the built-in VO deagging. This prevents accidental VO dragging.
2024-06-04 12:41:51 +02:00
nanahi a23098b555 input: fix mouse position equality check
The stored mouse position mouse_vo_x/y are scaled (currently only for
vo_xv), but the position equality check compares between raw position
and scaled position.

Fix this by storing and checking the raw position instead. The raw
position is useful for the next commit.
2024-06-04 12:41:51 +02:00
nanahi 82c8a98884 input: begin VO dragging when moving mouse while left button is down
Will be used for the VO dragging deadzone.
2024-06-04 12:41:51 +02:00
Guido Cella 3f83671f20 input: prioritize builtin bindings matching longer key sequences
This fixes 2 different bugs:

- mp.add_key_binding('c', ...) taking priority over the builtin g-c
  binding.

This follows up 994a08f5a7 which fixed this within the same input
section. This fixes it across different input sections.

- mp.add_key_binding('g-c', ...) not taking priority over a c binding
  defined in input.conf.

This happened because is_builtin of bindings added with
mp.add_key_binding is true though they're not actually builtin.
2024-05-20 17:57:12 +02:00
nanahi bc5863a631 input/cmd: add nonrepeatable prefix
This allows forcing certain commands to be non-repeatable, e.g. volume.
2024-05-20 17:47:01 +02:00
sfan5 54c755b08d various: add missing checks for directory streams
All of this code opens a stream and expects to read stuff from a file.
But streams can also be directories and that has to be handled.
2024-05-15 22:45:18 +02:00
Guido Cella 994a08f5a7 input: fix builtin sequence bindings
If g-p is a builtin binding and p is bound in input.conf, pressing g-p
triggers the p binding. Fix this by searching for builtin bindings that
match a longer key sequence even after a user-defined binding has been
found.

Even after changing the condition from >= to > bindings of the same key
defined later in input.conf are still preferred over earlier ones,
because bind_keys() overwrites duplicate bindings. Bindings defined by
later mp.add_key_binding calls are also still preferred.
2024-05-12 23:13:48 +02:00
nanahi 9f5edd4eed various: fix indentation 2024-05-07 11:23:08 +02:00
Kacper Michajłow 5cf0da2a6a various: remove unused sys/time.h include 2024-05-06 22:01:17 +02:00
Kacper Michajłow fffe723fc4 various: move strings.h inclusion to common.h 2024-05-06 22:01:17 +02:00
Kacper Michajłow 18ef834ef4 various: move unistd.h inclusion to common.h 2024-05-06 22:01:17 +02:00
nanahi 89aa10de24 input: add MP_TOUCH_RELEASE_ALL
Release all touch points. Used by some VOs like Wayland touch cancel
event.
2024-05-03 16:14:03 +02:00
nanahi 77809faea1 input: add --input-touch-emulate-mouse option
This adds --input-touch-emulate-mouse option, which controls whether to
enable legacy touch handling where touch inputs are emulated as mouse
inputs. This establishes a primary touch point (the one with the lowest
index) as the emulated mouse position, and MBTN_LEFT up/down with the
appearance of the first touch point and the disappearance of the last
touch point.

This fixes some problems with touch handling on Wayland, for example
attempting to pinch results in a double click.
2024-05-03 16:14:03 +02:00
nanahi 28a4fb8e4e input: add multitouch support functions
The goal of multitouch support is to interpret as little as possible:
mpv just stores the touch point information and makes the position
available for query. Does not participate in the deprecated input section
system.

The API is modeled after the common part of the touch input APIs of
Win32, X11, and Wayland, to make sure the platform-specific implementations
are as simple as possible.
2024-05-03 16:14:03 +02:00
nanahi 5109c599db input: fix deadlock in adding gamepad input src
mp_input_sdl_gamepad_add() calls mp_input_add_thread_src() which
already locks, so it cannot be called inside a lock.

Missed in e8b9476bf7 refactoring.
2024-04-19 21:04:02 +02:00
nanahi dbe377645f input: make mp_input_queue_cmd return a meaningful value
It's currently always a meaningless 1. Make it so it returns 0 is cmd
is NULL. Remove the unused return value from queue_cmd.
2024-04-17 23:42:35 +02:00
nanahi f4db4aaed7 input: don't use recursive mutex
Previous commits made sure that the lock will never be called for more
than once for all public functions. Thus deadlock is impossible, so
recursive mutex is unneeded and can be converted to a normal mutex.
2024-04-17 23:42:35 +02:00
nanahi e8b9476bf7 input: avoid unnecessary recursive locks
The absense of a call hierarchy between public and private functions
results in many unnecessary recursive locks: public functions require
locks, which are also called by other public and private functions in this
file. Fortunately, since the lock is private to this file, this situation
can be avoided by establishing a call hierarchy:

- Public functions must lock, and can only call private functions in
  this file
- Private functions must not lock, and can only call private functions
  in this file
- No function can call any public function in this file, the only
  exception being mp_input_wakeup and mp_input_parse_cmd.

This arrangement ensures that there will be no locks more than necessary:
All public function calls will lock only once, and never recursively.
2024-04-17 23:42:35 +02:00
nanahi 3cbb34fd03 input: remove mp prefix for static functions
This makes it easy to eyeball check the call hierarchy between public
and private functions.
2024-04-17 23:42:35 +02:00
nanahi ce4294bc37 input: fix locking of mp_input_bind_key
This is a public function, yet its access to ictx through
get_bind_section is not locked.

Fixes: 4614d432a8
2024-04-17 23:42:35 +02:00