app.dhover×461 error×22all
// macOS/AppKit F14 demo — window state transitions & the vetoable close
// (../../../features/f14-window-state.md).
// The deliverable is the ORDERED delegate-method + notification sequence for each
// state transition (zoom:, miniaturize:/deminiaturize:, toggleFullScreen:,
// orderOut:/orderFront:) plus the close contract (windowShouldClose: as the
// first-class veto, and the proof that -close skips the delegate ask while
// -performClose: honors it).
//
// Instrumentation: every NSWindowDelegate method the demo implements logs
// `delegate m=<method>` and a catch-all NSNotificationCenter observer
// (addObserver:selector:name:nil object:window) logs `note name=<NSWindow…>` —
// interleaving the two by timestamp yields the choreography per transition.
// A `phase=` tag carried on every line names the request being serviced.
// NSWindowDidUpdateNotification fires once per run-loop pass and would flood the
// log; it is counted and suppressed.
//
// A[ssh]: built/run on mac-bsn over SSH; the console-session lock state is read
// from CGSessionCopyCurrentDictionary (CGSSessionScreenIsLocked) and logged so
// findings can be labelled honestly (miniaturize/fullscreen behave differently
// when no one is watching).
//
// Modes: WSI_AUTO_EXIT=1 = bounded scripted run (the sequence below); without it
// the window stays up for a manual (Tier C) session. Headless-safe: prints
// `SKIP:` and exits 0 when there is no window server.
module 
(module) app
app
;
import
(package) core
core
.
(module) core.attribute

This module contains UDA's (User Defined Attributes) either used in the runtime or special UDA's recognized by compiler.

Attribute Name, Linkage, Description

gnuAbiTag, C++, Declares an ABI tag on a C++ symbol. mustuse,, Ensures that values of a struct or union type are not discarded. optional, Objective-C, Makes an Objective-C interface method optional. selector, Objective-C, Attaches an Objective-C selector to a method. standalone,, Marks a shared module constructor as not depending on any other module constructor being run first. weak,, Specifies that a global symbol should be emitted with weak linkage.

Source

core/attribute.d

@copyrightCopyright Jacob Carlborg 2015.@licenseBoost License 1.0@authorsJacob Carlborg
attribute
: selector;
module `core.attribute` import `selector` not found
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdio

D header file for C99 <stdio.h>

pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h

Source

core/stdc/stdio.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
stdio
:
(alias) app.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdlib

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/stdlib.h.html, stdlib.h

Source

core/stdc/stdlib.d

@copyrightCopyright Sean Kelly 2005 - 2014.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
stdlib
:
(alias) app.getenv = char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
;
import instrument : instr, instrInit, instrNowUs;
unable to read module `instrument` Expected 'instrument.d' or 'instrument/package.d' in one of the following import paths:
unable to read module `instrument` Expected 'instrument.d' or 'instrument/package.d' in one of the following import paths:
unable to read module `instrument` Expected 'instrument.d' or 'instrument/package.d' in one of the following import paths:
import objc.autorelease : autoreleasepool_push, autoreleasepool_pop; // objective-d
unable to read module `autorelease` Expected 'objc/autorelease.d' or 'objc/autorelease/package.d' in one of the following import paths:
unable to read module `autorelease` Expected 'objc/autorelease.d' or 'objc/autorelease/package.d' in one of the following import paths:
unable to read module `autorelease` Expected 'objc/autorelease.d' or 'objc/autorelease/package.d' in one of the following import paths:
import objc.rt : SEL;
unable to read module `rt` Expected 'objc/rt.d' or 'objc/rt/package.d' in one of the following import paths:
unable to read module `rt` Expected 'objc/rt.d' or 'objc/rt/package.d' in one of the following import paths:
unable to read module `rt` Expected 'objc/rt.d' or 'objc/rt/package.d' in one of the following import paths:
// --- Geometry ---------------------------------------------------------------------- extern (C) struct
(struct) app.NSPoint
NSPoint
{ double
(field) double app.NSPoint.x
x
,
(field) double app.NSPoint.y
y
;
} extern (C) struct
(struct) app.NSSize
NSSize
{ double
(field) double app.NSSize.width
width
,
(field) double app.NSSize.height
height
;
} extern (C) struct
(struct) app.NSRect
NSRect
{
(struct) app.NSPoint
NSPoint
(field) app.NSPoint app.NSRect.origin
origin
;
(struct) app.NSSize
NSSize
(field) app.NSSize app.NSRect.size
size
;
} // --- CoreGraphics / CoreFoundation C API ------------------------------------------- extern (C) nothrow @nogc { uint
uint app.CGMainDisplayID() nothrow @nogc
CGMainDisplayID
();
(struct) app.NSRect
NSRect
app.NSRect app.CGDisplayBounds(uint display) nothrow @nogc
CGDisplayBounds
(uint
(parameter) uint display
display
);
// Session dictionary: carries CGSSessionScreenIsLocked when the console is locked. void*
void* app.CGSessionCopyCurrentDictionary() nothrow @nogc
CGSessionCopyCurrentDictionary
();
void*
void* app.CFStringCreateWithCString(void* alloc, const(char)* s, uint encoding) nothrow @nogc
CFStringCreateWithCString
(void*
(parameter) void* alloc
alloc
, const(char)*
(parameter) const(char)* s
s
, uint
(parameter) uint encoding
encoding
);
void*
void* app.CFDictionaryGetValue(void* dict, void* key) nothrow @nogc
CFDictionaryGetValue
(void*
(parameter) void* dict
dict
, void*
(parameter) void* key
key
);
ubyte
ubyte app.CFBooleanGetValue(void* b) nothrow @nogc
CFBooleanGetValue
(void*
(parameter) void* b
b
);
void
void app.CFRelease(void* obj) nothrow @nogc
CFRelease
(void*
(parameter) void* obj
obj
);
void
void app.CGContextSetRGBFillColor(void* ctx, double r, double g, double b, double a) nothrow @nogc
CGContextSetRGBFillColor
(void*
(parameter) void* ctx
ctx
, double
(parameter) double r
r
, double
(parameter) double g
g
, double
(parameter) double b
b
, double
(parameter) double a
a
);
void
void app.CGContextFillRect(void* ctx, app.NSRect rect) nothrow @nogc
CGContextFillRect
(void*
(parameter) void* ctx
ctx
,
(struct) app.NSRect
NSRect
(parameter) app.NSRect rect
rect
);
} enum uint
(constant) uint app.kCFStringEncodingUTF8 = 134217984u
kCFStringEncodingUTF8
= 0x08000100;
// Logs lock state via the CGSSessionScreenIsLocked key (absent when unlocked). void
void app.logSessionLockState()
logSessionLockState
()
{ void*
(local variable) void* dict
dict
=
void* app.CGSessionCopyCurrentDictionary() nothrow @nogc
CGSessionCopyCurrentDictionary
();
if (
(local variable) void* dict
dict
is null)
{ instr("session", "lock_state=no_session_dictionary"); return; } void*
(local variable) void* kLocked
kLocked
=
void* app.CFStringCreateWithCString(void* alloc, const(char)* s, uint encoding) nothrow @nogc
CFStringCreateWithCString
(null, "CGSSessionScreenIsLocked",
(constant) uint app.kCFStringEncodingUTF8 = 134217984u
kCFStringEncodingUTF8
);
void*
(local variable) void* kConsole
kConsole
=
void* app.CFStringCreateWithCString(void* alloc, const(char)* s, uint encoding) nothrow @nogc
CFStringCreateWithCString
(null, "kCGSSessionOnConsoleKey",
(constant) uint app.kCFStringEncodingUTF8 = 134217984u
kCFStringEncodingUTF8
);
void*
(local variable) void* locked
locked
=
void* app.CFDictionaryGetValue(void* dict, void* key) nothrow @nogc
CFDictionaryGetValue
(
(local variable) void* dict
dict
,
(local variable) void* kLocked
kLocked
);
void*
(local variable) void* console
console
=
void* app.CFDictionaryGetValue(void* dict, void* key) nothrow @nogc
CFDictionaryGetValue
(
(local variable) void* dict
dict
,
(local variable) void* kConsole
kConsole
);
instr("session", "screen_locked=%d on_console=%d", locked !is null && CFBooleanGetValue(locked) ? 1 : 0, console !is null && CFBooleanGetValue(console) ? 1 : 0);
void app.CFRelease(void* obj) nothrow @nogc
CFRelease
(
(local variable) void* kLocked
kLocked
);
void app.CFRelease(void* obj) nothrow @nogc
CFRelease
(
(local variable) void* kConsole
kConsole
);
void app.CFRelease(void* obj) nothrow @nogc
CFRelease
(
(local variable) void* dict
dict
);
} // --- AppKit class declarations ----------------------------------------------------- extern (Objective-C): extern class
(class) app.NSObject
NSObject
class `app.NSObject` Objective-C classes not supported
{ } extern class
(class) app.NSString
NSString
:
(class) app.NSObject
NSObject
class `app.NSString` Objective-C classes not supported
{ static
(class) app.NSString
NSString
app.NSString app.NSString.alloc()
alloc
() @selector("alloc");
(class) app.NSString
NSString
app.NSString app.NSString.initWithUTF8String(const(char)* s)
initWithUTF8String
(const(char)*
(parameter) const(char)* s
s
) @selector("initWithUTF8String:");
const(char)*
const(char)* app.NSString.UTF8String()
UTF8String
() @selector("UTF8String");
} extern class
(class) app.NSNotification
NSNotification
:
(class) app.NSObject
NSObject
class `app.NSNotification` Objective-C classes not supported
{
(class) app.NSString
NSString
app.NSString app.NSNotification.name()
name
() @selector("name");
(class) app.NSObject
NSObject
app.NSObject app.NSNotification.object()
object
() @selector("object");
} extern class
(class) app.NSNotificationCenter
NSNotificationCenter
:
(class) app.NSObject
NSObject
class `app.NSNotificationCenter` Objective-C classes not supported
{ static
(class) app.NSNotificationCenter
NSNotificationCenter
app.NSNotificationCenter app.NSNotificationCenter.defaultCenter()
defaultCenter
() @selector("defaultCenter");
void
app.NSNotificationCenter.addObserver
addObserver
(
(class) app.NSObject
NSObject
observer, SEL sel,
(class) app.NSString
NSString
(parameter) NSString name
name
,
(class) app.NSObject
NSObject
(parameter) NSObject obj
obj
)
@selector("addObserver:selector:name:object:"); } extern class
(class) app.NSEvent
NSEvent
:
(class) app.NSObject
NSObject
class `app.NSEvent` Objective-C classes not supported
{ static
(class) app.NSEvent
NSEvent
app.NSEvent app.NSEvent.otherEventWithType(long type, app.NSPoint location, ulong modifierFlags, double timestamp, long windowNumber, app.NSObject context, short subtype, long data1, long data2)
otherEventWithType
(long
(parameter) long type
type
,
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint location
location
, ulong
(parameter) ulong modifierFlags
modifierFlags
,
double
(parameter) double timestamp
timestamp
, long
(parameter) long windowNumber
windowNumber
,
(class) app.NSObject
NSObject
(parameter) app.NSObject context
context
, short
(parameter) short subtype
subtype
,
long
(parameter) long data1
data1
, long
(parameter) long data2
data2
)
@selector("otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:"); } extern class
(class) app.NSTimer
NSTimer
:
(class) app.NSObject
NSObject
class `app.NSTimer` Objective-C classes not supported
{ static
(class) app.NSTimer
NSTimer
app.NSTimer.scheduledTimerWithTimeInterval
scheduledTimerWithTimeInterval
(double interval,
(class) app.NSObject
NSObject
target,
SEL sel,
(class) app.NSObject
NSObject
userInfo, bool repeats)
@selector("scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:"); } extern class
(class) app.NSApplication
NSApplication
:
(class) app.NSObject
NSObject
class `app.NSApplication` Objective-C classes not supported
{ static
(class) app.NSApplication
NSApplication
app.NSApplication app.NSApplication.sharedApplication()
sharedApplication
() @selector("sharedApplication");
void
void app.NSApplication.setActivationPolicy(long policy)
setActivationPolicy
(long
(parameter) long policy
policy
) @selector("setActivationPolicy:");
void
void app.NSApplication.activateIgnoringOtherApps(bool flag)
activateIgnoringOtherApps
(bool
(parameter) bool flag
flag
) @selector("activateIgnoringOtherApps:");
void
void app.NSApplication.run()
run
() @selector("run");
void
void app.NSApplication.stop(app.NSObject sender)
stop
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("stop:");
void
void app.NSApplication.postEvent(app.NSEvent event, bool atStart)
postEvent
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent event
event
, bool
(parameter) bool atStart
atStart
) @selector("postEvent:atStart:");
} extern class
(class) app.NSGraphicsContext
NSGraphicsContext
:
(class) app.NSObject
NSObject
class `app.NSGraphicsContext` Objective-C classes not supported
{ static
(class) app.NSGraphicsContext
NSGraphicsContext
app.NSGraphicsContext app.NSGraphicsContext.currentContext()
currentContext
() @selector("currentContext");
void*
void* app.NSGraphicsContext.CGContext()
CGContext
() @selector("CGContext");
} extern class
(class) app.NSView
NSView
:
(class) app.NSObject
NSObject
class `app.NSView` Objective-C classes not supported
{
(struct) app.NSRect
NSRect
app.NSRect app.NSView.bounds()
bounds
() @selector("bounds");
} extern class
(class) app.NSWindow
NSWindow
:
(class) app.NSObject
NSObject
class `app.NSWindow` Objective-C classes not supported
{ static
(class) app.NSWindow
NSWindow
app.NSWindow app.NSWindow.alloc()
alloc
() @selector("alloc");
(class) app.NSWindow
NSWindow
app.NSWindow app.NSWindow.initWithContentRect(app.NSRect contentRect, ulong styleMask, ulong backing, bool defer)
initWithContentRect
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect contentRect
contentRect
, ulong
(parameter) ulong styleMask
styleMask
,
ulong
(parameter) ulong backing
backing
, bool
(parameter) bool defer
defer
) @selector("initWithContentRect:styleMask:backing:defer:");
void
void app.NSWindow.setTitle(app.NSString title)
setTitle
(
(class) app.NSString
NSString
(parameter) app.NSString title
title
) @selector("setTitle:");
void
void app.NSWindow.setContentView(app.NSObject view)
setContentView
(
(class) app.NSObject
NSObject
(parameter) app.NSObject view
view
) @selector("setContentView:");
void
void app.NSWindow.setDelegate(app.NSObject d)
setDelegate
(
(class) app.NSObject
NSObject
(parameter) app.NSObject d
d
) @selector("setDelegate:");
void
void app.NSWindow.setReleasedWhenClosed(bool b)
setReleasedWhenClosed
(bool
(parameter) bool b
b
) @selector("setReleasedWhenClosed:");
void
void app.NSWindow.makeKeyAndOrderFront(app.NSObject sender)
makeKeyAndOrderFront
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("makeKeyAndOrderFront:");
void
void app.NSWindow.orderOut(app.NSObject sender)
orderOut
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("orderOut:");
void
void app.NSWindow.orderFront(app.NSObject sender)
orderFront
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("orderFront:");
long
long app.NSWindow.windowNumber()
windowNumber
() @selector("windowNumber");
(struct) app.NSRect
NSRect
app.NSRect app.NSWindow.frame()
frame
() @selector("frame");
// State requests + readbacks. void
void app.NSWindow.zoom(app.NSObject sender)
zoom
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("zoom:");
bool
bool app.NSWindow.isZoomed()
isZoomed
() @selector("isZoomed");
void
void app.NSWindow.miniaturize(app.NSObject sender)
miniaturize
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("miniaturize:");
void
void app.NSWindow.deminiaturize(app.NSObject sender)
deminiaturize
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("deminiaturize:");
bool
bool app.NSWindow.isMiniaturized()
isMiniaturized
() @selector("isMiniaturized");
void
void app.NSWindow.toggleFullScreen(app.NSObject sender)
toggleFullScreen
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("toggleFullScreen:");
ulong
ulong app.NSWindow.styleMask()
styleMask
() @selector("styleMask");
ulong
ulong app.NSWindow.collectionBehavior()
collectionBehavior
() @selector("collectionBehavior");
void
void app.NSWindow.setCollectionBehavior(ulong b)
setCollectionBehavior
(ulong
(parameter) ulong b
b
) @selector("setCollectionBehavior:");
bool
bool app.NSWindow.isVisible()
isVisible
() @selector("isVisible");
bool
bool app.NSWindow.isKeyWindow()
isKeyWindow
() @selector("isKeyWindow");
ulong
ulong app.NSWindow.occlusionState()
occlusionState
() @selector("occlusionState");
// The close pair under test. void
void app.NSWindow.performClose(app.NSObject sender)
performClose
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("performClose:");
void
void app.NSWindow.close()
close
() @selector("close");
} // The content view — a flat fill so state changes have something to composite. class
(class) app.StateView
StateView
:
(class) app.NSView
NSView
class `app.StateView` Objective-C classes not supported
{ static
(class) app.StateView
StateView
app.StateView app.StateView.alloc()
alloc
() @selector("alloc");
(class) app.StateView
StateView
app.StateView app.StateView.initWithFrame(app.NSRect frame)
initWithFrame
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect frame
frame
) @selector("initWithFrame:");
void
void app.StateView.drawRect(app.NSRect dirtyRect)
drawRect
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect dirtyRect
dirtyRect
) @selector("drawRect:")
{ void*
_error_ ctx
ctx
= NSGraphicsContext.
NSGraphicsContext.currentContext
currentContext
().
NSGraphicsContext.currentContext().CGContext
CGContext
();
CGContextSetRGBFillColor(ctx, 0.15, 0.25, 0.35, 1); CGContextFillRect(ctx, this.
this.bounds
bounds
());
} } // The NSWindowDelegate + catch-all notification observer + script driver, in one // pure-D NSObject subclass (selector-matched methods need no protocol declaration). class
(class) app.StateDelegate
StateDelegate
:
(class) app.NSObject
NSObject
class `app.StateDelegate` Objective-C classes not supported
{ static
(class) app.StateDelegate
StateDelegate
app.StateDelegate app.StateDelegate.alloc()
alloc
() @selector("alloc");
(class) app.StateDelegate
StateDelegate
app.StateDelegate app.StateDelegate.init()
init
() @selector("init");
// --- Close contract ------------------------------------------------------------ bool
bool app.StateDelegate.windowShouldClose(app.NSWindow sender)
windowShouldClose
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow sender
sender
) @selector("windowShouldClose:")
{ immutable
_error_ isMain
isMain
= sender is g_win;
if (isMain && g_dirty) { g_dirty = false; // once-veto: the dirty flag is consumed instr("close_requested", "veto=1 win=%s phase=%s mechanism=windowShouldClose_NO", winLabel(sender), g_phase); return false; } instr("close_requested", "veto=0 win=%s phase=%s", winLabel(sender), g_phase); return true; } void
void app.StateDelegate.windowWillClose(app.NSNotification n)
windowWillClose
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowWillClose:")
{ instr("delegate", "m=windowWillClose win=%s phase=%s", winLabel(cast(
(unresolved type) NSWindow
NSWindow
) n.
n.object
object
()), g_phase);
if (cast(
(unresolved type) NSWindow
NSWindow
) n.
n.object
object
() is g_win)
stopApp(); // second close request → willClose → terminate } // --- Zoom (maximize) choreography ------------------------------------------------
(struct) app.NSRect
NSRect
app.NSRect app.StateDelegate.windowWillUseStandardFrame(app.NSWindow w, app.NSRect frame)
windowWillUseStandardFrame
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow w
w
,
(struct) app.NSRect
NSRect
(parameter) app.NSRect frame
frame
)
@selector("windowWillUseStandardFrame:defaultFrame:") { instr("delegate", "m=windowWillUseStandardFrame default=(%.0f,%.0f %.0fx%.0f) phase=%s", frame.
frame.origin
origin
.
frame.origin.x
x
, frame.
frame.origin
origin
.
frame.origin.y
y
, frame.
frame.size
size
.
frame.size.width
width
, frame.
frame.size
size
.
frame.size.height
height
, g_phase);
return frame; } bool
bool app.StateDelegate.windowShouldZoom(app.NSWindow w, app.NSRect frame)
windowShouldZoom
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow w
w
,
(struct) app.NSRect
NSRect
(parameter) app.NSRect frame
frame
)
@selector("windowShouldZoom:toFrame:") { instr("delegate", "m=windowShouldZoom toFrame=(%.0f,%.0f %.0fx%.0f) phase=%s answer=YES", frame.
frame.origin
origin
.
frame.origin.x
x
, frame.
frame.origin
origin
.
frame.origin.y
y
, frame.
frame.size
size
.
frame.size.width
width
, frame.
frame.size
size
.
frame.size.height
height
, g_phase);
return true; }
(struct) app.NSSize
NSSize
app.NSSize app.StateDelegate.windowWillResize(app.NSWindow w, app.NSSize size)
windowWillResize
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow w
w
,
(struct) app.NSSize
NSSize
(parameter) app.NSSize size
size
)
@selector("windowWillResize:toSize:") { instr("delegate", "m=windowWillResize toSize=%.0fx%.0f phase=%s", size.
size.width
width
, size.
size.height
height
, g_phase);
return size; } void
void app.StateDelegate.windowDidResize(app.NSNotification n)
windowDidResize
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidResize:")
{ immutable
_error_ f
f
= g_win.
g_win.frame
frame
();
instr("delegate", "m=windowDidResize frame=(%.0f,%.0f %.0fx%.0f) phase=%s", f.
f.origin
origin
.
f.origin.x
x
, f.
f.origin
origin
.
f.origin.y
y
, f.
f.size
size
.
f.size.width
width
, f.
f.size
size
.
f.size.height
height
, g_phase);
} void
void app.StateDelegate.windowDidMove(app.NSNotification n)
windowDidMove
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidMove:")
{ instr("delegate", "m=windowDidMove phase=%s", g_phase); } void
void app.StateDelegate.windowWillStartLiveResize(app.NSNotification n)
windowWillStartLiveResize
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowWillStartLiveResize:")
{ instr("delegate", "m=windowWillStartLiveResize phase=%s", g_phase); } void
void app.StateDelegate.windowDidEndLiveResize(app.NSNotification n)
windowDidEndLiveResize
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidEndLiveResize:")
{ instr("delegate", "m=windowDidEndLiveResize phase=%s", g_phase); } // --- Miniaturize ------------------------------------------------------------------ void
void app.StateDelegate.windowWillMiniaturize(app.NSNotification n)
windowWillMiniaturize
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowWillMiniaturize:")
{ instr("delegate", "m=windowWillMiniaturize phase=%s", g_phase); } void
void app.StateDelegate.windowDidMiniaturize(app.NSNotification n)
windowDidMiniaturize
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidMiniaturize:")
{ instr("delegate", "m=windowDidMiniaturize miniaturized=%d phase=%s", g_win.
g_win.isMiniaturized
isMiniaturized
() ? 1 : 0, g_phase);
} void
void app.StateDelegate.windowDidDeminiaturize(app.NSNotification n)
windowDidDeminiaturize
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidDeminiaturize:")
{ instr("delegate", "m=windowDidDeminiaturize phase=%s", g_phase); } // --- Focus / key status ------------------------------------------------------------- void
void app.StateDelegate.windowDidBecomeKey(app.NSNotification n)
windowDidBecomeKey
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidBecomeKey:")
{ instr("focus", "state=in win=%s phase=%s reason=didBecomeKey", winLabel(cast(
(unresolved type) NSWindow
NSWindow
) n.
n.object
object
()), g_phase);
} void
void app.StateDelegate.windowDidResignKey(app.NSNotification n)
windowDidResignKey
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidResignKey:")
{ instr("focus", "state=out win=%s phase=%s reason=didResignKey", winLabel(cast(
(unresolved type) NSWindow
NSWindow
) n.
n.object
object
()), g_phase);
} void
void app.StateDelegate.windowDidBecomeMain(app.NSNotification n)
windowDidBecomeMain
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidBecomeMain:")
{ instr("focus", "state=main_in win=%s phase=%s", winLabel(cast(
(unresolved type) NSWindow
NSWindow
) n.
n.object
object
()), g_phase);
} void
void app.StateDelegate.windowDidResignMain(app.NSNotification n)
windowDidResignMain
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidResignMain:")
{ instr("focus", "state=main_out win=%s phase=%s", winLabel(cast(
(unresolved type) NSWindow
NSWindow
) n.
n.object
object
()), g_phase);
} // --- Fullscreen (Space transition) ---------------------------------------------------- void
void app.StateDelegate.windowWillEnterFullScreen(app.NSNotification n)
windowWillEnterFullScreen
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowWillEnterFullScreen:")
{ g_fsT0 = instrNowUs(); instr("delegate", "m=windowWillEnterFullScreen phase=%s", g_phase); } void
void app.StateDelegate.windowDidEnterFullScreen(app.NSNotification n)
windowDidEnterFullScreen
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidEnterFullScreen:")
{ g_fsEntered = true; instr("delegate", "m=windowDidEnterFullScreen dur_ms=%.1f styleMask=0x%llx phase=%s", (instrNowUs() - g_fsT0) / 1000.0, g_win.
g_win.styleMask
styleMask
(), g_phase);
} void
void app.StateDelegate.windowWillExitFullScreen(app.NSNotification n)
windowWillExitFullScreen
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowWillExitFullScreen:")
{ g_fsT0 = instrNowUs(); instr("delegate", "m=windowWillExitFullScreen phase=%s", g_phase); } void
void app.StateDelegate.windowDidExitFullScreen(app.NSNotification n)
windowDidExitFullScreen
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidExitFullScreen:")
{ g_fsExited = true; instr("delegate", "m=windowDidExitFullScreen dur_ms=%.1f styleMask=0x%llx phase=%s", (instrNowUs() - g_fsT0) / 1000.0, g_win.
g_win.styleMask
styleMask
(), g_phase);
} void
void app.StateDelegate.windowDidFailToEnterFullScreen(app.NSWindow w)
windowDidFailToEnterFullScreen
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow w
w
)
@selector("windowDidFailToEnterFullScreen:") { g_fsFailed = true; instr("delegate", "m=windowDidFailToEnterFullScreen phase=%s", g_phase); } // --- Catch-all notification observer + script timer ------------------------------------- void
void app.StateDelegate.onNote(app.NSNotification n)
onNote
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("onNote:")
{ const(char)*
_error_ name
name
= n.
n.name
name
().
n.name().UTF8String
UTF8String
();
// NSWindowDidUpdateNotification fires once per run-loop drawing pass — count, don't log. if (streq(name, "NSWindowDidUpdateNotification")) { ++g_updates; return; } instr("note", "name=%s phase=%s", name, g_phase); } void
void app.StateDelegate.tick(app.NSTimer t)
tick
(
(class) app.NSTimer
NSTimer
(parameter) app.NSTimer t
t
) @selector("tick:")
{ onStep(); } } extern (D): // back to D linkage enum
(constant) int app.NSApplicationActivationPolicyRegular = 0
NSApplicationActivationPolicyRegular
= 0;
enum : ulong {
(enum value) app.NSWindowStyleMaskTitled = 1LU
NSWindowStyleMaskTitled
= 1,
(enum value) app.NSWindowStyleMaskClosable = 2LU
NSWindowStyleMaskClosable
= 2,
(enum value) app.NSWindowStyleMaskMiniaturizable = 4LU
NSWindowStyleMaskMiniaturizable
= 4,
(enum value) app.NSWindowStyleMaskResizable = 8LU
NSWindowStyleMaskResizable
= 8,
(enum value) app.NSWindowStyleMaskFullScreen = 16384LU
NSWindowStyleMaskFullScreen
= 1 << 14,
} enum ulong
(constant) ulong app.NSBackingStoreBuffered = 2LU
NSBackingStoreBuffered
= 2;
enum long
(constant) long app.NSEventTypeApplicationDefined = 15L
NSEventTypeApplicationDefined
= 15;
enum ulong
(constant) ulong app.NSWindowCollectionBehaviorFullScreenPrimary = 128LU
NSWindowCollectionBehaviorFullScreenPrimary
= 1 << 7;
// --- Demo state ----------------------------------------------------------------------- __gshared
(class) app.NSApplication
NSApplication
(__gshared global) app.NSApplication app.g_app
g_app
;
__gshared
(class) app.NSWindow
NSWindow
(__gshared global) app.NSWindow app.g_win
g_win
; // the main window under test
__gshared
(class) app.NSWindow
NSWindow
(__gshared global) app.NSWindow app.g_aux
g_aux
; // throwaway window for the close-vs-performClose proof
__gshared
(class) app.StateDelegate
StateDelegate
(__gshared global) app.StateDelegate app.g_dlg
g_dlg
;
__gshared bool
(__gshared global) bool app.g_auto
g_auto
;
__gshared int
(__gshared global) int app.g_step
g_step
;
__gshared int
(__gshared global) int app.g_waitTicks
g_waitTicks
; // budget for async (fullscreen) waits
__gshared const(char)*
(__gshared global) const(char)* app.g_phase
g_phase
= "init"; // request currently being serviced
__gshared bool
(__gshared global) bool app.g_dirty
g_dirty
; // the vetoable-close dirty flag
__gshared bool
(__gshared global) bool app.g_fsEntered
g_fsEntered
,
(__gshared global) bool app.g_fsExited
g_fsExited
,
(__gshared global) bool app.g_fsFailed
g_fsFailed
;
__gshared ulong
(__gshared global) ulong app.g_fsT0
g_fsT0
;
__gshared int
(__gshared global) int app.g_updates
g_updates
; // suppressed NSWindowDidUpdateNotification count
bool
bool app.streq(const(char)* a, const(char)* b) nothrow @nogc
streq
(const(char)*
(parameter) const(char)* a
a
, const(char)*
(parameter) const(char)* b
b
) nothrow @nogc
{ import core.stdc.string : strcmp; return a !is null && b !is null && strcmp(a, b) == 0; } const(char)*
const(char)* app.winLabel(app.NSWindow w)
winLabel
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow w
w
)
{ if (w is g_win) return "main"; if (w is g_aux) return "aux"; return "other"; } void
void app.logState(const(char)* tag)
logState
(const(char)*
(parameter) const(char)* tag
tag
)
{ immutable
_error_ f
f
= g_win.
g_win.frame
frame
();
instr("state_changed", "tag=%s frame=(%.0f,%.0f %.0fx%.0f) zoomed=%d mini=%d visible=%d key=%d occlusion=0x%llx fullscreen=%d", tag, f.
f.origin
origin
.
f.origin.x
x
, f.
f.origin
origin
.
f.origin.y
y
, f.
f.size
size
.
f.size.width
width
, f.
f.size
size
.
f.size.height
height
,
g_win.
g_win.isZoomed
isZoomed
() ? 1 : 0, g_win.
g_win.isMiniaturized
isMiniaturized
() ? 1 : 0,
g_win.
g_win.isVisible
isVisible
() ? 1 : 0, g_win.
g_win.isKeyWindow
isKeyWindow
() ? 1 : 0,
g_win.
g_win.occlusionState
occlusionState
(),
(g_win.
g_win.styleMask
styleMask
() & NSWindowStyleMaskFullScreen) ? 1 : 0);
} void
void app.stopApp()
stopApp
()
{ instr("step", "name=NSApp_stop"); g_app.
g_app.stop
stop
(null);
(unresolved type) NSEvent
NSEvent
_error_ ev
ev
= NSEvent.
NSEvent.otherEventWithType
otherEventWithType
(NSEventTypeApplicationDefined,
NSPoint(0, 0), 0, 0, 0, null, 0, 0, 0); g_app.
g_app.postEvent
postEvent
(ev, true); // stop: is only checked after an event dispatch
} // --- The scripted run -------------------------------------------------------------------- void
void app.onStep()
onStep
()
{ if (!g_auto) return; switch (g_step) { case 0: // Baseline. g_phase = "baseline"; logState("baseline"); instr("collection_behavior", "before=0x%llx", g_win.
g_win.collectionBehavior
collectionBehavior
());
g_win.
g_win.setCollectionBehavior
setCollectionBehavior
(NSWindowCollectionBehaviorFullScreenPrimary);
instr("collection_behavior", "after=0x%llx note=FullScreenPrimary_prerequisite_for_toggleFullScreen", g_win.
g_win.collectionBehavior
collectionBehavior
());
break; case 1: // Zoom on (programmatic maximize). g_phase = "zoom_on"; instr("state_request", "kind=zoom api=zoom: zoomed_before=%d", g_win.
g_win.isZoomed
isZoomed
() ? 1 : 0);
g_win.
g_win.zoom
zoom
(null);
logState("after_zoom_on"); break; case 2: // Zoom off (restore). g_phase = "zoom_off"; instr("state_request", "kind=zoom_restore api=zoom: zoomed_before=%d", g_win.
g_win.isZoomed
isZoomed
() ? 1 : 0);
g_win.
g_win.zoom
zoom
(null);
logState("after_zoom_off"); break; case 3: // Miniaturize. g_phase = "miniaturize"; instr("state_request", "kind=minimize api=miniaturize:"); g_win.
g_win.miniaturize
miniaturize
(null);
logState("after_miniaturize"); break; case 4: // Deminiaturize. g_phase = "deminiaturize"; instr("state_request", "kind=restore api=deminiaturize:"); g_win.
g_win.deminiaturize
deminiaturize
(null);
logState("after_deminiaturize"); break; case 5: // orderOut (hide without state). g_phase = "order_out"; instr("state_request", "kind=hide api=orderOut:"); g_win.
g_win.orderOut
orderOut
(null);
logState("after_order_out"); break; case 6: // orderFront + makeKey restore. g_phase = "order_front"; instr("state_request", "kind=show api=makeKeyAndOrderFront:"); g_win.
g_win.makeKeyAndOrderFront
makeKeyAndOrderFront
(null);
logState("after_order_front"); break; case 7: // Fullscreen enter — async Space transition; wait for didEnter. g_phase = "fullscreen_enter"; instr("state_request", "kind=fullscreen api=toggleFullScreen:"); g_fsEntered = g_fsFailed = false; g_waitTicks = 40; // 8 s budget at 200 ms ticks g_win.
g_win.toggleFullScreen
toggleFullScreen
(null);
break; case 8: // Wait for the enter transition to settle (or time out). if (!g_fsEntered && !g_fsFailed && --g_waitTicks > 0) return; // stay on this step instr("state_settled", "kind=fullscreen entered=%d failed=%d timed_out=%d", g_fsEntered ? 1 : 0, g_fsFailed ? 1 : 0, g_waitTicks <= 0 ? 1 : 0); logState("after_fullscreen_enter"); break; case 9: // Fullscreen exit. g_phase = "fullscreen_exit"; if (g_win.
g_win.styleMask
styleMask
() & NSWindowStyleMaskFullScreen)
{ instr("state_request", "kind=fullscreen_exit api=toggleFullScreen:"); g_fsExited = false; g_waitTicks = 40; g_win.
g_win.toggleFullScreen
toggleFullScreen
(null);
} else { instr("state_request", "kind=fullscreen_exit skipped=not_fullscreen"); g_step += 1; // skip the wait step too } break; case 10: if (!g_fsExited && --g_waitTicks > 0) return; instr("state_settled", "kind=fullscreen_exit exited=%d timed_out=%d", g_fsExited ? 1 : 0, g_waitTicks <= 0 ? 1 : 0); logState("after_fullscreen_exit"); break; case 11: // Proof: -close skips windowShouldClose:; -performClose: asks first. g_phase = "aux_close_direct"; instr("close_probe", "api=close win=aux expect=no_windowShouldClose"); g_aux.
g_aux.close
close
(); // delegate's windowShouldClose must NOT fire; willClose must
break; case 12: // Vetoable close, attempt 1: dirty → veto. g_phase = "veto_close_1"; g_dirty = true; instr("close_probe", "api=performClose win=main dirty=1 expect=veto"); g_win.
g_win.performClose
performClose
(null);
instr("close_probe", "after=performClose still_visible=%d dirty=%d", g_win.
g_win.isVisible
isVisible
() ? 1 : 0, g_dirty ? 1 : 0);
break; case 13: // Attempt 2: flag consumed → close proceeds → willClose stops the app. g_phase = "veto_close_2"; instr("close_probe", "api=performClose win=main dirty=0 expect=close"); g_win.
g_win.performClose
performClose
(null);
break; default: // Safety net if windowWillClose never fired. instr("close_probe", "result=window_did_not_close visible=%d", g_win.
g_win.isVisible
isVisible
() ? 1 : 0);
stopApp(); break; } ++g_step; } int
int D main()
main
()
{ g_auto = getenv("WSI_AUTO_EXIT") !is null; instrInit("APPKIT_F14"); instr("init_start", "auto_exit=%d", g_auto ? 1 : 0); if (CGMainDisplayID() == 0) { printf("SKIP: no macOS window server (CGMainDisplayID == 0)\n"); return 0; } logSessionLockState(); auto
_error_ pool
pool
= autoreleasepool_push();
scope (exit) autoreleasepool_pop(pool); g_app = NSApplication.
NSApplication.sharedApplication
sharedApplication
();
g_app.
g_app.setActivationPolicy
setActivationPolicy
(NSApplicationActivationPolicyRegular);
immutable
_error_ mask
mask
= NSWindowStyleMaskTitled | NSWindowStyleMaskClosable
| NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; g_win = NSWindow.
NSWindow.alloc
alloc
().
NSWindow.alloc().initWithContentRect
initWithContentRect
(
NSRect(NSPoint(120, 120), NSSize(480, 320)), mask, NSBackingStoreBuffered, false); g_win.
g_win.setTitle
setTitle
(NSString.
NSString.alloc
alloc
().
NSString.alloc().initWithUTF8String
initWithUTF8String
("wsi-f14-window-state"));
g_win.
g_win.setReleasedWhenClosed
setReleasedWhenClosed
(false); // we read isVisible after close
(unresolved type) StateView
StateView
_error_ view
view
= StateView.
StateView.alloc
alloc
().
StateView.alloc().initWithFrame
initWithFrame
(NSRect(NSPoint(0, 0), NSSize(480, 320)));
g_win.
g_win.setContentView
setContentView
(view);
g_aux = NSWindow.
NSWindow.alloc
alloc
().
NSWindow.alloc().initWithContentRect
initWithContentRect
(
NSRect(NSPoint(700, 120), NSSize(200, 120)), mask, NSBackingStoreBuffered, false); g_aux.
g_aux.setTitle
setTitle
(NSString.
NSString.alloc
alloc
().
NSString.alloc().initWithUTF8String
initWithUTF8String
("wsi-f14-aux"));
g_aux.
g_aux.setReleasedWhenClosed
setReleasedWhenClosed
(false);
g_dlg = StateDelegate.
StateDelegate.alloc
alloc
().
StateDelegate.alloc().init
init
();
g_win.
g_win.setDelegate
setDelegate
(g_dlg);
g_aux.
g_aux.setDelegate
setDelegate
(g_dlg);
// Catch-all observer: every notification whose object is the main window. NSNotificationCenter.
NSNotificationCenter.defaultCenter
defaultCenter
().
NSNotificationCenter.defaultCenter().addObserver
addObserver
(g_dlg, SEL.register("onNote:"),
null, g_win); g_aux.
g_aux.orderFront
orderFront
(null);
g_win.
g_win.makeKeyAndOrderFront
makeKeyAndOrderFront
(null);
g_app.
g_app.activateIgnoringOtherApps
activateIgnoringOtherApps
(true);
instr("window_created", "main_win=%ld aux_win=%ld styleMask=0x%llx", g_win.
g_win.windowNumber
windowNumber
(), g_aux.
g_aux.windowNumber
windowNumber
(), g_win.
g_win.styleMask
styleMask
());
instr("step", "name=script_timer_start interval_ms=200"); NSTimer.
NSTimer.scheduledTimerWithTimeInterval
scheduledTimerWithTimeInterval
(0.2, g_dlg, SEL.register("tick:"), null, true);
instr("step", "name=NSApp_run"); g_app.
g_app.run
run
();
instr("loop_exit", "steps=%d suppressed_didUpdate_notes=%d", g_step, g_updates); return 0; }