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

Global shortcuts on the main view does not work for Linux platform #412

Closed
dajoha opened this issue Apr 4, 2024 · 1 comment
Closed

Comments

@dajoha
Copy link

dajoha commented Apr 4, 2024

On a Linux OS, when adding .on_key_up() or .on_key_down() to the main view in order to register some global shortcuts, nothing happens. Hitting any key does not trigger the keyboard event.

How to reproduce

On a Linux OS, run this code (floem = 0.1.1):

use floem::{
    keyboard::{Key, NamedKey, ModifiersState},
    view::View,
    views::{Decorators, empty},
};

fn app_view() -> impl View {
    empty().on_key_up(Key::Named(NamedKey::F11), ModifiersState::empty(), move |_| {
        println!("Hit F11");
    })
}

fn main() {
    floem::launch(app_view);
}

Then press the "F11" key => nothing is printed to the console.

The same problem happens:

  • when running the floem example "counter" (hitting "F11" should open the inspector);
  • when using another keystroke (nothing to deal with "Fxx" keys).

Tiny investigation

Maybe this is because the user's main view is wrapped into a stack(container()) for linux platforms:

#[cfg(target_os = "linux")]

        #[cfg(target_os = "linux")]
        let view = with_scope(scope, move || {
            stack((
                container(view_fn(window_id)).style(|s| s.size(100.pct(), 100.pct())),
                context_menu_view(scope, window_id, context_menu, size),
            ))
            .style(|s| s.size(100.pct(), 100.pct()))
            .any()
        });

As an experiment I tried to replace this block by:

        #[cfg(target_os = "linux")]
        let view = with_scope(scope, move || view_fn(window_id));

Then the global shortcut worked (it crashed the app totally, but it prooves that the keyboard event was triggered, indeed other keys did nothing at all).

@jrmoulton
Copy link
Collaborator

@dajoha this should have been recently fixed in c24d36e

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