HelloThisIsFlo / Deckpad

Use your SteamDeck as a wireless PC controller
91 stars 7 forks source link

[Feature] Use volume keys instead of touchpad to quit #8

Closed olee closed 5 months ago

olee commented 1 year ago

The volume buttons still register presses on the deck when connected. By detecting a volume change (or maybe even the media button key press) Deckpad could quit without requiring the installed pacman tools. What do you think?

PS: Especially, because quitting by clicking the touchscreen does not seem to work for me as well

HelloThisIsFlo commented 1 year ago

Hey @olee

That sounds like a genius idea!! I never thought about it.

Indeed, if we could capture the volume key, or any other key that isn't captured by the USB streaming software, that would make things much easier!

Do you know by any chance how we could do that? Do you have maybe a snippet of code that shows how to capture volume buttons (or any other relevant button)?

olee commented 1 year ago

I didn't investigate this any further yet, but my current guess is that changing the volume will modify a system file the same way as eg. the brightness modification you are doing. So just watching that particular file for any change could a really simple ... though kinda hacky ... solution, to get this resolved 🤔

HelloThisIsFlo commented 1 year ago

That's a good idea.

Unfortunately, I looked into it a bit and I couldn't find a super straightforward way to find the volume.

If you have more ideas I'd be happy to try

olee commented 1 year ago

Wow ... seems like it is surprisingly difficult... One thing about your problem with having a different audio setup: Wouldn't it be fine to just watch all playback devices if any of them changes? There aren't many and if any one changes, it's definitely caused by some user interaction.

HelloThisIsFlo commented 1 year ago

It's probably possible. The tricky part is that because I have a different setup than anyone else, I won't be able to make sure whatever I code works on non-modified steam decks. So this can quickly become a maintainability nightmare, with simple issues taking days or weeks to fix due to the back and forth, regaining context, etc...

My output at the moment is this:

Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right - Rear Left - Rear Right - Front Center - Woo
fer - Side Left - Side Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 65398 [100%] [on]
  Front Right: Playback 65398 [100%] [on]
  Rear Left: Playback 65398 [100%] [on]
  Rear Right: Playback 65398 [100%] [on]
  Front Center: Playback 65398 [100%] [on]
  Woofer: Playback 65398 [100%] [on]
  Side Left: Playback 65398 [100%] [on]
  Side Right: Playback 65398 [100%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 65536
  Front Left: Capture 26213 [40%] [on]
  Front Right: Capture 26213 [40%] [on]

Could you post your output for the amixer command? Then please change the volume and post again.

I'm thinking maybe I could monitor Playback XXXXX and see when that changes. I'm not sure how to monitor a value for change in bash, but if that's the only unknown I should be able to figure it out quickly

olee commented 1 year ago

I checked it as well on my side and indeed, the Playback value should be usable for this: image

So simply running amixer periodically and checking for Playback value changes by regex (sed?) etc. should already be working just fine. Actually, even just checking for any change in the whole output of amixer could be enough already.

HelloThisIsFlo commented 1 year ago

Hi @olee

Thanks for the update. Yes, it does look like our outputs are similar enough to consider this a viable solution.

One thing I was a bit worried about was the fact that changing volume would change at different places in a vanilla setup vs my custom setup. And it is confirmed, when you changed the volume you can see it changed a different part of the output.

That being said, as you mentioned, checking for any change in the output should be enough. That's a very good point.

I'll try a quick prototype when I'll have some time to look at it.

HelloThisIsFlo commented 1 year ago

Update

Unfortunately it wasn't as easy as expected. When running the amixer within a the run_as_root function, I get this error

amixer: Mixer attach default error: Host is down

I tried a couple of things to be able to call amixer as the root user, but none of them worked.

My next thought was to see if I needed root at all, if we use the volume buttons. But we do need sudo for the virtualhere tool itself. I also use sudo to ensure 2 things while Deckpad is running: Brightness remains low, the device doesn't go to sleep.

I could maybe rework the whole thing to split the process into parts that don't require sudo and parts that do. But there are 2 problems:

  1. The teardown (cleanup after quitting) requires sudo to restore settings as they were originally. I don't want the user to have to type their password when exiting again. It's confusing and would leave the system in a half-broken state if they skip the prompt.
  2. Reworking the whole logic is a lot of work. I already spent 1h on this amixer investigation today. I can see this large refactor take another 3-4h hours, and I unfortunately don't prioritize this project enough at the moment to dedicate it an entire afternoon.

If you do have ideas or suggestions you'd like me to try, feel free to share. Maybe we can get around this amixer error in some way? Or if you want to try and implement it yourself, I'd be happy to receive a PR.

Thanks for your help so far 👍

DarkionAvey commented 9 months ago

why not a combo of keys, like the four back buttons at the same time? the terminal quit method doesn't work on my device.

HelloThisIsFlo commented 9 months ago

@DarkionAvey Yeah, that would be cool, but unfortunately, the whole reason I'm using the touchscreen and tried with the volume buttons is because the regular buttons are all sent to the remote computer and as far as I know we don't have access to them once 'virtualhere' is connected to the remote PC.

However, if you can think of a way to actually get notify of button presses and/or combos of buttons that would be super nice. Do you have an idea how to do that?

HelloThisIsFlo commented 5 months ago

Since there hasn't been any update on this in a while, I'm closing it. Feel free to re-open if you want to add some ideas on how to implement this feature