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

window focus status not correct under windows system #1043

Open
CedricDaniels opened this issue Jan 10, 2025 · 0 comments
Open

window focus status not correct under windows system #1043

CedricDaniels opened this issue Jan 10, 2025 · 0 comments

Comments

@CedricDaniels
Copy link

Describe the bug
After the application launches, a Focussed event should be triggered, but no such event occurs. At this point, calling the window's is_focused method should return true, but the actual result is false. Subsequently, when the window loses focus for the first time, a Focussed event should be emitted, and the focus state should be false, yet nothing happens.

Steps To Reproduce

use tao::{
    event::{self, DeviceEvent, Event, RawKeyEvent, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    keyboard::KeyCode,
    window::WindowBuilder,
};

fn main() {
    let event_loop = EventLoop::new();

    let mut window = Some(WindowBuilder::new().build(&event_loop).unwrap());

    println!("Press '1' to display is window focused status.");

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;

        match event {
            Event::DeviceEvent {
                event:
                    DeviceEvent::Key(RawKeyEvent {
                        physical_key,
                        state: event::ElementState::Pressed,
                    }),
                ..
            } => {
                if KeyCode::Digit1 == physical_key {
                    if let Some(ref win) = window {
                        // status should always be true here, but get false after app launched
                        println!("window focues status={} when press '1'", win.is_focused())
                    }
                }
            }

            Event::WindowEvent {
                event,
                window_id: _,
                ..
            } => match event {
                WindowEvent::CloseRequested => {
                    window = None;
                    *control_flow = ControlFlow::Exit;
                }
                WindowEvent::Focused(focues_flag) => {
                    if let Some(_) = window {
                        // should print `window gain focus` after app launched, but nothing happened
                        if focues_flag {
                            println!("window gain focus")
                        } else {
                            println!("window lose focus")
                        }
                    } else {
                        println!("window is destoryed")
                    }
                }

                _ => (),
            },

            _ => (),
        }
    });
}


Expected behavior

  1. console print window gain focus after app launched, actually nothing happened
  2. console print window focues status=true when press '1' after app launched, actually status=false
  3. console print window lose focus when windown lose focus first time, actually nothing happened

Platform and Versions (please complete the following information):
OS: Windows 11
Rustc: 1.83.0
dao: 0.31.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant