2

How to create darker and larger shadow when window becomes active in borderless window?

I subclassed NSWindow and my window becomes main window and key window but that's not helping.. shadow still small. So maybe someone knows how to fix this? I also tried invalidate shadow, but that didn't help too..

Subclassed NSWindow:

- (id)initWithContentRect:(NSRect)contentRect
            styleMask:(NSUInteger)windowStyle
              backing:(NSBackingStoreType)bufferingType
                defer:(BOOL)flag
{

    self = [super initWithContentRect: contentRect
                  styleMask: NSBorderlessWindowMask 
                    backing: NSBackingStoreBuffered
                      defer: NO];

    if(self)
    {
        [self setHasShadow:YES];

        [self setBackgroundColor:[NSColor clearColor]];
        [self setOpaque:NO];
    }   

return self;
}
Justin Boo
  • 10,132
  • 8
  • 50
  • 71

3 Answers3

2

This is tied to the window's styleMask. If it is set to NSTitledWindowMask window will get a larger shadow.

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
1

In general I think Dalmazio is correct in his observation that borderless windows have a less pronounced shadow for whatever reason. Maybe file radar with apple.

Matt
  • 203
  • 1
  • 12
1

If this were my problem, I'd probably turn the shadow property off for the borderless window and then handle the shadow drawing from a display function within my NSWindow subclass (making sure to call [super display] so the various content & sub views get their own draw methods called).

Here's a potentially related question with an answer for you to consider.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Thanks for quick response. Hmm.. thats not solved the problem.. in your example which You gave me is the same problem (RoundTransparentWindow project). In this project is always small shadow just like in my app. I tried Your sugestion [super display], but this also didn't help. – Justin Boo Jan 20 '12 at 22:09
  • What I was saying was that you should do the shadow drawing yourself, when `display` is called. AFAIK, that's the only way you're going to get a "darker larger shadow" than what the OS provides. When `display` is called, get the rect of the window frame, and then figure out how to draw a rectangle just outside of those bounds. – Michael Dautermann Jan 20 '12 at 22:22
  • Hmm.. thanks for Your suggestions I will try it to do this. +1 – Justin Boo Jan 20 '12 at 22:36
  • 2
    I have a similar problem since I'm defining my own custom borderless window and want to draw shadows to mimic Apple's window shadows. I've noticed that the default shadow that is drawn seems to be the same as the shadow Apple draws for all non-key windows (small). The much larger, richer shadow for key windows does not appear to be available to custom borderless windows. Perhaps an oversight on Apple's part? Even with overriding -canBecomeKeyWindow and -canBecomeMainWindow to return YES. Let us know how it goes. – Dalmazio Jan 24 '12 at 12:45