2006-03-21 23:32:02 -05:00
|
|
|
! Copyright (C) 2005, 2006 Eduardo Cavazos and Slava Pestov
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-03-20 00:05:04 -05:00
|
|
|
IN: x11
|
2006-03-21 15:17:49 -05:00
|
|
|
USING: arrays errors freetype gadgets gadgets-launchpad
|
2006-05-31 18:45:11 -04:00
|
|
|
gadgets-listener hashtables kernel kernel-internals math
|
|
|
|
namespaces opengl sequences strings ;
|
2006-03-20 00:05:04 -05:00
|
|
|
|
2006-03-21 23:32:02 -05:00
|
|
|
! In the X11 backend, world-handle is a pair { window context }.
|
|
|
|
! The window is an X11 window ID, and the context is a
|
|
|
|
! GLX context pointer.
|
|
|
|
|
2006-03-23 16:14:53 -05:00
|
|
|
M: world expose-event ( event world -- ) nip relayout ;
|
|
|
|
|
2006-05-28 20:23:54 -04:00
|
|
|
: configured-loc ( event -- dim )
|
|
|
|
dup XConfigureEvent-x swap XConfigureEvent-y
|
|
|
|
0 3array ;
|
|
|
|
|
|
|
|
: configured-dim ( event -- dim )
|
2006-05-29 00:27:11 -04:00
|
|
|
dup XConfigureEvent-width swap XConfigureEvent-height
|
|
|
|
0 3array ;
|
2006-05-28 20:23:54 -04:00
|
|
|
|
|
|
|
M: world configure-event ( event world -- )
|
|
|
|
over configured-loc over set-world-loc
|
|
|
|
swap configured-dim swap set-gadget-dim ;
|
2006-03-20 00:05:04 -05:00
|
|
|
|
2006-03-23 16:57:14 -05:00
|
|
|
: button&loc ( event -- button# loc )
|
|
|
|
dup XButtonEvent-button
|
|
|
|
over XButtonEvent-x
|
|
|
|
rot XButtonEvent-y 0 3array ;
|
|
|
|
|
2006-03-21 18:19:06 -05:00
|
|
|
M: world button-down-event ( event world -- )
|
2006-03-23 16:57:14 -05:00
|
|
|
>r button&loc r> send-button-down ;
|
2006-03-21 18:19:06 -05:00
|
|
|
|
|
|
|
M: world button-up-event ( event world -- )
|
2006-03-23 16:57:14 -05:00
|
|
|
>r button&loc r> send-button-up ;
|
2006-03-21 18:19:06 -05:00
|
|
|
|
2006-03-23 16:01:47 -05:00
|
|
|
M: world wheel-event ( event world -- )
|
2006-03-28 21:14:08 -05:00
|
|
|
>r button&loc >r 4 = r> r> send-wheel ;
|
2006-03-23 16:01:47 -05:00
|
|
|
|
2006-06-03 01:53:34 -04:00
|
|
|
M: world enter-event ( event world -- ) motion-event ;
|
|
|
|
|
|
|
|
M: world leave-event ( event world -- ) 2drop forget-rollover ;
|
|
|
|
|
2006-03-21 18:19:06 -05:00
|
|
|
M: world motion-event ( event world -- )
|
|
|
|
>r dup XMotionEvent-x swap XMotionEvent-y 0 3array r>
|
|
|
|
move-hand ;
|
|
|
|
|
2006-03-22 02:07:21 -05:00
|
|
|
: modifiers
|
|
|
|
{
|
2006-05-18 22:01:38 -04:00
|
|
|
{ S+ HEX: 1 }
|
|
|
|
{ C+ HEX: 4 }
|
|
|
|
{ A+ HEX: 8 }
|
2006-03-22 02:07:21 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
: key-codes
|
|
|
|
H{
|
|
|
|
{ HEX: FF08 "BACKSPACE" }
|
|
|
|
{ HEX: FF09 "TAB" }
|
|
|
|
{ HEX: FF0D "RETURN" }
|
|
|
|
{ HEX: FF1B "ESCAPE" }
|
|
|
|
{ HEX: FFFF "DELETE" }
|
|
|
|
{ HEX: FF50 "HOME" }
|
|
|
|
{ HEX: FF51 "LEFT" }
|
|
|
|
{ HEX: FF52 "UP" }
|
|
|
|
{ HEX: FF53 "RIGHT" }
|
|
|
|
{ HEX: FF54 "DOWN" }
|
|
|
|
{ HEX: FF55 "PAGE_UP" }
|
|
|
|
{ HEX: FF56 "PAGE_DOWN" }
|
|
|
|
{ HEX: FF57 "END" }
|
|
|
|
{ HEX: FF58 "BEGIN" }
|
|
|
|
} ;
|
|
|
|
|
|
|
|
: ignored-key? ( keycode -- ? )
|
|
|
|
{
|
|
|
|
HEX: FFE1 HEX: FFE2 HEX: FFE3 HEX: FFE4 HEX: FFE5
|
|
|
|
HEX: FFE6 HEX: FFE7 HEX: FFE8 HEX: FFE9 HEX: FFEA
|
|
|
|
HEX: FFEB HEX: FFEC HEX: FFED HEX: FFEE
|
|
|
|
} member? ;
|
|
|
|
|
|
|
|
: key-code ( event -- keycode )
|
|
|
|
lookup-string drop dup ignored-key? [
|
|
|
|
drop f
|
|
|
|
] [
|
|
|
|
dup key-codes hash [ ] [ ch>string ] ?if
|
|
|
|
] if ;
|
|
|
|
|
2006-05-25 01:35:49 -04:00
|
|
|
: event>gesture ( event quot -- gesture )
|
|
|
|
>r dup XKeyEvent-state modifiers modifier swap key-code
|
|
|
|
r> [ drop f ] if* ;
|
2006-03-22 02:07:21 -05:00
|
|
|
|
|
|
|
M: world key-down-event ( event world -- )
|
2006-05-25 01:35:49 -04:00
|
|
|
world-focus over [ <key-down> ] event>gesture [
|
2006-03-22 02:07:21 -05:00
|
|
|
over handle-gesture
|
2006-03-22 17:22:05 -05:00
|
|
|
[ swap lookup-string nip swap user-input ] [ 2drop ] if
|
2006-03-22 02:07:21 -05:00
|
|
|
] [
|
2006-03-22 17:22:05 -05:00
|
|
|
2drop
|
2006-03-22 02:07:21 -05:00
|
|
|
] if* ;
|
|
|
|
|
2006-05-25 01:35:49 -04:00
|
|
|
M: world key-up-event ( event world -- )
|
2006-06-03 19:25:50 -04:00
|
|
|
world-focus over [ <key-up> ] event>gesture
|
|
|
|
[ over handle-gesture drop ] [ 2drop ] if* ;
|
2006-03-21 18:19:06 -05:00
|
|
|
|
2006-05-28 20:23:54 -04:00
|
|
|
M: world focus-in-event ( event world -- ) nip focus-world ;
|
|
|
|
|
|
|
|
M: world focus-out-event ( event world -- ) nip unfocus-world ;
|
|
|
|
|
2006-06-03 19:25:50 -04:00
|
|
|
M: world selection-event ( event world -- )
|
|
|
|
>r selection-from-event r> world-focus user-input ;
|
|
|
|
|
2006-03-22 18:23:32 -05:00
|
|
|
: close-box? ( event -- ? )
|
2006-03-22 02:27:07 -05:00
|
|
|
dup XClientMessageEvent-message_type "WM_PROTOCOLS" x-atom =
|
2006-05-31 06:14:01 -04:00
|
|
|
swap XClientMessageEvent-data0 "WM_DELETE_WINDOW" x-atom =
|
2006-03-21 23:32:02 -05:00
|
|
|
and ;
|
|
|
|
|
|
|
|
M: world client-event ( event world -- )
|
|
|
|
swap close-box? [
|
2006-03-23 16:24:26 -05:00
|
|
|
dup world-handle
|
|
|
|
>r close-world
|
|
|
|
r> first2 destroy-window*
|
2006-03-21 23:32:02 -05:00
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] if ;
|
|
|
|
|
2006-05-26 02:29:44 -04:00
|
|
|
: gadget-window ( world -- )
|
2006-05-29 02:13:07 -04:00
|
|
|
[
|
|
|
|
dup world-loc over rect-dim glx-window >r
|
|
|
|
[ register-window ] keep r> 2array
|
|
|
|
] keep set-world-handle ;
|
2006-03-20 00:05:04 -05:00
|
|
|
|
|
|
|
IN: gadgets
|
|
|
|
|
2006-05-26 02:29:44 -04:00
|
|
|
: set-title ( string world -- )
|
|
|
|
world-handle first dpy get -rot swap XStoreName drop ;
|
|
|
|
|
|
|
|
: open-window* ( world -- )
|
2006-06-03 16:08:35 -04:00
|
|
|
dup gadget-window dup start-world
|
2006-05-26 02:44:31 -04:00
|
|
|
world-handle first map-window* ;
|
2006-03-20 00:05:04 -05:00
|
|
|
|
2006-03-21 15:17:49 -05:00
|
|
|
: select-gl-context ( handle -- )
|
2006-03-21 17:15:53 -05:00
|
|
|
dpy get swap first2 glXMakeCurrent
|
2006-03-21 15:17:49 -05:00
|
|
|
[ "Failed to set current GLX context" throw ] unless ;
|
|
|
|
|
|
|
|
: flush-gl-context ( handle -- )
|
|
|
|
dpy get swap first glXSwapBuffers ;
|
|
|
|
|
2006-03-20 00:05:04 -05:00
|
|
|
IN: shells
|
|
|
|
|
|
|
|
: ui ( -- )
|
|
|
|
[
|
|
|
|
f [
|
2006-06-02 16:28:57 -04:00
|
|
|
init-timers
|
2006-06-03 19:25:50 -04:00
|
|
|
init-clipboard
|
2006-05-27 17:39:38 -04:00
|
|
|
restore-windows? [
|
|
|
|
restore-windows
|
|
|
|
] [
|
2006-06-02 16:28:57 -04:00
|
|
|
init-ui
|
2006-05-27 17:39:38 -04:00
|
|
|
launchpad-window
|
|
|
|
listener-window
|
|
|
|
] if
|
2006-03-20 00:05:04 -05:00
|
|
|
event-loop
|
|
|
|
] with-x
|
|
|
|
] with-freetype ;
|
|
|
|
|
|
|
|
IN: kernel
|
|
|
|
|
2006-03-22 02:39:36 -05:00
|
|
|
: default-shell "DISPLAY" os-env empty? "tty" "ui" ? ;
|