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

In windows, windows modifier key (in any form of Win, LWin, RWin) seem to NOT be registered/tracked by egui #5604

Open
yakrider opened this issue Jan 13, 2025 · 2 comments
Labels
bug Something is broken

Comments

@yakrider
Copy link

They dont even seem to be in the Modifiers struct, and of the fields in that struct, none seem to track the Win modifier key press/release.

Its a bigger deal than just not being able to code to those, because since egui windows seem to 'eat' key events, doing something like a win key press outside then release inside the egui window can make external apps not see the release event and think the win key is stuck etc

@yakrider yakrider added the bug Something is broken label Jan 13, 2025
@YgorSouza
Copy link
Contributor

The modifiers are assigned here:

WindowEvent::ModifiersChanged(state) => {
let state = state.state();
let alt = state.alt_key();
let ctrl = state.control_key();
let shift = state.shift_key();
let super_ = state.super_key();
self.egui_input.modifiers.alt = alt;
self.egui_input.modifiers.ctrl = ctrl;
self.egui_input.modifiers.shift = shift;
self.egui_input.modifiers.mac_cmd = cfg!(target_os = "macos") && super_;
self.egui_input.modifiers.command = if cfg!(target_os = "macos") {
super_
} else {
ctrl
};

But the super key is only being handled on macOS. The mac_cmd field should probably be renamed to super and track the key on all OSes, like on winit. The command extra field already ensures you can more easily handle the difference in shortcuts between the OSes (macOS uses super like Windows and Linux use ctrl), so I guess it can stay as is.

@YgorSouza
Copy link
Contributor

There is also the web implementation, where the super key is mapped to the mac_cmd field on all platforms:

pub fn modifiers_from_mouse_event(event: &web_sys::MouseEvent) -> egui::Modifiers {
egui::Modifiers {
alt: event.alt_key(),
ctrl: event.ctrl_key(),
shift: event.shift_key(),
// Ideally we should know if we are running or mac or not,
// but this works good enough for now.
mac_cmd: event.meta_key(),
// Ideally we should know if we are running or mac or not,
// but this works good enough for now.
command: event.ctrl_key() || event.meta_key(),
}
}

So for example, super+Z does the undo shortcut on Windows and Linux, which it probably shouldn't. I think it would be better to keep mac_cmd, either as a field or as a method, making sure it is only ever true on macOS, and add a new super_key field that tracks the super/meta/os key on all platforms.

There is #5237 that is adding the fn modifier, so it would be good to review and merge/close that PR before working on this one to avoid conflicts.

@yakrider yakrider changed the title In windows, windows modifier key (in any form of Win, LWin, RWin) seem to be registered/tracked by egui In windows, windows modifier key (in any form of Win, LWin, RWin) seem to NOT be registered/tracked by egui Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants