Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions for 4th and 5th mouse buttons #2258

Closed
wants to merge 5 commits into from

Conversation

brunoais
Copy link
Contributor

@brunoais brunoais commented Apr 16, 2021

For now, the 4th and 5th mouse buttons have erratic behavior from misinterpretation as being either 1st or 3rd buttons.

Nowadays, non-basic mice have, at least, 4 buttons, so, for me, makes most sense that those buttons are assigned. In this case, they are assigned based on my perceived difficulty in activating the feature using the mouse and how often used.

Given such, I decided that app switch to be the 4th button and notifications panel to be the 5th button.
These are what I believe to be the best use for these two. The 4th button being the app switch should be close to the no-brainer.
As for the notifications being the 5th, that one is more open for discussion. IMO, the major competitors being:

  1. Notifications panel
  2. Pinch-to-zoom
  3. paste

No more buttons are assigned because SDL doesn't support them.
For now, I would present this way, as a way to start a discussion

rom1v added 3 commits April 16, 2021 17:53
Some mouse clicks DOWN are captured for shortcuts, but the matching UP
event was still forwarded to the device.

Instead, capture both DOWN and UP for shortcuts, and do nothing on UP.
With this change, the actual HOME is handled by Android on UP on the
device. This is consistent with the keyboard shortcut (MOD+h) behavior.
The shortcut "back on screen on" is a bit special: the control is
requested by the client, but the actual event injection (POWER or BACK)
is determined on the device.

To properly inject DOWN and UP events for BACK, transmit the action as
a control parameter.

If the screen is off:
 - on DOWN, inject POWER (DOWN and UP) (wake up the device immediately)
 - on UP, do nothing
If the screen is on:
 - on DOWN, inject BACK DOWN
 - on UP, inject BACK UP

A corner case is when the screen turns off between the DOWN and UP
event. In that case, a BACK UP event will be injected, so it's harmless.

With this change, the actual BACK is handled by Android on UP on the
device (instead of DOWN). This is consistent with the keyboard shortcut
(Mod+b) behavior.
@rom1v
Copy link
Collaborator

rom1v commented Apr 16, 2021

👍 It's better to bind them to something.

I made some changes on dev to properly handle DOWN and UP events for shortcuts: #2259
Could you review/test, please?

That way, you could properly propagate them in your action_app_switch().

The 4th button being the app switch should be close to the no-brainer.

Yes, I guess.

As for the notifications being the 5th, that one is more open for discussion.

Why not. But it's maybe odd to bind "open navigation panel" but not "close navigation panel".
Maybe MENU (MOD+m), especially because it's the "unlock screen" shortcut?

I'd like other opinions on that (and my mouse has 3 buttons).

(In the future, I would like to implement some kind of shortcut customization. But it's not a priority.)

@brunoais
Copy link
Contributor Author

+1 It's better to bind them to something.

I made some changes on dev to properly handle DOWN and UP events for shortcuts: #2259
Could you review/test, please?

Sure. I will be able to in about 1h.

As for the notifications being the 5th, that one is more open for discussion.

Why not. But it's maybe odd to bind "open navigation panel" but not "close navigation panel".
Maybe MENU (MOD+m), especially because it's the "unlock screen" shortcut?

No need. Just right click (back button) and it closes. No need for a button to close when the back button does that already. I wanted to have a shortcut key to open towards the 2nd menu, when sliding the finger the 2nd time. Maybe I will end up implementing it as a finger slide... Unsure...

I'd like other opinions on that (and my mouse has 3 buttons).

Mine has 7. Unexpected behaviors happen when I try them all.

(In the future, I would like to implement some kind of shortcut customization. But it's not a priority.)

Great. Want me to try that?

@brunoais brunoais force-pushed the actions_for_extra_buttons branch from 842ca67 to fd9a218 Compare April 16, 2021 21:30
@brunoais
Copy link
Contributor Author

Your branch looks good. I rebased this one on the one you did.

app/src/input_manager.c Outdated Show resolved Hide resolved
rom1v added a commit that referenced this pull request Apr 17, 2021
Some mouse clicks DOWN are captured for shortcuts, but the matching UP
events were still forwarded to the device.

Instead, capture both DOWN and UP for shortcuts, and do nothing on UP.

PR #2259 <#2259>
Refs #2258 <#2258>
rom1v added a commit that referenced this pull request Apr 17, 2021
As a consequence of this change, the HOME button is now handled by
Android on mouse released. This is consistent with the keyboard shortcut
(MOD+h) behavior.

PR #2259 <#2259>
Refs #2258 <#2258>
rom1v added a commit that referenced this pull request Apr 17, 2021
The shortcut "back on screen on" is a bit special: the control is
requested by the client, but the actual event injection (POWER or BACK)
is determined on the device.

To properly inject DOWN and UP events for BACK, transmit the action as
a control parameter.

If the screen is off:
 - on DOWN, inject POWER (DOWN and UP) (wake up the device immediately)
 - on UP, do nothing
If the screen is on:
 - on DOWN, inject BACK DOWN
 - on UP, inject BACK UP

A corner case is when the screen turns off between the DOWN and UP
event. In that case, a BACK UP event will be injected, so it's harmless.

As a consequence of this change, the BACK button is now handled by
Android on mouse released. This is consistent with the keyboard shortcut
(Mod+b) behavior.

PR #2259 <#2259>
Refs #2258 <#2258>
rom1v pushed a commit that referenced this pull request Apr 17, 2021
Bind APP_SWITCH to button 4 and expand notification panel on button 5.

PR #2258 <#2258>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@rom1v
Copy link
Collaborator

rom1v commented Apr 17, 2021

Merged into dev: b28adab

Thank you.

@rom1v rom1v closed this Apr 17, 2021
rom1v pushed a commit that referenced this pull request Apr 17, 2021
Bind APP_SWITCH to button 4 and expand notification panel on button 5.

PR #2258 <#2258>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@rom1v
Copy link
Collaborator

rom1v commented Apr 17, 2021

Oops, sorry, I changed X2 to RIGHT_CLICK to test locally, and I kept that in the commit. 🤦

I just fixed and force-pushed dev: c4f3a76 b9c3f65

brunoais added a commit to brunoais/scrcpy that referenced this pull request Apr 17, 2021
Bind APP_SWITCH to button 4 and expand notification panel on button 5.

PR Genymobile#2258 <Genymobile#2258>

Signed-off-by: Romain Vimont <rom@rom1v.com>
rom1v added a commit that referenced this pull request Apr 19, 2021
The shortcut "back on screen on" is a bit special: the control is
requested by the client, but the actual event injection (POWER or BACK)
is determined on the device.

To properly inject DOWN and UP events for BACK, transmit the action as
a control parameter.

If the screen is off:
 - on DOWN, inject POWER (DOWN and UP) (wake up the device immediately)
 - on UP, do nothing
If the screen is on:
 - on DOWN, inject BACK DOWN
 - on UP, inject BACK UP

A corner case is when the screen turns off between the DOWN and UP
event. In that case, a BACK UP event will be injected, so it's harmless.

As a consequence of this change, the BACK button is now handled by
Android on mouse released. This is consistent with the keyboard shortcut
(Mod+b) behavior.

PR #2259 <#2259>
Refs #2258 <#2258>
rom1v pushed a commit that referenced this pull request Apr 19, 2021
Bind APP_SWITCH to button 4 and expand notification panel on button 5.

PR #2258 <#2258>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@luke-jr
Copy link

luke-jr commented Aug 29, 2021

The 4th button is typically interpreted as "Back" by regular PC applications...

Can we at least have a setting for that normalish behaviour?

@brunoais
Copy link
Contributor Author

Can we at least have a setting for that normalish behaviour?

Because we already have that function assigned to the right click mouse button.
If you prefer the 4th button to be a back button, feel free to make your own build of scrcpy that does that or use some other program that temporarily reassigns buttons.

@luke-jr
Copy link

luke-jr commented Aug 29, 2021

Wouldn't it make more sense to support standard behaviours, and have people who want non-standard behaviours reassign things? :/

Switching between right-click and back-click between applications has been a bit confusing since I started using scrcpy.

@rom1v
Copy link
Collaborator

rom1v commented Aug 29, 2021

Switching between right-click and back-click between applications has been a bit confusing since I started using scrcpy.

The reason is that BACK is very useful even if you have a 2-button mouse.

Yes, designing a "reassing buttons" feature could be useful, but it's not done.

@123SONIC321
Copy link

How can I customize the 4th and 5th mouse button clicks?

I'm not a programmer, but I think this shouldn't be too difficult to do. If anyone can guide me through the process, that would be great.

@brunoais
Copy link
Contributor Author

How can I customize the 4th and 5th mouse button clicks?

What do you want them to do? The process is different depending on what you want them to mean.

@123SONIC321
Copy link

What do you want them to do?

As a habit, I use mouse buttons 4 and 5 to go back and forward. I would like to set button 4 (the one that is used to go back) as the back button, and I don't care what the forward button is set to as I don't use it much.

@brunoais
Copy link
Contributor Author

I would like to set button 4 (the one that is used to go back) as the back button

In that case, you edit here:

https://github.com/Genymobile/scrcpy/pull/2258/files#diff-fd408d3adc5df68bc93e54b8de3830f0e2814ff8e07c581f41f60008f1e4775eR665

Replace that line's code with:

press_back_or_turn_screen_on(im->controller, ACTION_DOWN)

@123SONIC321
Copy link

Replace that line's code with

Thanks a lot, but as I mentioned, I sadly don't know anything about coding. I think for this, I should fork this repository, make the change you mentioned, then release it and use it?

Or is there an easier way to do this without having to create a fork?

@rom1v
Copy link
Collaborator

rom1v commented Jun 23, 2024

@123SONIC321 Please read #4877 (comment)

rom1v added a commit that referenced this pull request Jun 24, 2024
Add a new option --mouse-bind=xxxx.

The argument must be exactly 4 characters, one for each secondary click:

    --mouse-bind=xxxx
                 ^^^^
                 ||||
                 ||| `- 5th click
                 || `-- 4th click
                 | `--- middle click
                  `---- right click

Each character must be one of the following:
 - `+`: forward the click to the device
 - `-`: ignore the click
 - `b`: trigger shortcut BACK (or turn screen on if off)
 - `h`: trigger shortcut HOME
 - `s`: trigger shortcut APP_SWITCH
 - `n`: trigger shortcut "expand notification panel"

This deprecates --forward-all-clicks (use --mouse-bind=++++ instead).

Refs <#2258 (comment)>
PR #5022 <#5022>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this pull request Aug 2, 2024
Add a new option --mouse-bind=xxxx.

The argument must be exactly 4 characters, one for each secondary click:

    --mouse-bind=xxxx
                 ^^^^
                 ||||
                 ||| `- 5th click
                 || `-- 4th click
                 | `--- middle click
                  `---- right click

Each character must be one of the following:
 - `+`: forward the click to the device
 - `-`: ignore the click
 - `b`: trigger shortcut BACK (or turn screen on if off)
 - `h`: trigger shortcut HOME
 - `s`: trigger shortcut APP_SWITCH
 - `n`: trigger shortcut "expand notification panel"

This deprecates --forward-all-clicks (use --mouse-bind=++++ instead).

Refs <Genymobile#2258 (comment)>
PR Genymobile#5022 <Genymobile#5022>
Gottox pushed a commit to Gottox/scrcpy that referenced this pull request Sep 29, 2024
Add a new option --mouse-bind=xxxx.

The argument must be exactly 4 characters, one for each secondary click:

    --mouse-bind=xxxx
                 ^^^^
                 ||||
                 ||| `- 5th click
                 || `-- 4th click
                 | `--- middle click
                  `---- right click

Each character must be one of the following:
 - `+`: forward the click to the device
 - `-`: ignore the click
 - `b`: trigger shortcut BACK (or turn screen on if off)
 - `h`: trigger shortcut HOME
 - `s`: trigger shortcut APP_SWITCH
 - `n`: trigger shortcut "expand notification panel"

This deprecates --forward-all-clicks (use --mouse-bind=++++ instead).

Refs <Genymobile#2258 (comment)>
PR Genymobile#5022 <Genymobile#5022>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants