PreviousUpNext

15.4.1467  src/lib/x-kit/xclient/pkg/window/cursors.pkg

## cursors.pkg
#
# Support for the X windows "standard cursors".
#
# This is the library-internal versio of this package;
# for the library client version see:
#
#     src/lib/x-kit/xclient/xclient.pkg

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


stipulate
    package xt  = xtypes;                               # xtypes                is from   src/lib/x-kit/xclient/pkg/wire/xtypes.pkg
    package sn  = xsession;                             # xsession              is from   src/lib/x-kit/xclient/pkg/window/xsession.pkg
    package et  = event_types;                          # event_types           is from   src/lib/x-kit/xclient/pkg/wire/event-types.pkg
    package fb  = font_base;                            # font_base             is from   src/lib/x-kit/xclient/pkg/window/font-base.pkg
    package v2w = value_to_wire;                        # value_to_wire         is from   src/lib/x-kit/xclient/pkg/wire/value-to-wire.pkg
herein

    package cursors {

        # The names of the standard cursors
        # predefined by every X server,
        # taken from X11/cursorfont:h:

        Standard_Xcursor
            =
            STANDARD_XCURSOR  Int;

        x_cursor                = STANDARD_XCURSOR 0;
        arrow                   = STANDARD_XCURSOR 2;
        based_arrow_down        = STANDARD_XCURSOR 4;
        based_arrow_up          = STANDARD_XCURSOR 6;
        boat                    = STANDARD_XCURSOR 8;
        bogosity                = STANDARD_XCURSOR 10;
        bottom_left_corner      = STANDARD_XCURSOR 12;
        bottom_right_corner     = STANDARD_XCURSOR 14;
        bottom_side             = STANDARD_XCURSOR 16;
        bottom_tee              = STANDARD_XCURSOR 18;
        box_spiral              = STANDARD_XCURSOR 20;
        center_ptr              = STANDARD_XCURSOR 22;
        circle                  = STANDARD_XCURSOR 24;
        clock                   = STANDARD_XCURSOR 26;
        coffee_mug              = STANDARD_XCURSOR 28;
        cross                   = STANDARD_XCURSOR 30;
        cross_reverse           = STANDARD_XCURSOR 32;
        crosshair               = STANDARD_XCURSOR 34;
        diamond_cross           = STANDARD_XCURSOR 36;
        dot                     = STANDARD_XCURSOR 38;
        dotbox                  = STANDARD_XCURSOR 40;
        double_arrow            = STANDARD_XCURSOR 42;
        draft_large             = STANDARD_XCURSOR 44;
        draft_small             = STANDARD_XCURSOR 46;
        draped_box              = STANDARD_XCURSOR 48;
        exchange                = STANDARD_XCURSOR 50;
        fleur                   = STANDARD_XCURSOR 52;
        gobbler                 = STANDARD_XCURSOR 54;
        gumby                   = STANDARD_XCURSOR 56;
        hand1                   = STANDARD_XCURSOR 58;
        hand2                   = STANDARD_XCURSOR 60;
        heart                   = STANDARD_XCURSOR 62;
        icon                    = STANDARD_XCURSOR 64;
        iron_cross              = STANDARD_XCURSOR 66;
        left_ptr                = STANDARD_XCURSOR 68;
        left_side               = STANDARD_XCURSOR 70;
        left_tee                = STANDARD_XCURSOR 72;
        leftbutton              = STANDARD_XCURSOR 74;
        ll_angle                = STANDARD_XCURSOR 76;
        lr_angle                = STANDARD_XCURSOR 78;
        man                     = STANDARD_XCURSOR 80;
        middlebutton            = STANDARD_XCURSOR 82;
        mouse                   = STANDARD_XCURSOR 84;
        pencil                  = STANDARD_XCURSOR 86;
        pirate                  = STANDARD_XCURSOR 88;
        plus                    = STANDARD_XCURSOR 90;
        question_arrow          = STANDARD_XCURSOR 92;
        right_ptr               = STANDARD_XCURSOR 94;
        right_side              = STANDARD_XCURSOR 96;
        right_tee               = STANDARD_XCURSOR 98;
        rightbutton             = STANDARD_XCURSOR 100;
        rtl_logo                = STANDARD_XCURSOR 102;
        sailboat                = STANDARD_XCURSOR 104;
        sb_down_arrow           = STANDARD_XCURSOR 106;
        sb_h_double_arrow       = STANDARD_XCURSOR 108;
        sb_left_arrow           = STANDARD_XCURSOR 110;
        sb_right_arrow          = STANDARD_XCURSOR 112;
        sb_up_arrow             = STANDARD_XCURSOR 114;
        sb_v_double_arrow       = STANDARD_XCURSOR 116;
        shuttle                 = STANDARD_XCURSOR 118;
        sizing                  = STANDARD_XCURSOR 120;
        spider                  = STANDARD_XCURSOR 122;
        spraycan                = STANDARD_XCURSOR 124;
        star                    = STANDARD_XCURSOR 126;
        target                  = STANDARD_XCURSOR 128;
        tcross                  = STANDARD_XCURSOR 130;
        top_left_arrow          = STANDARD_XCURSOR 132;
        top_left_corner         = STANDARD_XCURSOR 134;
        top_right_corner        = STANDARD_XCURSOR 136;
        top_side                = STANDARD_XCURSOR 138;
        top_tee                 = STANDARD_XCURSOR 140;
        trek                    = STANDARD_XCURSOR 142;
        ul_angle                = STANDARD_XCURSOR 144;
        umbrella                = STANDARD_XCURSOR 146;
        ur_angle                = STANDARD_XCURSOR 148;
        watch                   = STANDARD_XCURSOR 150;
        xterm                   = STANDARD_XCURSOR 152;

        Xcursor
            =
            XCURSOR
              { id:        xt::Cursor_Id,
                xsession:  sn::Xsession
              };

        # Identity test:
        #
        fun same_cursor
            ( XCURSOR { id=>id1, xsession=>xsession1 },
              XCURSOR { id=>id2, xsession=>xsession2 }
            )
            =
            (id1 == id2)
            and
            sn::same_xsession (xsession1, xsession2);

        # Return the named standard cursor:
        #
        fun get_standard_xcursor xsession (STANDARD_XCURSOR cursor)
            =
            {   include display;

                xsession -> sn::XSESSION { xdisplay => XDISPLAY { next_xid, ... }, ... };

                (sn::open_font  xsession  "cursor")
                    ->
                    fb::FONT { id=>font_id, ... };
                    

                cursor_id = next_xid();

                # The cursor font contains the shape glyph followed by the mask
                # glyph; so character position 0 contains a shape, 1 the mask for 0,
                # 2 a shape, etc.
                #
                sn::send_xrequest  xsession
                  (
                    v2w::encode_create_glyph_cursor
                      {
                        cursor    => cursor_id,

                        src_font  => font_id,
                        mask_font => THE font_id,

                        src_chr   => cursor,
                        mask_chr  => cursor+1,

                        foreground_rgb  => rgb::black,
                        background_rgb  => rgb::white
                      }
                  );

                XCURSOR { id=>cursor_id, xsession };
            };

        # Change the color of a cursor.
        # foreground_rgb is the foreground color,
        # background_rgb is the background color:
        #
        fun recolor_cursor
            { cursor as XCURSOR { id, xsession },
              foreground_rgb:  rgb::Rgb,
              background_rgb:  rgb::Rgb
            }
            =
            sn::send_xrequest  xsession
              (
                v2w::encode_recolor_cursor
                  {
                    cursor     =>  id,
                    foreground_color =>  rgb::rgb_normalize  foreground_rgb,
                    background_color =>  rgb::rgb_normalize  background_rgb
                  }
              );

        # Change the cursor during
        # an "active grab" of mouse:
        #
        fun change_active_grab_cursor  xsession  cursor
            =
            sn::send_xrequest  xsession
              (
                v2w::encode_change_active_pointer_grab
                  {
                    cursor => case cursor    (XCURSOR { id, ... } ) => THE id; esac,
                    time   => xt::CURRENT_TIME,
                    #
                    event_mask => et::mask_of_xevent_list
                                    [
                                      et::n::POINTER_MOTION,
                                      et::n::BUTTON_PRESS,
                                      et::n::BUTTON_RELEASE
                                    ]
                  }
              );

    };          # package cursors

end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext