PreviousUpNext

15.4.1439  src/lib/x-kit/widget/gui/gui-event-types.pkg

## gui-event-types.pkg
#
# 2014-06-27: At the moment the below is a clone of the corresponding X stuff.
#             The idea is for this to become platform-independent and replace
#             the X event types at the platform-independent guiboss-imp.pkg level.
#
# Define the representation of X events
# used throughout x-kit.  These get created in
#
#     src/lib/x-kit/xclient/src/wire/wire-to-value.pkg
#
# and then routed through the widget mail system by
#
#     src/lib/x-kit/xclient/src/window/xsocket-to-hostwindow-router-old.pkg
#     src/lib/x-kit/xclient/src/window/hostwindow-to-widget-router-old.pkg
#
# and finally consumed by clients like
#
#     src/lib/x-kit/xclient/src/window/window-old.pkg
#
# These may be printed using
#
#     src/lib/x-kit/xclient/src/to-string/xevent-to-string.pkg

# Compiled by:
#     src/lib/x-kit/widget/xkit-widget.sublib

stipulate
    package g2d =  geometry2d;          # geometry2d            is from   src/lib/std/2d/geometry2d.pkg
    package f8b =  eight_byte_float;    # eight_byte_float      is from   src/lib/std/eight-byte-float.pkg
#   package ts  =  xserver_timestamp;   # xserver_timestamp     is from   src/lib/x-kit/xclient/src/wire/xserver-timestamp.pkg
#   package xt  =  xtypes;              # xtypes                is from   src/lib/x-kit/xclient/src/wire/xtypes.pkg
herein

    package gui_event_types {

        ################ start of xserver-timestamp section ####################################    
        #
        # This part is a clone of src/lib/x-kit/xclient/src/wire/xserver-timestamp.pkg
        # 
        package t {
            Xserver_Timestamp
                =
                XSERVER_TIMESTAMP  one_word_unt::Unt;

            fun bin_op operator (XSERVER_TIMESTAMP t1, XSERVER_TIMESTAMP t2) =  XSERVER_TIMESTAMP (operator (t1, t2));
            fun cmp_op operator (XSERVER_TIMESTAMP t1, XSERVER_TIMESTAMP t2) =  operator (t1, t2);

            fun to_float (XSERVER_TIMESTAMP w)
                =
                convert w
                where 
                    fun convert w
                        =
                        if (w >= 0ux40000000)
                            #
                            convert (w - 0ux40000000) + 1073741824.0;
                        else
                            f8b::from_int  (one_word_unt::to_int  w);
                        fi;
                end;

            my (+) = bin_op one_word_unt::(+);
            my (-) = bin_op one_word_unt::(-);

            # If you use these, remember that X server times
            # WRAP AROUND MONTHLY, so you cannot assume that
            #
            #     time1 < time2
            #     =>                            # DANGER!
            #     time1 earlier_than_time2:
            #
            my (<)  = cmp_op one_word_unt::(<);
            my (<=) = cmp_op one_word_unt::(<=);
            my (>)  = cmp_op one_word_unt::(>);
            my (>=) = cmp_op one_word_unt::(>=);
        };
        #
        ################ end of xserver-timestamp section ####################################    

        ################ start of xtypes section ####################################    
        #
        # This part is a clone of src/lib/x-kit/xclient/src/wire/xtypes.pkg
        # 

        # X authentication information.
        # This gets exported via duplication in:
        # 
        #     src/lib/x-kit/xclient/xclient.api
        #
        Xauthentication
            =
            XAUTHENTICATION
              {
                family:   Int,
                address:  String,
                display:  String,
                name:     String,
                data:     vector_of_one_byte_unts::Vector
              };

        # X atoms 
        #
        Atom = XATOM  Unt;

        # X resource ids.  These are used to name
        # windows, pixmaps, fonts, graphics contexts,
        # cursors and colormaps.  We collapse all of
        # these types into xid and leave it to a higher
        # level interface to distinguish them.
        # Type synonyms are defined for documentary purposes.
        # 
        # NOTE: the X11 protocol spec guarantees that
        # Xid values can be represented in 29 bits.
        #
        Xid = Unt;

        fun xid_to_unt unt
            =
            unt;

        fun xid_to_int unt
            =
            unt::to_int unt;

        fun xid_from_int  int
            =
            unt::from_int  int;

        fun xid_from_unt  (unt: Xid)
            =
            unt;

        fun xid_to_string  (unt: Xid)
            =
            unt::to_string unt;

        fun same_xid  (u1: Xid,  u2: Xid)
            =
            u1 == u2;

        fun xid_compare  (u1: Xid,  u2: Xid)
            =
            if   (u1 == u2)  EQUAL;
            elif (u1 <  u2)  LESS;
            else             GREATER;
            fi;

        Window_Id           = Xid;
        Pixmap_Id           = Xid;
        Drawable_Id         = Xid;              # Either window_id or pixmap_id.
        Font_Id             = Xid;
        Graphics_Context_Id = Xid;
        Fontable_Id         = Xid;              # Either Font_id or Graphics_Context_id.
        Cursor_Id           = Xid;
        Colormap_Id         = Xid;

        Plane_Mask = PLANEMASK  Unt;

        Visual_Id = VISUAL_ID  Unt;             #  should this be int?? 

        # Keysyms are a portable representation
        # of keycap symbols.
        #
        # It is nontrivial to translate a keysym with matching
        # modifier keys state to an ASCII char -- see
        #
        #     src/lib/x-kit/xclient/src/window/keysym-to-ascii.pkg
        #       
        #
        Keysym = NO_SYMBOL
               | KEYSYM  Int
               ;

        package k {                             # Some keysym constants for the convenient of client code.
            keypad_space    =  0xFF80;          # Keypad space key.
            backspace       =  0xFF08;          # <Backspace> key.
            tab             =  0xFF09;          # <Tab> key.
            linefeed        =  0xFF0A;          # <Linefeed> key.
            return          =  0xFF0D;          # <Return> key.
            esc             =  0xFF1B;          # <Esc> key.
            delete          =  0xFFFF;          # <Delete> key.
            keypad_enter    =  0xFF8D;          # Keypad <Enter> key.
            keypad_multiply =  0xFFAA;          # Keypad "*" key.
            keypad_add      =  0xFFAB;          # Keypad "+" key.
            keypad_subtract =  0xFFAD;          # Keypad "-" key.
            keypad_divide   =  0xFFAF;          # Keypad "/" key.
            keypad_1        =  0xFFB1;          # Keypad "1" key.
            keypad_2        =  0xFFB2;          # Keypad "2" key.
            keypad_3        =  0xFFB3;          # Keypad "3" key.
            keypad_4        =  0xFFB4;          # Keypad "4" key.
            keypad_5        =  0xFFB5;          # Keypad "5" key.
            keypad_6        =  0xFFB6;          # Keypad "6" key.
            keypad_7        =  0xFFB7;          # Keypad "7" key.
            keypad_8        =  0xFFB8;          # Keypad "8" key.
            keypad_9        =  0xFFB9;          # Keypad "9" key.
            keypad_equal    =  0xFFBD;          # Keypad "=" key.
        };



        Keycode = KEYCODE  Int;

        any_key = (KEYCODE 0);

        # X time stamps are either the
        # Current Time or an X Server time value: 
        #
        Timestamp = CURRENT_TIME
                  | TIMESTAMP  t::Xserver_Timestamp
                  ;


        # Raw data from server (in ClientMessage, property values, ...) 
        #
        Raw_Format = RAW08
                   | RAW16
                   | RAW32
                   ;
        #
        Raw_Data =  RAW_DATA
                      { format:  Raw_Format,
                        data:    vector_of_one_byte_unts::Vector
                      };

        # X property values.  A property value has a type,
        # which is an atom, and a value.  The value is a
        # sequence of 8, 16 or 32-bit items, represented
        # as a format and a string.
        #
        Property_Value
            =
            PROPERTY_VALUE
              { type:   Atom,
                value:  Raw_Data
              };

        # Modes for  src/lib/x-kit/xclient/src/iccc/window-property-old.pkg
        #
        Change_Property_Mode
          #
          = REPLACE_PROPERTY
          | PREPEND_PROPERTY
          |  APPEND_PROPERTY
          ;

        # Polygon shapes 
        #
        Shape =   COMPLEX_SHAPE
              | NONCONVEX_SHAPE
              |    CONVEX_SHAPE
              ;

        # Color items 
        #
        Color_Item
            =
            COLORITEM
              { rgb8:   rgb8::Rgb8,
                red:    Null_Or( Unt ),
                green:  Null_Or( Unt ),
                blue:   Null_Or( Unt )
              };

        # Text/font items, used by PolyText[8, 16] 
        #
        Text_Font
          = FONT_ITEM  Font_Id          #  set new font 
          | TEXT_ITEM  (Int, String)    #  text item 
          ;

        # Modifier keys and mouse buttons 
        #
        Modifier_Key
          #
          = SHIFT_KEY
          | LOCK_KEY
          | CONTROL_KEY
          | MOD1KEY
          | MOD2KEY
          | MOD3KEY
          | MOD4KEY
          | MOD5KEY
          | ANY_MODIFIER
          ;

        Mousebutton =  MOUSEBUTTON Int;                 # Values may range 1-13 or more.  Typically 1=left, 2=middle, 3=right, 4=mousewheel-forward, 5=mousewheel-back.
        #
        button1 =  MOUSEBUTTON 1;
        button2 =  MOUSEBUTTON 2;
        button3 =  MOUSEBUTTON 3;
        button4 =  MOUSEBUTTON 4;                       # NB: Rotating the mousewheel usually produces a sequence of button4 downclick+upclick pairs going forward and button5 ones going backward.
        button5 =  MOUSEBUTTON 5;
            #
            # The X protocol docs are not overly specific
            # about mouse button encodings.  p7 of
            #
            #     http://mythryl.org/pub/exene/X-protocol-R6.pdf
            #
            # says laconically
            #
            #     6. Pointers
            #     Buttons are always numbered starting with one.
            #
            # On my system
            #
            #     /usr/include/X11/X.h
            #
            # is more explicit:
            #
            #     /* button names. Used as arguments to GrabButton and as detail in ButtonPress
            #    and ButtonRelease events.  Not to be confused with button masks above.
            #    Note that 0 is already defined above as "AnyButton".  */
            #
            #     #define Button1                       1
            #     #define Button2                       2
            #     #define Button3                       3
            #     #define Button4                       4
            #     #define Button5                       5


        Modifier_Keys_State
          =
          { shift_key_was_down:         Bool,
            shiftlock_key_was_down:     Bool,                   # Should we say 'set' instead of 'down'?
            control_key_was_down:       Bool,
            mod1_key_was_down:          Bool,
            mod2_key_was_down:          Bool,
            mod3_key_was_down:          Bool,
            mod4_key_was_down:          Bool,
            mod5_key_was_down:          Bool
          };
                                                                # On Linux/Posix run xmodmap to show current modifiers, output looks like:
                                                                #
                                                                #    shift       Shift_L (0x32),  Shift_R (0x3e)
                                                                #    lock        Caps_Lock (0x42)
                                                                #    control     Control_L (0x25),  Control_R (0x69)
                                                                #    mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
                                                                #    mod2        Num_Lock (0x4d)
                                                                #    mod3
                                                                #    mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
                                                                #    mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)
                                                                #    
                                                                # The Super_L and Super_R keysyms correspond to the Win keys on your keyboard.
                                                                # More info available at:
                                                                #    http://www.emacswiki.org/emacs/MetaKeyProblems

        fun modifier_keys_state__to__string (s:  Modifier_Keys_State)
            =
            {   shift = s.shift_key_was_down     ?? [ "shift" ]     :: [];
                lock  = s.shiftlock_key_was_down ?? [ "shiftlock" ] :: [];
                ctrl  = s.control_key_was_down   ?? [ "ctrl" ]      :: [];
                mod1  = s.mod1_key_was_down      ?? [ "mod1" ]      :: [];
                mod2  = s.mod2_key_was_down      ?? [ "mod2" ]      :: [];
                mod3  = s.mod3_key_was_down      ?? [ "mod3" ]      :: [];
                mod4  = s.mod4_key_was_down      ?? [ "mod4" ]      :: [];
                mod5  = s.mod5_key_was_down      ?? [ "mod5" ]      :: [];

                string::join' "<" " " ">" (list::cat [ shift, lock, ctrl, mod1, mod2, mod3, mod4, mod5 ]);
            };



        no_modifier_keys_were_down
          =
          { shift_key_was_down      =>  FALSE,
            shiftlock_key_was_down  =>  FALSE,
            control_key_was_down    =>  FALSE,
            mod1_key_was_down       =>  FALSE,
            mod2_key_was_down       =>  FALSE,
            mod3_key_was_down       =>  FALSE,
            mod4_key_was_down       =>  FALSE,
            mod5_key_was_down       =>  FALSE
          };

        Mousebuttons_State                                      # Note that MOUSEBUTTON values may range 1-13 or more, but we only track 1-5 in Mousebuttons_State.
          =
          { mousebutton_1_was_down:     Bool,
            mousebutton_2_was_down:     Bool,
            mousebutton_3_was_down:     Bool,
            mousebutton_4_was_down:     Bool,                   # NB: Rotating the mousewheel usually produces a sequence of button4 downclick+upclick pairs going forward and button5 ones going backward.
            mousebutton_5_was_down:     Bool
          };

        no_mouse_buttons_were_down
          =
          { mousebutton_1_was_down   => FALSE,
            mousebutton_2_was_down   => FALSE,
            mousebutton_3_was_down   => FALSE,
            mousebutton_4_was_down   => FALSE,
            mousebutton_5_was_down   => FALSE
          };

        only_mouse_button_1_was_down
          =
          { mousebutton_1_was_down   => TRUE,
            mousebutton_2_was_down   => FALSE,
            mousebutton_3_was_down   => FALSE,
            mousebutton_4_was_down   => FALSE,
            mousebutton_5_was_down   => FALSE
          };

        fun pressed_mousebutton_count (b: Mousebuttons_State)
            #
            =   (b.mousebutton_1_was_down ?? 1 :: 0)
            +   (b.mousebutton_2_was_down ?? 1 :: 0)
            +   (b.mousebutton_3_was_down ?? 1 :: 0)
            +   (b.mousebutton_4_was_down ?? 1 :: 0)
            +   (b.mousebutton_5_was_down ?? 1 :: 0)
            ;

        # Modes for AllowEvents 
        #
        Event_Mode
          #
          = ASYNC_POINTER
          | SYNC_POINTER
          | REPLAY_POINTER
          | ASYNC_KEYBOARD
          | SYNC_KEYBOARD
          | REPLAY_KEYBOARD
          | ASYNC_BOTH
          | SYNC_BOTH
          ;

        # Keyboard focus modes 
        #
        Focus_Mode
          #
          = FOCUS_NORMAL
          | FOCUS_WHILE_GRABBED
          | FOCUS_GRAB
          | FOCUS_UNGRAB
          ;
        #
        Focus_Detail
          #
          = FOCUS_ANCESTOR
          | FOCUS_VIRTUAL
          | FOCUS_INFERIOR
          | FOCUS_NONLINEAR
          | FOCUS_NONLINEAR_VIRTUAL
          | FOCUS_POINTER
          | FOCUS_POINTER_ROOT
          | FOCUS_NONE
          ;

        # Input focus modes:
        #
        Input_Focus
          #
          = INPUT_FOCUS_NONE
          | INPUT_FOCUS_POINTER_ROOT
          | INPUT_FOCUS_WINDOW       Window_Id
          ;
        #
        Focus_Revert
          #
          = REVERT_TO_NONE
          | REVERT_TO_POINTER_ROOT
          | REVERT_TO_PARENT
          ;

        # SendEvent targets 
        #
        Send_Event_To
          #
          = SEND_EVENT_TO_POINTER_WINDOW
          | SEND_EVENT_TO_INPUT_FOCUS
          | SEND_EVENT_TO_WINDOW        Window_Id
          ;

        # Input device grab modes 
        #
        Grab_Mode = SYNCHRONOUS_GRAB | ASYNCHRONOUS_GRAB;

        # Input device grab status:
        #
        Grab_Status
          #
          = GRAB_SUCCESS
          | ALREADY_GRABBED
          | GRAB_INVALID_TIME
          | GRAB_NOT_VIEWABLE
          | GRAB_FROZEN
          ;

        # Input device mapping status:
        #
        Mapping_Status
          #
          = MAPPING_SUCCESS
          | MAPPING_BUSY
          | MAPPING_FAILED
          ;

        # Visibility 
        #
        Visibility
          = VISIBILITY_UNOBSCURED
          | VISIBILITY_PARTIALLY_OBSCURED
          | VISIBILITY_FULLY_OBSCURED
          ;

        # Window stacking modes:
        #
        Stack_Mode
          #
          = ABOVE
          | BELOW
          | TOP_IF
          | BOTTOM_IF
          | OPPOSITE
          ;

        # Window circulation request:
        #
        Stack_Pos
          #
          = PLACE_ON_TOP
          | PLACE_ON_BOTTOM
          ;

        # Window backing-store ilks:
        #
        Backing_Store
          #
          = BS_NOT_USEFUL
          | BS_WHEN_MAPPED
          | BS_ALWAYS
          ;

        # Window map states:
        #
        Map_State
          #
          = WINDOW_IS_UNMAPPED
          | WINDOW_IS_UNVIEWABLE
          | WINDOW_IS_VIEWABLE
          ;

        # Rectangle list orderings for SetClipRectangles 
        #
        Box_Order
          #
          = UNSORTED_ORDER
          | YSORTED_ORDER
          | YXSORTED_ORDER
          | YXBANDED_ORDER
          ;

        # Font drawing direction:
        # 
        Font_Drawing_Direction
          #
          = DRAW_FONT_LEFT_TO_RIGHT
          | DRAW_FONT_RIGHT_TO_LEFT
          ;

        # Font properties:
        #
        Font_Prop
            =
            FONT_PROP
              { name:   Atom,                           # Name of the property.
                value:  one_word_unt::Unt               # Property value: interpret according to the property. 
              };

        Font_Height = { ascent:     Int,                                                                                # Letters (glyphs) in font rise at most this many pixels above baseline.  (Think of the ascent  stroke on an 'h'.)
                        descent:    Int                                                                                 # Letters (glyphs) in font drop at most this many pixels below baseline.  (Think of the descent stroke on a  'q'.)
                      };

        Font =  { id:                           Id,
                  font_height:                  Font_Height,
                  string_length_in_pixels:      String -> Int
                };

        # Per-character font info 
        #
        Char_Info
            =
            CHAR_INFO
              {
                left_bearing:   Int,
                right_bearing:  Int,
                char_width:     Int,
                ascent:         Int,
                descent:        Int,
                #
                attributes:     Unt
              };

        # Graphics functions:
        #
        Graphics_Op
          #
          = OP_CLR                      #  0 
          | OP_AND                      #  src AND dst 
          | OP_AND_NOT                  #  src AND NOT dst 
          | OP_COPY                     #  src 
          | OP_AND_INVERTED             #  NOT src AND dst 
          | OP_NOP                      #  Dst 
          | OP_XOR                      #  src XOR dst 
          | OP_OR                       #  src OR dst 
          | OP_NOR                      #  NOT src AND NOT dst 
          | OP_EQUIV                    #  NOT src XOR dst 
          | OP_NOT                      #  NOT dst 
          | OP_OR_NOT                   #  src OR NOT dst 
          | OP_COPY_NOT                 #  NOT src 
          | OP_OR_INVERTED              #  NOT src OR dst 
          | OP_NAND                     #  NOT src OR NOT dst 
          | OP_SET                      #  1 
          ;


        # Gravity. (Both window-gravity and bit-gravity.)
        # Used in window-manager hints -- see:
        #
        #     src/lib/x-kit/xclient/src/wire/wire-to-value-pith.pkg
        #     src/lib/x-kit/xclient/src/wire/value-to-wire-pith.pkg
        #
        Gravity
          #
          =    FORGET_GRAVITY           #  Bit gravity only 
          |     UNMAP_GRAVITY           #  window gravity only 
          | NORTHWEST_GRAVITY
          |     NORTH_GRAVITY
          | NORTHEAST_GRAVITY
          |      WEST_GRAVITY
          |    CENTER_GRAVITY
          |      EAST_GRAVITY
          | SOUTHWEST_GRAVITY
          |     SOUTH_GRAVITY
          | SOUTHEAST_GRAVITY
          |    STATIC_GRAVITY
          ;

        # Event masks:
        #
        Event_Mask = EVENT_MASK  Unt;

        # Value "lists".
        #
        # We call these lists because that is
        # the X protocol doc terminology;
        # they are actually vectors:
        #
        Value_Mask = VALUE_MASK  Unt;
        Value_List = VALUE_LIST  rw_vector::Rw_Vector( Null_Or( Unt ) );

        # Ilks for QueryBestSize:
        #
        Best_Size_Ilk
          = CURSOR_SHAPE                # Largest size that can be displayed.
          | TILE_SHAPE                  # Size tiled fastest.
          | STIPPLE_SHAPE               # Size stippled fastest.
          ;

        # Resource close-down modes: 
        #
        Close_Down_Mode
          #
          = DESTROY_ALL
          | RETAIN_PERMANENT
          | RETAIN_TEMPORARY
          ;

        # 'io_class' arg for create_window
        # and  encode_create_window:
        #
        Io_Class
          #
          = SAME_IO_AS_PARENT
          | INPUT_OUTPUT
          | INPUT_ONLY
          ;

        # 'visual_id' arg for create_window
        # and          encode_create_window:
        #
        Visual_Id_Choice
          #
          = SAME_VISUAL_AS_PARENT
          | OVERRIDE_PARENT_VISUAL Visual_Id
          ;

        # X hosts 
        #
        Xhost
          #
          = INTERNET_HOST  String
          | DECNET_HOST  String
          | CHAOS_HOST  String
          ;

        # Image byte-orders and bitmap bit-orders 
        #
        Order = MSBFIRST | LSBFIRST;

        # Image formats 
        #
        Image_Format
          #
          = XYBITMAP            #  Depth 1, XYFormat 
          | XYPIXMAP            #  Depth == drawable depth 
          | ZPIXMAP             #  Depth == drawable depth 
          ;     

        Pixmap_Format
            =
            FORMAT
              { depth:           Int,
                bits_per_pixel:  Int,
                scanline_pad:    Raw_Format 
              };

        Display_Class
          #
          = STATIC_GRAY
          | GRAY_SCALE
          | STATIC_COLOR
          | PSEUDO_COLOR
          | TRUE_COLOR
          | DIRECT_COLOR
          ;

        # Our type "Visual" here is actually a merging of
        # the X protocol types of "depth" and "visual":
        #
        Visual
          #
          = NO_VISUAL_FOR_THIS_DEPTH  Int               # A depth with no visuals.
          #
          | VISUAL
              {
                visual_id:     Visual_Id,               # The associated visual id.
                depth:         Int,                     # The depth.
                ilk:           Display_Class,
                cmap_entries:  Int,
                bits_per_rgb:  Int,
                red_mask:      Unt,
                green_mask:    Unt,
                blue_mask:     Unt
              };


        # This holds the information we get back from
        # a (successful) connect request to the X server.
        # These values get constructed by
        #
        #     decode_connect_request_reply
        #
        # from   src/lib/x-kit/xclient/src/wire/wire-to-value.pkg
        #
        # and may be rendered into a human-readable string via
        #
        #     xserver_info_to_string
        #
        # from   src/lib/x-kit/xclient/src/to-string/xserver-info-to-string.pkg
        #     
        Xserver_Screen
            =
            { backing_store:    Backing_Store, 
              #
              black_rgb8:       rgb8::Rgb8,
              white_rgb8:       rgb8::Rgb8,
              #
              default_colormap: Xid, 
              input_masks:      Event_Mask, 
              #
              installed_colormaps
                  :
                  { min:        Int,
                    max:        Int
                  }, 

              millimeters_high: Int,
              millimeters_wide: Int, 
              #
              pixels_high:      Int,
              pixels_wide:      Int, 
              #
              root_depth:       Int,
              root_visualid:    Visual_Id, 
              root_window:      Xid,
              #
              save_unders:      Bool,
              visuals:          List( Visual )
            };

        Xserver_Info
            =
            { bitmap_order:         Order, 
              image_byte_order:     Order, 
              #
              bitmap_scanline_pad:  Raw_Format, 
              bitmap_scanline_unit: Raw_Format, 
              #
              pixmap_formats:  List(Pixmap_Format), 
              #
              max_keycode:          Keycode,
              min_keycode:          Keycode,
              #
              motion_buf_size:      Int, 
              max_request_length:   Int, 
              #
              protocol_version: { minor: Int,
                                  major: Int
                                }, 
              release_number: Int, 

              screens:   List( Xserver_Screen ),

              xid_base:  Unt,           # See Note[1], below.
              xid_mask:  Unt,           # "                ".

              vendor:    String
            };

        # These are used as arguments to
        #
        #     value::make_window_attribute_list
        #
        # whose result in turn is an argument for:
        #
        #     value_to_wire::encode_create_window
        #     value_to_wire::encode_change_window_attributes
        #
        package a {

            Window_Attribute
              #
              = BACKGROUND_PIXMAP_NONE
              | BACKGROUND_PIXMAP_PARENT_RELATIVE
              | BACKGROUND_PIXMAP               Pixmap_Id
              | BACKGROUND_PIXEL                rgb8::Rgb8
              #
              | BORDER_PIXMAP_COPY_FROM_PARENT
              | BORDER_PIXMAP                   Pixmap_Id
              | BORDER_PIXEL                    rgb8::Rgb8
              #
              | BIT_GRAVITY                     Gravity
              | WINDOW_GRAVITY                  Gravity
              #
              | BACKING_STORE                   Backing_Store
              | BACKING_PLANES                  Plane_Mask
              | BACKING_PIXEL                   rgb8::Rgb8
              #
              | EVENT_MASK                      Event_Mask
              | DO_NOT_PROPAGATE_MASK           Event_Mask
              #
              | SAVE_UNDER                      Bool
              | OVERRIDE_REDIRECT               Bool
              #
              | COLOR_MAP_COPY_FROM_PARENT
              | COLOR_MAP                       Colormap_Id
              | CURSOR_NONE
              | CURSOR                          Cursor_Id
              ;
        };

        package xid_map =   unt_red_black_map;                                          # unt_red_black_map     is from   src/lib/src/unt-red-black-map.pkg
            #
            # Defining this here allows us to re-use the unt_red_black_map implementation.
            # Client code cannot do this because our Xid type is exported as opaque;
            # they would have to construct a new specialization of red_black_map_g(),
            # which would be binary-identical to unt_red_black_map and thus a complete
            # waste of codespace.

        #
        ################ end of xtypes section ####################################    

        ################ start of xserver-timestamp section ####################################    
        #
        # This part is a clone of src/lib/x-kit/xclient/src/wire/xevent-types.pkg
        # 

        stipulate

            my (&)  = unt::bitwise_and;
            my (|)  = unt::bitwise_or;
            my (<<) = unt::(<<);

            infix my | << & ;

        herein

            # X event names 
            #
            package n {

                Xevent_Name
                  #
                  = KEY_PRESS
                  | KEY_RELEASE
                  | BUTTON_PRESS
                  | BUTTON_RELEASE
                  | ENTER_WINDOW
                  | LEAVE_WINDOW
                  | POINTER_MOTION
                  | POINTER_MOTION_HINT
                  | BUTTON1MOTION
                  | BUTTON2MOTION
                  | BUTTON3MOTION
                  | BUTTON4MOTION
                  | BUTTON5MOTION
                  | BUTTON_MOTION
                  | KEYMAP_STATE
                  | EXPOSURE
                  | VISIBILITY_CHANGE
                  | STRUCTURE_NOTIFY
                  | RESIZE_REDIRECT
                  | SUBSTRUCTURE_NOTIFY
                  | SUBSTRUCTURE_REDIRECT
                  | FOCUS_CHANGE
                  | PROPERTY_CHANGE
                  | COLORMAP_CHANGE
                  | OWNER_GRAB_BUTTON
                  ;
            };

            # The types of the information
            # carried by some XEvents: 
            #
            Key_Xevtinfo                                                        # KeyPress and KeyRelease 
              =
              { root_window_id:         Window_Id,                              # Root of the source window.
                event_window_id:        Window_Id,                              # The window in which this was generated.
                child_window_id:        Null_Or( Window_Id ),                   # The child of the event window that is the 
                                                                                # ancestor of the source window.
                same_screen:            Bool,                                   #  
                root_point:             g2d::Point,                             # Event coordinates in the root window.
                event_point:            g2d::Point,                             # Event coordinates in the event window.
                #
                keycode:                Keycode,                                # Keycode of the depressed key.
                keysym:                 Keysym,                                 # Keysym  of the depressed key.  This is not present in the X version of Key_Kevtinfo; added for widget-code convenience.
                ascii:                  String,                                 # Ascii  for the depressed key.  This is not present in the X version of Key_Kevtinfo; added for widget-code convenience.
                #
                modifier_keys_state:    Modifier_Keys_State,                    # State of the modifier keys (shift, ctrl...).
                mousebuttons_state:     Mousebuttons_State,                     # State of mouse buttons as bool record.
                timestamp:              t::Xserver_Timestamp
              };

            Button_Xevtinfo                                                     # ButtonPress and ButtonRelease.
              =
              {
                root_window_id:         Window_Id,                              # Root of the source window.
                event_window_id:        Window_Id,                              # Window in which this was generated.
                child_window_id:        Null_Or( Window_Id ),                   # The child of the event window that is the 
                                                                                # ancestor of the source window.
                same_screen:            Bool,                                   #  
                root_point:             g2d::Point,                             # Event coordinates in the root window.
                event_point:            g2d::Point,                             # Event coordinates in the event window.
                mouse_button:           Mousebutton,                            # The button that was pressed.
                modifier_keys_state:    Modifier_Keys_State,                    # State of the modifier keys (shift, ctrl...).
                mousebuttons_state:     Mousebuttons_State,                     # State of mouse buttons as bool record.
                timestamp:              t::Xserver_Timestamp
              };

            Motion_Xevtinfo
              =
              {
                root_window_id:         Window_Id,                              # The root of the source window.
                event_window_id:        Window_Id,                              # The window in which this was generated.
                child_window_id:        Null_Or(Window_Id),                     # The child of the event window that is the 
                                                                                # ancestor of the source window 
                same_screen:            Bool,                                   #  
                root_point:             g2d::Point,                             # Event coords in the root window.
                event_point:            g2d::Point,                             # Event coords in the event window.
                hint:                   Bool,                                   # TRUE if PointerMotionHint is selected.
                modifier_keys_state:    Modifier_Keys_State,                    # State of the modifier keys (shift, ctrl...).
                mousebuttons_state:     Mousebuttons_State,                     # State of mouse buttons as bool record.
                timestamp:              t::Xserver_Timestamp
              };

            Inout_Xevtinfo                                                      #  EnterNotify and LeaveNotify 
              =
              {
                root_window_id:         Window_Id,                              # Root window for the pointer position.
                event_window_id:        Window_Id,                              # Event window.
                child_window_id:        Null_Or( Window_Id ),                   # Child of event containing the pointer.
                same_screen:            Bool,                                   #  
                root_point:             g2d::Point,                             # Final pointer position in root coordinates.
                event_point:            g2d::Point,                             # Final pointer position in event coordinates 
                mode:                   Focus_Mode,                             # 
                detail:                 Focus_Detail,                           #  
                modifier_keys_state:    Modifier_Keys_State,                    # State of the modifier keys (shift, ctrl...).
                mousebuttons_state:     Mousebuttons_State,                     # State of mouse buttons as bool record.
                focus:                  Bool,                                   # TRUE, if event is the focus 
                timestamp:              t::Xserver_Timestamp
              };

            Focus_Xevtinfo                                                      # FocusIn and FocusOut 
              =
              { event_window_id:        Window_Id,                              # The window that gained the focus 
                mode:                   Focus_Mode,
                detail:                 Focus_Detail
              };


            # X event messages:
            #
            package x {

                Graphics_Expose_Record
                  =
                  { drawable:      Drawable_Id,
                    box:           g2d::Box,                                    # The obscured rectangle. 
                    count:         Int,                                         # The number of additional GraphicsExpose events.
                    major_opcode:  Unt,                                         # The graphics operation code.
                    minor_opcode:  Unt                                          # Always 0 for core protocol.
                  };

                Expose_Record
                  =
                  { exposed_window_id:  Window_Id,                              # The exposed window. 
                    boxes:              List( g2d::Box ),                       # The exposed rectangle.  The list is
                                                                                # so  that multiple events can be widget. 
                    count:              Int                                     # Number of subsequent expose events.
                  };

                Event
                  = KEY_PRESS       Key_Xevtinfo
                  | KEY_RELEASE     Key_Xevtinfo
                  | BUTTON_PRESS    Button_Xevtinfo
                  | BUTTON_RELEASE  Button_Xevtinfo
                  #
                  | MOTION_NOTIFY   Motion_Xevtinfo
                  #
                  | ENTER_NOTIFY    Inout_Xevtinfo
                  | LEAVE_NOTIFY    Inout_Xevtinfo
                  #
                  | FOCUS_IN        Focus_Xevtinfo
                  | FOCUS_OUT       Focus_Xevtinfo
                  #
                  | KEYMAP_NOTIFY   { }

                  | EXPOSE                    Expose_Record
                  | GRAPHICS_EXPOSE  Graphics_Expose_Record

                  | NO_EXPOSE
                      { drawable:               Drawable_Id,
                        major_opcode:           Unt,                            # The graphics operation code.
                        minor_opcode:           Unt                             # Always 0 for core protocol.
                      }

                  | VISIBILITY_NOTIFY
                      { changed_window_id:      Window_Id,                      # The window with changed visibility state.
                        state:                  Visibility                      # The new visibility state.
                      }

                  | CREATE_NOTIFY
                      { parent_window_id:       Window_Id,                      # The created window's parent.
                        created_window_id:      Window_Id,                      # The created window.
                        box:                    g2d::Box,                       # The window's rectangle.
                        border_wid:             Int,                            # The width of the border.
                        override_redirect:      Bool                            #  
                      }

                  | DESTROY_NOTIFY
                      { event_window_id:        Window_Id,                      # The window on which this was generated.
                        destroyed_window_id:    Window_Id                       # The destroyed window.
                      }

                  | UNMAP_NOTIFY
                      { event_window_id:        Window_Id,                      # The window on which this was generated.
                        unmapped_window_id:     Window_Id,                      # The window being unmapped.
                        from_config:            Bool                            # TRUE if parent was resized.
                      }

                  | MAP_NOTIFY
                      { event_window_id:        Window_Id,                      # The window on which this was generated.
                        mapped_window_id:       Window_Id,                      # The window being mapped.
                        override_redirect:      Bool                            #  
                      }

                  | MAP_REQUEST
                      { parent_window_id:       Window_Id,                      # The parent.
                        mapped_window_id:       Window_Id                       # The mapped window.
                      }

                  | REPARENT_NOTIFY
                      { event_window_id:        Window_Id,                      # The window on which this was generated.
                        parent_window_id:       Window_Id,                      # The new parent.
                        rerooted_window_id:     Window_Id,                      # The re-rooted window.
                        upperleft_corner:       g2d::Point,                     # The upper-left corner.
                        override_redirect:      Bool                            #  
                      }

                  | CONFIGURE_NOTIFY
                      { event_window_id:        Window_Id,                      # The window on which this was generated.
                        configured_window_id:   Window_Id,                      # The reconfigured window.
                        sibling_window_id:      Null_Or(Window_Id),             # The sibling that window is above (if any).
                        box:                    g2d::Box,                       # The window's rectangle.
                        border_wid:             Int,                            # The width of the border.
                        override_redirect:      Bool                            #  
                      }

                  | CONFIGURE_REQUEST
                      { parent_window_id:       Window_Id,                      # The parent.
                        configure_window_id:    Window_Id,                      # The window to reconfigure.
                        sibling_window_id:      Null_Or(Window_Id),             # The new sibling (if any).
                        x:                      Null_Or(Int),                   # The window's rectangle.
                        y:                      Null_Or(Int),
                        wide:                   Null_Or(Int),
                        high:                   Null_Or(Int),
                        border_wid:             Null_Or(Int),                   # The width of the border.
                        stack_mode:  Null_Or(Stack_Mode)                        # The mode for stacking windows.
                      }

                  | GRAVITY_NOTIFY  {
                    event_window_id:            Window_Id,                      # The window on which this was generated.
                    moved_window_id:            Window_Id,                      # The window being moved.
                    upperleft_corner:           g2d::Point                      # Upper-left corner of window.
                  }             

                  | RESIZE_REQUEST  {
                    resize_window_id:           Window_Id,                      # The window to resize.
                    req_size:                   g2d::Size                       # The requested new size.
                  }

                  | CIRCULATE_NOTIFY  {
                    event_window_id:            Window_Id,                      # The window on which this was generated.
                    circulated_window_id:       Window_Id,                      # The window being circulated.
                    parent_window_id:           Window_Id,                      # The parent.
                    place:                      Stack_Pos                       # The new place.
                  }

                  | CIRCULATE_REQUEST  {
                    parent_window_id:           Window_Id,                      # The parent.
                    circulate_window_id:        Window_Id,                      # The window to circulate.
                    place:                      Stack_Pos                       # The place to circulate the window to.
                  }

                  | PROPERTY_NOTIFY  {
                    changed_window_id:          Window_Id,                      # The window with the changed property.
                    atom:                       Atom,                           # The affected property.
                    timestamp:                  t::Xserver_Timestamp,           # When the property was changed.
                    deleted:                    Bool                            # TRUE if the property was deleted.
                  }

                  | SELECTION_CLEAR  {
                    owning_window_id:           Window_Id,                      # The current owner of the selection.
                    selection:                  Atom,                           # The selection.
                    timestamp:                  t::Xserver_Timestamp            # The last-change time.
                  }             

                  | SELECTION_REQUEST  {
                    owning_window_id:           Window_Id,                      # The owner of the selection.
                    selection:                  Atom,                           # The selection.
                    target:                     Atom,                           # The requested type for the selection.
                    requesting_window_id:       Window_Id,                      # The requesting window.
                    property:                   Null_Or( Atom ),                # The property to store the selection in. 
                    timestamp:                  Timestamp                       #  
                  }

                  | SELECTION_NOTIFY  {
                    requesting_window_id:       Window_Id,                      # The requestor of the selection.
                    selection:                  Atom,                           # The selection.
                    target:                     Atom,                           # The requested type of the selection.
                    property:                   Null_Or( Atom ),                # The property to store the selection in.
                    timestamp:                  Timestamp                       #  
                  }

                  | COLORMAP_NOTIFY  {
                    window_id:                  Window_Id,                      # The affected window.
                    cmap:                       Null_Or( Colormap_Id ),         # The colormap.
                    new:                        Bool,                           # TRUE, if the colormap attribute is changed.
                    installed:                  Bool                            # TRUE, if the colormap is installed.
                  }

                  | CLIENT_MESSAGE  {
                    window_id:                  Window_Id,                      #  
                    type:                       Atom,                           # The type of the message.
                    value:                      Raw_Data                        # The message value.
                  }

                  | MODIFIER_MAPPING_NOTIFY                                     # Really a MappingNotify event.

                  | KEYBOARD_MAPPING_NOTIFY                                     # Really a MappingNotify event.
                      {
                        first_keycode:  Keycode,
                        count:          Int
                      }

                  | POINTER_MAPPING_NOTIFY                                      # Really a MappingNotify event.
                  ;
            };

            fun mask_of_xevent n::KEY_PRESS             => EVENT_MASK (0u1 << 0u0);
                mask_of_xevent n::KEY_RELEASE           => EVENT_MASK (0u1 << 0u1);
                mask_of_xevent n::BUTTON_PRESS          => EVENT_MASK (0u1 << 0u2);
                mask_of_xevent n::BUTTON_RELEASE        => EVENT_MASK (0u1 << 0u3);
                mask_of_xevent n::ENTER_WINDOW          => EVENT_MASK (0u1 << 0u4);
                mask_of_xevent n::LEAVE_WINDOW          => EVENT_MASK (0u1 << 0u5);
                mask_of_xevent n::POINTER_MOTION        => EVENT_MASK (0u1 << 0u6);
                mask_of_xevent n::POINTER_MOTION_HINT   => EVENT_MASK (0u1 << 0u7);
                mask_of_xevent n::BUTTON1MOTION         => EVENT_MASK (0u1 << 0u8);
                mask_of_xevent n::BUTTON2MOTION         => EVENT_MASK (0u1 << 0u9);
                mask_of_xevent n::BUTTON3MOTION         => EVENT_MASK (0u1 << 0u10);
                mask_of_xevent n::BUTTON4MOTION         => EVENT_MASK (0u1 << 0u11);
                mask_of_xevent n::BUTTON5MOTION         => EVENT_MASK (0u1 << 0u12);
                mask_of_xevent n::BUTTON_MOTION         => EVENT_MASK (0u1 << 0u13);
                mask_of_xevent n::KEYMAP_STATE          => EVENT_MASK (0u1 << 0u14);
                mask_of_xevent n::EXPOSURE              => EVENT_MASK (0u1 << 0u15);
                mask_of_xevent n::VISIBILITY_CHANGE     => EVENT_MASK (0u1 << 0u16);
                mask_of_xevent n::STRUCTURE_NOTIFY      => EVENT_MASK (0u1 << 0u17);
                mask_of_xevent n::RESIZE_REDIRECT       => EVENT_MASK (0u1 << 0u18);
                mask_of_xevent n::SUBSTRUCTURE_NOTIFY   => EVENT_MASK (0u1 << 0u19);
                mask_of_xevent n::SUBSTRUCTURE_REDIRECT => EVENT_MASK (0u1 << 0u20);
                mask_of_xevent n::FOCUS_CHANGE          => EVENT_MASK (0u1 << 0u21);
                mask_of_xevent n::PROPERTY_CHANGE       => EVENT_MASK (0u1 << 0u22);
                mask_of_xevent n::COLORMAP_CHANGE       => EVENT_MASK (0u1 << 0u23);
                mask_of_xevent n::OWNER_GRAB_BUTTON     => EVENT_MASK (0u1 << 0u24);
            end;

            fun mask_of_xevent_list l
                =
                f (l, 0u0)
                where 

                    fun f ([], m)
                            =>
                            EVENT_MASK m;

                        f (xevent ! r, m)
                            => 
                            {   my (EVENT_MASK m')
                                    =
                                    mask_of_xevent xevent;

                                f (r, m | m');
                            };
                    end;

                end;

            fun union_xevent_masks (EVENT_MASK m1, EVENT_MASK m2) = EVENT_MASK (m1 | m2);
            fun inter_xevent_masks (EVENT_MASK m1, EVENT_MASK m2) = EVENT_MASK (m1 & m2);

        end;    # stipulate

        #
        ################ end of xtypes section ####################################    


    };          # package xevent_types

end;



Comments and suggestions to: bugs@mythryl.org

PreviousUpNext