Skip to content

Commit

Permalink
Merge pull request #77 from guzba/master
Browse files Browse the repository at this point in the history
mac, win32 floating window
  • Loading branch information
treeform authored Mar 14, 2022
2 parents 3640e2e + b56fb2c commit d6a3c65
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/windy/platforms/macos/macdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type
NSStringEncoding* = uint
NSStringEncodingConversionOptions* = uint
NSBitmapImageFileType* = uint
NSWindowLevel* = int

NSRect* = CGRect
NSPoint* = CGPoint
Expand Down Expand Up @@ -104,6 +105,8 @@ const
NSTrackingEnabledDuringMouseDrag* = 0x400.NSTrackingAreaOptions
NSUTF32StringEncoding* = 0x8c000100.NSStringEncoding
NSBitmapImageFileTypePNG* = 4.NSBitmapImageFileType
NSNormalWindowLevel* = 0.NSWindowLevel
NSFloatingWindowLevel* = 3.NSWindowLevel

var
NSApp* {.importc.}: NSApplication
Expand Down Expand Up @@ -218,6 +221,8 @@ objc:
proc toggleFullscreen*(self: NSWindow, _: ID)
proc invalidateCursorRectsForView*(self: NSWindow, _: NSView)
proc mouseLocationOutsideOfEventStream*(self: NSWindow): NSPoint
proc level*(self: NSWindow): NSWindowLevel
proc setLevel*(self: NSWindow, _: NSWindowLevel)
proc convertRectToBacking*(self: NSView, _: NSRect): NSRect
proc window*(self: NSView): NSWindow
proc bounds*(self: NSView): NSRect
Expand Down
14 changes: 14 additions & 0 deletions src/windy/platforms/macos/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ proc style*(window: Window): WindowStyle =
proc fullscreen*(window: Window): bool =
(window.inner.styleMask and NSWindowStyleMaskFullScreen) != 0

proc floating*(window: Window): bool =
window.inner.level == NSFloatingWindowLevel

proc contentScale*(window: Window): float32 =
autoreleasepool:
let
Expand Down Expand Up @@ -151,6 +154,17 @@ proc `fullscreen=`*(window: Window, fullscreen: bool) =
autoreleasepool:
window.inner.toggleFullscreen(0.ID)

proc `floating=`*(window: Window, floating: bool) =
if window.floating == floating:
return
autoreleasepool:
let level =
if floating:
NSFloatingWindowLevel
else:
NSNormalWindowLevel
window.inner.setLevel(level)

proc `size=`*(window: Window, size: IVec2) =
autoreleasepool:
let virtualSize = (size.vec2 / window.contentScale)
Expand Down
22 changes: 21 additions & 1 deletion src/windy/platforms/win32/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type
state: WindowState
trackMouseEventRegistered: bool
exitFullscreenInfo: ExitFullscreenInfo
isFloating: bool

hWnd: HWND
hdc: HDC
Expand Down Expand Up @@ -328,6 +329,9 @@ proc style*(window: Window): WindowStyle =
proc fullscreen*(window: Window): bool =
window.exitFullscreenInfo != nil

proc floating*(window: Window): bool =
window.isFloating

proc contentScale*(window: Window): float32 =
let dpi = GetDpiForWindow(window.hWnd)
result = dpi.float32 / defaultScreenDpi
Expand Down Expand Up @@ -432,7 +436,7 @@ proc `fullscreen=`*(window: Window, fullscreen: bool) =
let mi = window.monitorInfo
discard SetWindowPos(
window.hWnd,
HWND_TOPMOST,
HWND_TOP,
mi.rcMonitor.left,
mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left,
Expand Down Expand Up @@ -470,6 +474,22 @@ proc `fullscreen=`*(window: Window, fullscreen: bool) =
if maximized:
discard SendMessageW(window.hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0)

proc `floating=`*(window: Window, floating: bool) =
if window.floating == floating:
return

window.isFloating = floating

discard SetWindowPos(
window.hWnd,
if floating: HWND_TOPMOST else: HWND_NOTOPMOST,
0,
0,
0,
0,
SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE
)

proc `size=`*(window: Window, size: IVec2) =
if window.fullscreen:
return
Expand Down

0 comments on commit d6a3c65

Please sign in to comment.