Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/XAwtState.java
32288 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* This class is a placeholder for all internal static objects that represent27* system state. We keep our representation up-to-date with actual system28* state by tracking events, such as X Focus, Component under cursor etc.29* All attributes should be static private with accessors to simpify change30* tracking.31*/32package sun.awt.X11;3334import java.awt.Component;35import java.lang.ref.WeakReference;3637class XAwtState {38/**39* The mouse is over this component.40* If the component is not disabled, it received MOUSE_ENTERED but no MOUSE_EXITED.41*/42private static WeakReference componentMouseEnteredRef = null;4344static void setComponentMouseEntered(Component component) {45XToolkit.awtLock();46try {47if (component == null) {48componentMouseEnteredRef = null;49return;50}51if (component != getComponentMouseEntered()) {52componentMouseEnteredRef = new WeakReference(component);53}54} finally {55XToolkit.awtUnlock();56}57}5859static Component getComponentMouseEntered() {60XToolkit.awtLock();61try {62if (componentMouseEnteredRef == null) {63return null;64}65return (Component)componentMouseEnteredRef.get();66} finally {67XToolkit.awtUnlock();68}69}7071/**72* The XBaseWindow is created with OwnerGrabButtonMask73* (see X vol. 1, 8.3.3.2) so inside the app Key, Motion, and Button events74* are received by the window they actualy happened on, not the grabber.75* Then XBaseWindow dispatches them to the grabber. As a result76* XAnyEvent.get_window() returns actual window the event is originated,77* though the event is dispatched by the grabber.78*/79private static boolean inManualGrab = false;8081static boolean isManualGrab() {82return inManualGrab;83}8485private static WeakReference grabWindowRef = null;8687/**88* The X Active Grab overrides any other active grab by the same89* client see XGrabPointer, XGrabKeyboard90*/91static void setGrabWindow(XBaseWindow grabWindow) {92setGrabWindow(grabWindow, false);93}9495/**96* Automatic passive grab doesn't override active grab see XGrabButton97*/98static void setAutoGrabWindow(XBaseWindow grabWindow) {99setGrabWindow(grabWindow, true);100}101102private static void setGrabWindow(XBaseWindow grabWindow, boolean isAutoGrab) {103XToolkit.awtLock();104try {105if (inManualGrab && isAutoGrab) {106return;107}108inManualGrab = grabWindow != null && !isAutoGrab;109if (grabWindow == null) {110grabWindowRef = null;111return;112}113if (grabWindow != getGrabWindow()) {114grabWindowRef = new WeakReference(grabWindow);115}116} finally {117XToolkit.awtUnlock();118}119}120121static XBaseWindow getGrabWindow() {122XToolkit.awtLock();123try {124if (grabWindowRef == null) {125return null;126}127XBaseWindow xbw = (XBaseWindow)grabWindowRef.get();128if( xbw != null && xbw.isDisposed() ) {129xbw = null;130grabWindowRef = null;131}else if( xbw == null ) {132grabWindowRef = null;133}134return xbw;135} finally {136XToolkit.awtUnlock();137}138}139}140141142