580 return ((Window)target).isAutoRequestFocus(); |
580 return ((Window)target).isAutoRequestFocus(); |
581 } |
581 } |
582 } |
582 } |
583 |
583 |
584 /* |
584 /* |
585 * Converts native focused X window id into Java peer. |
585 * Retrives real native focused window and converts it into Java peer. |
586 */ |
586 */ |
587 static XWindowPeer getNativeFocusedWindowPeer() { |
587 static XWindowPeer getNativeFocusedWindowPeer() { |
588 XBaseWindow baseWindow = XToolkit.windowToXWindow(xGetInputFocus()); |
588 XBaseWindow baseWindow = XToolkit.windowToXWindow(xGetInputFocus()); |
589 return (baseWindow instanceof XWindowPeer) ? (XWindowPeer)baseWindow : |
589 return (baseWindow instanceof XWindowPeer) ? (XWindowPeer)baseWindow : |
590 (baseWindow instanceof XFocusProxyWindow) ? |
590 (baseWindow instanceof XFocusProxyWindow) ? |
591 ((XFocusProxyWindow)baseWindow).getOwner() : null; |
591 ((XFocusProxyWindow)baseWindow).getOwner() : null; |
|
592 } |
|
593 |
|
594 /* |
|
595 * Retrives real native focused window and converts it into Java window. |
|
596 */ |
|
597 static Window getNativeFocusedWindow() { |
|
598 XWindowPeer peer = getNativeFocusedWindowPeer(); |
|
599 return peer != null ? (Window)peer.target : null; |
592 } |
600 } |
593 |
601 |
594 boolean isFocusableWindow() { |
602 boolean isFocusableWindow() { |
595 if (XToolkit.isToolkitThread() || SunToolkit.isAWTLockHeldByCurrentThread()) |
603 if (XToolkit.isToolkitThread() || SunToolkit.isAWTLockHeldByCurrentThread()) |
596 { |
604 { |
1738 window = (Window) ComponentAccessor.getParent_NoClientCode(window); |
1746 window = (Window) ComponentAccessor.getParent_NoClientCode(window); |
1739 } |
1747 } |
1740 return window; |
1748 return window; |
1741 } |
1749 } |
1742 |
1750 |
|
1751 public boolean requestWindowFocus(XWindowPeer actualFocusedWindow) { |
|
1752 setActualFocusedWindow(actualFocusedWindow); |
|
1753 return requestWindowFocus(); |
|
1754 } |
|
1755 |
1743 public boolean requestWindowFocus() { |
1756 public boolean requestWindowFocus() { |
1744 return requestWindowFocus(0, false); |
1757 return requestWindowFocus(0, false); |
1745 } |
1758 } |
1746 |
1759 |
1747 public boolean requestWindowFocus(long time, boolean timeProvided) { |
1760 public boolean requestWindowFocus(long time, boolean timeProvided) { |
1748 focusLog.fine("Request for window focus"); |
1761 focusLog.fine("Request for window focus"); |
1749 // If this is Frame or Dialog we can't assure focus request success - but we still can try |
1762 // If this is Frame or Dialog we can't assure focus request success - but we still can try |
1750 // If this is Window and its owner Frame is active we can be sure request succedded. |
1763 // If this is Window and its owner Frame is active we can be sure request succedded. |
1751 Window win = (Window) target; |
1764 Window ownerWindow = XWindowPeer.getDecoratedOwner((Window)target); |
1752 Window owner = XWindowPeer.getDecoratedOwner(win); |
1765 Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow(); |
1753 |
1766 Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow); |
1754 final Window activeWindow = |
1767 |
1755 XWindowPeer.getDecoratedOwner(XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow()); |
1768 if (isWMStateNetHidden()) { |
1756 if (activeWindow == owner) { |
1769 focusLog.fine("The window is unmapped, so rejecting the request"); |
|
1770 return false; |
|
1771 } |
|
1772 if (activeWindow == ownerWindow) { |
1757 focusLog.fine("Parent window is active - generating focus for this window"); |
1773 focusLog.fine("Parent window is active - generating focus for this window"); |
1758 handleWindowFocusInSync(-1); |
1774 handleWindowFocusInSync(-1); |
1759 return true; |
1775 return true; |
1760 } else { |
1776 } |
1761 focusLog.fine("Parent window is not active"); |
1777 focusLog.fine("Parent window is not active"); |
1762 } |
1778 |
1763 ComponentPeer peer = ComponentAccessor.getPeer(owner); |
1779 XDecoratedPeer wpeer = (XDecoratedPeer)ComponentAccessor.getPeer(ownerWindow); |
1764 if (peer instanceof XDecoratedPeer) { |
1780 if (wpeer != null && wpeer.requestWindowFocus(this, time, timeProvided)) { |
1765 XDecoratedPeer wpeer = (XDecoratedPeer) peer; |
1781 focusLog.fine("Parent window accepted focus request - generating focus for this window"); |
1766 if (wpeer.requestWindowFocus(this, time, timeProvided)) { |
1782 return true; |
1767 focusLog.fine("Parent window accepted focus request - generating focus for this window"); |
|
1768 return true; |
|
1769 } |
|
1770 } |
1783 } |
1771 focusLog.fine("Denied - parent window is not active and didn't accept focus request"); |
1784 focusLog.fine("Denied - parent window is not active and didn't accept focus request"); |
1772 return false; |
1785 return false; |
1773 } |
1786 } |
1774 |
1787 |