Commit Graph

910 Commits

Author SHA1 Message Date
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
der richter 7e07e1a087 mac/apphub: migrate remaining events functionality to new AppHub
add new app_bridge objc file for bridging between mpv core and app
functionality. replace old EventsResponder singleton with AppHub.

another step to clean up all App functionality and have one central
place for it.
2024-03-24 23:03:48 +01:00
nanahi 520849dd48 input: remove max active section limit
585d8c6856 increased max active
section limit from 5 to 50 but this obviously doesn't properly fix
the problem. Input still breaks if more than 25 scripts are loaded,
or if some scripts define lots of input sections.

Remove the limit completely by using a dynamic array for active sections.

Fixes: https://github.com/mpv-player/mpv/issues/13707
2024-03-21 03:11:19 +01:00
nanahi a5dbf34094 input: raise maximum key down limit to 16
The current limit of 4 is stupidly low, and won't be future proof
in case proper multi-touch support is added.
2024-03-21 03:11:19 +01:00
nanahi 092f556898 input: centralize VO dragging
Currently, VO dragging logic is hardcoded into each VO, where a left mouse
button down event unconditionally begins dragging if the VO dragging test
passes. This method is extremely unflexible as the VO has no knowledge of
what is happening in the input system: while begin dragging with the second
click of a doubleclick is undesired, it cannot determine whether a click
is a double click or not because it's determined by the input system.

The better way to do it is to handle it somewhere in the downstream
consumers of the events instead, as they have more information to make
this decision. The input system is the perfect place for this as the logic
for checking doubleclick already exists. So just issue a begin-vo-dragging
command if it detects a left mouse button down which isn't also a
doubleclick in this case, and delete all hardcoded VO dragging logic
in win32, x11, and wayland.

Note that this solution hardcodes left mouse button down for now, but
because the VO dragging is now centralized, it's possible to make more
improvements, such as a deadzone mechanism to fix the conflict with
MBTN_LEFT mouse bind.
2024-03-01 18:25:12 +01:00
der richter 86fa9b18a3 osdep/mac: make mac naming of files, folders and function consistent
rename all macOS namings (osx, macosx, macOS, macos, apple) to mac, to
make naming consistent.
2024-02-28 15:52:47 +01:00
David Vaughan a8a314b829 input: add insert-next support for drag-and-drop
This commit adds a DND_INSERT_NEXT action option for drag-and-drop,
allows for selecting it through the --drag-and-drop=insert-next option,
and adds the necessary plumbing to make that happen when something is
dragged onto the player.
2024-02-26 02:03:21 +00:00
nanahi 690dc201ad input: add --input-preprocess-wheel option
This adds --input-preprocess-wheel option, which can be used to control
whether to preprocess received wheel events.

Commit 937128697f added preprocessing of
wheel events to prevent the accidental scrolling of another direction
when one direction is being scrolled for touchpads, which is problematic
with the default wheel bindings where unrelated functions (seeking and
volume) are used for the 2 directions.

However, this behavior is undesirable in the following situations:

- When custom wheel bindings are used so that the 2 directions are used
for closely related actions, such as panning. With preprocessing,
diagonal movement is impossible.
- Since the wheel deadzone was introduced to prevent accidental scrolling
for touchpads, this filtering provides no benefit for high resolution
unidirectional mouse wheels, while causing a regression where scrolling at
least 0.125 units is required to trigger the event, causing input delay.

By adding this option, these two use cases are addressed.
2024-02-15 16:44:32 +00:00
Guido Cella 4ab521f080 command: add load-input-conf
This can be used to auto reload the input configuration file, e.g. in
vim:

autocmd BufWritePost ~/.config/mpv/input.conf silent !echo load-input-conf %:p | socat - /tmp/mpvsocket

Partially fixes #6362.

Additionally this can be used as a replacement for deprecated input
sections if they are ever actually removed. For example, if you want to
define different bindings for images, you can load-input-conf an
input.conf for images, and load the original again when switching to a
video. Though currently you would have to redefine builtin bindings that
were overwritten with image ones in the default input.conf.
2024-02-04 15:12:02 +00:00
Guido Cella 68e3412fee input: make parse_config_file return bool
This return value is only used to set bool config_ok in
mp_input_load_config so it makes more sense to return bool.
2024-02-04 15:12:02 +00:00
Guido Cella 484ab32a41 input: remove unused parameter from parse_config_file
This is unused since fb4d26e769.
2024-02-04 15:12:02 +00:00
sfan5 a08e8e0b46 input: add value argument for mp_input_put_key_artificial 2023-12-17 18:36:16 +01:00
Graham Booker 4754bd54c7 player/command: add ability to scale overlay 2023-12-08 13:37:26 +01:00
nanahi 4c47dbe22c input: add missing forward media key
XF86Back and XF86Forward are mostly used to navigate file and web browsers
to go back/forward in history. XF86Forward isn't recognized right now,
so add it.

Because XF86AudioForward already takes the "FORWARD" name, rename the
browse keys to GO_BACK and GO_FORWARD instead.
2023-12-06 11:07:37 +01:00
nanahi 26c6f228fe input: fix double click handling
On practically all platforms and GUI toolkits, a triggered double click
event clears the mouse input buffer so that the next click won't
trigger another double click event. mpv doesn't do this, so a third click
results in another double click event.

Fix this by resetting the double click timer after a double click event
is triggered which achieves the same effect.
2023-12-03 22:23:05 +01:00