Window on top of the StatusBar?

Mac OSX specific forum
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Window on top of the StatusBar?

Post by deseven »

Hello.

I wrote this code as an example, but can't figure out how to override screen boundaries:

Code: Select all

ExamineDesktops()

CreateImage(0,DesktopWidth(0),22,32)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,DesktopWidth(0),22,RGBA(213,74,102,100))
StopDrawing()

OpenWindow(0,0,0,DesktopWidth(0),22,"test",#PB_Window_BorderLess)
CocoaMessage(0,WindowID(0),"setLevel:",20)
CocoaMessage(0,WindowID(0),"setOpaque:",#NO)
CocoaMessage(0,WindowID(0),"setBackgroundColor:",CocoaMessage(0,0,"NSColor colorWithPatternImage:",ImageID(0)))
CocoaMessage(0,WindowID(0),"setMovableByWindowBackground:",#NO)
CocoaMessage(0,WindowID(0),"setHasShadow:",#NO)
CocoaMessage(0,WindowID(0),"setIgnoresMouseEvents:",#YES)

Repeat
  Delay(10)
  i + 3
  ResizeWindow(0,-i,0,#PB_Ignore,#PB_Ignore)
  WindowEvent()
  If i = DesktopWidth(0) : Break : EndIf
Until ev = #PB_Event_CloseWindow
Can someone port this solution to PB?
Last edited by deseven on Tue Jan 12, 2016 12:36 pm, edited 1 time in total.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Window on top of the StatusBar?

Post by Danilo »

Looks like you have to use at least 24 for setLevel on El Capitan.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Window on top of the StatusBar?

Post by deseven »

It works! Thanks!
Where did you find that constant?
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Window on top of the StatusBar?

Post by Danilo »

deseven wrote:Where did you find that constant?
Trial & Error. ;)

The correct method:

Code: Select all

Import ""
    CGWindowLevelForKey(key)
EndImport

Enumeration CGCommonWindowLevelKey
   #kCGBaseWindowLevelKey              = 0
   #kCGMinimumWindowLevelKey
   #kCGDesktopWindowLevelKey
   #kCGBackstopMenuLevelKey
   #kCGNormalWindowLevelKey
   #kCGFloatingWindowLevelKey
   #kCGTornOffMenuWindowLevelKey
   #kCGDockWindowLevelKey
   #kCGMainMenuWindowLevelKey
   #kCGStatusWindowLevelKey
   #kCGModalPanelWindowLevelKey
   #kCGPopUpMenuWindowLevelKey
   #kCGDraggingWindowLevelKey
   #kCGScreenSaverWindowLevelKey
   #kCGMaximumWindowLevelKey
   #kCGOverlayWindowLevelKey
   #kCGHelpWindowLevelKey
   #kCGUtilityWindowLevelKey
   #kCGDesktopIconWindowLevelKey
   #kCGCursorWindowLevelKey
   #kCGAssistiveTechHighWindowLevelKey
   #kCGNumberOfWindowLevelKeys 
EndEnumeration
   
NSNormalWindowLevel      = CGWindowLevelForKey(#kCGNormalWindowLevelKey)
NSFloatingWindowLevel    = CGWindowLevelForKey(#kCGFloatingWindowLevelKey)
NSSubmenuWindowLevel     = CGWindowLevelForKey(#kCGTornOffMenuWindowLevelKey)
NSTornOffMenuWindowLevel = CGWindowLevelForKey(#kCGTornOffMenuWindowLevelKey)
NSMainMenuWindowLevel    = CGWindowLevelForKey(#kCGMainMenuWindowLevelKey)
NSStatusWindowLevel      = CGWindowLevelForKey(#kCGStatusWindowLevelKey)
NSModalPanelWindowLevel  = CGWindowLevelForKey(#kCGModalPanelWindowLevelKey)
NSPopUpMenuWindowLevel   = CGWindowLevelForKey(#kCGPopUpMenuWindowLevelKey)
NSScreenSaverWindowLevel = CGWindowLevelForKey(#kCGScreenSaverWindowLevelKey)
NSDockWindowLevel        = CGWindowLevelForKey(#kCGDockWindowLevelKey)

Debug NSMainMenuWindowLevel

; that's what you should use, according to your linked article at stackoverflow:
Debug NSMainMenuWindowLevel + 2
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Window on top of the StatusBar?

Post by deseven »

That's really useful, thanks again!
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Window on top of the StatusBar?

Post by Danilo »

I think it is best you really use:

Code: Select all

NSMainMenuWindowLevel    = CGWindowLevelForKey(#kCGMainMenuWindowLevelKey)
...
CocoaMessage(0,WindowID(0),"setLevel:", NSMainMenuWindowLevel + 2)
Because CGWindowLevelForKey() is an OS function, it could return different results on different OS versions.
So better don't hardcode '24' or '26'.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Window on top of the StatusBar?

Post by deseven »

Sure, that's why i asked you where did you get that constant.
No one knows what apple will do in the next os x version... :)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Window on top of the StatusBar?

Post by wilbert »

Depending on what you exactly want to create, you could also use NSScreenSaverWindowLevel .
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Window on top of the StatusBar?

Post by deseven »

Nothing special. I just watched this video and, out of curiosity, decided to learn how it's done.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Window on top of the StatusBar?

Post by Danilo »

deseven wrote:Nothing special. I just watched this video and, out of curiosity, decided to learn how it's done.
Wouldn't it be better to Resize the Window Width then?
You move the Window, and it appears on my left screen.

Also had to change:

Code: Select all

  If i = DesktopWidth(0) : Break : EndIf
to:

Code: Select all

  If i => DesktopWidth(0) : Break : EndIf
otherwise it never ends.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Window on top of the StatusBar?

Post by deseven »

Of course there is a huge room for improvements. For example, it's better to get the system bar height from cocoa, instead of defining it manually.
But i wrote my example in 5 minutes. I didn't think about multi-monitor configurations or other stuff and i don't want to. It's just a proof-of-concept.
I did what i wanted with your help and that's it, nothing more, nothing less.
Post Reply