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

How to trigger a response given a focus change event #784

Open
DaveTJones opened this issue Apr 13, 2023 · 6 comments
Open

How to trigger a response given a focus change event #784

DaveTJones opened this issue Apr 13, 2023 · 6 comments

Comments

@DaveTJones
Copy link

DaveTJones commented Apr 13, 2023

Conditionally executing print statements as a result of FocusGained or FocusLost events from within alacritty/gnome terminal doesn't produce any output when switching between panes. Based on the way things are presented within examples, this looks like it should be fairly straightforward.

To reproduce the issue, run the following script in a terminal (I used alacritty on Pop!_OS). Changing window focus doesn't result in printing:

use crossterm::event::{read, Event};

fn print_events() {
    loop {
        match read() {
            Ok(Event::FocusGained) => println!("FocusGained"),
            Ok(Event::FocusLost) => println!("FocusLost"),
            _ => (),
        }
    }
}

fn main() {
    print_events();
}

How do I go about getting this to work? Or am I misunderstanding what these events represent?

@sigmaSd
Copy link
Contributor

sigmaSd commented Apr 13, 2023

@DaveTJones
Copy link
Author

Thanks a tonne, that fixed it. Although that example is pretty clear, the one I initially used from the docs was slightly misleading https://docs.rs/crossterm/latest/crossterm/event/index.html

@sigmaSd
Copy link
Contributor

sigmaSd commented Apr 14, 2023

yeah that part could use a pr , there is a section about mouse events https://docs.rs/crossterm/latest/crossterm/event/index.html#mouse-events but its the same case with focus event and paste event

@DaveTJones
Copy link
Author

I'll submit one later if that's cool?

@sigmaSd
Copy link
Contributor

sigmaSd commented Apr 14, 2023

sure thanks

@DaveTJones
Copy link
Author

Also noticed that this is missing from at least one other example. https://github.com/crossterm-rs/crossterm/blob/master/examples/event-poll-read.rs looks like it implements focus gain and loss events but is missing the relevant execute statements.

illiteratewriter added a commit to illiteratewriter/crossterm that referenced this issue Feb 29, 2024
TimonPost pushed a commit that referenced this issue Jun 16, 2024
* docs: update docs for focus change event (#784)

* docs: update example to include execute command

- add space between links
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