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

Handling of super key on other platforms #4333

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f0b7737
Update memory.rs
rustbasic Mar 23, 2024
3b98d7f
Update epi_integration.rs
rustbasic Mar 23, 2024
af5a7bb
Update memory.rs
rustbasic Mar 23, 2024
7f66b56
Update memory.rs
rustbasic Mar 23, 2024
6396c4a
Update epi_integration.rs
rustbasic Mar 23, 2024
9fe42ff
Merge branch 'emilk:master' into master
rustbasic Mar 25, 2024
d7673fe
Merge branch 'emilk:master' into master
rustbasic Mar 25, 2024
a7edc53
Merge branch 'emilk:master' into master
rustbasic Mar 26, 2024
2432784
Merge branch 'emilk:master' into master
rustbasic Mar 27, 2024
9b6209b
Merge branch 'emilk:master' into master
rustbasic Mar 27, 2024
f3687f6
Merge branch 'emilk:master' into master
rustbasic Mar 28, 2024
78880de
Merge branch 'emilk:master' into master
rustbasic Mar 29, 2024
01ba2ec
Merge branch 'emilk:master' into master
rustbasic Mar 29, 2024
0ae2451
Merge branch 'emilk:master' into master
rustbasic Mar 29, 2024
e6c84ce
Merge branch 'emilk:master' into master
rustbasic Mar 30, 2024
821dff0
Update epi_integration.rs
rustbasic Mar 30, 2024
eecfafd
Merge branch 'emilk:master' into master
rustbasic Mar 30, 2024
cbb5ac7
Merge branch 'emilk:master' into master
rustbasic Mar 30, 2024
07b5143
Merge branch 'emilk:master' into master
rustbasic Mar 31, 2024
3313633
Update epi_integration.rs
rustbasic Mar 31, 2024
90b968c
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
13af44f
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
5d95f09
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
4be440a
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
1ef0e10
Merge branch 'emilk:master' into master
rustbasic Apr 2, 2024
6541324
Merge branch 'emilk:master' into master
rustbasic Apr 2, 2024
8abc161
Merge branch 'emilk:master' into master
rustbasic Apr 3, 2024
1b21742
Merge branch 'emilk:master' into master
rustbasic Apr 4, 2024
052bb68
Merge branch 'emilk:master' into master
rustbasic Apr 5, 2024
64b0493
Update lib.rs
rustbasic Apr 7, 2024
93aa0cc
Update input.rs
rustbasic Apr 7, 2024
d29de83
Update input.rs
rustbasic Apr 7, 2024
a57e2f0
Update input.rs
rustbasic Apr 7, 2024
78cac96
Update input.rs
rustbasic Apr 7, 2024
604d22a
Update input.rs
rustbasic Apr 7, 2024
abe28d9
Update input.rs
rustbasic Apr 7, 2024
a00b29b
Merge branch 'emilk:master' into patch38
rustbasic Apr 19, 2024
e8a6d97
Merge branch 'emilk:master' into patch38
rustbasic Apr 21, 2024
d0d38e0
Update input.rs
rustbasic Apr 22, 2024
8285f50
Merge branch 'emilk:master' into patch38
rustbasic Apr 22, 2024
ef7afd0
Merge branch 'emilk:master' into patch38
rustbasic Apr 22, 2024
0889156
Merge branch 'emilk:master' into patch38
rustbasic Apr 23, 2024
7d02e31
Merge branch 'emilk:master' into patch38
rustbasic Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ impl State {
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.mac_cmd = super_;
self.egui_input.modifiers.command = if cfg!(target_os = "macos") {
super_
} else {
Expand Down
36 changes: 32 additions & 4 deletions crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ pub struct Modifiers {
/// Either of the shift keys are down.
pub shift: bool,

/// The Mac ⌘ Command key. Should always be set to `false` on other platforms.
/// The Mac ⌘ Command key. Is the super key on other platforms.
pub mac_cmd: bool,

/// On Windows and Linux, set this to the same value as `ctrl`.
Expand Down Expand Up @@ -651,20 +651,48 @@ impl Modifiers {
self.alt && self.ctrl && self.shift && self.command
}

/// Is alt the only pressed button?
#[inline]
pub fn alt_only(&self) -> bool {
self.alt && !(self.ctrl || self.shift || self.command)
}

/// Is ctrl the only pressed button?
#[inline]
pub fn ctrl_only(&self) -> bool {
self.ctrl && !(self.alt || self.shift || self.command)
}

/// Is shift the only pressed button?
#[inline]
pub fn shift_only(&self) -> bool {
self.shift && !(self.alt || self.command)
self.shift && !(self.alt || self.ctrl || self.command)
}

/// Is super the only pressed button?
#[inline]
pub fn super_only(&self) -> bool {
self.mac_cmd && !(self.alt || self.ctrl || self.shift)
}

/// true if only [`Self::mac_cmd`] is pressed on `MacOs`.
#[inline]
pub fn mac_cmd_only(&self) -> bool {
if !cfg!(target_os = "macos") {
return false;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use the compile-time target_os in egui, since that won't work on wasm32. That's why we have ctx.os()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.os() didn't seem to work here.
Let me check again.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need this check at all. Let's just define mac_cmd to mean super?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to

    pub fn mac_cmd_only(&self) -> bool {
        self.super_only()
    }


self.mac_cmd && !(self.alt || self.ctrl || self.shift)
}

/// true if only [`Self::ctrl`] or only [`Self::mac_cmd`] is pressed.
#[inline]
pub fn command_only(&self) -> bool {
!self.alt && !self.shift && self.command
self.command && !(self.alt || self.shift)
}

/// Checks that the `ctrl/cmd` matches, and that the `shift/alt` of the argument is a subset
/// of the pressed ksey (`self`).
/// of the pressed key (`self`).
///
/// This means that if the pattern has not set `shift`, then `self` can have `shift` set or not.
///
Expand Down