]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/backend/cocoa/views/views.factor
ui.backend.cocoa: disable appearance changing temporarily.
[factor.git] / basis / ui / backend / cocoa / views / views.factor
1 ! Copyright (C) 2006, 2010 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.data alien.strings
4 arrays assocs classes cocoa cocoa.application cocoa.classes
5 cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.touchbar
6 cocoa.types cocoa.views combinators core-foundation.strings
7 core-graphics core-graphics.types core-text io.encodings.string
8 io.encodings.utf16n io.encodings.utf8 kernel literals math
9 math.order math.parser math.rectangles math.vectors namespaces
10 opengl sequences splitting threads
11 ui.backend.cocoa.input-methods ui.commands ui.gadgets
12 ui.gadgets.editors ui.gadgets.line-support ui.gadgets.private
13 ui.gadgets.worlds ui.gestures ui.private ui.theme
14 ui.theme.switching words ;
15 IN: ui.backend.cocoa.views
16
17 SLOT: window
18
19 : send-mouse-moved ( view event -- )
20     [ mouse-location ] [ drop window ] 2bi
21     [ move-hand fire-motion yield ] [ drop ] if* ;
22
23 ! Issue #1453
24 : button ( event -- n )
25     ! Cocoa -> Factor UI button mapping
26     -> buttonNumber {
27         { 0 [ 1 ] }
28         { 1 [ 3 ] }
29         { 2 [ 2 ] }
30         [ ]
31     } case ;
32
33 CONSTANT: NSAlphaShiftKeyMask 0x10000
34 CONSTANT: NSShiftKeyMask      0x20000
35 CONSTANT: NSControlKeyMask    0x40000
36 CONSTANT: NSAlternateKeyMask  0x80000
37 CONSTANT: NSCommandKeyMask    0x100000
38 CONSTANT: NSNumericPadKeyMask 0x200000
39 CONSTANT: NSHelpKeyMask       0x400000
40 CONSTANT: NSFunctionKeyMask   0x800000
41
42 CONSTANT: modifiers {
43         { S+ $ NSShiftKeyMask }
44         { C+ $ NSControlKeyMask }
45         { M+ $ NSCommandKeyMask }
46         { A+ $ NSAlternateKeyMask }
47     }
48
49 CONSTANT: key-codes
50     H{
51         { 71 "CLEAR" }
52         { 36 "RET" }
53         { 76 "ENTER" }
54         { 53 "ESC" }
55         { 48 "TAB" }
56         { 51 "BACKSPACE" }
57         { 115 "HOME" }
58         { 117 "DELETE" }
59         { 119 "END" }
60         { 122 "F1" }
61         { 120 "F2" }
62         { 99 "F3" }
63         { 118 "F4" }
64         { 96 "F5" }
65         { 97 "F6" }
66         { 98 "F7" }
67         { 100 "F8" }
68         { 123 "LEFT" }
69         { 124 "RIGHT" }
70         { 125 "DOWN" }
71         { 126 "UP" }
72         { 116 "PAGE_UP" }
73         { 121 "PAGE_DOWN" }
74     }
75
76 : key-code ( event -- string ? )
77     dup -> keyCode key-codes at
78     [ t ] [ -> charactersIgnoringModifiers CF>string f ] ?if ;
79
80 : event-modifiers ( event -- modifiers )
81     -> modifierFlags modifiers modifier ;
82
83 : key-event>gesture ( event -- modifiers keycode action? )
84     [ event-modifiers ] [ key-code ] bi ;
85
86 : send-key-event ( view gesture -- )
87     swap window [ propagate-key-gesture ] [ drop ] if* ;
88
89 : interpret-key-event ( view event -- )
90     NSArray swap -> arrayWithObject: -> interpretKeyEvents: ;
91
92 : send-key-down-event ( view event -- )
93     [ key-event>gesture <key-down> send-key-event ]
94     [ interpret-key-event ]
95     2bi ;
96
97 : send-key-up-event ( view event -- )
98     key-event>gesture <key-up> send-key-event ;
99
100 : mouse-event>gesture ( event -- modifiers button )
101     [ event-modifiers ] [ button ] bi ;
102
103 : send-button-down$ ( view event -- )
104     [ nip mouse-event>gesture <button-down> ]
105     [ mouse-location ]
106     [ drop window ]
107     2tri
108     [ send-button-down ] [ 2drop ] if* ;
109
110 : send-button-up$ ( view event -- )
111     [ nip mouse-event>gesture <button-up> ]
112     [ mouse-location ]
113     [ drop window ]
114     2tri
115     [ send-button-up ] [ 2drop ] if* ;
116
117 : send-scroll$ ( view event -- )
118     [ nip [ -> deltaX ] [ -> deltaY ] bi [ neg ] bi@ 2array ]
119     [ mouse-location ]
120     [ drop window ]
121     2tri
122     [ send-scroll ] [ 2drop ] if* ;
123
124 : send-action$ ( view event gesture -- )
125     [ drop window ] dip over [ send-action ] [ 2drop ] if ;
126
127 : string-or-nil? ( NSString -- ? )
128     [ CF>string NSStringPboardType = ] [ t ] if* ;
129
130 : valid-service? ( gadget send-type return-type -- ? )
131     2dup [ string-or-nil? ] [ string-or-nil? ] bi* and
132     [ drop [ gadget-selection? ] [ drop t ] if ] [ 3drop f ] if ;
133
134 : NSRect>rect ( NSRect world -- rect )
135     [ [ [ CGRect-x ] [ CGRect-y ] bi ] [ dim>> second ] bi* swap - 2array ]
136     [ drop [ CGRect-w ] [ CGRect-h ] bi 2array ]
137     2bi <rect> ;
138
139 : rect>NSRect ( rect world -- NSRect )
140     [ [ loc>> first2 ] [ dim>> second ] bi* swap - ]
141     [ drop dim>> first2 ]
142     2bi <CGRect> ;
143
144 CONSTANT: selector>action H{
145     { "undo:" undo-action }
146     { "redo:" redo-action }
147     { "cut:" cut-action }
148     { "copy:" copy-action }
149     { "paste:" paste-action }
150     { "delete:" delete-action }
151     { "selectAll:" select-all-action }
152     { "newDocument:" new-action }
153     { "openDocument:" open-action }
154     { "saveDocument:" save-action }
155     { "saveDocumentAs:" save-as-action }
156     { "revertDocumentToSaved:" revert-action }
157 }
158
159 : validate-action ( world selector -- ? validated? )
160     selector>action at
161     [ swap world-focus parents-handle-gesture? t ] [ drop f f ] if* ;
162
163 : touchbar-commands ( -- commands/f gadget )
164     world get-global [
165         children>> [
166             class-of "commands" word-prop
167             "touchbar" of dup [ commands>> ] when
168         ] map-find
169     ] [ f f ] if* ;
170
171 TUPLE: send-touchbar-command target command ;
172
173 M: send-touchbar-command send-queued-gesture
174     [ target>> ] [ command>> ] bi invoke-command ;
175
176 : touchbar-invoke-command ( n -- )
177     [ touchbar-commands ] dip over [
178         rot nth second
179         send-touchbar-command queue-gesture notify-ui-thread
180         yield
181     ] [ 3drop ] if ;
182
183 IMPORT: NSAttributedString
184
185 <PRIVATE
186
187 :: >codepoint-index ( str utf16-index -- codepoint-index )
188     0 utf16-index 2 * str utf16n encode subseq utf16n decode length ;
189
190 :: >utf16-index ( str codepoint-index -- utf16-index )
191     0 codepoint-index str subseq utf16n encode length 2 /i ;
192
193 :: earlier-caret/mark ( editor -- loc )
194     editor editor-caret :> caret
195     editor editor-mark :> mark
196     caret first mark first = [
197         caret second mark second < [ caret ] [ mark ] if
198     ] [
199         caret first mark first < [ caret ] [ mark ] if
200     ] if ;
201
202 :: make-preedit-underlines ( gadget text range -- underlines )
203     f gadget preedit-selection-mode?<<
204     { } clone :> underlines!
205     text -> length :> text-length
206     0 0 <NSRange> :> effective-range
207     text -> string CF>string :> str
208     str utf16n encode :> byte-16n
209     0 :> cp-loc!
210     "NSMarkedClauseSegment" <NSString> :> segment-attr
211     [ effective-range [ location>> ] [ length>> ] bi + text-length < ] [
212         text
213         segment-attr
214         effective-range [ location>> ] [ length>> ] bi +
215         effective-range >c-ptr
216         -> attribute:atIndex:effectiveRange: drop
217         1 :> thickness!
218         range location>> effective-range location>> = [
219             2 thickness!
220             t gadget preedit-selection-mode?<<
221         ] when
222         underlines
223         effective-range [ location>> ] [ length>> ] bi over +
224         [ str swap >codepoint-index ] bi@ swap - :> len
225         cp-loc cp-loc len + dup cp-loc!
226         2array thickness 2array
227         suffix underlines!
228     ] while 
229     underlines length 1 = [
230         underlines first first 2 2array 1array  ! thickness: 2
231     ] [ underlines ] if ;
232
233 :: update-marked-text ( gadget str selectedRange replacementRange -- )
234     replacementRange location>> NSNotFound = [
235         gadget editor-caret first
236         dup gadget editor-line
237         [ 
238             replacementRange location>>
239             >codepoint-index
240             2array gadget set-caret
241         ] [
242             replacementRange [ location>> ] [ length>> ] bi +
243             >codepoint-index
244             2array gadget set-mark
245         ] 2bi
246         gadget earlier-caret/mark dup
247         gadget preedit-start<<
248         0 1 2array v+ gadget preedit-end<<
249     ] unless
250
251     gadget preedit? [
252         gadget remove-preedit-text
253     ] when
254
255     gadget earlier-caret/mark dup
256     gadget preedit-start<<
257     0 str length 2array v+ gadget preedit-end<<
258     str gadget temp-im-input drop
259     gadget preedit-start>>
260     0 str selectedRange location>> >codepoint-index 2array v+
261     dup gadget preedit-selected-start<<
262     0
263     selectedRange [ location>> ] [ length>> ] bi + selectedRange location>>
264     [ str swap >codepoint-index ] bi@ -
265     2array v+
266     dup gadget preedit-selected-end<<
267     dup gadget set-caret gadget set-mark
268     gadget preedit-start>> gadget preedit-end>> = [
269         gadget remove-preedit-info 
270     ] when ;
271
272 PRIVATE>
273
274 <CLASS: FactorView < NSOpenGLView
275     COCOA-PROTOCOL: NSTextInputClient
276
277     METHOD: void prepareOpenGL [
278
279         self SEL: setWantsBestResolutionOpenGLSurface:
280         -> respondsToSelector: c-bool> [
281
282             self 1 { void { id SEL char } } ?-> setWantsBestResolutionOpenGLSurface:
283
284             self { double { id SEL } } ?-> backingScaleFactor
285
286             dup 1.0 > [
287                 gl-scale-factor set-global t retina? set-global
288                 cached-lines get-global clear-assoc
289             ] [ drop ] if
290
291             self -> update
292         ] when
293     ] ;
294
295     METHOD: void reshape [
296         self window :> window
297         window [
298             self view-dim window dim<<
299         ] when
300     ] ;
301
302     ! TouchBar
303     METHOD: void touchBarCommand0 [ 0 touchbar-invoke-command ] ;
304     METHOD: void touchBarCommand1 [ 1 touchbar-invoke-command ] ;
305     METHOD: void touchBarCommand2 [ 2 touchbar-invoke-command ] ;
306     METHOD: void touchBarCommand3 [ 3 touchbar-invoke-command ] ;
307     METHOD: void touchBarCommand4 [ 4 touchbar-invoke-command ] ;
308     METHOD: void touchBarCommand5 [ 5 touchbar-invoke-command ] ;
309     METHOD: void touchBarCommand6 [ 6 touchbar-invoke-command ] ;
310     METHOD: void touchBarCommand7 [ 7 touchbar-invoke-command ] ;
311
312     METHOD: id makeTouchBar [
313         touchbar-commands drop [
314             length 8 min <iota> [ number>string ] map
315         ] [ { } ] if* self make-touchbar
316     ] ;
317
318     METHOD: id touchBar: id touchbar makeItemForIdentifier: id string [
319         touchbar-commands drop [
320             [ self string CF>string dup string>number ] dip nth
321             second name>> "com-" ?head drop over
322             "touchBarCommand" prepend make-NSTouchBar-button
323         ] [ f ] if*
324     ] ;
325
326     ! Rendering
327     METHOD: void drawRect: NSRect rect [
328         self window [
329             draw-world yield
330         ] when*
331     ] ;
332
333     ! Light/Dark Mode
334
335 !    METHOD: void viewDidChangeEffectiveAppearance [
336 !        self -> effectiveAppearance -> name [
337 !            CF>string "NSAppearanceNameDarkAqua" =
338 !            dark-theme light-theme ? switch-theme-if-default
339 !        ] when*
340 !    ] ;
341
342     ! Events
343     METHOD: char acceptsFirstMouse: id event [ 0 ] ;
344
345     METHOD: void mouseEntered: id event [ self event send-mouse-moved ] ;
346
347     METHOD: void mouseExited: id event [ forget-rollover ] ;
348
349     METHOD: void mouseMoved: id event [ self event send-mouse-moved ] ;
350
351     METHOD: void mouseDragged: id event [ self event send-mouse-moved ] ;
352
353     METHOD: void rightMouseDragged: id event [ self event send-mouse-moved ] ;
354
355     METHOD: void otherMouseDragged: id event [ self event send-mouse-moved ] ;
356
357     METHOD: void mouseDown: id event [ self event send-button-down$ ] ;
358
359     METHOD: void mouseUp: id event [ self event send-button-up$ ] ;
360
361     METHOD: void rightMouseDown: id event [ self event send-button-down$ ] ;
362
363     METHOD: void rightMouseUp: id event [ self event send-button-up$ ] ;
364
365     METHOD: void otherMouseDown: id event [ self event send-button-down$ ] ;
366
367     METHOD: void otherMouseUp: id event [ self event send-button-up$ ] ;
368
369     METHOD: void scrollWheel: id event [ self event send-scroll$ ] ;
370
371     METHOD: void keyDown: id event [ self event send-key-down-event ] ;
372
373     METHOD: void keyUp: id event [ self event send-key-up-event ] ;
374
375     METHOD: char validateUserInterfaceItem: id event
376     [
377         self window :> window
378         window [
379             window world-focus :> gadget
380             gadget [
381                 gadget preedit? not [
382                     window event -> action utf8 alien>string validate-action
383                     [ >c-bool ] [ drop self event SUPER-> validateUserInterfaceItem: ] if
384                 ] [ 0 ] if
385             ] [ 0 ] if
386         ] [ 0 ] if
387     ] ;
388
389     METHOD: void undo: id event [ self event undo-action send-action$ ] ;
390
391     METHOD: void redo: id event [ self event redo-action send-action$ ] ;
392
393     METHOD: void cut: id event [ self event cut-action send-action$ ] ;
394
395     METHOD: void copy: id event [ self event copy-action send-action$ ] ;
396
397     METHOD: void paste: id event [ self event paste-action send-action$ ] ;
398
399     METHOD: void delete: id event [ self event delete-action send-action$ ] ;
400
401     METHOD: void selectAll: id event [ self event select-all-action send-action$ ] ;
402
403     METHOD: void newDocument: id event [ self event new-action send-action$ ] ;
404
405     METHOD: void openDocument: id event [ self event open-action send-action$ ] ;
406
407     METHOD: void saveDocument: id event [ self event save-action send-action$ ] ;
408
409     METHOD: void saveDocumentAs: id event [ self event save-as-action send-action$ ] ;
410
411     METHOD: void revertDocumentToSaved: id event [ self event revert-action send-action$ ] ;
412
413     ! Multi-touch gestures
414     METHOD: void magnifyWithEvent: id event
415     [
416         self event
417         dup -> deltaZ sgn {
418             {  1 [ zoom-in-action send-action$ ] }
419             { -1 [ zoom-out-action send-action$ ] }
420             {  0 [ 2drop ] }
421         } case
422     ] ;
423
424     METHOD: void swipeWithEvent: id event
425     [
426         self event
427         dup -> deltaX sgn {
428             {  1 [ left-action send-action$ ] }
429             { -1 [ right-action send-action$ ] }
430             {  0
431                 [
432                     dup -> deltaY sgn {
433                         {  1 [ up-action send-action$ ] }
434                         { -1 [ down-action send-action$ ] }
435                         {  0 [ 2drop ] }
436                     } case
437                 ]
438             }
439         } case
440     ] ;
441
442     METHOD: char acceptsFirstResponder [ 1 ] ;
443
444     ! Services
445     METHOD: id validRequestorForSendType: id sendType returnType: id returnType
446     [
447         ! We return either self or nil
448         self window [
449             world-focus sendType returnType
450             valid-service? [ self ] [ f ] if
451         ] [ f ] if*
452     ] ;
453
454     METHOD: char writeSelectionToPasteboard: id pboard types: id types
455     [
456         NSStringPboardType types CF>string-array member? [
457             self window [
458                 world-focus gadget-selection
459                 [ pboard set-pasteboard-string 1 ] [ 0 ] if*
460             ] [ 0 ] if*
461         ] [ 0 ] if
462     ] ;
463
464     METHOD: char readSelectionFromPasteboard: id pboard
465     [
466         self window :> window
467         window [
468             pboard pasteboard-string
469             [ window user-input 1 ] [ 0 ] if*
470         ] [ 0 ] if
471     ] ;
472
473     ! Text input
474     METHOD: void insertText: id text replacementRange: NSRange replacementRange [
475         self window :> window
476         window [
477             "" clone :> str!
478             text NSString -> class -> isKindOfClass: 0 = not [
479                 text CF>string str!
480             ] [
481                 text -> string CF>string str!
482             ] if
483             window world-focus :> gadget
484             gadget [
485                 gadget support-input-methods? [
486                     replacementRange location>> NSNotFound = [
487                         gadget editor-caret first
488                         dup gadget editor-line
489                         [ 
490                             replacementRange location>> >codepoint-index
491                             2array gadget set-caret
492                         ] [
493                             replacementRange [ location>> ] [ length>> ] bi +
494                             >codepoint-index
495                             2array gadget set-mark
496                         ] 2bi
497                     ] unless
498                     gadget preedit? [
499                         gadget remove-preedit-text
500                         gadget remove-preedit-info
501                         str gadget user-input* drop
502                         f gadget preedit-selection-mode?<<
503                     ] [
504                         str window user-input
505                     ] if
506                 ] [ 
507                     str window user-input
508                 ] if
509             ] when
510         ] when
511     ] ;
512
513     METHOD: char hasMarkedText [
514         self window :> window
515         window [
516             window world-focus :> gadget
517             gadget [
518                 gadget preedit? 1 0 ?
519             ] [ 0 ] if
520         ] [ 0 ] if
521     ] ;
522
523     METHOD: NSRange markedRange [
524         self window :> window
525         window [
526             window world-focus :> gadget
527             gadget [
528                 gadget preedit? [
529                     gadget preedit-start>> second
530                     gadget preedit-end>> second < [
531                         gadget preedit-start>> first gadget editor-line :> str
532                         gadget preedit-start>> second           ! location
533                         gadget preedit-end>> second
534                         [ str swap >utf16-index ] bi@ over -    ! length
535                     ] [ NSNotFound 0 ] if
536                 ] [ NSNotFound 0 ] if
537             ] [ NSNotFound 0 ] if
538         ] [ NSNotFound 0 ] if
539         <NSRange>
540     ] ;
541
542     METHOD: NSRange selectedRange [
543         self window :> window
544         window [
545             window world-focus :> gadget
546             gadget [
547                 gadget support-input-methods? [
548                     gadget editor-caret first gadget editor-line :> str
549                     gadget preedit? [
550                         str
551                         gadget preedit-selected-start>> second
552                         gadget preedit-start>> second
553                         - >utf16-index                        ! location
554                         gadget preedit-selected-end>> second
555                         gadget preedit-selected-start>> second
556                         [ str swap >utf16-index ] bi@ -       ! length
557                     ] [
558                         str gadget editor-caret second >utf16-index 0
559                     ] if
560                 ] [ 0 0 ] if
561             ] [ 0 0 ] if
562         ] [ 0 0 ] if 
563         <NSRange>
564     ] ;
565
566     METHOD: void setMarkedText: id text selectedRange: NSRange selectedRange
567                                      replacementRange: NSRange replacementRange [
568         self window :> window
569         window [
570             window world-focus :> gadget
571             gadget [
572                 { } clone :> underlines!
573                 "" clone :> str!
574                 text NSString -> class -> isKindOfClass: 0 = not [
575                     text CF>string str!
576                 ] [
577                     text -> string CF>string str!
578                     gadget support-input-methods? [
579                         gadget text selectedRange make-preedit-underlines underlines!
580                     ] when
581                 ] if
582                 gadget support-input-methods? [
583                     gadget str selectedRange replacementRange update-marked-text
584                     underlines gadget preedit-underlines<<
585                 ] when
586             ] when
587         ] when
588     ] ;
589
590     METHOD: void unmarkText [
591         self window :> window
592         window [
593             window world-focus :> gadget
594             gadget [
595                 gadget support-input-methods? [
596                     gadget preedit? [
597                         gadget {
598                             [ preedit-start>> second ]
599                             [ preedit-end>> second ]
600                             [ preedit-start>> first ]
601                             [ editor-line ]
602                         } cleave subseq
603                         gadget remove-preedit-text
604                         gadget remove-preedit-info
605                         gadget user-input* drop
606                     ] when
607                     f gadget preedit-selection-mode?<<
608                 ] when
609             ] when
610         ] when
611     ] ;
612
613     METHOD: id validAttributesForMarkedText [
614         NSArray "NSMarkedClauseSegment" <NSString> -> arrayWithObject:
615     ] ;
616
617     METHOD: id attributedSubstringForProposedRange: NSRange aRange
618                                        actualRange: id actualRange [ f ] ;
619
620     METHOD: NSUInteger characterIndexForPoint: NSPoint point [ 0 ] ;
621
622     METHOD: NSRect firstRectForCharacterRange: NSRange aRange
623                                   actualRange: NSRange actualRange [
624         self window :> window
625         window [
626             window world-focus :> gadget
627             gadget [
628                 gadget support-input-methods? [
629                     gadget editor-caret first gadget editor-line :> str
630                     str aRange location>> >codepoint-index :> start-pos
631                     gadget editor-caret first start-pos 2array gadget loc>x
632                     gadget caret-loc second gadget caret-dim second + 
633                     2array                     ! character pos
634                     gadget screen-loc v+       ! + gadget pos
635                     { 1 -1 } v*
636                     window handle>> window>> dup -> frame -> contentRectForFrameRect:
637                     CGRect-top-left 2array v+  ! + window pos
638                     first2 [ >fixnum ] bi@ 0 gadget line-height >fixnum
639                 ] [ 0 0 0 0 ] if
640             ] [ 0 0 0 0 ] if
641         ] [ 0 0 0 0 ] if
642         <CGRect>
643     ] ;
644
645     METHOD: void doCommandBySelector: SEL selector [ ] ;
646
647     ! Initialization
648     METHOD: id initWithFrame: NSRect frame pixelFormat: id pixelFormat
649     [
650         self frame pixelFormat SUPER-> initWithFrame:pixelFormat:
651     ] ;
652
653     METHOD: char isOpaque [ 0 ] ;
654
655     METHOD: void dealloc
656     [
657         self remove-observer
658         self SUPER-> dealloc
659     ] ;
660 ;CLASS>
661
662 : sync-refresh-to-screen ( GLView -- )
663     -> openGLContext -> CGLContextObj NSOpenGLCPSwapInterval 1 int <ref>
664     CGLSetParameter drop ;
665
666 : <FactorView> ( dim pixel-format -- view )
667     [ FactorView ] 2dip <GLView> [ sync-refresh-to-screen ] keep ;
668
669 : save-position ( world window -- )
670     -> frame CGRect-top-left 2array >>window-loc drop ;
671
672 <CLASS: FactorWindowDelegate < NSObject
673
674     METHOD: void windowDidMove: id notification
675     [
676         notification -> object -> contentView window
677         [ notification -> object save-position ] when*
678     ] ;
679
680     METHOD: void windowDidBecomeKey: id notification
681     [
682         notification -> object -> contentView window
683         [ focus-world ] when*
684     ] ;
685
686     METHOD: void windowDidResignKey: id notification
687     [
688         forget-rollover
689         notification -> object -> contentView :> view
690         view window :> window
691         window [
692             view -> isInFullScreenMode 0 =
693             [ window unfocus-world ] when
694         ] when
695     ] ;
696
697     METHOD: char windowShouldClose: id notification [ 1 ] ;
698
699     METHOD: void windowWillClose: id notification
700     [
701         notification -> object -> contentView
702         [ window ungraft ] [ unregister-window ] bi
703     ] ;
704
705     METHOD: void windowDidChangeBackingProperties: id notification
706     [
707
708         notification -> object dup SEL: backingScaleFactor
709         -> respondsToSelector: c-bool> [
710             { double { id SEL } } ?-> backingScaleFactor
711
712             [ [ 1.0 > ] keep f ? gl-scale-factor set-global ]
713             [ 1.0 > retina? set-global ] bi
714         ] [ drop ] if
715     ] ;
716 ;CLASS>
717
718 : install-window-delegate ( window -- )
719     FactorWindowDelegate install-delegate ;