Ejemplo n.º 1
0
        //throws IOException
        public static Data build(Display display)
        {
            //    display.connection.socket.setSoTimeout (0); // FIXME use Socket.Select instead.

            int code = display.connection.din.Read ();

            /* Set the timeout to 10 seconds, a very safe bet to avoid premature
             * timeout in slow networks. Setting a timeout avoid being locked
             * when reading a reply or an event of a shorter length than
             * expected, due to bugs in X server. For instance, the reply of
             * {@link DBE#visual_info(Drawable[])} has a wrong reply length field
             * in XFree86 4.0.1 or eariler servers.
             *
             * Note that timeout is reset to 0 (no timeout) before reading the
             * first byte of the message because a blocking read of the next event
             * or a blocking read of the expected reply from a slow X server should
             * not be timed out.
             */
            //    display.connection.socket.setSoTimeout (10000); // FIXME use Socket.Select instead.

            if (code == 0) 		// X Error
              throw build_error (display);

            else if (code == 1) 	// X Reply
              return build_reply (display);

            else 			// X Event
              return build_event (display, code);
        }
Ejemplo n.º 2
0
        //throws NotFoundException
        protected Extension(Display display, String name, 
    String [] minor_opcode_strings, int error_count, int event_count)
        {
            this.display = display;
            this.name = name;

            Display.ExtensionReply er = display.extension (name);
            if (!er.present ()) throw new NotFoundException (name);

            first_event = er.first_event ();
            first_error = er.first_error ();
            major_opcode = er.major_opcode ();

            // register opcode strings
            display.extension_opcode_strings [major_opcode - 128] = name;
            display.extension_minor_opcode_strings [major_opcode - 128]
              = minor_opcode_strings;

            // register error factory
            for (int i=0; i<error_count; i++)
              display.extension_error_factories [first_error - 128 + i]
            = (ErrorFactory) this;

            // register event factory
            for (int i=0; i<event_count; i++)
              display.extension_event_factories [first_event - 64 + i]
            = (EventFactory) this;
        }
Ejemplo n.º 3
0
 public XBM(Display display, int width, int height, int [] xbm)
     : base(display, width, height)
 {
     // take <code>int</code> as parameter to avoid casting in java
     for (int i=0; i<data.Length; i++)
       data [i] = (byte) xbm [i];
 }
Ejemplo n.º 4
0
     public Error build(Display display, Data data, int code,
 int seq_no, int bad, int minor_opcode, int major_opcode)
     {
         String error_string = ERROR_STRINGS [code - first_error];
         return new Error (display, error_string, code, seq_no, bad,
           minor_opcode, major_opcode);
     }
Ejemplo n.º 5
0
        /** Writing. */
        public Event(Display display, int code, int window_offset)
        {
            this.display = display;
            this.window_offset = window_offset;

            data = new byte [32];
            data [0] = (byte) code;
        }
Ejemplo n.º 6
0
 //throws NotFoundException {
 // shape opcode 0 - query version
 /**
    * @see <a href="XShapeQueryExtension.html">XShapeQueryExtension</a>
    */
 public Shape(Display display)
     : base(display, "SHAPE", MINOR_OPCODE_STRINGS, 0, 1)
 {
     // check version before any other operations
     Request request = new Request (display, major_opcode, 0, 1);
     Data reply = display.read_reply (request);
     server_major_version = reply.read2 (8);
     server_minor_version = reply.read2 (10);
 }
Ejemplo n.º 7
0
        /** Reading. */
        public Event(Display display, byte [] data, int window_offset)
            : base(data)
        {
            this.display = display;
            this.window_offset = window_offset;

            synthetic = (this.data [0] & 0x80) != 0;
            this.data [0] &= 0x7f;
        }
Ejemplo n.º 8
0
 //throws gnu.x11.extension.NotFoundException {
 // print opcode 0 - query version
 /**
    * @see <a href="XpQueryVersion.html">XpQueryVersion</a>
    */
 public Print(Display display)
     : base(display, "XpExtension", MINOR_OPCODE_STRINGS, 2, 2)
 {
     // check version before any other operations
     Request request = new Request (display, major_opcode, 0, 1);
     Data reply = display.read_reply (request);
     server_major_version = reply.read2 (4);
     server_minor_version = reply.read2 (4);
 }
Ejemplo n.º 9
0
        public ZPixmap(Display display, int width, int height, Pixmap.Format format)
            : base(width, height, FORMAT, format)
        {
            image_byte_order = display.image_byte_order;
            pixel_byte_count = pixmap_format.bits_per_pixel () / 8;

            if (display.default_depth < 24)
              throw new Error ("Unsupported root depth < 24: " +
            display.default_depth);
        }
Ejemplo n.º 10
0
        public Bitmap(Display display, int width, int height)
            : base(width, height, FORMAT, display.pixmap_formats [0])
        {
            if (display.image_byte_order != LSB_FIRST
              || display.bitmap_format_bit_order != LEAST_SIGNIFICANT)
              throw new Error ("Unsupported image format");

            scanline_unit = display.bitmap_format_scanline_unit;
            unit_byte_count = scanline_unit / 8;
        }
Ejemplo n.º 11
0
        public ZPixmap(Display display)
        {
            // for subclass loading
            format = FORMAT;
            pixmap_format = display.default_pixmap_format;
            image_byte_order = display.image_byte_order;
            pixel_byte_count = pixmap_format.bits_per_pixel () / 8;

            if (display.default_depth < 24)
              throw new Error ("Unsupported root depth < 24: " +
            display.default_depth);
        }
Ejemplo n.º 12
0
        // opcode 45 - open font
        /**
           * @see <a href="XLoadFont.html">XLoadFont</a>
           */
        public Font(Display display, String name)
            : base(display)
        {
            this.name = name;

            Request request = new Request (display, 45, 3+Data.unit (name));
            request.write4 (id);
            request.write2 (name.Length);
            request.write2_unused ();
            request.write1 (name);
            display.send_request (request);
        }
Ejemplo n.º 13
0
 //throws NotFoundException {
 // evi opcode 0 - get version
 /**
    * @see <a href="XeviQueryVersion.html">XeviQueryVersion</a>
    */
 public EVI(Display display)
     : base(display, "Extended-Visual-Information", MINOR_OPCODE_STRINGS)
 {
     // check version before any other operations
     /* Note that the specification says the request includes a major and a
      * minor version, but most implementation (xfree86 3.3/4.0) does not.
      * Which one is bugged?
      */
     Request request = new Request (display, major_opcode, 0, 1);
     Data reply = display.read_reply (request);
     server_major_version = reply.read2 (8);
     server_minor_version = reply.read2 (10);
 }
Ejemplo n.º 14
0
        // TODO
        public XPM(Display display, String [] xpm)
            : base(display)
        {
            String [] values = xpm [0].Split(new char[] { ' ' });
            width = Int32.Parse (values[0]);
            height = Int32.Parse (values[1]);
            int num_colors = Int32.Parse (values[2]);
            int chars_per_pixel = Int32.Parse (values[3]);

            // TODO how to select best SUITABLE format?
            format = FORMAT;
            pixmap_format = display.default_pixmap_format;
            image_byte_order = display.image_byte_order;
            pixel_byte_count = pixmap_format.bits_per_pixel () / 8;
            init ();

            Hashtable mapping = new Hashtable (2*num_colors);
            Colormap cmap = display.default_colormap;

            for (int i=0; i<num_colors; i++) {
              String [] color = xpm [i+1].Split(new char[] {' '});
              String symbol = color[0];

              while (color.Length>1
            && color[1].Equals ("c")) { // can only parse c for now

            String color_value = color[2];

            if (color_value[0] == '#') {
              int pixel = Int32.Parse (
            color_value.Substring (1, color_value.Length), System.Globalization.NumberStyles.HexNumber);

              mapping.Add (symbol, new Color (pixel));

            } else			// not starting with #
              mapping.Add (symbol, cmap.alloc_named_color (color_value));
              }
            }

            // TODO more efficient linear for-loop
            for (int y=0; y<height; y++) {
              String pixels = xpm [1+num_colors+y];

              for (int x=0; x<width; x++) {
            String symbol = pixels.Substring (x*chars_per_pixel,
              (x+1)*chars_per_pixel);
            Color color = (Color) mapping[symbol];
            set (x, y, color.pixel);
              }
            }
        }
Ejemplo n.º 15
0
        // xc-misc opcode 0 - get version
        public XCMisc(gnu.x11.Display display) //throws NotFoundException {
            : base(display, "XC-MISC", MINOR_OPCODE_STRINGS)
        {
            // check version before any other operations
            Request request = new Request(display, major_opcode, 0, 2);

            request.write2(CLIENT_MAJOR_VERSION);
            request.write2(CLIENT_MINOR_VERSION);

            Data reply = display.read_reply(request);

            server_major_version = reply.read2(8);
            server_minor_version = reply.read2(10);
        }
Ejemplo n.º 16
0
        // dbe opcode 0 - get version
        public DBE(gnu.x11.Display display) //throws NotFoundException {
            : base(display, "DOUBLE-BUFFER", MINOR_OPCODE_STRINGS, 1, 0)
        {
            // check version before any other operations
            Request request = new Request(display, major_opcode, 0, 2);

            request.write1(CLIENT_MAJOR_VERSION);
            request.write1(CLIENT_MINOR_VERSION);

            Data reply = display.read_reply(request);

            server_major_version = reply.read1(8);
            server_minor_version = reply.read1(9);
        }
Ejemplo n.º 17
0
        protected Application(String [] args)
            : base(args, new Option (args))
        {
            // cast `gnu.util.Option option' to `gnu.x11.Option'
            option = (Option) base.option;
            String env = Environment.GetEnvironmentVariable ("DISPLAY");
            if(env==null || env.Length==0) env="localhost:1";
            Display.Name display_name = option.display_name ("display",
              "X server to connect to", new Display.Name (env));

            int send_mode = option.Enum ("send-mode", "request sending mode",
              Connection.SEND_MODE_STRINGS, Connection.ASYNCHRONOUS);

            if (help_option) return;
            display = new Display (display_name);
            display.connection.send_mode = send_mode;
        }
Ejemplo n.º 18
0
        public Display.Name display_name(String name, String description,
    Display.Name default_value)
        {
            Display.Name retval = default_value;

            try {
              String opt = option (name);
              if (opt != null) retval = new Display.Name (opt);

            } catch (Exception e) {
              invalid_names.Append (name + ", ");
              // fall through
            }

            add_spec (name, "display name", description, default_value.ToString (),
              retval.ToString ());
            return retval;
        }
Ejemplo n.º 19
0
        //throws IOException
        public static Error build_connection_error(Display display)
        {
            BinaryReader din = display.connection.din;
            int msg_len = (Int32)din.ReadUInt32 ();
            int major_version = din.ReadUInt16 ();
            int minor_version = din.ReadUInt16 ();
            int total_len = 4 * din.ReadUInt16 ();
            byte [] buffer = new byte [total_len];
            din.Read (buffer,0,total_len);

            Decoder dec	 = Encoding.ASCII.GetDecoder();
            char [] d = new char[msg_len];
            msg_len = dec.GetChars(buffer,0,msg_len,d,0);

            String reason = new String (d, 0, msg_len);

            return new Error ("X server connection error"
              + "\n  protocol-major-version: " + major_version
              + "\n  protocol-minor-version " + minor_version
              + "\n  reason: " + reason);
        }
Ejemplo n.º 20
0
        //throws IOException
        // WARNING: very naive parsing
        // TODO
        public PPM(Display display, StreamReader bin)
            : base(display)
        {
            // format

            String format = bin.ReadLine ();
            if (!(format.Equals ("P6")))
              throw new Error ("Unsupported format: " + format);

            // dimension

            String dimension = bin.ReadLine ();
            int index = dimension.IndexOf (' ');
            try {
              width = Int32.Parse (dimension.Substring (0, index));
              height = Int32.Parse (dimension.Substring (
            index+1, dimension.Length));

            } catch (Exception e) {
              throw new Error ("Invalid dimension: " + dimension);
            }

            String color_count = bin.ReadLine ();

            // fill up data

            init ();
            Colormap cmap = display.default_colormap;

            for (int y=0; y<height; y++)
              for (int x=0; x<width; x++) {
            int r = bin.Read ();
            int g = bin.Read ();
            int b = bin.Read ();

            // FIXME cache and index color
            set (x, y, cmap.alloc_color8 (r, g, b));
              }
        }
Ejemplo n.º 21
0
 public Request (Display display, int opcode, int unit) {
   init (display, opcode, 0, unit);
 }
Ejemplo n.º 22
0
 public Request (Display display, int opcode, bool b, int unit) {
   init (display, opcode, b ? 1 : 0, unit);
 }
Ejemplo n.º 23
0
     /**
        * @see #Atom(Display, String, bool)
        */
     public static Object intern(Display display, String name, 
 bool only_if_exists)
     {
         Object value = display.atom_names[name];
         if (value != null && value is Atom) return value;
         return new Atom (display, name, only_if_exists);
     }
Ejemplo n.º 24
0
     /**
        * @see #Atom(Display, int, bool)
        */
     public static Object intern(Display display, int id, 
 bool only_if_exists)
     {
         Object value = display.atom_ids[id];
         if (value != null && value is Atom) return value;
         return new Atom (display, id, only_if_exists);
     }
Ejemplo n.º 25
0
 /**
    * @see #Atom(Display, String, bool)
    */
 public static Object intern(Display display, String name)
 {
     return intern (display, name, false);
 }
Ejemplo n.º 26
0
 /**
    * @see #Atom(Display, int, bool)
    */
 public static Object intern(Display display, int id)
 {
     return intern (display, id, false);
 }
Ejemplo n.º 27
0
 public gnu.x11.Error build(gnu.x11.Display display, Data data,
                            int code, int seq_no, int bad, int minor_opcode, int major_opcode)
 {
     return(new gnu.x11.Error(display, ERROR_STRING, code, seq_no, bad,
                              minor_opcode, major_opcode));
 }
Ejemplo n.º 28
0
        // opcode 16 - intern atom
        /**
           * @see <a href="XInternAtom.html">XInternAtom</a>
           */
        public Atom(Display display, String name, bool only_if_exists)
        {
            this.display = display;
            this.name = name;

            Request request = new Request (display, 16, only_if_exists, 2+Data.unit (name));
            request.write2 (name.Length);
            request.write2_unused ();
            request.write1 (name);

            Data reply = display.read_reply (request);
            id = reply.read4 (8);

            display.atom_ids.Add (id, this);
            display.atom_names.Add (name, this);
        }
Ejemplo n.º 29
0
 public FocusOut(Display display, byte [] data)
     : base(display, data, 8)
 {
 }
Ejemplo n.º 30
0
 public Input(Display display, int min_keycode, int max_keycode)
 {
     this.display = display;
     this.min_keycode = min_keycode;
     this.max_keycode = max_keycode;
 }
Ejemplo n.º 31
0
   public ValueList (Display display, int opcode, int unit, 
     int id, gnu.x11.ValueList vl) {
 
     this.display = display;
     this.opcode = opcode;
     this.unit = unit;
     this.id = id;
     this.vl = vl;
   }
Ejemplo n.º 32
0
        // opcode 17 - get atom name
        /**
           * @see <a href="XGetAtomName.html">XGetAtomName</a>
           */
        public Atom(Display display, int id, bool only_if_exists)
        {
            this.display = display;
            this.id = id;

            Request request = new Request (display, 17, 2);
            request.write4 (id);

            Data reply = display.read_reply (request);
            int len = reply.read2 (8);
            Decoder dec	 = Encoding.ASCII.GetDecoder();
            char [] d = new char[len];
            len = dec.GetChars(reply.data,32,len,d,0);
            name = new String (d, 0, len);

            display.atom_ids.Add (id, this);
            display.atom_names.Add (name, this);
        }
Ejemplo n.º 33
0
  public void init (Display display, int opcode, 
    int second_field, int unit) {

    // x extensions use extended_maximum_request_length? (glx does not). if
    // not, we should check opcode here
    
    if (display.connected
      && unit > display.extended_maximum_request_length)

      throw new Exception ("Request too long (in byte): "
        + (unit*4) + " > " 
        + (display.extended_maximum_request_length*4));


    // big requests in use
    bool big = display.big_requests_present
      && unit > display.maximum_request_length;   

    if (big) unit++;            // extra storage
    length = unit * 4;
    data = new byte [length];

    write1 (opcode);
    write1 (second_field);

    if (!big)
      write2 (unit);

    else {
      write2 (0);               // extended length flag
      write4 (unit);
    }
  }
Ejemplo n.º 34
0
 public BigRequests(gnu.x11.Display display) : base(display, "BIG-REQUESTS", null)
 {
 }