PreviousUpNext

15.4.1609  src/lib/x-kit/xclient/src/to-string/xserver-info-to-string.pkg

## xserver-into-to-string.pkg
#
# See comments in
#     src/lib/x-kit/xclient/src/to-string/xserver-info-to-string.api

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


stipulate
    package xt  =  xtypes;                                      # xtypes                        is from   src/lib/x-kit/xclient/src/wire/xtypes.pkg
herein


    package   xserver_info_to_string
    :         Xserver_Info_To_String                            # Xserver_Info_To_String        is from   src/lib/x-kit/xclient/src/to-string/xserver-info-to-string.api
    {
        # Stringify the reply from an
        # X-server connection request:
        #
        stipulate

            fun visual_id_to_int  (xt::VISUAL_ID  unt) =  unt::to_int unt;
            fun event_mask_to_int (xt::EVENT_MASK unt) =  unt::to_int unt;

            fun display_class_to_string  (d: xt::Display_Class)
                =
                case d
                    #
                    xt::STATIC_GRAY     => "STATIC_GRAY";
                    xt::GRAY_SCALE      => "GRAY_SCALE";
                    xt::STATIC_COLOR    => "STATIC_COLOR";
                    xt::PSEUDO_COLOR    => "PSEUDO_COLOR";
                    xt::TRUE_COLOR      => "TRUE_COLOR";
                    xt::DIRECT_COLOR    => "DIRECT_COLOR";
                esac;

            fun raw_format_to_string f
                =
                case f
                    #
                    xt::RAW08 => "8";
                    xt::RAW16 => "16";
                    xt::RAW32 => "32";
                esac;

            fun backing_store_to_string  backing_store
                =
                case backing_store
                    #
                    xt::BS_NOT_USEFUL  => "is not useful";
                    xt::BS_WHEN_MAPPED => "only when window is mapped";
                    xt::BS_ALWAYS      => "always";
                esac;

            fun pixmap_format_to_string (xt::FORMAT f)
                =
                {    result
                        =
                        [ sprintf "depth          d=%d" f.depth,
                          sprintf "bits_per_pixel d=%d" f.bits_per_pixel,
                          sprintf "scanline_pad   s=%s" (raw_format_to_string f.scanline_pad)
                        ];

                    result =  "" ! reverse result;                                      # Restore natural order and prepend a blank linke.
                    result =  map   {. "        " + #string + "\n"; }   result;         # Indent each line and append a newline.
                    result =  cat result;                                               # Reduce to a single result string.

                    result;
                };

            fun pixmap_formats_to_string ([], result_so_far)
                    =>
                    cat (reverse result_so_far);

                pixmap_formats_to_string (format ! formats, result_so_far)
                    =>
                    pixmap_formats_to_string (formats, pixmap_format_to_string format ! result_so_far);
            end;

            fun visual_to_string  (v: xt::Visual)
                =
                {   result
                        =
                        case v
                            #
                            xt::NO_VISUAL_FOR_THIS_DEPTH i
                                =>
                                [ "",
                                  sprintf "No visuals for depth %d" i
                                ];

                            xt::VISUAL v
                                =>
                                [ "",
                                  sprintf "visual id         x=%x"  (visual_id_to_int v.visual_id),
                                  sprintf "depth             d=%d"   v.depth,
                                  sprintf "colormap entries  d=%d"   v.cmap_entries,
                                  sprintf "colorbits_per_rgb d=%d"   v.bits_per_rgb,
                                  sprintf "red_mask          x=%08x" (unt::to_int v.red_mask),
                                  sprintf "green_mask        x=%08x" (unt::to_int v.green_mask),
                                  sprintf "blue_mask         x=%08x" (unt::to_int v.blue_mask),
                                  sprintf "display_class     s=%s"   (display_class_to_string  v.ilk)
                                ];
                        esac;

                    result =  map   {. "            " + #string + "\n"; }   result;             # Indent each line and append a newline.
                    result =  cat result;                                                       # Reduce to a single result string.

                    result;
                };

            fun visuals_to_string ([], result_so_far)
                    =>
                    cat (reverse result_so_far);

                visuals_to_string (depth ! depths, result_so_far)
                    =>
                    visuals_to_string (depths, visual_to_string depth ! result_so_far);
            end;

            fun screen_to_string  (s: xt::Xserver_Screen)
                =
                {   result
                        =
                        [ "",
                          sprintf  "root_window id   x=%x"  (xt::xid_to_int    s.root_window),
                          sprintf  "root_depth       d=%d"                     s.root_depth,
                          "",
                          sprintf  "root_visual_id   d=%d"  (visual_id_to_int  s.root_visualid),
                          sprintf  "default_colormap x=%x"  (xt::xid_to_int    s.default_colormap),
                          "",
                          sprintf  "millimeters_high d=%d"  s.millimeters_high,
                          sprintf  "millimeters_wide d=%d"  s.millimeters_wide,
                          "",
                          sprintf  "pixels_high d=%d"       s.pixels_high,
                          sprintf  "pixels_wide d=%d"       s.pixels_wide,
                          "",
                          sprintf  "backing store %s"      (backing_store_to_string s.backing_store),
                          sprintf  "save_unders s=%s"      (s.save_unders ?? "TRUE" :: "FALSE"),
                          "",
                          sprintf  "black_rgb8  x=%x"      (rgb8::rgb8_to_int s.black_rgb8),
                          sprintf  "white_rgb8  x=%x"      (rgb8::rgb8_to_int s.white_rgb8),

                                   "",
                                   "Graphics hardware colormap support:   # (These days usually min==max==1 -- colormaps are largely obsolete.)",
                          sprintf  "    min     d=%d                       # Minimum simultaneous colormaps guaranteed supported by the hardware."       s.installed_colormaps.min,
                          sprintf  "    max     d=%d                       # Maximum simultaneous colormaps possibly   supported by the hardware."       s.installed_colormaps.max,
                          sprintf  "input_masks d=%d"      (event_mask_to_int s.input_masks),

                          "",
                          sprintf  "%d visuals:" (list::length s.visuals),
                          visuals_to_string      (s.visuals, [])
                        ];
                    
                    result =  map   {. "        " + #string + "\n"; }   result;         # Indent each line and append a newline.
                    result =  cat result;                                               # Reduce to a single result string.

                    result;
                };

            fun screens_to_string ([], result_so_far)
                    =>
                    cat (reverse result_so_far);

                screens_to_string (screen ! screens, result_so_far)
                    =>
                    screens_to_string (screens, screen_to_string screen ! result_so_far);
            end;

        herein

            fun xserver_info_to_string  (i:   xt::Xserver_Info)
                =
                {   result =    [ "",
                                  "",
                                  "X server info from connection reply.",
                                  "For details on this stuff see pages 9-12 in http://mythryl.org/pub/exene/X-protocol.pdf",
                                  "",
                                  sprintf "protocol_version      d= %d.%d" i.protocol_version.major i.protocol_version.minor,
                                  sprintf "release_number        d= %d"    i.release_number,
                                  sprintf "vendor                s= '%s'"  i.vendor,

                                  sprintf "xid_base              x= %x"    (unt::to_int  i.xid_base),
                                  sprintf "xid_mask              x= %x"    (unt::to_int  i.xid_mask),

                                  sprintf "motion_buf_size       d= %d"    i.motion_buf_size,
                                  sprintf "max_request_length    d= %d"    i.max_request_length,

                                  sprintf "image_byte_order      s= %s"    case i.image_byte_order  xt::LSBFIRST => "LEAST_SIGNIFICANT_BYTE_FIRST"; xt::MSBFIRST => "MOST_SIGNIFICANT_BYTE_FIRST"; esac,
                                  sprintf "bitmap_order          s= %s"    case i.bitmap_order      xt::LSBFIRST => "LEAST_SIGNIFICANT_BIT_FIRST";  xt::MSBFIRST => "MOST_SIGNIFICANT_BIT_FIRST";  esac,

                                  sprintf "bitmap_scanline_unit  s= %s"    case i.bitmap_scanline_unit   xt::RAW08 => "8 bits"; xt::RAW16 => "16 bits"; xt::RAW32 => "32 bits"; esac,
                                  sprintf "bitmap_scanline_pad   s= %s"    case i.bitmap_scanline_pad    xt::RAW08 => "8 bits"; xt::RAW16 => "16 bits"; xt::RAW32 => "32 bits"; esac,

                                  sprintf "min_keycode           d= %d"    case i.min_keycode  xt::KEYCODE i => i; esac,
                                  sprintf "max_keycode           d= %d"    case i.max_keycode  xt::KEYCODE i => i; esac,

                                  "",
                                  sprintf "%d pixmap formats:"   (list::length  i.pixmap_formats),
                                  pixmap_formats_to_string         (i.pixmap_formats,      []),

                                  "",
                                  sprintf "%d screens:" (list::length  i.screens),
                                  screens_to_string  (i.screens, [])

                                ];

                    result =  map   {. "    " + #string + "\n"; }   result;             # Indent each line and append a newline.
                    result =  cat result;                                               # Combine lines into a single final string.

                    result;     
                };
        end;                    # stipulate
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext