static void reqChangeProperty(Client c) throws IOException { int foo; byte mode; int prpty; byte frmt; int typ; int n; IO io = c.client; mode = (byte) c.data; if ((mode != PropModeReplace) && (mode != PropModeAppend) && (mode != PropModePrepend)) { // System.err.println("error!!"); c.errorValue = mode; c.errorReason = 2; // BadValue; } n = c.length; ; foo = io.readInt(); Window w = c.lookupWindow(foo); if (c.errorReason == 0 && w == null) { c.errorValue = foo; c.errorReason = 3; // BadWindow; } prpty = io.readInt(); typ = io.readInt(); frmt = (byte) io.readByte(); if (c.errorReason == 0 && (frmt != 8) && (frmt != 16) && (frmt != 32)) { c.errorValue = frmt; c.errorReason = 3; // BadWindow; } io.readPad(3); foo = io.readInt(); int totalSize = foo * (frmt / 8); byte[] bar = null; if (totalSize > 0) { bar = new byte[totalSize]; io.readByte(bar, 0, totalSize); if (c.swap) { switch (frmt) { case 16: swapS(bar, 0, totalSize); break; case 32: swapL(bar, 0, totalSize); break; default: } } io.readPad((-totalSize) & 3); } c.length = 0; if (c.errorReason != 0) { return; } changeWindowProperty(c, w, prpty, typ, frmt, mode, foo, bar, true); }
static void reqSetSelectionOwner(Client c) throws IOException { int foo; int selection; IO io = c.client; foo = io.readInt(); c.length -= 2; Window w = null; if (foo != 0) { w = c.lookupWindow(foo); if (w == null) { c.errorValue = foo; c.errorReason = 3; // BadWindow return; } } selection = io.readInt(); foo = io.readInt(); c.length -= 2; int time = 0; time = (int) System.currentTimeMillis(); time = foo; // ?? if (Atom.valid(selection)) { int i = 0; Selection s = getSelection(selection); if (s != null) { if (s.client != null && (w == null || (s.client != c))) { if (s.client != null) { c.cevent.mkSelectionClear(time, s.wid, s.selection); s.client.sendEvent(c.cevent, 1, Event.NoEventMask, Event.NoEventMask, null); } } s.window = w; s.wid = (w != null ? w.id : 0); s.lastTimeChanged = time; s.client = (w != null ? c : null); } else { // System.out.println("add"); addSelection(selection, time, w, c); } return; } else { c.errorValue = selection; c.errorReason = 5; return; } }
static void reqListProperties(Client c) throws IOException { int foo, n; 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; } synchronized (io) { io.writeByte(1); Property p = w.getProperty(); int i = 0; while (p != null) { i++; p = p.next; } io.writePad(1); io.writeShort(c.seq); io.writeInt(i); io.writeShort(i); io.writePad(22); p = w.getProperty(); while (p != null) { io.writeInt(p.propertyName); p = p.next; } io.flush(); } }
static void reqGetSelectionOwner(Client c) throws IOException { int foo; int selection; IO io = c.client; selection = io.readInt(); c.length -= 2; if (!Atom.valid(selection)) { c.errorValue = selection; c.errorReason = 5; // BadAtom return; } synchronized (io) { io.writeByte(1); Selection s = getSelection(selection); io.writePad(1); io.writeShort(c.seq); io.writeInt(0); if (s != null) { io.writeInt(s.wid); } else { io.writeInt(0); } io.writePad(20); io.flush(); } }
static void reqDeleteProperty(Client c) throws IOException { int foo, propty; IO io = c.client; foo = io.readInt(); Window w = c.lookupWindow(foo); if (w == null) { c.errorValue = foo; c.errorReason = 3; // BadWindow; } propty = foo = io.readInt(); c.length -= 3; if (c.errorReason != 0) { return; } if (w.parent != null) { Property.delProperty(c, w, propty, 0); } }
static void reqConvertSelection(Client c) throws IOException { int foo; int selection, requestor, target, property, time; boolean paramsOkay = true; IO io = c.client; requestor = io.readInt(); Window w = c.lookupWindow(requestor); if (w == null) { c.errorValue = requestor; c.errorReason = 3; // BadWindow; } selection = io.readInt(); paramsOkay = Atom.valid(selection); target = io.readInt(); paramsOkay &= Atom.valid(target); property = io.readInt(); if (property != 0) { paramsOkay &= Atom.valid(property); } time = io.readInt(); c.length -= 6; if (c.errorReason != 0) { return; } if (paramsOkay) { Selection s = getSelection(selection); if (s != null && s.client != null) { c.cevent.mkSelectionRequest(time, s.wid, requestor, selection, target, property); if (s.client.sendEvent(c.cevent, 1, Event.NoEventMask, Event.NoEventMask, null) != 0) return; } c.cevent.mkSelectionNotify(time, requestor, selection, target, 0); c.sendEvent(c.cevent, 1, Event.NoEventMask, Event.NoEventMask, null); return; } else { // System.out.println("error!!"); c.errorValue = property; c.errorReason = 5; // BadAtom return; } }
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); } }
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]; } } }
// Connects to server, starts a NetThread, then waits for messages. public static void main(String[] args) { int port = -1; String host = null; if (args.length >= 3) { name = args[0]; host = args[1]; try { port = Integer.parseInt(args[2]); } catch (Exception e) { port = -1; } } if (port == (-1)) { io.p("What server would you like to connect to? "); host = io.readLine(); io.p("What port would you like to connect on? "); port = io.readInt(); if ((port < 1) || (port > 65535)) { io.pl("Invalid port number."); System.exit(1); } } io.pl("Connecting to " + host + ":" + port + "..."); Socket s = null; try { s = new Socket(host, port); } catch (Exception e) { io.pl("Couldn't connect to that server."); UIWindow.alert(null, "Couldn't connect to that server."); System.exit(1); } server = new NetThread(s, al, -1); io.pl("Connected to server."); Message nameMessage = new Message(Message.SET_NAME, name, null); server.sendMessage(nameMessage); while (true) { synchronized (al) { if (haveMessages()) { Message m = null; m = al.get(0); al.remove(0); handleMessage(m); } else { try { al.wait(); } catch (Exception e) { io.pl("An exception occurred while trying to wait for messages from the server."); UIWindow.alert(null, "AI Client error occurred."); System.exit(1); } } } } }