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