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

Keyboard media controls not working #90

Open
ZeroByter opened this issue Jun 2, 2024 · 5 comments
Open

Keyboard media controls not working #90

ZeroByter opened this issue Jun 2, 2024 · 5 comments

Comments

@ZeroByter
Copy link

While playing a song, trying to pause/play songs, skip forward to the next stop, or going back to the start of the song (or last song if pressed twice quickly) via keyboard buttons doesn't work.
I'm on Ubuntu.

@ZeroByter ZeroByter changed the title Keyboard controls not working Keyboard media controls not working Jun 3, 2024
@ccgauche
Copy link
Owner

ccgauche commented Jun 3, 2024

Hello thanks for your feedback! Are you talking about DBus controls or shortcuts in the app ? What terminal are you using? Can you send the ytermusic log?

@ZeroByter
Copy link
Author

ZeroByter commented Jun 3, 2024

Not sure what is DBus controls, I'm referring to physical keyboard buttons (sometimes fn+key buttons) to pause/play, next track
and previous track.

I actually cloned your repo and tried to implement this myself but couldn't get it to work, even though I think it should work, here is what I tried:

Added line PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES); in mod.rs

pub fn run(&mut self, updater: &Receiver<ManagerMessage>) -> Result<(), io::Error> {
        // setup terminal
        enable_raw_mode()?;
        let mut stdout = io::stdout();
        execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
        let backend = CrosstermBackend::new(stdout);
        let mut terminal = Terminal::new(backend)?;

        // create app and run it
        let tick_rate = Duration::from_millis(250);

        // V Added this line here V
        PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES);
        // ^ Added this line here ^

        let mut last_tick = Instant::now();
        'a: loop {

Added lines in music_player.rs

fn on_key_press(&mut self, key: KeyEvent, _: &ratatui::layout::Rect) -> EventResponse {
        match key.code {
            KeyCode::Media(media_key) => match media_key {
                MediaKeyCode::PlayPause => {
                    SoundAction::PlayPause.apply_sound_action(self);
                    EventResponse::None
                }
                _ => EventResponse::None,
            },
        ...

I'm actually not that familiar with Rust, so I tried making a new empty Rust project just to see if I could at all capture these MediaKeyCodes but I couldn't, perhaps it's a problem with crossterm? Or with Linux? I haven't tried on Windows yet.

Where is the log file? I'll happily send it.

@ccgauche
Copy link
Owner

ccgauche commented Jun 4, 2024

I don't know how FN + FX keys are handled but it think they should use DBus too (A linux protocol for media actions cross-desktop). To confirm I've been using souvlaki underneath so maybe you should look there. Thanks for the investigation!

@ZeroByter
Copy link
Author

ZeroByter commented Jun 4, 2024

I just googled souvlaki and it looks promising, I'll give it a try later today and if I hopefully get it to work, will send a PR :) Thanks for the help!

Edited update: I just found the souvlaki code in the project and messed around with it and I just now realized what is the DBus protocol that you are talking about, but that is not what I am referring to.

I am referring to these keyboard buttons:

I confirmed in a new standalone project, kebyoard media buttons are not captured by souvlaki

@ZeroByter
Copy link
Author

Created a crossterm bug report about this: crossterm-rs/crossterm#897

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

No branches or pull requests

2 participants