Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Stop using NSFullSizeContentViewWindowMask to get borderless windows, #68

Merged
merged 1 commit into from
Feb 26, 2016

Conversation

pcwalton
Copy link

@pcwalton pcwalton commented Feb 3, 2016

because that disables the swap interval.

This hack is very simple but a little evil. We get the superview of the
content view, which is the NSThemeFrame, and install an OpenGL context
into it. NSThemeFrame is a private class, but we only call public
NSView APIs on it here, so this seems OK in terms of being supported
by Apple going forward.

The reason for using this hack as opposed to
NSFullSizeContentViewWindowMask is that the latter forces the window
to be Core Animation-backed, which results in us rendering to an off
screen surface. Not only does this inject another compositor into the
system, but it also results in us rendering to an off-screen surface,
disabling the swap interval.

This depends on a cocoa-rs upgrade to add a binding to the -[NSView superview] method.

Known issues:

  • The traffic light buttons are not drawn but still function if you
    click on them. This can be worked around in browser.html.
  • The top border is not rounded, although the shadow properly displays.
    This should be able to be worked around in browser.html.
  • The title bar reappears if you go to full screen and then go back.
    This is the most serious issue, but I suspect it'll be fixable and
    it's better than what we have right now.

This should fix servo/servo#9431.

r? @jdm

Review on Reviewable

@jdm
Copy link
Member

jdm commented Feb 3, 2016

This is way outside any of my limited Cocoa experience, sadly. @mstange do you have any feedback on this?

@pcwalton
Copy link
Author

pcwalton commented Feb 3, 2016

Let me see if I can actually fix the full screen issue since it's bugging me.

because that disables the swap interval.

This hack is very simple but a little evil. We get the superview of the
content view, which is the `NSThemeFrame`, and install an OpenGL context
into it.  `NSThemeFrame` is a private class, but we never speak its
name, we get to it with public APIs, and we only call public `NSView`
APIs on it, so this seems OK in terms of being supported by Apple going
forward.

Additionally, we remove the standard window buttons so that they
disappear and the user can't click them. This can also be done using
public APIs.

The reason for using this hack as opposed to
`NSFullSizeContentViewWindowMask` is that the latter forces the window
to be Core Animation-backed, which results in us rendering to an off
screen surface. Not only does this inject another compositor into the
system, but it also results in us rendering to an off-screen surface,
disabling the swap interval.

This depends on a `cocoa-rs` upgrade to add a binding to the `-[NSView
superview]` method.

Note that the top edge of the window is not rounded, although the shadow
is. Applications that wish to use this mode will need to round the top
edge themselves if they wish. (This is how Cocoa internally works:
rounding is done by the app, not the window manager.)

This should fix servo/servo#9431.
@pcwalton
Copy link
Author

pcwalton commented Feb 3, 2016

OK, seems to be fixed now. r? @mstange

@paulrouget
Copy link

The top border is not rounded, although the shadow properly displays. This should be able to be worked around in browser.html.

How? Using border-radius doesn't appear to work.

The title bar reappears if you go to full screen and then go back.

How did you manage to go fullscreen?

@pcwalton
Copy link
Author

pcwalton commented Feb 4, 2016

I'm not surprised that border radius doesn't work, though it should. I think it's straightforwardly fixable in WR.

As for full screen, that was an older version of the patch. We should be able to go full screen by calling the Cocoa API to do so, which we can expose to content JS.

@paulrouget
Copy link

I'll file followup issues once this lands.

@mstange
Copy link

mstange commented Feb 24, 2016

Nice and simple! I like it.
The way you're removing the buttons is probably a little brittle; I expect the modern Cocoa fullscreen method to put the buttons back, just like changing the window mask manually would. But I don't have a good solution for you at the moment, and you can still fix it once you run into it.

@pcwalton
Copy link
Author

@bors-servo: r+

(assuming mstange is a qualified reviewer here—if someone else wants to drop in feel free)

@bors-servo
Copy link

📌 Commit 5731ad2 has been approved by pcwalton

@bors-servo
Copy link

⌛ Testing commit 5731ad2 with merge 565e8a1...

bors-servo pushed a commit that referenced this pull request Feb 26, 2016
Stop using `NSFullSizeContentViewWindowMask` to get borderless windows,

because that disables the swap interval.

This hack is very simple but a little evil. We get the superview of the
content view, which is the `NSThemeFrame`, and install an OpenGL context
into it.  `NSThemeFrame` is a private class, but we only call public
`NSView` APIs on it here, so this seems OK in terms of being supported
by Apple going forward.

The reason for using this hack as opposed to
`NSFullSizeContentViewWindowMask` is that the latter forces the window
to be Core Animation-backed, which results in us rendering to an off
screen surface. Not only does this inject another compositor into the
system, but it also results in us rendering to an off-screen surface,
disabling the swap interval.

This depends on a `cocoa-rs` upgrade to add a binding to the `-[NSView
superview]` method.

Known issues:

* The traffic light buttons are not drawn but still function if you
  click on them. This can be worked around in browser.html.

* The top border is not rounded, although the shadow properly displays.
  This should be able to be worked around in browser.html.

* The title bar reappears if you go to full screen and then go back.
  This is the most serious issue, but I suspect it'll be fixable and
  it's better than what we have right now.

This should fix servo/servo#9431.

r? @jdm

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/glutin/68)
<!-- Reviewable:end -->
@bors-servo
Copy link

☀️ Test successful - travis

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

With --no-native-titlebar, requestAnimationFrame runs at 500 FPS
5 participants