-
Notifications
You must be signed in to change notification settings - Fork 950
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
subclass windows in macos so they can be made resizable even with no decorations #408
subclass windows in macos so they can be made resizable even with no decorations #408
Conversation
fixes rust-windowing#368 The subclassing logic was copied from servo's fork of glutin: https://github.com/servo/glutin/blob/63026a0f4c8ba8bdc40787f8305ab008e5eb45e3/src/api/cocoa/mod.rs#L418
src/platform/macos/window.rs
Outdated
decl.add_method(sel!(canBecomeMainWindow), yes as extern fn(&Object, Sel) -> BOOL); | ||
decl.add_method(sel!(canBecomeKeyWindow), yes as extern fn(&Object, Sel) -> BOOL); | ||
decl.add_method(sel!(mouseDownCanMoveWindow), yes as extern fn(&Object, Sel) -> BOOL); | ||
decl.add_method(sel!(isMovableByWindowBackground), yes as extern fn(&Object, Sel) -> 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.
Are mouseDownCanMoveWindow
and isMovableByWindowBackground
necessary?
Does the window move when you click and drag anywhere in the window? If so, is that the behavior you want. And is this the behavior we want when there is a titlebar?
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.
Great point, and I also see that there's a separate platform attribute movable_by_window_background
that already handles that independently. I'll remove those.
examples/window.rs
Outdated
|
||
fn main() { | ||
let mut events_loop = winit::EventsLoop::new(); | ||
|
||
let _window = winit::WindowBuilder::new() | ||
.with_title("A fantastic window!") | ||
.with_decorations(false) |
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.
Not sure we want that in the example.
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.
yup, that was just from my testing, I've removed it
The window is not movable at that point. I'm not 100% sure what kind of behavior we want to achieve here. Like… how will drag-to-move work, or should we keep the window buttons, the rounded corner and the shadow. But maybe adding these masks will make the window look better?
|
To be clear, this behavior is with an explicit
I've tested with .with_movable_by_window_background(true)
.with_decorations(false) and that creates an undecorated window that is movable by dragging anywhere in the window. Maybe it makes sense for most or all of those separate masks to be granularly configurable as separate platform attribute methods, with I'd be happy to add that to this PR if that's the direction we want to go. I think it makes the configuration story for downstream projects a little complicated, though. E.g., currently alacritty just exposes a platform-agnostic boolean |
So there are 3 different setups:
winit only have one switch. So we need to pick between Let's go for the current setup (nothing). If anyone wants to add back the window controls, they can use |
You moved from NSFullSizeContentViewWindowMask to NSBorderlessWindowMask and removed the closable and miniaturizable masks. Can you explain exactly why these were necessary? |
My understanding of |
So I think this PR achieves:
While #389 would allow:
And I think it makes sense to call "nothing + no round borders" |
Ok. That works for me. @tomaka happy with these changes? |
Are we sure this behavior is something we want implicitly true with the |
@Osspial fair question. I guess it depends on what Also, iiuc, #389 would offer more granular controls over the masks such that you could still achieve non-resizeable borderless windows. |
Both scenario are covered. Both scenario are valid. It's a matter of what we do by default, what the expectation is. I would recommend to land this as it is, and in #389 add enough documentation / examples to explain how to achieve both behaviors. |
Anything blocking this from merging? @tomaka ? |
I'm okay with adding an option to make borderless windows resizable, but my biggest issue is that it both changes the current default behavior and makes the default behavior inconsistent across platforms. Also, I could be reading the diff incorrectly, but there doesn't seem to be a way to configure it to use the current behavior, which seems like an important thing to have. EDIT: @sodiumjoe you mentioned that #389 would add the ability to create the current behavior. How so? The documentation doesn't suggest that it does, but I can't say I'm versed enough in OSX platform development to tell if the underlying code lets you do this. |
My understanding is that borderless windows on windows and linux are resizable through other means, just not by dragging the borders (because the borders aren't there). Please correct me if I'm wrong. If this is the case, then I think neither behavior is perfectly consistent across platforms. In fact, I'm not sure it's possible to achieve this in macos (i.e. borderless windows that are not resizeable by dragging the edges of the window, but resizeable through other means, like a window manager). The more granular control is represented by #389, not this PR. |
Testing it, it looks like borderless windows on Windows are completely unresizable (or at least, I can't figure out a way to do it, even with keyboard shortcuts). On Linux, it seems to depend on the window manager. I tested in with Xfce, and was able to resize borderless windows with |
Note that under X11, it is technically impossible for a client to prevent the window manager from resizing its windows however it likes, so the existence of the possibility under some particular state shouldn't be read into too heavily. |
@Osspial I can see your point about it being slightly more consistent behavior across You're right that #389 doesn't have the settings for controlling this specifically, but I think it shows us how to use the window builder extension to expose all the granular settings that we would need to to allow it. |
@tomaka would love your input on this. If this is not acceptable as is, I would like to get started on the WindowBuilderExt work to get the resizable window with no titlebar that I want. |
Sorry, it's just that I don't really have a good opinion on this. |
@tomaka Hmmm, ok, so whom do I need to convince to get this merged or rejected? |
I'm just a user but I sure do hope that this get's merged as I would love to have borderless windows that I can move around and resize (with external programs in macOS). On that note @sodiumjoe If you could cut a release of your alacritty (with this change) that would be amazing. |
@oschrenk you just need to clone alacritty, glutin, and winit, then reference your local copy of winit from glutin, and glutin from alacritty:
in
I've been using this build of alacritty since I started this PR and really enjoying it. |
Maybe split this PR in 2. The Then as what to do with the mask, it doesn't really matter, you can always do that via |
I made a PR to @robertgzr 's branch for #389 to add another But it depends on this one getting merged first. |
@tomaka I believe all the objections to this PR have been resolved. |
@tomaka anything else necessary here? |
Needs a rebase or a merge, and I'll merge! |
@tomaka merged, thanks! |
I just tried testing this on macos and this seems to break the
macos 10.12.4 |
I can repro, I'll check it out |
@mitchmindtree fixed, can you verify? |
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.
Just tested the multiwindow example again and it seems to be working fine! Also checked the events that are being emitted and they seem to still look good too.
@mitchmindtree awesome, thanks for the quick verification! Anything else I need to do to get this merged? |
@tomaka just my weekly check-in on this PR 😄 |
@sodiumjoe this should have a CHANGELOG entry. |
@francesca64 done! |
|
@francesca64 Ok, how does it look now? |
@sodiumjoe Looks good, thanks! While I'm able to merge this, I'm not sure how comfortable @tomaka is with me merging things. With how busy he is, I want to do as much to help out with winit as I can, so I'm hoping for some clarification on his policy. ...that said, since he already approved this, I'll merge it. |
…pcwalton Make the fields of `TextMetrics` lazily calculated, and add an API that eliminates double layouts. This adds an extension to the HTML canvas API that allows you to pass the `TextMetrics` object returned by `measure_text()` to `fill_text()` and/or `stroke_text()` to draw the measured text without laying it out again. It improves performance on the `canvas_nanovg` demo.
* feat: support theme on macOS * Update support-theme-on-macos.md Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <[email protected]>
The subclassing logic was copied from servo's fork of glutin:
https://github.com/servo/glutin/blob/63026a0f4c8ba8bdc40787f8305ab008e5eb45e3/src/api/cocoa/mod.rs#L418