app.dhover×789 error×33all
// macOS/AppKit F15 demo — popup with "grab" (../../../features/f15-popup.md).
// macOS has no popup grab: a context menu built from raw windows is a borderless
// NSWindow (NSWindowStyleMaskBorderless) raised to NSPopUpMenuWindowLevel, and
// "dismiss on outside click" must be assembled from events the popup never
// receives. This demo implements and compares BOTH dismissal mechanisms:
//   (a) +[NSEvent addLocalMonitorForEventsMatchingMask:handler:] (in-app events,
//       block callback) and the global variant (other apps' events — needs
//       nothing for mouse, Accessibility for keys; what each actually sees under
//       an SSH-launched locked session is logged);
//   (b) the key-window route: canBecomeKeyWindow override (borderless windows
//       refuse key status by default — also required for Esc/keyDown!) +
//       windowDidResignKey as the dismissal signal.
// Plus: 3 items with tracking-area hover highlight, Esc via keyDown →
// interpretKeyEvents: → cancelOperation:, app-computed clamping near the
// bottom-right screen edge (and whether constrainFrameRect:toScreen: auto-clamps
// a borderless window — the override logs every call), and a one-level submenu
// as a child window (addChildWindow:ordered: — stacking + move-with-parent).
//
// All clicks/keys are synthetic (A[ssh], locked console): CGEvent-wrapped
// right-click per the f06/f07 recipes, plain NSEvent left-clicks/keys, dispatched
// via [NSApp postEvent:] (so local monitors see them) or [window sendEvent:]
// (fallback: direct method call — every route taken is logged).
//
// Modes: WSI_AUTO_EXIT=1 = bounded scripted run; without it the window stays up
// for a manual (Tier C) session. Headless-safe: prints `SKIP:` and exits 0.
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;
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.block : Block,
(error) _error_
block
;
unable to read module `block` Expected 'objc/block.d' or 'objc/block/package.d' in one of the following import paths:
unable to read module `block` Expected 'objc/block.d' or 'objc/block/package.d' in one of the following import paths:
unable to read module `block` Expected 'objc/block.d' or 'objc/block/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
);
int
int app.CGWindowLevelForKey(int key) nothrow @nogc
CGWindowLevelForKey
(int
(parameter) int key
key
);
void*
void* app.CGEventCreateMouseEvent(void* source, uint type, app.NSPoint pos, uint button) nothrow @nogc
CGEventCreateMouseEvent
(void*
(parameter) void* source
source
, uint
(parameter) uint type
type
,
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint pos
pos
, uint
(parameter) uint button
button
);
void
void app.CFRelease(void* obj) nothrow @nogc
CFRelease
(void*
(parameter) void* obj
obj
);
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.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;
enum uint
(constant) uint app.kCGEventRightMouseDown = 3u
kCGEventRightMouseDown
= 3;
enum uint
(constant) uint app.kCGMouseButtonRight = 1u
kCGMouseButtonRight
= 1;
// CGWindowLevelKey values (CGWindowLevel.h). enum : int {
(enum value) app.kCGNormalWindowLevelKey = 4
kCGNormalWindowLevelKey
= 4,
(enum value) app.kCGFloatingWindowLevelKey = 5
kCGFloatingWindowLevelKey
= 5,
(enum value) app.kCGPopUpMenuWindowLevelKey = 11
kCGPopUpMenuWindowLevelKey
= 11,
(enum value) app.kCGScreenSaverWindowLevelKey = 13
kCGScreenSaverWindowLevelKey
= 13,
(enum value) app.kCGMaximumWindowLevelKey = 14
kCGMaximumWindowLevelKey
= 14,
} 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* locked
locked
=
void* app.CFDictionaryGetValue(void* dict, void* key) nothrow @nogc
CFDictionaryGetValue
(
(local variable) void* dict
dict
,
(local variable) void* kLocked
kLocked
);
instr("session", "screen_locked=%d", locked !is null && CFBooleanGetValue(locked) ? 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* 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:");
} extern class
(class) app.NSArray
NSArray
:
(class) app.NSObject
NSObject
class `app.NSArray` Objective-C classes not supported
{ static
(class) app.NSArray
NSArray
app.NSArray app.NSArray.arrayWithObject(app.NSObject o)
arrayWithObject
(
(class) app.NSObject
NSObject
(parameter) app.NSObject o
o
) @selector("arrayWithObject:");
} extern class
(class) app.NSNotification
NSNotification
:
(class) app.NSObject
NSObject
class `app.NSNotification` Objective-C classes not supported
{
(class) app.NSObject
NSObject
app.NSObject app.NSNotification.object()
object
() @selector("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.mouseEventWithType(long type, app.NSPoint location, ulong modifierFlags, double timestamp, long windowNumber, app.NSObject context, long eventNumber, long clickCount, double pressure)
mouseEventWithType
(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
, long
(parameter) long eventNumber
eventNumber
,
long
(parameter) long clickCount
clickCount
, double
(parameter) double pressure
pressure
)
@selector("mouseEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:"); static
(class) app.NSEvent
NSEvent
app.NSEvent app.NSEvent.keyEventWithType(long type, app.NSPoint location, ulong modifierFlags, double timestamp, long windowNumber, app.NSObject context, app.NSString characters, app.NSString charactersIgnoringModifiers, bool isARepeat, ushort keyCode)
keyEventWithType
(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
,
(class) app.NSString
NSString
(parameter) app.NSString characters
characters
,
(class) app.NSString
NSString
(parameter) app.NSString charactersIgnoringModifiers
charactersIgnoringModifiers
, bool
(parameter) bool isARepeat
isARepeat
, ushort
(parameter) ushort keyCode
keyCode
)
@selector("keyEventWithType:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:"); static
(class) app.NSEvent
NSEvent
app.NSEvent app.NSEvent.eventWithCGEvent(void* cgEvent)
eventWithCGEvent
(void*
(parameter) void* cgEvent
cgEvent
) @selector("eventWithCGEvent:");
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:"); static
(class) app.NSObject
NSObject
app.NSEvent.addLocalMonitorForEventsMatchingMask
addLocalMonitorForEventsMatchingMask
(ulong mask,
Block!(void*, void*)* handler)
template instance `Block!(void*, void*)` `Block` is not a template declaration, it is a alias
@selector("addLocalMonitorForEventsMatchingMask:handler:"); static
(class) app.NSObject
NSObject
app.NSEvent.addGlobalMonitorForEventsMatchingMask
addGlobalMonitorForEventsMatchingMask
(ulong mask,
Block!(void, void*)* handler)
template instance `Block!(void, void*)` `Block` is not a template declaration, it is a alias
@selector("addGlobalMonitorForEventsMatchingMask:handler:"); static void
void app.NSEvent.removeMonitor(app.NSObject monitor)
removeMonitor
(
(class) app.NSObject
NSObject
(parameter) app.NSObject monitor
monitor
) @selector("removeMonitor:");
long
long app.NSEvent.type()
type
() @selector("type");
(struct) app.NSPoint
NSPoint
app.NSPoint app.NSEvent.locationInWindow()
locationInWindow
() @selector("locationInWindow");
long
long app.NSEvent.windowNumber()
windowNumber
() @selector("windowNumber");
ushort
ushort app.NSEvent.keyCode()
keyCode
() @selector("keyCode");
} 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
(parameter) NSObject target
target
,
SEL sel,
(class) app.NSObject
NSObject
(parameter) NSObject userInfo
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:");
void
void app.NSApplication.sendEvent(app.NSEvent event)
sendEvent
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent event
event
) @selector("sendEvent:");
} 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.NSTrackingArea
NSTrackingArea
:
(class) app.NSObject
NSObject
class `app.NSTrackingArea` Objective-C classes not supported
{ static
(class) app.NSTrackingArea
NSTrackingArea
app.NSTrackingArea app.NSTrackingArea.alloc()
alloc
() @selector("alloc");
(class) app.NSTrackingArea
NSTrackingArea
app.NSTrackingArea app.NSTrackingArea.initWithRect(app.NSRect rect, ulong options, app.NSObject owner, app.NSObject userInfo)
initWithRect
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect rect
rect
, ulong
(parameter) ulong options
options
,
(class) app.NSObject
NSObject
(parameter) app.NSObject owner
owner
,
(class) app.NSObject
NSObject
(parameter) app.NSObject userInfo
userInfo
) @selector("initWithRect:options:owner:userInfo:");
} 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");
void
void app.NSView.setNeedsDisplay(bool flag)
setNeedsDisplay
(bool
(parameter) bool flag
flag
) @selector("setNeedsDisplay:");
void
void app.NSView.addTrackingArea(app.NSTrackingArea area)
addTrackingArea
(
(class) app.NSTrackingArea
NSTrackingArea
(parameter) app.NSTrackingArea area
area
) @selector("addTrackingArea:");
void
void app.NSView.interpretKeyEvents(app.NSArray events)
interpretKeyEvents
(
(class) app.NSArray
NSArray
(parameter) app.NSArray events
events
) @selector("interpretKeyEvents:");
bool
bool app.NSView.acceptsFirstResponder()
acceptsFirstResponder
() @selector("acceptsFirstResponder");
} extern class
(class) app.NSWindow
NSWindow
:
(class) app.NSObject
NSObject
class `app.NSWindow` Objective-C classes not supported
{ // (alloc is declared on the leaf classes — a base declaration clashes with // the covariant leaf override, per the scaffold recipe.)
(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:");
bool
bool app.NSWindow.makeFirstResponder(app.NSObject responder)
makeFirstResponder
(
(class) app.NSObject
NSObject
(parameter) app.NSObject responder
responder
) @selector("makeFirstResponder:");
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:");
void
void app.NSWindow.sendEvent(app.NSEvent event)
sendEvent
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent event
event
) @selector("sendEvent:");
long
long app.NSWindow.windowNumber()
windowNumber
() @selector("windowNumber");
(struct) app.NSRect
NSRect
app.NSRect app.NSWindow.frame()
frame
() @selector("frame");
void
void app.NSWindow.setFrameOrigin(app.NSPoint p)
setFrameOrigin
(
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint p
p
) @selector("setFrameOrigin:");
(struct) app.NSRect
NSRect
app.NSRect app.NSWindow.convertRectToScreen(app.NSRect r)
convertRectToScreen
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect r
r
) @selector("convertRectToScreen:");
long
long app.NSWindow.level()
level
() @selector("level");
void
void app.NSWindow.setLevel(long level)
setLevel
(long
(parameter) long level
level
) @selector("setLevel:");
bool
bool app.NSWindow.isKeyWindow()
isKeyWindow
() @selector("isKeyWindow");
bool
bool app.NSWindow.isVisible()
isVisible
() @selector("isVisible");
void
void app.NSWindow.addChildWindow(app.NSWindow child, long ordered)
addChildWindow
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow child
child
, long
(parameter) long ordered
ordered
) @selector("addChildWindow:ordered:");
void
void app.NSWindow.removeChildWindow(app.NSWindow child)
removeChildWindow
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow child
child
) @selector("removeChildWindow:");
(class) app.NSWindow
NSWindow
app.NSWindow app.NSWindow.parentWindow()
parentWindow
() @selector("parentWindow");
bool
bool app.NSWindow.canBecomeKeyWindow()
canBecomeKeyWindow
() @selector("canBecomeKeyWindow");
(struct) app.NSRect
NSRect
app.NSRect app.NSWindow.constrainFrameRect(app.NSRect frameRect, app.NSObject screen)
constrainFrameRect
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect frameRect
frameRect
,
(class) app.NSObject
NSObject
(parameter) app.NSObject screen
screen
)
@selector("constrainFrameRect:toScreen:"); } // A plain leaf so the main window can be alloc'd (see the note in NSWindow). class
(class) app.PlainWindow
PlainWindow
:
(class) app.NSWindow
NSWindow
class `app.PlainWindow` Objective-C classes not supported
{ static
(class) app.PlainWindow
PlainWindow
app.PlainWindow app.PlainWindow.alloc()
alloc
() @selector("alloc");
} // The borderless popup window. canBecomeKeyWindow=YES is mechanism (b)'s enabler // AND the prerequisite for receiving keyDown (Esc); the constrainFrameRect // override logs whether AppKit ever asks to clamp a borderless window. class
(class) app.PopupWindow
PopupWindow
:
(class) app.NSWindow
NSWindow
class `app.PopupWindow` Objective-C classes not supported
{ static
(class) app.PopupWindow
PopupWindow
app.PopupWindow app.PopupWindow.alloc()
alloc
() @selector("alloc");
override bool
bool app.PopupWindow.canBecomeKeyWindow()
canBecomeKeyWindow
() @selector("canBecomeKeyWindow")
{ return true; } override
(struct) app.NSRect
NSRect
app.NSRect app.PopupWindow.constrainFrameRect(app.NSRect frameRect, app.NSObject screen)
constrainFrameRect
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect frameRect
frameRect
,
(class) app.NSObject
NSObject
(parameter) app.NSObject screen
screen
)
@selector("constrainFrameRect:toScreen:") { immutable
_error_ r
r
= super.
super.constrainFrameRect
constrainFrameRect
(frameRect, screen);
instr("constrain_frame_rect", "in=(%.0f,%.0f %.0fx%.0f) out=(%.0f,%.0f %.0fx%.0f) screen_nil=%d", frameRect.
frameRect.origin
origin
.
frameRect.origin.x
x
, frameRect.
frameRect.origin
origin
.
frameRect.origin.y
y
, frameRect.
frameRect.size
size
.
frameRect.size.width
width
, frameRect.
frameRect.size
size
.
frameRect.size.height
height
,
r.
r.origin
origin
.
r.origin.x
x
, r.
r.origin
origin
.
r.origin.y
y
, r.
r.size
size
.
r.size.width
width
, r.
r.size
size
.
r.size.height
height
, screen is null ? 1 : 0);
return r; } } // The menu surface: 3 items, hover highlight via tracking areas, item click, // Esc via keyDown → interpretKeyEvents: → cancelOperation:. class
(class) app.MenuView
MenuView
:
(class) app.NSView
NSView
class `app.MenuView` Objective-C classes not supported
{ static
(class) app.MenuView
MenuView
app.MenuView app.MenuView.alloc()
alloc
() @selector("alloc");
(class) app.MenuView
MenuView
app.MenuView app.MenuView.initWithFrame(app.NSRect frame)
initWithFrame
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect frame
frame
) @selector("initWithFrame:");
override bool
bool app.MenuView.acceptsFirstResponder()
acceptsFirstResponder
() @selector("acceptsFirstResponder")
{ return true; } void
void app.MenuView.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
();
immutable
_error_ b
b
= this.
this.bounds
bounds
();
CGContextSetRGBFillColor(ctx, 0.22, 0.22, 0.24, 1); CGContextFillRect(ctx, b); foreach (
(parameter) i
i
; 0 .. kItems)
{ if (i == g_hover) CGContextSetRGBFillColor(ctx, 0.30, 0.42, 0.65, 1); // hover highlight else CGContextSetRGBFillColor(ctx, 0.27, 0.27, 0.30, 1); immutable
_error_ r
r
= itemRect(b, i);
CGContextFillRect(ctx, NSRect(NSPoint(r.
r.origin
origin
.
r.origin.x
x
+ 2, r.
r.origin
origin
.
r.origin.y
y
+ 1),
NSSize(r.
r.size
size
.
r.size.width
width
- 4, r.
r.size
size
.
r.size.height
height
- 2)));
} } void
void app.MenuView.mouseEntered(app.NSEvent e)
mouseEntered
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent e
e
) @selector("mouseEntered:")
{ immutable
_error_ i
i
= itemAt(e.
e.locationInWindow
locationInWindow
());
instr("tracking", "event=mouseEntered item=%d", i); setHover(i); } void
void app.MenuView.mouseExited(app.NSEvent e)
mouseExited
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent e
e
) @selector("mouseExited:")
{ instr("tracking", "event=mouseExited item=%d", g_hover); setHover(-1); } void
void app.MenuView.mouseMoved(app.NSEvent e)
mouseMoved
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent e
e
) @selector("mouseMoved:")
{ ++g_movesSeen; } void
void app.MenuView.mouseDown(app.NSEvent e)
mouseDown
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent e
e
) @selector("mouseDown:")
{ ++g_itemClicks; immutable
_error_ p
p
= e.
e.locationInWindow
locationInWindow
();
immutable
_error_ i
i
= itemAt(p);
instr("popup_item", "event=mouseDown item=%d loc=(%.0f,%.0f)", i, p.
p.x
x
, p.
p.y
y
);
if (i == 1) openSubmenu(); // item 1 = "Submenu >" — child-window test else if (i >= 0) dismissPopup("item_click"); } void
void app.MenuView.keyDown(app.NSEvent e)
keyDown
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent e
e
) @selector("keyDown:")
{ instr("key", "event=keyDown keycode=%u routing=interpretKeyEvents", e.
e.keyCode
keyCode
());
g_escViaCancel = false; this.
this.interpretKeyEvents
interpretKeyEvents
(NSArray.
NSArray.arrayWithObject
arrayWithObject
(e));
if (!g_escViaCancel && e.
e.keyCode
keyCode
() == 53)
{ // Fallback path if the text system did not map Esc to cancelOperation:. instr("key", "esc_route=keyCode_fallback"); dismissPopup("esc_keydown"); } } // Esc lands here when routed through the text system (doCommandBySelector:). void
void app.MenuView.cancelOperation(app.NSObject sender)
cancelOperation
(
(class) app.NSObject
NSObject
(parameter) app.NSObject sender
sender
) @selector("cancelOperation:")
{ g_escViaCancel = true; instr("key", "esc_route=cancelOperation"); dismissPopup("esc_cancelOperation"); } } // Mechanism (b): the popup's delegate — losing key status means "clicked elsewhere". class
(class) app.PopupDelegate
PopupDelegate
:
(class) app.NSObject
NSObject
class `app.PopupDelegate` Objective-C classes not supported
{ static
(class) app.PopupDelegate
PopupDelegate
app.PopupDelegate app.PopupDelegate.alloc()
alloc
() @selector("alloc");
(class) app.PopupDelegate
PopupDelegate
app.PopupDelegate app.PopupDelegate.init()
init
() @selector("init");
void
void app.PopupDelegate.windowDidResignKey(app.NSNotification n)
windowDidResignKey
(
(class) app.NSNotification
NSNotification
(parameter) app.NSNotification n
n
) @selector("windowDidResignKey:")
{ instr("popup_focus", "event=windowDidResignKey armed=%d", g_resignArmed ? 1 : 0); if (g_resignArmed && g_popup !is null) dismissPopup("resign_key"); } } // The main window's content view: right-click target. class
(class) app.MainView
MainView
:
(class) app.NSView
NSView
class `app.MainView` Objective-C classes not supported
{ static
(class) app.MainView
MainView
app.MainView app.MainView.alloc()
alloc
() @selector("alloc");
(class) app.MainView
MainView
app.MainView app.MainView.initWithFrame(app.NSRect frame)
initWithFrame
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect frame
frame
) @selector("initWithFrame:");
void
void app.MainView.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.13, 0.16, 0.13, 1); CGContextFillRect(ctx, this.
this.bounds
bounds
());
} void
void app.MainView.rightMouseDown(app.NSEvent e)
rightMouseDown
(
(class) app.NSEvent
NSEvent
(parameter) app.NSEvent e
e
) @selector("rightMouseDown:")
{ immutable
_error_ p
p
= e.
e.locationInWindow
locationInWindow
();
// Anchor = the click point in screen coords; popup opens below-right. immutable
_error_ sp
sp
= g_win.
g_win.convertRectToScreen
convertRectToScreen
(NSRect(p, NSSize(1, 1))).
g_win.convertRectToScreen(NSRect(p, NSSize(1, 1))).origin
origin
;
instr("right_click", "loc_window=(%.0f,%.0f) anchor_screen=(%.0f,%.0f)", p.
p.x
x
, p.
p.y
y
, sp.
sp.x
x
, sp.
sp.y
y
);
openPopup(sp, "right_click"); } void
void app.MainView.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.NSWindowStyleMaskBorderless = 0LU
NSWindowStyleMaskBorderless
= 0,
(enum value) app.NSWindowStyleMaskTitled = 1LU
NSWindowStyleMaskTitled
= 1,
(enum value) app.NSWindowStyleMaskClosable = 2LU
NSWindowStyleMaskClosable
= 2,
(enum value) app.NSWindowStyleMaskResizable = 8LU
NSWindowStyleMaskResizable
= 8,
} enum ulong
(constant) ulong app.NSBackingStoreBuffered = 2LU
NSBackingStoreBuffered
= 2;
enum : long {
(enum value) app.NSEventTypeLeftMouseDown = 1L
NSEventTypeLeftMouseDown
= 1,
(enum value) app.NSEventTypeRightMouseDown = 3L
NSEventTypeRightMouseDown
= 3,
(enum value) app.NSEventTypeMouseMoved = 5L
NSEventTypeMouseMoved
= 5,
(enum value) app.NSEventTypeKeyDown = 10L
NSEventTypeKeyDown
= 10,
(enum value) app.NSEventTypeApplicationDefined = 15L
NSEventTypeApplicationDefined
= 15,
} enum ulong
(constant) ulong app.NSEventMaskLeftMouseDown = 2LU
NSEventMaskLeftMouseDown
= 1UL <<
(enum value) app.NSEventTypeLeftMouseDown = 1L
NSEventTypeLeftMouseDown
;
enum ulong
(constant) ulong app.NSEventMaskRightMouseDown = 8LU
NSEventMaskRightMouseDown
= 1UL <<
(enum value) app.NSEventTypeRightMouseDown = 3L
NSEventTypeRightMouseDown
;
enum long
(constant) long app.NSWindowAbove = 1L
NSWindowAbove
= 1;
// NSPopUpMenuWindowLevel == kCGPopUpMenuWindowLevel (read at runtime, expected 101). enum ulong
(constant) ulong app.kTrackingOptions = 129LU
kTrackingOptions
= 0x01 /*MouseEnteredAndExited*/ | 0x80 /*ActiveAlways*/ ;
enum int
(constant) int app.kItems = 3
kItems
= 3;
enum double
(constant) double app.kItemH = 28.0
kItemH
= 28,
(constant) double app.kMenuW = 160.0
kMenuW
= 160;
enum double
(constant) double app.kMenuH = 84.0
kMenuH
=
(constant) int app.kItems = 3
kItems
*
(constant) double app.kItemH = 28.0
kItemH
;
// --- 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
; // main window
__gshared
(class) app.PopupWindow
PopupWindow
(__gshared global) app.PopupWindow app.g_popup
g_popup
; // the open popup (null when closed)
__gshared
(class) app.PopupWindow
PopupWindow
(__gshared global) app.PopupWindow app.g_submenu
g_submenu
; // child window (null when closed)
__gshared
(class) app.MenuView
MenuView
(__gshared global) app.MenuView app.g_menuView
g_menuView
;
__gshared
(class) app.PopupDelegate
PopupDelegate
(__gshared global) app.PopupDelegate app.g_popupDlg
g_popupDlg
;
__gshared
(class) app.MainView
MainView
(__gshared global) app.MainView app.g_mainView
g_mainView
;
__gshared long
(__gshared global) long app.g_winNum
g_winNum
;
__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_hover
g_hover
= -1;
__gshared int
(__gshared global) int app.g_movesSeen
g_movesSeen
;
__gshared bool
(__gshared global) bool app.g_escViaCancel
g_escViaCancel
;
__gshared bool
(__gshared global) bool app.g_resignArmed
g_resignArmed
; // mechanism (b) active for the current popup
__gshared
(class) app.NSObject
NSObject
(__gshared global) app.NSObject app.g_localMon
g_localMon
,
(__gshared global) app.NSObject app.g_globalMon
g_globalMon
;
__gshared Block!(void*, void*)
_error_ app.g_localBlock
g_localBlock
;
template instance `Block!(void*, void*)` `Block` is not a template declaration, it is a alias
__gshared Block!(void, void*)
_error_ app.g_globalBlock
g_globalBlock
;
template instance `Block!(void, void*)` `Block` is not a template declaration, it is a alias
__gshared int
(__gshared global) int app.g_localSeen
g_localSeen
,
(__gshared global) int app.g_globalSeen
g_globalSeen
;
__gshared int
(__gshared global) int app.g_opens
g_opens
;
__gshared int
(__gshared global) int app.g_itemClicks
g_itemClicks
;
(struct) app.NSRect
NSRect
app.NSRect app.itemRect(app.NSRect b, int i)
itemRect
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect b
b
, int
(parameter) int i
i
)
{ return NSRect(NSPoint(0, b.
b.size
size
.
b.size.height
height
- (i + 1) * kItemH), NSSize(b.
b.size
size
.
b.size.width
width
, kItemH));
} int
int app.itemAt(app.NSPoint p)
itemAt
(
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint p
p
)
{ if (p.
p.x
x
< 0 || p.
p.x
x
>= kMenuW || p.
p.y
y
< 0 || p.
p.y
y
>= kMenuH)
return -1; immutable
_error_ i
i
= cast(int) ((kMenuH - p.
p.y
y
) / kItemH);
return i >= 0 && i < kItems ? i : -1; } void
void app.setHover(int i)
setHover
(int
(parameter) int i
i
)
{ if (g_hover == i) return; g_hover = i; instr("hover", "item=%d", i); if (g_menuView !is null) g_menuView.
g_menuView.setNeedsDisplay
setNeedsDisplay
(true);
} double
double app.screenHeight()
screenHeight
()
{ return CGDisplayBounds(CGMainDisplayID()).
CGDisplayBounds(CGMainDisplayID()).size
size
.
CGDisplayBounds(CGMainDisplayID()).size.height
height
;
} // --- Event monitors (mechanism a) ------------------------------------------------------ // Called from the local-monitor block (via an attribute-erasing cast — the body // is ObjC message sends, which never GC-allocate or throw here). void
void app.onLocalEvent(void* ev)
onLocalEvent
(void*
(parameter) void* ev
ev
)
{ ++g_localSeen;
(unresolved type) NSEvent
NSEvent
_error_ e
e
= cast(
(unresolved type) NSEvent
NSEvent
) ev;
immutable
_error_ wn
wn
= e.
e.windowNumber
windowNumber
();
immutable
_error_ popupWn
popupWn
= g_popup !is null ? g_popup.
g_popup.windowNumber
windowNumber
() : -1;
immutable
_error_ subWn
subWn
= g_submenu !is null ? g_submenu.
g_submenu.windowNumber
windowNumber
() : -1;
immutable
_error_ outside
outside
= wn != popupWn && wn != subWn;
instr("monitor", "scope=local type=%ld win=%ld outside_popup=%d", e.
e.type
type
(), wn,
outside ? 1 : 0); if (e.
e.type
type
() == NSEventTypeLeftMouseDown && outside && g_popup !is null)
dismissPopup("outside_click_local_monitor"); } void
void app.onGlobalEvent(void* ev)
onGlobalEvent
(void*
(parameter) void* ev
ev
)
{ ++g_globalSeen; instr("monitor", "scope=global type=%ld", (cast(
(unresolved type) NSEvent
NSEvent
) ev).
(cast(NSEvent)ev).type
type
());
} void
void app.installMonitors()
installMonitors
()
{ g_localBlock = block((void*
(parameter) void* ev
ev
) {
(cast(void function(void*) nothrow @nogc) &onLocalEvent)(ev); return ev; // pass the event through to normal dispatch }); g_globalBlock = block((void*
(parameter) void* ev
ev
) {
(cast(void function(void*) nothrow @nogc) &onGlobalEvent)(ev); }); g_localMon = NSEvent.
NSEvent.addLocalMonitorForEventsMatchingMask
addLocalMonitorForEventsMatchingMask
(
NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown, &g_localBlock); g_globalMon = NSEvent.
NSEvent.addGlobalMonitorForEventsMatchingMask
addGlobalMonitorForEventsMatchingMask
(
NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown, &g_globalBlock); instr("monitor", "installed local=%d global=%d note=global_sees_only_other_apps_no_a11y_needed_for_mouse", g_localMon !is null ? 1 : 0, g_globalMon !is null ? 1 : 0); } void
void app.removeMonitors()
removeMonitors
()
{ if (g_localMon !is null) NSEvent.
NSEvent.removeMonitor
removeMonitor
(g_localMon);
if (g_globalMon !is null) NSEvent.
NSEvent.removeMonitor
removeMonitor
(g_globalMon);
g_localMon = g_globalMon = null; } // --- Popup open / dismiss ---------------------------------------------------------------- // Opens the popup below-right of `anchor` (AppKit screen coords, y-up), with // app-computed clamping to the screen rect — placement ownership on macOS is // 100% the app's; nothing repositions a borderless window for you.
(struct) app.NSRect
NSRect
app.NSRect app.clampToScreen(app.NSRect r, app.NSPoint anchor)
clampToScreen
(
(struct) app.NSRect
NSRect
(parameter) app.NSRect r
r
,
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint anchor
anchor
)
{ immutable
_error_ sh
sh
= screenHeight();
immutable
_error_ sw
sw
= CGDisplayBounds(CGMainDisplayID()).
CGDisplayBounds(CGMainDisplayID()).size
size
.
CGDisplayBounds(CGMainDisplayID()).size.width
width
;
auto
_error_ placed
placed
= r;
if (placed.
placed.origin
origin
.
placed.origin.x
x
+ r.
r.size
size
.
r.size.width
width
> sw)
placed.
placed.origin
origin
.
placed.origin.x
x
= sw - r.
r.size
size
.
r.size.width
width
; // slide left off the right edge
if (placed.
placed.origin
origin
.
placed.origin.y
y
< 0)
placed.
placed.origin
origin
.
placed.origin.y
y
= anchor.
anchor.y
y
; // flip above the anchor off the bottom edge
if (placed.
placed.origin
origin
.
placed.origin.y
y
+ r.
r.size
size
.
r.size.height
height
> sh)
placed.
placed.origin
origin
.
placed.origin.y
y
= sh - r.
r.size
size
.
r.size.height
height
;
return placed; } // `doClamp=false` places the popup at the raw (possibly off-screen) frame so the // edge test can measure whether anything else (AppKit, WindowServer) clamps it. void
void app.openPopup(app.NSPoint anchor, const(char)* why, bool doClamp = true)
openPopup
(
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint anchor
anchor
, const(char)*
(parameter) const(char)* why
why
, bool
(parameter) bool doClamp
doClamp
= true)
{ if (g_popup !is null) dismissPopup("reopen"); ++g_opens; immutable
_error_ db
db
= CGDisplayBounds(CGMainDisplayID());
// Desired: top-left corner at the anchor → frame origin (bottom-left, y-up). auto
_error_ want
want
= NSRect(NSPoint(anchor.
anchor.x
x
, anchor.
anchor.y
y
- kMenuH), NSSize(kMenuW, kMenuH));
auto
_error_ placed
placed
= doClamp ? clampToScreen(want, anchor) : want;
instr("popup_open", "cause=%s anchor=(%.0f,%.0f) gravity=bottom_right want=(%.0f,%.0f %.0fx%.0f) placed=(%.0f,%.0f %.0fx%.0f) app_clamp=%d screen=%.0fx%.0f", why, anchor.
anchor.x
x
, anchor.
anchor.y
y
, want.
want.origin
origin
.
want.origin.x
x
, want.
want.origin
origin
.
want.origin.y
y
, want.
want.size
size
.
want.size.width
width
,
want.
want.size
size
.
want.size.height
height
, placed.
placed.origin
origin
.
placed.origin.x
x
, placed.
placed.origin
origin
.
placed.origin.y
y
, placed.
placed.size
size
.
placed.size.width
width
,
placed.
placed.size
size
.
placed.size.height
height
, doClamp ? 1 : 0, db.
db.size
size
.
db.size.width
width
, db.
db.size
size
.
db.size.height
height
);
g_popup = cast(
(unresolved type) PopupWindow
PopupWindow
) PopupWindow.
PopupWindow.alloc
alloc
().
PopupWindow.alloc().initWithContentRect
initWithContentRect
(placed,
NSWindowStyleMaskBorderless, NSBackingStoreBuffered, false); g_popup.
g_popup.setReleasedWhenClosed
setReleasedWhenClosed
(false);
g_popup.
g_popup.setLevel
setLevel
(CGWindowLevelForKey(kCGPopUpMenuWindowLevelKey));
g_menuView = MenuView.
MenuView.alloc
alloc
().
MenuView.alloc().initWithFrame
initWithFrame
(NSRect(NSPoint(0, 0), placed.
placed.size
size
));
g_popup.
g_popup.setContentView
setContentView
(g_menuView);
g_popup.
g_popup.setDelegate
setDelegate
(g_popupDlg);
foreach (
(parameter) i
i
; 0 .. kItems)
g_menuView.
g_menuView.addTrackingArea
addTrackingArea
(NSTrackingArea.
NSTrackingArea.alloc
alloc
().
NSTrackingArea.alloc().initWithRect
initWithRect
(
itemRect(NSRect(NSPoint(0, 0), placed.
placed.size
size
), i), kTrackingOptions,
g_menuView, null)); g_hover = -1; g_popup.
g_popup.makeKeyAndOrderFront
makeKeyAndOrderFront
(null); // key status: mechanism (b) + Esc delivery
g_popup.
g_popup.makeFirstResponder
makeFirstResponder
(g_menuView);
g_resignArmed = false; // armed explicitly by the resign-key script step installMonitors(); immutable
_error_ f
f
= g_popup.
g_popup.frame
frame
();
instr("popup_placed", "rect=(%.0f,%.0f %.0fx%.0f) level=%ld is_key=%d can_become_key=%d", 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_popup.
g_popup.level
level
(),
g_popup.
g_popup.isKeyWindow
isKeyWindow
() ? 1 : 0, g_popup.
g_popup.canBecomeKeyWindow
canBecomeKeyWindow
() ? 1 : 0);
} void
void app.openSubmenu()
openSubmenu
()
{ immutable
_error_ pf
pf
= g_popup.
g_popup.frame
frame
();
// One level deep: to the right of item 1, top-aligned with it. auto
_error_ rect
rect
= NSRect(NSPoint(pf.
pf.origin
origin
.
pf.origin.x
x
+ kMenuW - 4,
pf.
pf.origin
origin
.
pf.origin.y
y
+ kMenuH - 2 * kItemH), NSSize(kMenuW, 2 * kItemH));
g_submenu = cast(
(unresolved type) PopupWindow
PopupWindow
) PopupWindow.
PopupWindow.alloc
alloc
().
PopupWindow.alloc().initWithContentRect
initWithContentRect
(rect,
NSWindowStyleMaskBorderless, NSBackingStoreBuffered, false); g_submenu.
g_submenu.setReleasedWhenClosed
setReleasedWhenClosed
(false);
auto
_error_ v
v
= MenuView.
MenuView.alloc
alloc
().
MenuView.alloc().initWithFrame
initWithFrame
(NSRect(NSPoint(0, 0), rect.
rect.size
size
));
g_submenu.
g_submenu.setContentView
setContentView
(v);
g_popup.
g_popup.addChildWindow
addChildWindow
(g_submenu, NSWindowAbove);
g_submenu.
g_submenu.orderFront
orderFront
(null);
immutable
_error_ f
f
= g_submenu.
g_submenu.frame
frame
();
instr("submenu_open", "rect=(%.0f,%.0f %.0fx%.0f) parent_win=%ld child_win=%ld level_parent=%ld level_child=%ld ordered=NSWindowAbove", 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_popup.
g_popup.windowNumber
windowNumber
(), g_submenu.
g_submenu.windowNumber
windowNumber
(), g_popup.
g_popup.level
level
(),
g_submenu.
g_submenu.level
level
());
} void
void app.dismissPopup(const(char)* cause)
dismissPopup
(const(char)*
(parameter) const(char)* cause
cause
)
{ if (g_popup is null) return; instr("popup_dismiss", "cause=%s", cause); g_resignArmed = false; if (g_submenu !is null) { g_popup.
g_popup.removeChildWindow
removeChildWindow
(g_submenu);
g_submenu.
g_submenu.orderOut
orderOut
(null);
g_submenu = null; } removeMonitors(); g_popup.
g_popup.setDelegate
setDelegate
(null);
g_popup.
g_popup.orderOut
orderOut
(null);
g_popup = null; g_menuView = null; } // --- Synthetic input ------------------------------------------------------------------------ // Right-click, CGEvent-backed (the f06/f07 "route 2 object, route 1 dispatch" // hybrid): build a CGEvent, wrap via eventWithCGEvent:, dispatch in-process. void
void app.injectRightClick(app.NSPoint viewPt)
injectRightClick
(
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint viewPt
viewPt
)
{ immutable
_error_ sp
sp
= g_win.
g_win.convertRectToScreen
convertRectToScreen
(NSRect(viewPt, NSSize(1, 1))).
g_win.convertRectToScreen(NSRect(viewPt, NSSize(1, 1))).origin
origin
;
immutable
_error_ cgPt
cgPt
= NSPoint(sp.
sp.x
x
, screenHeight() - sp.
sp.y
y
); // CG is y-down
void*
_error_ cg
cg
= CGEventCreateMouseEvent(null, kCGEventRightMouseDown, cgPt,
kCGMouseButtonRight);
(unresolved type) NSEvent
NSEvent
_error_ e
e
= NSEvent.
NSEvent.eventWithCGEvent
eventWithCGEvent
(cg);
instr("inject", "kind=right_click route=cgevent_wrap view=(%.0f,%.0f) cg=(%.0f,%.0f) wrapped_win=%ld", viewPt.
viewPt.x
x
, viewPt.
viewPt.y
y
, cgPt.
cgPt.x
x
, cgPt.
cgPt.y
y
, e !is null ? e.
e.windowNumber
windowNumber
() : -1);
// A wrapped CGEvent carries no window; sendEvent on the target window routes // by responder chain, falling back to the direct method call if undelivered. if (e !is null) g_win.
g_win.sendEvent
sendEvent
(e);
if (g_popup is null) { instr("inject", "kind=right_click result=sendEvent_not_delivered fallback=direct_call");
(unresolved type) NSEvent
NSEvent
_error_ plain
plain
= NSEvent.
NSEvent.mouseEventWithType
mouseEventWithType
(NSEventTypeRightMouseDown, viewPt,
0, 0, g_winNum, null, 0, 1, 0); g_mainView.
g_mainView.rightMouseDown
rightMouseDown
(plain);
} CFRelease(cg); } // Plain left-click at a window-local point, posted through the app queue so the // local monitor (which hooks the app's dispatch) gets to see it. void
void app.postLeftClick(app.NSWindow target, app.NSPoint pt, const(char)* label)
postLeftClick
(
(class) app.NSWindow
NSWindow
(parameter) app.NSWindow target
target
,
(struct) app.NSPoint
NSPoint
(parameter) app.NSPoint pt
pt
, const(char)*
(parameter) const(char)* label
label
)
{
(unresolved type) NSEvent
NSEvent
_error_ e
e
= NSEvent.
NSEvent.mouseEventWithType
mouseEventWithType
(NSEventTypeLeftMouseDown, pt, 0, 0,
target.
target.windowNumber
windowNumber
(), null, 0, 1, 0);
instr("inject", "kind=left_click label=%s win=%ld loc=(%.0f,%.0f) route=postEvent", label, target.
target.windowNumber
windowNumber
(), pt.
pt.x
x
, pt.
pt.y
y
);
g_app.
g_app.postEvent
postEvent
(e, false);
} void
void app.injectEsc()
injectEsc
()
{
(unresolved type) NSString
NSString
_error_ esc
esc
= NSString.
NSString.alloc
alloc
().
NSString.alloc().initWithUTF8String
initWithUTF8String
("\x1b");
(unresolved type) NSEvent
NSEvent
_error_ e
e
= NSEvent.
NSEvent.keyEventWithType
keyEventWithType
(NSEventTypeKeyDown, NSPoint(0, 0), 0, 0,
g_popup.
g_popup.windowNumber
windowNumber
(), null, esc, esc, false, 53);
instr("inject", "kind=esc keycode=53 win=%ld is_key=%d route=sendEvent", g_popup.
g_popup.windowNumber
windowNumber
(), g_popup.
g_popup.isKeyWindow
isKeyWindow
() ? 1 : 0);
g_popup.
g_popup.sendEvent
sendEvent
(e);
} // --- The scripted run -------------------------------------------------------------------------- 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);
} void
void app.onStep()
onStep
()
{ if (!g_auto) return; switch (g_step) { case 0: // The window-level ladder this demo slots into. instr("levels", "normal=%d floating=%d popup_menu=%d screensaver=%d maximum=%d", CGWindowLevelForKey(kCGNormalWindowLevelKey), CGWindowLevelForKey(kCGFloatingWindowLevelKey), CGWindowLevelForKey(kCGPopUpMenuWindowLevelKey), CGWindowLevelForKey(kCGScreenSaverWindowLevelKey), CGWindowLevelForKey(kCGMaximumWindowLevelKey)); break; case 1: // Open via synthetic right-click. injectRightClick(NSPoint(240, 160)); break; case 2: // Hover: do synthetic moves reach tracking areas? (cursor-driven — no) { if (g_popup is null) break;
(unresolved type) NSEvent
NSEvent
_error_ mv
mv
= NSEvent.
NSEvent.mouseEventWithType
mouseEventWithType
(NSEventTypeMouseMoved,
NSPoint(kMenuW / 2, kMenuH - kItemH / 2), 0, 0, g_popup.
g_popup.windowNumber
windowNumber
(), null, 0, 0, 0);
immutable
_error_ before
before
= g_movesSeen;
g_popup.
g_popup.sendEvent
sendEvent
(mv);
instr("tracking", "probe=synthetic_mouseMoved delivered_to_view=%d entered_fired=%d note=tracking_areas_are_cursor_driven", g_movesSeen - before, g_hover >= 0 ? 1 : 0); if (g_hover < 0) setHover(0); // drive the highlight directly for the visual path } break; case 3: // Click item 1 → submenu (child window). if (g_popup !is null) {
(unresolved type) NSEvent
NSEvent
_error_ e
e
= NSEvent.
NSEvent.mouseEventWithType
mouseEventWithType
(NSEventTypeLeftMouseDown,
NSPoint(kMenuW / 2, kMenuH - kItemH - kItemH / 2), 0, 0, g_popup.
g_popup.windowNumber
windowNumber
(), null, 0, 1, 0);
immutable
_error_ before
before
= g_itemClicks;
g_popup.
g_popup.sendEvent
sendEvent
(e);
if (g_itemClicks == before) { // Same f10 finding: [window sendEvent:] drops synthetic mouse // events under the locked session — call the handler directly. instr("inject", "kind=item_click result=sendEvent_not_delivered fallback=direct_call"); g_menuView.
g_menuView.mouseDown
mouseDown
(e);
} } break; case 4: // Move-with-parent proof. if (g_popup !is null && g_submenu !is null) { immutable
_error_ before
before
= g_submenu.
g_submenu.frame
frame
();
immutable
_error_ pf
pf
= g_popup.
g_popup.frame
frame
();
g_popup.
g_popup.setFrameOrigin
setFrameOrigin
(NSPoint(pf.
pf.origin
origin
.
pf.origin.x
x
+ 24, pf.
pf.origin
origin
.
pf.origin.y
y
+ 24));
immutable
_error_ after
after
= g_submenu.
g_submenu.frame
frame
();
instr("child_move", "parent_moved=(+24,+24) child_before=(%.0f,%.0f) child_after=(%.0f,%.0f) parent_of_child=%ld", before.
before.origin
origin
.
before.origin.x
x
, before.
before.origin
origin
.
before.origin.y
y
, after.
after.origin
origin
.
after.origin.x
x
, after.
after.origin
origin
.
after.origin.y
y
,
g_submenu.
g_submenu.parentWindow
parentWindow
() !is null
? g_submenu.
g_submenu.parentWindow
parentWindow
().
g_submenu.parentWindow().windowNumber
windowNumber
() : -1);
} break; case 5: // Outside click → local monitor dismissal (mechanism a). postLeftClick(g_win, NSPoint(50, 50), "outside_click"); break; case 6: // Reopen near the bottom-right screen edge, UNclamped: who fixes it? { instr("monitor", "after_outside_click popup_open=%d local_seen=%d global_seen=%d", g_popup !is null ? 1 : 0, g_localSeen, g_globalSeen); immutable
_error_ db
db
= CGDisplayBounds(CGMainDisplayID());
openPopup(NSPoint(db.
db.size
size
.
db.size.width
width
- 30, 40), "edge_test_bottom_right", false);
} break; case 7: // Nobody clamped it — apply the app-side math and read back. if (g_popup !is null) { immutable
_error_ before
before
= g_popup.
g_popup.frame
frame
();
immutable
_error_ db
db
= CGDisplayBounds(CGMainDisplayID());
immutable
_error_ anchor
anchor
= NSPoint(db.
db.size
size
.
db.size.width
width
- 30, 40);
immutable
_error_ target
target
= clampToScreen(NSRect(NSPoint(anchor.
anchor.x
x
, anchor.
anchor.y
y
- kMenuH),
NSSize(kMenuW, kMenuH)), anchor); g_popup.
g_popup.setFrameOrigin
setFrameOrigin
(target.
target.origin
origin
);
immutable
_error_ after
after
= g_popup.
g_popup.frame
frame
();
instr("edge_clamp", "offscreen_frame=(%.0f,%.0f) app_clamped_to=(%.0f,%.0f) readback=(%.0f,%.0f) owner=app", before.
before.origin
origin
.
before.origin.x
x
, before.
before.origin
origin
.
before.origin.y
y
, target.
target.origin
origin
.
target.origin.x
x
, target.
target.origin
origin
.
target.origin.y
y
,
after.
after.origin
origin
.
after.origin.x
x
, after.
after.origin
origin
.
after.origin.y
y
);
} break; case 8: // Esc → keyDown → cancelOperation: (needs key status on borderless!). if (g_popup !is null) injectEsc(); break; case 9: // Reopen, then arm mechanism (b) and steal key status. openPopup(NSPoint(400, 400), "resign_key_test"); g_resignArmed = true; break; case 10: if (g_popup !is null) { instr("popup_focus", "action=makeKeyAndOrderFront_main popup_is_key=%d", g_popup.
g_popup.isKeyWindow
isKeyWindow
() ? 1 : 0);
if (!g_popup.
g_popup.isKeyWindow
isKeyWindow
())
instr("popup_focus", "mechanism_b=untestable_headless note=no_window_gets_key_status_in_locked_session tier_c=resign_key_dismissal"); g_win.
g_win.makeKeyAndOrderFront
makeKeyAndOrderFront
(null); // → popup windowDidResignKey → dismiss
} break; case 11: instr("summary", "opens=%d popup_open=%d item_clicks=%d local_seen=%d global_seen=%d", g_opens, g_popup !is null ? 1 : 0, g_itemClicks, g_localSeen, g_globalSeen); dismissPopup("shutdown"); stopApp(); break; default: stopApp(); break; } ++g_step; } int
int D main()
main
()
{ g_auto = getenv("WSI_AUTO_EXIT") !is null; instrInit("APPKIT_F15"); 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_ contentRect
contentRect
= NSRect(NSPoint(120, 120), NSSize(480, 320));
g_win = PlainWindow.
PlainWindow.alloc
alloc
().
PlainWindow.alloc().initWithContentRect
initWithContentRect
(contentRect,
NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable, NSBackingStoreBuffered, false); g_win.
g_win.setTitle
setTitle
(NSString.
NSString.alloc
alloc
().
NSString.alloc().initWithUTF8String
initWithUTF8String
("wsi-f15-popup"));
g_win.
g_win.setReleasedWhenClosed
setReleasedWhenClosed
(false);
g_mainView = MainView.
MainView.alloc
alloc
().
MainView.alloc().initWithFrame
initWithFrame
(NSRect(NSPoint(0, 0), contentRect.
contentRect.size
size
));
g_win.
g_win.setContentView
setContentView
(g_mainView);
g_win.
g_win.makeKeyAndOrderFront
makeKeyAndOrderFront
(null);
g_app.
g_app.activateIgnoringOtherApps
activateIgnoringOtherApps
(true);
g_winNum = g_win.
g_win.windowNumber
windowNumber
();
g_popupDlg = PopupDelegate.
PopupDelegate.alloc
alloc
().
PopupDelegate.alloc().init
init
();
instr("window_created", "win_num=%ld", g_winNum); instr("step", "name=script_timer_start interval_ms=250"); NSTimer.
NSTimer.scheduledTimerWithTimeInterval
scheduledTimerWithTimeInterval
(0.25, g_mainView, SEL.register("tick:"), null, true);
instr("step", "name=NSApp_run"); g_app.
g_app.run
run
();
instr("loop_exit", "steps=%d opens=%d local_seen=%d global_seen=%d moves_seen=%d", g_step, g_opens, g_localSeen, g_globalSeen, g_movesSeen); return 0; }