forked from joejulian/gio
app: detect fullscreen mode for macOS and Windows
When an application goes into or out of fullscreen mode, Gio now emits a ConfigEvent with the current window mode. Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -679,6 +679,10 @@ func UpdateWindow(hwnd syscall.Handle) {
|
||||
_UpdateWindow.Call(uintptr(hwnd))
|
||||
}
|
||||
|
||||
func (p WindowPlacement) Rect() Rect {
|
||||
return p.rcNormalPosition
|
||||
}
|
||||
|
||||
// issue34474KeepAlive calls runtime.KeepAlive as a
|
||||
// workaround for golang.org/issue/34474.
|
||||
func issue34474KeepAlive(v interface{}) {
|
||||
|
||||
@@ -97,6 +97,11 @@ static void toggleFullScreen(CFTypeRef windowRef) {
|
||||
[window toggleFullScreen:nil];
|
||||
}
|
||||
|
||||
static NSWindowStyleMask getWindowStyleMask(CFTypeRef windowRef) {
|
||||
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||
return [window styleMask];
|
||||
}
|
||||
|
||||
static void closeWindow(CFTypeRef windowRef) {
|
||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||
[window performClose:nil];
|
||||
@@ -227,10 +232,20 @@ func (w *window) WriteClipboard(s string) {
|
||||
C.writeClipboard(chars, C.NSUInteger(len(u16)))
|
||||
}
|
||||
|
||||
func (w *window) updateWindowMode() {
|
||||
style := int(C.getWindowStyleMask(w.window))
|
||||
if style&C.NSWindowStyleMaskFullScreen > 0 {
|
||||
w.config.Mode = Fullscreen
|
||||
} else {
|
||||
w.config.Mode = Windowed
|
||||
}
|
||||
}
|
||||
|
||||
func (w *window) Configure(options []Option) {
|
||||
screenScale := float32(C.getScreenBackingScale())
|
||||
cfg := configFor(screenScale)
|
||||
prev := w.config
|
||||
w.updateWindowMode()
|
||||
cnf := w.config
|
||||
cnf.apply(cfg, options)
|
||||
cnf.Size = cnf.Size.Div(int(screenScale))
|
||||
@@ -473,6 +488,20 @@ func gio_onShow(view C.CFTypeRef) {
|
||||
w.setStage(system.StageRunning)
|
||||
}
|
||||
|
||||
//export gio_onFullscreen
|
||||
func gio_onFullscreen(view C.CFTypeRef) {
|
||||
w := mustView(view)
|
||||
w.config.Mode = Fullscreen
|
||||
w.w.Event(ConfigEvent{Config: w.config})
|
||||
}
|
||||
|
||||
//export gio_onWindowed
|
||||
func gio_onWindowed(view C.CFTypeRef) {
|
||||
w := mustView(view)
|
||||
w.config.Mode = Windowed
|
||||
w.w.Event(ConfigEvent{Config: w.config})
|
||||
}
|
||||
|
||||
//export gio_onAppHide
|
||||
func gio_onAppHide() {
|
||||
for _, w := range viewMap {
|
||||
|
||||
@@ -23,6 +23,14 @@ __attribute__ ((visibility ("hidden"))) CALayer *gio_layerFactory(void);
|
||||
NSWindow *window = (NSWindow *)[notification object];
|
||||
gio_onShow((__bridge CFTypeRef)window.contentView);
|
||||
}
|
||||
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
|
||||
NSWindow *window = (NSWindow *)[notification object];
|
||||
gio_onFullscreen((__bridge CFTypeRef)window.contentView);
|
||||
}
|
||||
- (void)windowWillExitFullScreen:(NSNotification *)notification {
|
||||
NSWindow *window = (NSWindow *)[notification object];
|
||||
gio_onWindowed((__bridge CFTypeRef)window.contentView);
|
||||
}
|
||||
- (void)windowDidChangeScreen:(NSNotification *)notification {
|
||||
NSWindow *window = (NSWindow *)[notification object];
|
||||
CGDirectDisplayID dispID = [[[window screen] deviceDescription][@"NSScreenNumber"] unsignedIntValue];
|
||||
|
||||
+33
-10
@@ -282,6 +282,27 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
||||
case windows.SIZE_MINIMIZED:
|
||||
w.setStage(system.StagePaused)
|
||||
case windows.SIZE_MAXIMIZED, windows.SIZE_RESTORED:
|
||||
var triggerEvent bool
|
||||
// Check the window size change.
|
||||
var r windows.Rect
|
||||
windows.GetClientRect(w.hwnd, &r)
|
||||
size := image.Point{
|
||||
X: int(r.Right - r.Left),
|
||||
Y: int(r.Bottom - r.Top),
|
||||
}
|
||||
if size != w.config.Size {
|
||||
w.config.Size = size
|
||||
triggerEvent = true
|
||||
}
|
||||
// Check the window mode.
|
||||
mode := w.config.Mode
|
||||
w.updateWindowMode()
|
||||
if mode != w.config.Mode {
|
||||
triggerEvent = true
|
||||
}
|
||||
if triggerEvent {
|
||||
w.w.Event(ConfigEvent{Config: w.config})
|
||||
}
|
||||
w.setStage(system.StageRunning)
|
||||
}
|
||||
case windows.WM_GETMINMAXINFO:
|
||||
@@ -426,16 +447,6 @@ func (w *window) setStage(s system.Stage) {
|
||||
}
|
||||
|
||||
func (w *window) draw(sync bool) {
|
||||
var r windows.Rect
|
||||
windows.GetClientRect(w.hwnd, &r)
|
||||
size := image.Point{
|
||||
X: int(r.Right - r.Left),
|
||||
Y: int(r.Bottom - r.Top),
|
||||
}
|
||||
if size != w.config.Size {
|
||||
w.config.Size = size
|
||||
w.w.Event(ConfigEvent{Config: w.config})
|
||||
}
|
||||
if w.config.Size.X == 0 || w.config.Size.Y == 0 {
|
||||
return
|
||||
}
|
||||
@@ -492,10 +503,22 @@ func (w *window) readClipboard() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *window) updateWindowMode() {
|
||||
p := windows.GetWindowPlacement(w.hwnd)
|
||||
r := p.Rect()
|
||||
mi := windows.GetMonitorInfo(w.hwnd)
|
||||
if r == mi.Monitor {
|
||||
w.config.Mode = Fullscreen
|
||||
} else {
|
||||
w.config.Mode = Windowed
|
||||
}
|
||||
}
|
||||
|
||||
func (w *window) Configure(options []Option) {
|
||||
dpi := windows.GetSystemDPI()
|
||||
cfg := configForDPI(dpi)
|
||||
prev := w.config
|
||||
w.updateWindowMode()
|
||||
cnf := w.config
|
||||
cnf.apply(cfg, options)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user