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.
db4
Björn Lindqvist 2015-10-27 19:00:28 +01:00
parent 73893693d3
commit 7bc1009973
8 changed files with 79 additions and 30 deletions

View File

@ -143,7 +143,8 @@ M:: cocoa-ui-backend (open-window) ( world -- )
world window save-position
window install-window-delegate
view window <window-handle> world handle<<
window f -> makeKeyAndOrderFront: ;
window f -> makeKeyAndOrderFront:
100 window active?<< ;
M: cocoa-ui-backend (close-window) ( handle -- )
[

View File

@ -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." } ;

View File

@ -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

View File

@ -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 ;

View File

@ -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 ;

View File

@ -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: <world>

View File

@ -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? <world-error> ui-error
swap 0 >>active? <world-error> ui-error
] recover
] with-variable
] [ drop ] if ;

View File

@ -64,7 +64,6 @@ SYMBOL: ui-windows
[ [ title>> ] keep set-title ]
[ begin-world ]
[ resize-world ]
[ t >>active? drop ]
[ request-focus ]
} cleave ;