-
Notifications
You must be signed in to change notification settings - Fork 947
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
implement focusable attribute for Window #4124
base: master
Are you sure you want to change the base?
Conversation
How keyboard input generally works with such windows or it doesn't and you have mostly pointer input? |
Yeah, they don't take keyboard focus, which is a feature - it allows you to interact with the overlay window without taking focus away from the current app. Imagine an on-screen keyboard, for example, we need to be able to click the keyboard buttons but have keyboard input still go to the app in the background. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macOS impl looks fine apart from the duplicated state. Requested changes because I'd like to see more docs, but am otherwise fine with the API.
/// | ||
/// The default is `true`. | ||
/// | ||
/// - **Windows:** Supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Add section ## Platform-specific
.
self.window.maybe_queue_on_main(move |w| w.set_focusable(focusable)) | ||
} | ||
|
||
/// Gets whether the window can be focused or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Link to set_focusable
.
/// | ||
/// - **Windows:** Supported. | ||
#[inline] | ||
pub fn set_focusable(&self, focusable: bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the semantics of the feature aren't clear just from reading the description here. Perhaps you could expand on how it works? Or state the example you gave in the PR (useful for ...).
In the absence of clear cross-platform semantics, I'd like if this could link to the underlying implementations (e.g. link to shouldDelayWindowOrderingForEvent:
for macOS, and others for the other platforms).
@@ -801,6 +809,7 @@ impl WinitView { | |||
forward_key_to_app: Default::default(), | |||
marked_text: Default::default(), | |||
accepts_first_mouse, | |||
focusable: focusable.into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I prefer Cell::new
explicitly.
focusable: focusable.into(), | |
focusable: Cell::new(focusable), |
if !self.ivars().focusable.get() { | ||
let mtm = MainThreadMarker::from(self); | ||
unsafe { | ||
NSApplication::sharedApplication(mtm).preventWindowOrdering(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It'd be nice with a comment here detailing why preventWindowOrdering
, an application-level method, is fine to call inside NSView
.
@@ -116,6 +116,7 @@ pub(crate) struct State { | |||
decorations: Cell<bool>, | |||
resizable: Cell<bool>, | |||
maximized: Cell<bool>, | |||
focusable: Cell<bool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid this state, query it from view.ivars().focusable instead.
changelog
module if knowledge of this change could be valuable to usersif focusable is false, a window won't take focus, even if you interact with it
this is very useful for always-on-top floating utility windows