0N/A/*
2362N/A * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.awt.*;
1696N/Aimport sun.util.logging.PlatformLogger;
0N/A
0N/Aclass XWINProtocol extends XProtocol implements XStateProtocol, XLayerProtocol {
1696N/A final static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWINProtocol");
0N/A
0N/A/* Gnome WM spec */
0N/A XAtom XA_WIN_SUPPORTING_WM_CHECK = XAtom.get("_WIN_SUPPORTING_WM_CHECK");
0N/A XAtom XA_WIN_PROTOCOLS = XAtom.get("_WIN_PROTOCOLS");
0N/A XAtom XA_WIN_STATE = XAtom.get("_WIN_STATE");
0N/A
0N/A public boolean supportsState(int state) {
0N/A return doStateProtocol(); // TODO - check for Frame constants
0N/A }
0N/A
0N/A public void setState(XWindowPeer window, int state) {
0N/A if (window.isShowing()) {
0N/A /*
0N/A * Request state transition from a Gnome WM (_WIN protocol) by sending
0N/A * _WIN_STATE ClientMessage to root window.
0N/A */
0N/A long win_state = 0;
0N/A
0N/A if ( (state & Frame.MAXIMIZED_VERT) != 0) {
0N/A win_state |= WIN_STATE_MAXIMIZED_VERT;
0N/A }
0N/A if ( (state & Frame.MAXIMIZED_HORIZ) != 0) {
0N/A win_state |= WIN_STATE_MAXIMIZED_HORIZ;
0N/A }
0N/A
0N/A XClientMessageEvent req = new XClientMessageEvent();
216N/A req.set_type(XConstants.ClientMessage);
0N/A req.set_window(window.getWindow());
0N/A req.set_message_type(XA_WIN_STATE.getAtom());
0N/A req.set_format(32);
0N/A req.set_data(0, (WIN_STATE_MAXIMIZED_HORIZ | WIN_STATE_MAXIMIZED_VERT));
0N/A req.set_data(1, win_state);
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("Sending WIN_STATE to root to change the state to " + win_state);
0N/A try {
0N/A XToolkit.awtLock();
0N/A XlibWrapper.XSendEvent(XToolkit.getDisplay(),
0N/A XlibWrapper.RootWindow(XToolkit.getDisplay(),
0N/A window.getScreenNumber()),
0N/A false,
216N/A XConstants.SubstructureRedirectMask | XConstants.SubstructureNotifyMask,
0N/A req.pData);
0N/A }
0N/A finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A req.dispose();
0N/A } else {
0N/A /*
0N/A * Specify initial state for a Gnome WM (_WIN protocol) by setting
0N/A * WIN_STATE property on the window to the desired state before
0N/A * mapping it.
0N/A */
0N/A /* Be careful to not wipe out state bits we don't understand */
0N/A long win_state = XA_WIN_STATE.getCard32Property(window);
0N/A long old_win_state = win_state;
0N/A
0N/A /*
0N/A * In their stupid quest of reinventing every wheel, Gnome WM spec
0N/A * have its own "minimized" hint (instead of using initial state
0N/A * and WM_STATE hints). This is bogus, but, apparently, some WMs
0N/A * pay attention.
0N/A */
0N/A if ((state & Frame.ICONIFIED) != 0) {
0N/A win_state |= WIN_STATE_MINIMIZED;
0N/A } else {
0N/A win_state &= ~WIN_STATE_MINIMIZED;
0N/A }
0N/A
0N/A if ((state & Frame.MAXIMIZED_VERT) != 0) {
0N/A win_state |= WIN_STATE_MAXIMIZED_VERT;
0N/A } else {
0N/A win_state &= ~WIN_STATE_MAXIMIZED_VERT;
0N/A }
0N/A
0N/A if ((state & Frame.MAXIMIZED_HORIZ) != 0) {
0N/A win_state |= WIN_STATE_MAXIMIZED_HORIZ;
0N/A } else {
0N/A win_state &= ~WIN_STATE_MAXIMIZED_HORIZ;
0N/A }
0N/A if ((old_win_state ^ win_state) != 0) {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("Setting WIN_STATE on " + window + " to change the state to " + win_state);
0N/A XA_WIN_STATE.setCard32Property(window, win_state);
0N/A }
0N/A }
0N/A }
0N/A
0N/A public int getState(XWindowPeer window) {
0N/A long win_state = XA_WIN_STATE.getCard32Property(window);
0N/A int java_state = Frame.NORMAL;
0N/A if ((win_state & WIN_STATE_MAXIMIZED_VERT) != 0) {
0N/A java_state |= Frame.MAXIMIZED_VERT;
0N/A }
0N/A if ((win_state & WIN_STATE_MAXIMIZED_HORIZ) != 0) {
0N/A java_state |= Frame.MAXIMIZED_HORIZ;
0N/A }
0N/A return java_state;
0N/A }
0N/A
0N/A public boolean isStateChange(XPropertyEvent e) {
0N/A return doStateProtocol() && e.get_atom() == XA_WIN_STATE.getAtom();
0N/A }
0N/A
0N/A public void unshadeKludge(XWindowPeer window) {
0N/A long win_state = XA_WIN_STATE.getCard32Property(window);
0N/A if ((win_state & WIN_STATE_SHADED) == 0) {
0N/A return;
0N/A }
0N/A win_state &= ~WIN_STATE_SHADED;
0N/A XA_WIN_STATE.setCard32Property(window, win_state);
0N/A }
0N/A
0N/A public boolean supportsLayer(int layer) {
0N/A return ((layer == LAYER_ALWAYS_ON_TOP) || (layer == LAYER_NORMAL)) && doLayerProtocol();
0N/A }
0N/A
0N/A public void setLayer(XWindowPeer window, int layer) {
0N/A if (window.isShowing()) {
0N/A XClientMessageEvent req = new XClientMessageEvent();
216N/A req.set_type(XConstants.ClientMessage);
0N/A req.set_window(window.getWindow());
0N/A req.set_message_type(XA_WIN_LAYER.getAtom());
0N/A req.set_format(32);
0N/A req.set_data(0, layer == LAYER_NORMAL ? WIN_LAYER_NORMAL : WIN_LAYER_ONTOP);
0N/A req.set_data(1, 0);
0N/A req.set_data(2, 0);
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("Setting layer " + layer + " by root message : " + req);
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.XSendEvent(XToolkit.getDisplay(),
0N/A XlibWrapper.RootWindow(XToolkit.getDisplay(),
0N/A window.getScreenNumber()),
0N/A false,
216N/A /*XConstants.SubstructureRedirectMask | */XConstants.SubstructureNotifyMask,
0N/A req.pData);
0N/A }
0N/A finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A req.dispose();
0N/A } else {
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("Setting layer property to " + layer);
0N/A XA_WIN_LAYER.setCard32Property(window, layer == LAYER_NORMAL ? WIN_LAYER_NORMAL : WIN_LAYER_ONTOP);
0N/A }
0N/A }
0N/A
0N/A XAtom XA_WIN_LAYER = XAtom.get("_WIN_LAYER");
0N/A
0N/A/* _WIN_STATE bits */
0N/A final static int WIN_STATE_STICKY =(1<<0); /* everyone knows sticky */
0N/A final static int WIN_STATE_MINIMIZED =(1<<1); /* Reserved - definition is unclear */
0N/A final static int WIN_STATE_MAXIMIZED_VERT =(1<<2); /* window in maximized V state */
0N/A final static int WIN_STATE_MAXIMIZED_HORIZ =(1<<3); /* window in maximized H state */
0N/A final static int WIN_STATE_HIDDEN =(1<<4); /* not on taskbar but window visible*/
0N/A final static int WIN_STATE_SHADED =(1<<5); /* shaded (MacOS / Afterstep style) */
0N/A/* _WIN_LAYER values */
0N/A final static int WIN_LAYER_ONTOP = 6;
0N/A final static int WIN_LAYER_NORMAL = 4;
0N/A
0N/A long WinWindow = 0;
0N/A boolean supportChecked = false;
0N/A void detect() {
0N/A if (supportChecked) {
0N/A return;
0N/A }
0N/A WinWindow = checkAnchor(XA_WIN_SUPPORTING_WM_CHECK, XAtom.XA_CARDINAL);
0N/A supportChecked = true;
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("### " + this + " is active: " + (WinWindow != 0));
0N/A }
0N/A
0N/A boolean active() {
0N/A detect();
0N/A return WinWindow != 0;
0N/A }
0N/A boolean doStateProtocol() {
0N/A boolean res = active() && checkProtocol(XA_WIN_PROTOCOLS, XA_WIN_STATE);
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("### " + this + " supports state: " + res);
0N/A return res;
0N/A }
0N/A
0N/A boolean doLayerProtocol() {
0N/A boolean res = active() && checkProtocol(XA_WIN_PROTOCOLS, XA_WIN_LAYER);
1696N/A if (log.isLoggable(PlatformLogger.FINE)) log.fine("### " + this + " supports layer: " + res);
0N/A return res;
0N/A }
0N/A}