PreviousUpNext

15.4.1693  src/lib/x-kit/xclient/src/wire/xtypes.pkg

## xtypes.pkg
#

# Compiled by:
#     src/lib/x-kit/xclient/xclient-internals.sublib



# X11 protocol low-level base types.


stipulate
    package ts = xserver_timestamp;                     # xserver_timestamp     is from   src/lib/x-kit/xclient/src/wire/xserver-timestamp.pkg
herein

    package  xtypes
    : (weak) Xtypes                                     # Xtypes                is from   src/lib/x-kit/xclient/src/wire/xtypes.api
    {                                                   # Need weak sealing here so Xid can be an equality type.

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

        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  ts::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;                 # We use the X protocol "BUTTON" wire encoding.
        #
        button1 =  MOUSEBUTTON 1;
        button2 =  MOUSEBUTTON 2;
        button3 =  MOUSEBUTTON 3;
        button4 =  MOUSEBUTTON 4;
        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


        # A modifier key (shift, ctrl...) state vector:
        #
        Modifier_Keys_State
          #
          = ANY_MOD_KEY
          | MKSTATE  Unt
          ;

        # A Mouse button state vector:
        #
        Mousebuttons_State
          =
          MOUSEBUTTON_STATE  Unt;               # We keep these in the X protocol wire encoding bitmap format.
                #                               # For the actual bit layout see   src/lib/x-kit/xclient/src/wire/keys-and-buttons.pkg
                # Having the above value        # or p114-115 (117-118)           http://mythryl.org/pub/exene/X-protocol-R6.pdf
                # be an Unt (vs Int)    
                # is a nuisance and doesn't
                # seem to do any real good.
                # XXX SUCKO FIXME

        # 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. 
              };

        # 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.

    };                  #  xtypes 

end;

# Notes:
#
# [1]:  X server resources are small (29-bit) integers global to
#       the running server process, i.e., shared by all X clients.
#       Rather than allocating them on the X server, the X
#       designers decided to have clients allot them locally,
#       to reduce network round-trip delays and X server load.
#       To prevent collisions, each client is assigned by the
#       X server its own identifier subspace from which it may
#       allot freely without need of network round trips to
#       the X server.  Quoting from X Volume Zero:
#
#          "The resource-id-mask consists of a single contiguous set of bits
#           (at least 18).  The client allocates resource IDs for types
#           WINDOW, PIXMAP, CURSOR, FONT, GCONTEXT, and COLORMAP by choosing
#           a value with only some subset of these bits set and ORing it with
#           resource-id-base.  Only values constructed in this way can be used
#           to name newly created resources over this connection.  Resource IDs
#           never have the top three bits set.  The client is not restricted
#           to linear or contiguous allocation of resource IDs.  Once an ID
#           has been freed, it can be reused, but this should not be necessary.
#           An ID must be unique with respect to the IDs of all other resources,
#           not just other resources of the same type.  However, note that the
#           value spaces of resource identifiers, atoms, visualids and keysyms
#           are distinguished by context and, as such, are not required  to be
#           disjoint; for example, a given numeric value might be both a valid
#           window ID, a valid atom, and a valid keysym."
#
#       The xlib implementation of this appears to be the routine  _XAllocID in:
#
#           libx11-1.3.3/src/XlibInt.c
#
#       with initialization done in routine   XOpenDisplay   in
#
#           libx11-1.3.3/src/OpenDis.c
#
#       For our implemention of this, see   spawn_xid_factory_thread()  in
#
#           src/lib/x-kit/xclient/src/wire/display-old.pkg



Comments and suggestions to: bugs@mythryl.org

PreviousUpNext