=== modified file 'src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java' --- src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java 2016-02-02 05:54:01 +0000 +++ src/com/goldencode/p2j/ui/client/chui/driver/web/ChuiWebSimulator.java 2016-02-03 21:18:40 +0000 @@ -229,9 +229,13 @@ * The window ID. * @param state * True if the window has been activated, otherwise false. + * @param focusOut + * The true value indicates that the current focus is moved from a non P2J window to + * a P2J window for an activation event or from a P2j window to a non P2j window + * for a deactivation event. */ @Override - public void windowActivated(int windowId, boolean state) + public void windowActivated(int windowId, boolean state, boolean focusOut) { // no-op } === modified file 'src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java' --- src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java 2016-02-02 05:54:01 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/ClientProtocolHooks.java 2016-02-03 21:18:40 +0000 @@ -106,8 +106,12 @@ * The window ID. * @param state * The boolean flag indicating that the target window has been activated or inactive. + * @param focusOut + * The true value indicates that the current focus is moved from a non P2J window to + * a P2J window for an activation event or from a P2j window to a non P2j window + * for a deactivation event. */ - public void windowActivated(int windowId, boolean state); + public void windowActivated(int windowId, boolean state, boolean focusOut); /** * Raise an event as the window was (de)iconified. === modified file 'src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js' --- src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2016-02-03 11:21:56 +0000 +++ src/com/goldencode/p2j/ui/client/driver/web/res/p2j.socket.js 2016-02-03 21:18:40 +0000 @@ -104,11 +104,15 @@ * The target window id * @param {Boolean} active * The flag indicating that the target window should be active or not. + * @param {Boolean} focusOut + * The true value indicates that the current focus is moved from a non P2J window to + * a P2J window for an activation event or from a P2j window to a non P2j window + * for a deactivation event. */ - me.sendWindowActive = function(wid, active) + me.sendWindowActive = function(wid, active, focusOut) { - // send the window activation to the java side - var msg = new Uint8Array(6); + // send the window activation/deactivation to the java side + var msg = new Uint8Array(7); // message type msg[0] = 0x0f; @@ -116,7 +120,8 @@ // 1. the window ID me.writeInt32BinaryMessage(msg, 1, wid); - msg[5] = active ? 1 : 0; + msg[5] = active ? 1 : 0; + msg[6] = focusOut ? 1 : 0; // send the window active event me.send(msg); === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2016-02-02 19:15:56 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java 2016-02-03 21:18:40 +0000 @@ -587,7 +587,7 @@ if (focus) { // activate the window and notify the upper layers - windowActivated(windowId, true); + windowActivated(windowId, true, false); } } @@ -891,41 +891,37 @@ * The window ID. * @param state * True if the window has been activated, otherwise false. + * @param focusOut + * The true value indicates that the current focus is moved from a non P2J window to + * a P2J window for an activation event or from a P2j window to a non P2j window + * for a deactivation event. */ @Override - public void windowActivated(int windowId, boolean state) + public void windowActivated(int windowId, boolean state, boolean focusOut) { // resolve window object TopLevelWindow window = (TopLevelWindow) WindowManager.findWindow(windowId); // this protects from activation already active window // it become important when overlay window is on screen - // in this case double activation will incorrectly dismiss overaly + // in this case double activation will incorrectly dismiss overlay TopLevelWindow currActiveWindow = WindowManager.getActiveWindow(); - TopLevelWindow currFocusWindow = WindowManager.getFocusWindow(); // check if overlay window exists OverlayWindow ow = WindowManager.findOverlayWindow(); // we do not need to activate already active window is there is no overlay on the screen - if (state && window == currActiveWindow && ow == null && currFocusWindow == currActiveWindow) + if (state && WindowManager.isWindowActive(window) && ow == null) { return; } // if overlay window exists and not a target of activation - remove it first - if (ow != null && ow != window && state) + if (state && ow != null && ow != window) { ThinClient.getInstance().postOSEvent(new WindowActivated(ow, false, false)); } - if (window == currFocusWindow && !state) - { - WindowManager.removeFocusWindow(); - } - if (state) - { - WindowManager.setFocusWindow(window); - } - ThinClient.getInstance().postOSEvent(new WindowActivated(window, state, false)); + + ThinClient.getInstance().postOSEvent(new WindowActivated(window, state, focusOut)); } /** === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-02-03 11:21:56 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-02-03 21:18:40 +0000 @@ -1282,16 +1282,16 @@ handled = true; } - else if (length == 6 && message[offset] == MSG_WINDOW_ACTIVATED) + else if (length == 7 && message[offset] == MSG_WINDOW_ACTIVATED) { int idx = offset + 1; int windowId = readMessageInt32(message, idx); - idx = idx + 4; - - boolean state = message[idx] == 1; - - this.callbacks.windowActivated(windowId, state); + + boolean state = message[idx + 4] == 1; + boolean focusOut = message[idx + 5] == 1; + + this.callbacks.windowActivated(windowId, state, focusOut); } else if (length == 6 && message[offset] == MSG_WINDOW_ICONIFY) { === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.mouse.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.mouse.js 2016-02-02 05:54:01 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.mouse.js 2016-02-03 21:18:40 +0000 @@ -117,12 +117,12 @@ if (topWindowId) { - p2j.socket.sendWindowActive(topWindowId, false); + p2j.socket.sendWindowActive(topWindowId, false, false); } // move the window to top win.moveToTop(); - p2j.socket.sendWindowActive(win.id, true); + p2j.socket.sendWindowActive(win.id, true, false); // consume the event evt.preventDefault(); === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-02-03 11:21:56 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-02-03 21:18:40 +0000 @@ -1638,12 +1638,13 @@ */ function activateTopVisibleWindow(id) { - p2j.socket.sendWindowActive(id, false); var topWindow = findTopVisibleWindow(id); + var focusOut = !(topWindow); + p2j.socket.sendWindowActive(id, false, focusOut); if (topWindow) { topWindow.moveToTop(); - p2j.socket.sendWindowActive(topWindow.id, true); + p2j.socket.sendWindowActive(topWindow.id, true, false); } } @@ -2409,11 +2410,12 @@ */ function sendWindowStateActive(windowId) { - var topWindowId = p2j.screen.topWindowId(); - if (topWindowId && topWindowId !== windowId) + var topWindow = findTopVisibleWindow(windowId); + if (topWindow) { - p2j.socket.sendWindowActive(topWindowId, false); + p2j.socket.sendWindowActive(topWindow.id, false, false); } + var focusOut = !(topWindow); var win = getWindow(windowId); if (!win.isVisible()) { @@ -2423,7 +2425,7 @@ win.deiconify(); // send the window activation to the java side - p2j.socket.sendWindowActive(windowId, true); + p2j.socket.sendWindowActive(windowId, true, focusOut); } /**