From 7bc1009973d26579dba598ceee2f10444ecb6749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Tue, 27 Oct 2015 19:00:28 +0100 Subject: [PATCH] ui.*: make active? an integer 0-100 A UI backend can delay setting active? to 100 until the windows actually is visible. That way, some redundant redraws that happen when the window isn't visible is supressed. It makes the Windows and GTK UI startup a little faster. --- basis/ui/backend/cocoa/cocoa.factor | 3 +- basis/ui/backend/gtk/gtk-docs.factor | 11 +++- basis/ui/backend/gtk/gtk.factor | 15 ++++-- basis/ui/backend/windows/windows.factor | 8 +-- basis/ui/backend/x11/x11.factor | 1 + basis/ui/gadgets/worlds/worlds-docs.factor | 62 ++++++++++++++++------ basis/ui/gadgets/worlds/worlds.factor | 8 +-- basis/ui/ui.factor | 1 - 8 files changed, 79 insertions(+), 30 deletions(-) diff --git a/basis/ui/backend/cocoa/cocoa.factor b/basis/ui/backend/cocoa/cocoa.factor index 7835c50d51..55b3433192 100644 --- a/basis/ui/backend/cocoa/cocoa.factor +++ b/basis/ui/backend/cocoa/cocoa.factor @@ -143,7 +143,8 @@ M:: cocoa-ui-backend (open-window) ( world -- ) world window save-position window install-window-delegate view window world handle<< - window f -> makeKeyAndOrderFront: ; + window f -> makeKeyAndOrderFront: + 100 window active?<< ; M: cocoa-ui-backend (close-window) ( handle -- ) [ diff --git a/basis/ui/backend/gtk/gtk-docs.factor b/basis/ui/backend/gtk/gtk-docs.factor index 1b2753e29a..32d962ffeb 100644 --- a/basis/ui/backend/gtk/gtk-docs.factor +++ b/basis/ui/backend/gtk/gtk-docs.factor @@ -1,7 +1,16 @@ -USING: gtk.ffi help.markup help.syntax ; +USING: alien gdk.ffi gtk.ffi help.markup help.syntax kernel ; IN: ui.backend.gtk HELP: configure-im { $values { "win" GtkWindow } { "im" GtkIMContext } } { $description "Configures the input methods of the window. Must only be run after the window has been realized." } { $see-also gtk_widget_realize } ; + +HELP: on-configure +{ $values + { "win" alien } + { "event" alien } + { "user-data" alien } + { "?" boolean } +} +{ $description "Handles a configure event (" { $link GdkEventConfigure } " sent from the windowing system. The world is activated if it isn't already and a map event has been received. Then it is relayouted." } ; diff --git a/basis/ui/backend/gtk/gtk.factor b/basis/ui/backend/gtk/gtk.factor index b26eebb475..0263840425 100644 --- a/basis/ui/backend/gtk/gtk.factor +++ b/basis/ui/backend/gtk/gtk.factor @@ -257,20 +257,27 @@ CONSTANT: action-key-codes 2drop window relayout t ; : on-configure ( win event user-data -- ? ) - drop [ window ] [ GdkEventConfigure memory>struct ] bi* - [ event-loc >>window-loc ] [ event-dim >>dim ] bi - relayout-1 f ; + drop swap window dup active?>> 50 >= [ + 100 >>active? swap GdkEventConfigure memory>struct + [ event-loc >>window-loc ] [ event-dim >>dim ] bi + relayout-1 + ] [ 2drop ] if f ; : on-delete ( win event user-data -- ? ) 2drop window ungraft t ; +: on-map ( win event user-data -- ? ) + 2drop window 50 >>active? drop t ; + :: connect-win-state-signals ( win -- ) win "expose-event" [ on-expose yield ] GtkWidget:expose-event connect-signal win "configure-event" [ on-configure yield ] GtkWidget:configure-event connect-signal win "delete-event" [ on-delete yield ] - GtkWidget:delete-event connect-signal ; + GtkWidget:delete-event connect-signal + win "map-event" [ on-map yield ] + GtkWidget:map-event connect-signal ; ! Input methods diff --git a/basis/ui/backend/windows/windows.factor b/basis/ui/backend/windows/windows.factor index 0209f7f5b0..11afc7947b 100755 --- a/basis/ui/backend/windows/windows.factor +++ b/basis/ui/backend/windows/windows.factor @@ -271,7 +271,7 @@ CONSTANT: window-control>ex-style : handle-wm-paint ( hWnd uMsg wParam lParam -- ) ! wParam and lParam are unused ! only paint if width/height both > 0 - 3drop window relayout-1 yield ; + 3drop window 100 >>active? relayout-1 yield ; : handle-wm-size ( hWnd uMsg wParam lParam -- ) 2nip @@ -411,9 +411,9 @@ CONSTANT: exclude-keys-wm-char : handle-wm-syscommand ( hWnd uMsg wParam lParam -- n ) { - { [ over SC_MINIMIZE = ] [ f set-window-active ] } - { [ over SC_RESTORE = ] [ t set-window-active ] } - { [ over SC_MAXIMIZE = ] [ t set-window-active ] } + { [ over SC_MINIMIZE = ] [ 0 set-window-active ] } + { [ over SC_RESTORE = ] [ 100 set-window-active ] } + { [ over SC_MAXIMIZE = ] [ 100 set-window-active ] } { [ dup alpha? ] [ 4drop 0 ] } { [ t ] [ DefWindowProc ] } } cond ; diff --git a/basis/ui/backend/x11/x11.factor b/basis/ui/backend/x11/x11.factor index e030d2d418..ef22ab9cfc 100644 --- a/basis/ui/backend/x11/x11.factor +++ b/basis/ui/backend/x11/x11.factor @@ -57,6 +57,7 @@ M: world expose-event nip relayout ; M: world configure-event swap [ event-loc >>window-loc ] [ event-dim >>dim ] bi + 100 >>active? ! In case dimensions didn't change relayout-1 ; diff --git a/basis/ui/gadgets/worlds/worlds-docs.factor b/basis/ui/gadgets/worlds/worlds-docs.factor index 4c1fc3b964..c92fc98fa6 100644 --- a/basis/ui/gadgets/worlds/worlds-docs.factor +++ b/basis/ui/gadgets/worlds/worlds-docs.factor @@ -1,6 +1,5 @@ -USING: ui.gadgets ui.render ui.text ui.text.private -ui.gestures ui.backend help.markup help.syntax -models opengl sequences strings destructors ; +USING: destructors help.markup help.syntax math models strings +ui.backend ui.gadgets ui.gestures ui.render ; IN: ui.gadgets.worlds HELP: user-input @@ -47,19 +46,52 @@ HELP: focus-path HELP: world { $class-description "A gadget which appears at the top of the gadget hieararchy, and in turn may be displayed in a native window. Worlds have the following slots:" - { $list - { { $slot "active?" } " - if set to " { $link f } ", the world will not be drawn. This slot is set to " { $link f } " if an error is thrown while drawing the world; this prevents multiple debugger windows from being shown." } - { { $slot "layers" } " - a sequence of glass panes in front of the primary gadget, used to implement behaviors such as popup menus which are hidden when the mouse is clicked outside the menu. See " { $link "ui.gadgets.glass" } "." } - { { $slot "title" } " - a string to be displayed in the title bar of the native window containing the world." } - { { $slot "status" } " - a " { $link model } " holding a string to be displayed in the world's status bar." } - { { $slot "status-owner" } " - the gadget that displayed the most recent status message." } - { { $slot "focus" } " - the current owner of the keyboard focus in the world." } - { { $slot "focused?" } " - a boolean indicating if the native window containing the world has keyboard focus." } - { { $slot "grab-input?" } " - if set to " { $link t } ", the world will hide the mouse cursor and disable normal mouse input while focused. Use " { $link grab-input } " and " { $link ungrab-input } " to change this setting." } - { { $slot "handle" } " - a backend-specific native handle representing the native window containing the world, or " { $link f } " if the world is not grafted." } - { { $slot "window-loc" } " - the on-screen location of the native window containing the world. The co-ordinate system here is backend-specific." } - { { $slot "window-controls" } " - the set of " { $link "ui.gadgets.worlds-window-controls" } " with which the world window was created." } + { $table + { + { $slot "active?" } + { "an " { $link integer } " initially set to 0. The active " { $link ui-backend } " increases the value in steps up to 100 while the native window containing the world is being initialized but not yet visible on the screen. The world is only redrawn when the value is 100 which prevents redundant redraws from happening during initialization. The slot is set to 0 if an error is thrown while drawing the world; this prevents multiple debugger windows from being shown." } } + { + { $slot "layers" } + { "a sequence of glass panes in front of the primary gadget, used to implement behaviors such as popup menus which are hidden when the mouse is clicked outside the menu. See " { $link "ui.gadgets.glass" } "." } + } + { + { $slot "title" } + { "a string to be displayed in the title bar of the native window containing the world." } + } + { + { $slot "status" } + { "a " { $link model } " holding a string to be displayed in the world's status bar." } + } + { + { $slot "status-owner" } + { "the gadget that displayed the most recent status message." } + } + { + { $slot "focus" } + { "the current owner of the keyboard focus in the world." } + } + { + { $slot "focused?" } + { "a boolean indicating if the native window containing the world has keyboard focus." } + } + { + { $slot "grab-input?" } + { "if set to " { $link t } ", the world will hide the mouse cursor and disable normal mouse input while focused. Use " { $link grab-input } " and " { $link ungrab-input } " to change this setting." } + } + { + { $slot "handle" } + { "a backend-specific native handle representing the native window containing the world, or " { $link f } " if the world is not grafted." } + } + { + { $slot "window-loc" } + { "the on-screen location of the native window containing the world. The co-ordinate system here is backend-specific." } + } + { + { $slot "window-controls" } + { "the set of " { $link "ui.gadgets.worlds-window-controls" } " with which the world window was created." } + } + } } ; HELP: diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 5cf40ee329..43366603be 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -118,7 +118,7 @@ M: world request-focus-on ( child gadget -- ) : new-world ( class -- world ) vertical swap new-track t >>root? - f >>active? + 0 >>active? { 0 0 } >>window-loc f >>grab-input? V{ } clone >>window-resources @@ -177,7 +177,7 @@ M: world resize-world drop ; M: world dim<< [ call-next-method ] [ - dup active?>> [ + dup active?>> 100 = [ dup handle>> [ [ set-gl-context ] [ resize-world ] bi ] [ drop ] if @@ -199,7 +199,7 @@ M: world draw-world* : draw-world? ( world -- ? ) ! We don't draw deactivated worlds, or those with 0 size. ! On Windows, the latter case results in GL errors. - { [ active?>> ] [ handle>> ] [ dim>> [ 0 > ] all? ] } 1&& ; + { [ active?>> 100 = ] [ handle>> ] [ dim>> [ 0 > ] all? ] } 1&& ; TUPLE: world-error error world ; @@ -219,7 +219,7 @@ ui-error-hook [ [ rethrow ] ] initialize dup [ draw-world* ] with-gl-context flush-layout-cache-hook get call( -- ) ] [ - swap f >>active? ui-error + swap 0 >>active? ui-error ] recover ] with-variable ] [ drop ] if ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index 1a45ba95ba..dbbe7e7e19 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -64,7 +64,6 @@ SYMBOL: ui-windows [ [ title>> ] keep set-title ] [ begin-world ] [ resize-world ] - [ t >>active? drop ] [ request-focus ] } cleave ;