Exemplo n.º 1
0
 static void delProperty(Client c, Window w, int name, int type) throws IOException {
   Property p;
   synchronized (w) {
     p = w.getProperty();
     Property prev = null;
     while (p != null) {
       if (p.propertyName == name) break;
       prev = p;
       p = p.next;
     }
     if (p != null) {
       if (prev == null) { // head !!
         w.setProperty(p.next);
         if (p.next == null) {
           // checkWindowOptionalNeed();
         }
       } else {
         prev.next = p.next;
       }
       c.cevent.mkPropertyNotify(
           w.id,
           p.propertyName,
           (int) System.currentTimeMillis(),
           // Property.PropertyDelete
           1);
     }
   }
   if (p != null) {
     w.sendEvent(c.cevent, 1, null);
   }
 }
Exemplo n.º 2
0
  static void changeWindowProperty(
      Client c,
      Window w,
      int property,
      int type,
      short format,
      byte mode,
      int len,
      byte[] value,
      boolean sendevent)
      throws IOException {
    synchronized (w) {
      Property p;
      int totalSize = len * (format / 8);
      p = w.getProperty();
      while (p != null) {
        if (p.propertyName == property) break;
        p = p.next;
      }

      if (p != null) {
        if ((format != p.format) && (mode != PropModeReplace)) {
          System.err.println("error!");
          c.errorReason = 8; // BadMatch
          return;
        }
        if ((type != p.type) && (mode != PropModeReplace)) {
          System.err.println("error!");
          c.errorReason = 8; // BadMatch
          return;
        }
        if (mode == PropModeReplace) {
          p.data = value;
          p.size = len;
          p.format = format;
          p.type = type;
        } else if (len == 0) {
        } else if (mode == PropModeAppend) {
          byte[] foo = new byte[(format / 8) * (len + p.size)];
          if (p.size > 0) System.arraycopy(p.data, 0, foo, 0, p.size);
          System.arraycopy(value, 0, foo, p.size, totalSize);
          p.size += len;
          p.data = foo;
        } else if (mode == PropModePrepend) {
          byte[] foo = new byte[(format / 8) * (len + p.size)];
          System.arraycopy(value, 0, foo, 0, totalSize);
          if (p.size > 0) System.arraycopy(p.data, 0, foo, totalSize, p.size);
          p.size += len;
          p.data = foo;
        }
        // change;
      } else {
        //    w.setProperty(null);
        p = new Property();
        p.propertyName = property;
        p.type = type;
        p.format = (short) format;
        p.data = value;
        p.size = len;
        p.next = w.getProperty();
        w.setProperty(p);
      }

      if (p != null) {
        if (p.propertyName == 9
            && // CUT_BUFFER0
            w == w.screen.root
            && p.size > 0) {
          CopyPaste.setString(new String(p.data, 0, p.size));
        }
        if (w.screen.windowmode != WeirdX.InBrowser
            && p.propertyName == 39
            && p.type == 31
            && p.size > 0
            && w.ddxwindow != null) {
          java.awt.Window frame = w.getFrame();
          if (frame != null && (frame instanceof java.awt.Frame)) {
            ((java.awt.Frame) frame).setTitle(new String(p.data));
          }
        }
      }
    }

    if (sendevent) {
      c.cevent.mkPropertyNotify(w.id, property, (int) System.currentTimeMillis(), 0);
      w.sendEvent(c.cevent, 1, null);
    }
  }
Exemplo n.º 3
0
  static void reqGetProperty(Client c) throws IOException {
    int foo;
    int dlt;
    int prprty;
    int typ;
    int ffst, lngth;
    IO io = c.client;
    dlt = c.data;

    foo = io.readInt();
    Window w = c.lookupWindow(foo);
    if (w == null) {
      c.errorValue = foo;
      c.errorReason = 3; // BadWindow;
    }
    prprty = io.readInt();
    typ = io.readInt();
    ffst = io.readInt();
    lngth = io.readInt();
    c.length -= 6;
    if (c.errorReason != 0) {
      return;
    }
    int frmt;
    int seq;
    int ba;
    Property prop;
    prop = Property.getProperty(w, prprty, typ);

    synchronized (io) {
      io.writeByte(1);
      if (prop == null) {
        io.writeByte(0);
        io.writeShort(c.seq);
        io.writeInt(0);
        io.writeInt(0);
        io.writeInt(0);
        io.writeInt(0);
        io.writePad(12);
        io.flush();
        return;
      }

      if ((typ != prop.type) && typ != 0) {
        io.writeByte(prop.format);
        io.writeShort(c.seq);
        io.writeInt(0);
        io.writeInt(prop.type);
        io.writeInt(0);
        io.writeInt(0);
        io.writePad(12);
        io.flush();
        return;
      }

      int n = (prop.format / 8) * prop.size;

      int ind = ffst * 4;
      if (n < ind) {
        // System.err.println("procGetProperty: ind-n="+new Integer((ind-n)));
      }

      int len = ((n - ind) < lngth * 4) ? n - ind : lngth * 4;
      if ((lngth * 4) < 0) len = n - ind;
      ba = n - (ind + len);
      if (dlt != 0 && ba == 0) {
        c.cevent.mkPropertyNotify(w.id, prprty, (int) System.currentTimeMillis(), 1);
        w.sendEvent(c.cevent, 1, null);
      }

      io.writeByte(prop.format);
      io.writeShort(c.seq);
      io.writeInt((len + 3) / 4);
      io.writeInt(prop.type);
      io.writeInt(ba);
      if ((prop.format / 8) == 0) io.writeInt(0);
      else io.writeInt(len / (prop.format / 8));

      io.writePad(12);

      if (len > 0) {
        if (c.swap && (prop.format == 16 || prop.format == 32)) {
          byte[] b = new byte[len];
          System.arraycopy(prop.data, ind, b, 0, len);
          switch (prop.format) {
            case 16:
              swapS(b, 0, len);
              break;
            case 32:
              swapL(b, 0, len);
              break;
            default:
          }
          io.writeByte(b, 0, len);
        } else {
          io.writeByte(prop.data, ind, len);
        }
        if (((-len) & 3) > 0) {
          io.writePad((-len) & 3);
        }
      }
      io.flush();
    }

    if (dlt != 0 && ba == 0) {
      Property.delProperty(c, w, prprty, typ);
    }
  }
Exemplo n.º 4
0
  static void reqRotateProperties(Client c) throws IOException {
    int foo, propty;
    IO io = c.client;

    foo = io.readInt();
    Window w = c.lookupWindow(foo);
    c.length -= 2;
    if (w == null) {
      c.errorValue = foo;
      c.errorReason = 3; // BadWindow;
      return;
    }
    int n = (short) io.readShort();
    int delta = (short) io.readShort();

    c.length--;

    if (n == 0) {
      return;
    }

    int[] atoms = new int[n];
    Property[] props = new Property[n];
    Property p;
    int i = 0;
    while (n != 0) {
      atoms[i] = io.readInt();
      c.length--;
      if (!Atom.valid(atoms[i])) {
        c.errorValue = atoms[i];
        c.errorReason = 5; // BadAtom
        return;
      }
      p = w.getProperty();
      while (p != null) {
        if (p.propertyName == atoms[i]) {
          props[i] = p;
          break;
        }
        p = p.next;
      }
      if (p == null) {
        c.errorReason = 8; // BadMatch
        return;
      }
      i++;
      n--;
    }
    for (int j = 0; j < atoms.length; j++) {
      for (int k = j + 1; k < atoms.length; k++) {
        if (atoms[j] == atoms[k]) {
          c.errorReason = 8; // BadMatch
          return;
        }
      }
    }
    if (((delta < 0 ? -1 * delta : delta) % atoms.length) != 0) {
      while (delta < 0) {
        delta += atoms.length;
      }
      for (i = 0; i < atoms.length; i++) {
        c.cevent.mkPropertyNotify(
            w.id,
            props[i].propertyName,
            (int) System.currentTimeMillis(),
            // Property.PropertyNewValue
            0);
        w.sendEvent(c.cevent, 1, null);
        props[i].propertyName = atoms[(i + delta) % atoms.length];
      }
    }
  }