MCPcopy Create free account
hub / github.com/Effect-TS/effect / EffectUIWindowDragView

Class EffectUIWindowDragView

packages/ui/native/macos/EffectUIWindowDrag.swift:5–41  ·  view source on GitHub ↗

Moves the window when pressed where none of the element's children are, as a title bar does. A double click follows the user's title bar setting.

Source from the content-addressed store, hash-verified

3/// Moves the window when pressed where none of the element's children are,
4/// as a title bar does. A double click follows the user's title bar setting.
5final class EffectUIWindowDragView: NSView, EffectUIHostedView {
6 func update(_ changed: [String: Any]) {}
7
8 override var mouseDownCanMoveWindow: Bool {
9 true
10 }
11
12 // A title bar drags an inactive window too.
13 override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
14 true
15 }
16
17 override func mouseDown(with event: NSEvent) {
18 guard let window else { return }
19 if event.clickCount == 2 {
20 Self.titleBarDoubleClick(window)
21 } else {
22 window.performDrag(with: event)
23 }
24 }
25
26 // "Double-click a window's title bar to" in System Settings. AppKit has no
27 // public action for "Fill", so it zooms, as an unset value does.
28 static func titleBarDoubleClick(_ window: NSWindow) {
29 let defaults = UserDefaults.standard
30 switch defaults.string(forKey: "AppleActionOnDoubleClick") {
31 case "Minimize":
32 window.performMiniaturize(nil)
33 case "None":
34 break
35 case nil where defaults.bool(forKey: "AppleMiniaturizeOnDoubleClick"):
36 window.performMiniaturize(nil)
37 default:
38 window.performZoom(nil)
39 }
40 }
41}

Callers 1

registerViewsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected