Window Transparency? (Vibrancy)

It seems to me Apple has expanded the API – but the details are a bit hard to find. Where is NSFUllSizeContentViewWindowMask defined?

So, declaring the NSVisualEffectView is fairly easy (the example above is a Xojo window), but I’m still not that far with the view and subview handling– I can only manage to replace the complete view which is fairly useless except you want an empty window but with a vibrant background :wink:
Can anyone give me a hint how to handle the view hierarchy? Especially replacing the basic subview of a window?

@Norman: In the toolbar you can usually see it when you scroll contents upwards. Like this page: When the red image crosses the upper window border it gets reflected in Safari’s toolbar.

Here is an example which shows replacing the content view of a window with a scroll view so that you can scroll the window. The dame basic concept should apply to the NSVisualEffectView.

[quote=136166:@Norman Palardy]Interesting but I literally just yesterday scrubbed a drive clean and installed the release and mine looks nothing like the images posted
By default there doesn’t seem to be much translucency applied
I just booted it up now to see the differences but I can’t spot any translucency in the various apps mentioned[/quote]

I have opened the desktop pictures to compare, and the window is a lot less transluscent than the picture posted. The window bar barely shows a hint of the color behind it. It is there, but nowhere as visible as what Eduardo posted. Could it be some well hidden setting ?

Ulrich, are you saying that the following line of code you provided:

self.window.styleMask = self.window.styleMask | NSFullSizeContentViewWindowMask;

is Xcode, and needs to be converted into a declare, in order for the toolbar to obtain the translucency / vibrancy?

Thanks.

[quote=136102:@Richard Summers]Thanks guys - interesting information.
Jason, that seems like exactly what I was referring to. All we need now is a genius to convert that into a declare :slight_smile:

Thank you everyone - much appreciated.[/quote]
You should really check out the xDev article Michel is talking about, I explain how to get most of the Yosemite eye candy working in Xojo (Declares are included).

https://gumroad.com/l/DXbT

The next article will show you some tips on providing consistent interfaces with Mavericks & Yosemite (i.e. Declares to do the work for you).[quote=136174:@Ulrich Bogun]So, declaring the NSVisualEffectView is fairly easy (the example above is a Xojo window), but I’m still not that far with the view and subview handling– I can only manage to replace the complete view which is fairly useless except you want an empty window but with a vibrant background :wink:
Can anyone give me a hint how to handle the view hierarchy? Especially replacing the basic subview of a window?[/quote]
Check out the same article.

As for translucent toolbars, it does require a degree of understanding first. It works particularly well with a NSScrollView (which you have to tuck under the toolbar, but doing NSScrollViews in Xojo is a chore and also not advised.

If you want to see if my declares work before purchasing the magazine, check out my Backup To Go, which has been ready for Yosemite for about a month now. All the code I published in the magazine is what I used in my own apps.

[quote=136175:@Jason King]Here is an example which shows replacing the content view of a window with a scroll view so that you can scroll the window. The dame basic concept should apply to the NSVisualEffectView.
[/quote]

Please don’t swap out the content view with a scroll view. If you must muck with the view hierarchy, at least add the view as a child of the content view. It’s still unsupported, but it’s at least less horrible.

[quote=136185:@Sam Rowlands]You should really check out the xDev article Michel is talking about, I explain how to get most of the Yosemite eye candy working in Xojo (Declares are included).
[/quote]

Got it working using @Sam Rowlands article in XDev! Thanks Sam!

[quote=136184:@Richard Summers]Ulrich, are you saying that the following line of code you provided:

self.window.styleMask = self.window.styleMask | NSFullSizeContentViewWindowMask;

is Xcode, and needs to be converted into a declare, in order for the toolbar to obtain the translucency / vibrancy?
[/quote]
Hi Richard,
that‘s exactly how I read this. Unfortunately I have found no declaration of, phew, NSFullSizeContentViewWindowMask. NSWindow.stylemask is a bitmap mask creating by "OR"ing a few bits, so I have no simple enumeration to extend by +1 and try …

@Joe and @Jason: Yes, that’s the problem I have. I can read the view hierarchy and replace element 0 of the array, but writing it back has no influence on the appearance so I must be doing something wrong. The XDev article would be valuable, it seems, therefore:

@XDev distribution: Did you consider adding PayPal as payment method too? I own no credit card and therefore cannot buy that issue.

@Sam: Thanks a lot for the hint regarding Backup To Go. I have no doubt your article will be helpful, knowing your other snippets and helpful hints here.

Sam,
am I correct in understandiing that your article shows how to allow the window content (when scrolled), to become partly visible (but blurred) under the toolbar, AND also how to make the actual window background semi-transparent / foggy / vibrant (whatever the correct word is)?

:slight_smile:

Thanks.

[quote=136166:@Norman Palardy]Interesting but I literally just yesterday scrubbed a drive clean and installed the release and mine looks nothing like the images posted
By default there doesn’t seem to be much translucency applied
I just booted it up now to see the differences but I can’t spot any translucency in the various apps mentioned[/quote]

I see them in a recent MBA, but can’t see them in an old MBA and an even older iMac. I’m assuming a lot of this requires heavy GPU acceleration and it’s forcefully disabled in older hardware (or perhaps only works in Retina, I could try and verify that).

The screenshots come straight from John Siracusa’s review, so they could be from a prerelease version or he may have tweaked the images to emphasize his explications. I’ll try asking him later.

I’m running a 2013 Retina MBP so I can’t imagine theres an issue with hardware

I think the setting is not that hidden. This is what I have implemented so far (a bit too much; but I couldn’t make the view hierarchy work yet so there are some experimental declares):

[code]Sub Effect(Material as EffectMaterial, BlendingMode as EffectBlendingMode, State as EffectState)
// Sets up a NSVisualEffectView for the Window

#if targetmacos

dim EffectViewClass as Ptr = NSClassFromString ("NSVisualEffectView")
if EffectViewClass <> NIL then // we have at least OS X 10.10
  declare function initWithFrame lib CocoaLib selector "initWithFrame:" (id as ptr, frame as nsrect) as ptr
  declare sub setBlendingMode lib CocoaLib selector "setBlendingMode:" (id as ptr, mode as EffectBlendingMode)
  declare sub setState lib CocoaLib selector "setState:" (id as ptr, mode as EffectState)
  declare sub setMaterial lib CocoaLib selector "setMaterial:" (id as ptr, mode as EffectMaterial)
  declare sub addSubViewrelativeto lib CocoaLib selector "addSubview:positioned:relativeTo:" (id as ptr, view as ptr, position as integer, relativeTo as Ptr)
  declare sub addSubView lib CocoaLib selector "addSubview:" (id as ptr, view as ptr)
  
  declare sub replaceSubviewWith lib CocoaLib selector "replaceSubview:with:" (id as ptr, view as Ptr)
  declare function subviews lib CocoaLib selector "subviews" (id as ptr) as ptr
  declare function objectAtIndex lib CocoaLib selector "objectAtIndex:" (id as ptr, index as integer) as Ptr
  declare sub setSubviews lib CocoaLib selector "setSubviews:" (id as ptr, subviews as ptr)
  declare sub setWantsLayer lib CocoaLib selector "setWantsLayer:" (id as ptr, value as boolean)
  declare sub setLayer lib CocoaLib selector "setLayer:" (id as ptr, layer as ptr)
  
  dim WindowEffectView as Ptr = initWithFrame (alloc(EffectViewClass), FrameRect)
  setWantsLayer WindowEffectView, true
  setBlendingMode WindowEffectView, blendingmode
  setState WindowEffectView, state
  setMaterial WindowEffectView, Material
  // dim SubViewArray as Ptr = subviews (contentview)
  // dim backgroundview as ptr = objectAtIndex (SubViewArray, 0) // get the first NSView (that is the background)
  // addsubview contentview, WindowEffectView, -1, NIL
  // replaceSubviewWith backgroundview, WindowEffectView
  // setSubviews contentView, WindowEffectView
  contentView = WindowEffectView
  //setLayer contentview, WindowEffectView
  // addSubView contentView, WindowEffectView
end if

#endif
End Sub[/code]

You see there’s the properties Material, BlendingMode and State that affect the look of the VisualEffectView. I think the differences you notices have to do with those settings.

@Joe Ranieri What is the least horrible way to go about this then (besides not using a scroll view)?

I was also intrigued by this because I realised that HUD windows done using the MacOSLib declares allows to create “blurred” transparent windows.
The declare is basically using ‘OR’ mask of parameters to set the proper values. I thus modified the HUD declare (I have let the original code as comments underneath) to render it more generic (note that the HUD sets the value to 811 in the original version)

[code]Sub SetWinMask(pWindow As Window, MaskValue as UInt32)

// only works on floating (palette) windows (frame = 3 & 7)
#if TargetCocoa
'if ((pWindow.Frame = kWindowFrameFloatingWindow) OR (pWindow.Frame = kWindowFrameGlobalFloatingWindow)) then
DIM tStyleMask As UInt32 = MaskValue// OR 1 OR 16 //kWindowMaskHUD OR kWindowMaskTitled OR kWindowMaskUtility
'if (pWindow.Resizeable) then tStyleMask = tStyleMask or kWindowMaskResizable
'if (pWindow.CloseButton) then tStyleMask = tStyleMask or kWindowMaskClosable

soft declare sub setStyleMask lib "Cocoa" selector "setStyleMask:" (WindowRef As WindowPtr, Mask As UInt32)
setStyleMask pWindow, tStyleMask
'end if

#endif

// posted

End Sub

[/code]

I tried to understand how to “OR” the values properly but then decided to be more “empirical” and test several.
if you want to play, you can use the very simple application that I use to explore Window_Mask_test
Do not be afraid, some parameters make the application crash…

I thus found a few interesting parameters to use in SetWinMask:
321 : Window with white blurred background, no bar or button on window. The window can be moved though
8211 : HUD black blurred
8212 : HUD black transparent (not blurerd)
8213 : HUD Black blur no button

A strange one
20032 if the window is fullscreen then what is blurred in not what is under the window but the desktop picture.

if anyone find other interesting values…
In particular, I did not find a way to have a blurred background AND a title bar.

I meant in the out of the box Yosemite apps, the degree of vibrancy seems to be different according to versions. I never saw what I see in Eduardo pictures, so I thought there may be somewhere in the preferences a setting where one can select how much vibrancy is used. A bit like Aero on Windows, where the user can choose if he wants semi transparent window bars or not.

Thank you for your code, though :slight_smile:

Sam, just to let you know - I ran your Backup To Go, and there was no transparency / vibrancy at all ???
I am using the latest version of OS X.

[quote=136362:@Ulrich Bogun]I think the setting is not that hidden. This is what I have implemented so far (a bit too much; but I couldn’t make the view hierarchy work yet so there are some experimental declares):

<snip>

You see there’s the properties Material, BlendingMode and State that affect the look of the VisualEffectView. I think the differences you notices have to do with those settings.[/quote]

I figured out how to make this work. You were very close with your declares.

[code] // Sets up a NSVisualEffectView for the Window
#if targetmacos
declare function NSClassFromString lib CocoaLib (className as CFStringRef) as ptr
declare function alloc lib CocoaLib selector “alloc” (classRef as ptr) as ptr
dim EffectViewClass as Ptr = NSClassFromString (“NSVisualEffectView”)
if EffectViewClass <> NIL then // we have at least OS X 10.10
declare function initWithFrame lib CocoaLib selector “initWithFrame:” (id as ptr, frame as nsrect) as ptr

  declare sub addSubViewrelativeto lib CocoaLib selector "addSubview:positioned:relativeTo:" (id as ptr, view as ptr, position as integer, relativeTo as Ptr)
  
  declare sub setAutoresizingMask lib CocoaLib selector "setAutoresizingMask:" (view as ptr, mask as integer)

  dim frameRect as NSRect
  frameRect.x = 0
  frameRect.y = 0
  frameRect.w = self.Width
  frameRect.h = self.Height
  dim WindowEffectView as ptr = initWithFrame(alloc(EffectViewClass),FrameRect)
  setAutoresizingMask(WindowEffectView,18)
  
  Declare function contentView lib CocoaLib selector "contentView" (mwindow as integer) as ptr
  dim contentViewPtr as ptr = contentView(self.Handle)
  addSubViewrelativeto(contentViewPtr,WindowEffectView,-1,nil)
  
end if

#endif[/code]

[quote=138116:@Richard Summers]Sam, just to let you know - I ran your Backup To Go, and there was no transparency / vibrancy at all ???
I am using the latest version of OS X.[/quote]
I was going to ask if you’re joking right, Backup To GO has ‘had’ vibrancy since the first DP and I’ve even written articles on it… So I fired up my Yosemite machine running GM and sure enough that vibrancy is now gone.

Today I don’t give a shit, I’m too sick (no really I am) and tired of chasing bugs and issues that crept in with the GM release. I’ve never had an OS update cause me so much grief and it all comes at a time when I have to make regular hospital trips.