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

Is there a way to implement any event handling customized by the user in tao? #577

Closed
imxood opened this issue Oct 1, 2022 · 2 comments
Closed

Comments

@imxood
Copy link

imxood commented Oct 1, 2022

I want to implement listening for USB device plug and unplug events, in tao,

Like this, there are other event handling that tao does not implement, Is there a way to achieve any specific event handle the user wants?

Here is the hardcoded implementation of the code for usb plug and unplug events:
line 1031 in src\platform_impl\windows\event_loop.rs

win32wm::WM_DEVICECHANGE => {
      match wparam.0 as u32 {
        DBT_DEVICEARRIVAL => {
          println!("device arrival");
        }
        DBT_DEVICEREMOVECOMPLETE => {
          println!("device remove complete");
        }
        DBT_DEVNODES_CHANGED => {
          println!("dev nodes changed");
        }
        _ => {
          println!("WM_DEVICECHANGE message received, value {} unhandled", wparam.0);
        }
      }
      result = ProcResult::Value(LRESULT(0));
    }

Here is the code implemented by the user himself, using the windows api to register event notifications:

    let mut notify_filter = DEV_BROADCAST_DEVICEINTERFACE_W::default();
    notify_filter.dbcc_size = size_of::<DEV_BROADCAST_DEVICEINTERFACE_W>() as u32;
    notify_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE.0;
    notify_filter.dbcc_classguid = windows::core::GUID::from_values(
      0x25dbce51,
      0x6c8f,
      0x4a72,
      [0x8a, 0x6d, 0xb5, 0x4c, 0x2b, 0x4f, 0xc8, 0x35],
    );

    unsafe {
      RegisterDeviceNotificationW(
        HANDLE(thread_msg_target.0),
        &notify_filter as *const DEV_BROADCAST_DEVICEINTERFACE_W as *const c_void,
        POWER_SETTING_REGISTER_NOTIFICATION_FLAGS(
          DEVICE_NOTIFY_WINDOW_HANDLE.0 | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES,
        ),
      );
    }

    println!("RegisterDeviceNotification");

here is the effect:
image

@amrbashir
Copy link
Member

There is no plans on directly supporting this in tao at the moment since we plan to switch back to use winit which has plans to add access to the event loop rust-windowing/winit#2120

Alternatively, you could spawn a hidden window that you can manage its own event loop to fit your needs.

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2022
@imxood
Copy link
Author

imxood commented Oct 4, 2022

@amrbashir I use a thread to capture specific events through a hidden window to complete this function, thank you very much.

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