private void syncWindowStateNext() throws EOFException { AppXrw.logger.info("Enter syncWindowStateNext"); CreateWindowMsgArgs crtMsgArgs = new CreateWindowMsgArgs(); WindowXrw win; int controllingUserLen; int desiredZOrder; float rotY; // Currently ignored Vector3f userTranslation = new Vector3f(); crtMsgArgs.wid = bufQueue.nextInt(); crtMsgArgs.x = (short) bufQueue.nextInt(); crtMsgArgs.y = (short) bufQueue.nextInt(); crtMsgArgs.wAndBorder = bufQueue.nextInt(); crtMsgArgs.hAndBorder = bufQueue.nextInt(); crtMsgArgs.borderWidth = bufQueue.nextInt(); controllingUserLen = bufQueue.nextInt(); desiredZOrder = bufQueue.nextInt(); rotY = bufQueue.nextFloat(); // Just skipped userTranslation.x = bufQueue.nextFloat(); userTranslation.y = bufQueue.nextFloat(); userTranslation.z = bufQueue.nextFloat(); AppXrw.logger.info("userTranslation = " + userTranslation); /* TODO: 0.4 protocol: int transientFor = bufQueue.nextInt(); AppXrw.logger.info("transientFor = " + transientFor); */ // TODO: 0.4 protocol: skip isTransient int transientFor = bufQueue.nextInt(); int typeOrdinal = bufQueue.nextInt(); Window2D.Type type = Window2D.Type.values()[typeOrdinal]; AppXrw.logger.info("type = " + type); int parentWid = bufQueue.nextInt(); AppXrw.logger.info("parentWid = " + parentWid); crtMsgArgs.decorated = (bufQueue.nextByte() == 1) ? true : false; AppXrw.logger.info("client = " + client); AppXrw.logger.info("crtMsgArgs = " + crtMsgArgs); AppXrw.logger.info("desiredZOrder= " + desiredZOrder); // Make sure window is ready to receive data on creation win = client.createWindow(crtMsgArgs); if (win == null) { AppXrw.logger.warning("Cannot create slave window for " + crtMsgArgs.wid); return; } if (win.getType() != type) { win.setType(type); } // Defer parent assignment until all windows are created if (parentWid != WindowXrw.INVALID_WID) { windowParents.put(win, parentWid); } win.setDesiredZOrder(desiredZOrder); CellTransform userTransformCell = new CellTransform(null, null); userTransformCell.setTranslation(userTranslation); win.setUserTransformCellLocal(userTransformCell); boolean show = (bufQueue.nextByte() == 1) ? true : false; AppXrw.logger.info("show = " + show); if (controllingUserLen > 0) { byte[] controllingUserBuf = bufQueue.nextBuffer(); String controllingUser = new String(controllingUserBuf); AppXrw.logger.info("controlling user = " + controllingUser); win.setControllingUser(controllingUser); } int srcWidth = crtMsgArgs.wAndBorder; int srcHeight = crtMsgArgs.hAndBorder; int[] pixels = new int[srcWidth * srcHeight]; for (int y = 0; y < srcHeight; y++) { int srcLineOffset = y * srcWidth; for (int x = 0; x < srcWidth; x++) { pixels[srcLineOffset + x] = bufQueue.nextInt(); } } win.displayPixels(0, 0, srcWidth, srcHeight, pixels); /* TODO: 0.4 protocol: WindowXrw winTransientFor = client.lookupWindow(transientFor); win.setVisibleApp(show, winTransientFor); */ win.setVisibleApp(show); }
private void initialHandshake() throws EOFException { String userName = session.getUserID().getUsername(); int strLen = userName.length(); // Inform the server that we have connected by sending a hello message // with the name of this user byte[] helloBuf = new byte[Proto.ClientMessageType.HELLO.size() + strLen + Proto.SIGNATURE_SIZE]; helloBuf[0] = (byte) Proto.ClientMessageType.HELLO.ordinal(); helloBuf[1] = (byte) 0; // pad helloBuf[2] = (byte) ((strLen >> 8) & 0xff); helloBuf[3] = (byte) (strLen & 0xff); System.arraycopy(userName.getBytes(), 0, helloBuf, 4, strLen); try { slaveSocket.send(sign(helloBuf)); } catch (IOException ex) { throw new RuntimeException(ex); } AppXrw.logger.info("Broadcast slave Hello message for user " + userName); // Get the welcome message from the server. This contains the client id // Note: because the master hub broadcasts to all slaves, there is a chance // there might be irrelevant messages queued up for this // slave. These should be ignored. This come from the fact that it takes // some time after the slave joins the connection for the master to become // aware of it and to compose and send the welcome message. During this time // if there are any incoming messages from the X server they will be // forwarded to this slave even if it has not yet been officially welcomed. // Since the content of these messages will be reflected in the welcome message // and the slave can't really do anything until it is welcomed we need // to ignore these messages. ServerMessageType type = null; do { type = getMessageType(); } while (type != ServerMessageType.WELCOME); // TODO: eventually we should add a timeout // Skip 3 bytes of pad bufQueue.nextByte(); bufQueue.nextShort(); clientId = bufQueue.nextInt(); client.setClientId(clientId); windowParents.clear(); // Read the initial window state synchronization // part of the welcome message int numWins = bufQueue.nextInt(); AppXrw.logger.info("numWins = " + numWins); for (int i = 0; i < numWins; i++) { syncWindowStateNext(); } // All windows have been defined. Now assign the parents for (WindowXrw win : windowParents.keySet()) { Integer parentWid = windowParents.get(win); if (parentWid != null) { WindowXrw parentWin = client.lookupWindow(parentWid.intValue()); win.setParent(parentWin); } } windowParents.clear(); client.updateSlaveWindows(); }