jdk/src/solaris/classes/sun/awt/X11/XNETProtocol.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2472 b7aba00cabb6
child 4214 0fa32d38146b
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
     2
 * Copyright 2003-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    29
import java.awt.Frame;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    30
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    32
final class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    33
{
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    34
    private final static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XNETProtocol");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    35
    private final static PlatformLogger iconLog = PlatformLogger.getLogger("sun.awt.X11.icon.XNETProtocol");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    36
    private static PlatformLogger stateLog = PlatformLogger.getLogger("sun.awt.X11.states.XNETProtocol");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * XStateProtocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public boolean supportsState(int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        return doStateProtocol() ; // TODO - check for Frame constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public void setState(XWindowPeer window, int state) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    46
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("Setting state of " + window + " to " + state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        if (window.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            requestState(window, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            setInitialState(window, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private void setInitialState(XWindowPeer window, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        XAtomList old_state = window.getNETWMState();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    56
        log.fine("Current state of the window {0} is {1}", window, old_state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if ((state & Frame.MAXIMIZED_VERT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            old_state.add(XA_NET_WM_STATE_MAXIMIZED_VERT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            old_state.remove(XA_NET_WM_STATE_MAXIMIZED_VERT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if ((state & Frame.MAXIMIZED_HORIZ) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            old_state.add(XA_NET_WM_STATE_MAXIMIZED_HORZ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            old_state.remove(XA_NET_WM_STATE_MAXIMIZED_HORZ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
    67
        log.fine("Setting initial state of the window {0} to {1}", window, old_state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        window.setNETWMState(old_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private void requestState(XWindowPeer window, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         * We have to use toggle for maximization because of transitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         * from maximization in one direction only to maximization in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         * other direction only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int old_net_state = getState(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int max_changed = (state ^ old_net_state) & (Frame.MAXIMIZED_BOTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        XClientMessageEvent req = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            switch(max_changed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
              case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
              case Frame.MAXIMIZED_HORIZ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                  req.set_data(1, XA_NET_WM_STATE_MAXIMIZED_HORZ.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                  req.set_data(2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
              case Frame.MAXIMIZED_VERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                  req.set_data(1, XA_NET_WM_STATE_MAXIMIZED_VERT.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                  req.set_data(2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
              case Frame.MAXIMIZED_BOTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                  req.set_data(1, XA_NET_WM_STATE_MAXIMIZED_HORZ.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                  req.set_data(2, XA_NET_WM_STATE_MAXIMIZED_VERT.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   100
            if (log.isLoggable(PlatformLogger.FINE)) log.fine("Requesting state on " + window + " for " + state);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   101
            req.set_type((int)XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            req.set_window(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            req.set_message_type(XA_NET_WM_STATE.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            req.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            req.set_data(0, _NET_WM_STATE_TOGGLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                XlibWrapper.XSendEvent(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                        XlibWrapper.RootWindow(XToolkit.getDisplay(), window.getScreenNumber()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        false,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   111
                        XConstants.SubstructureRedirectMask | XConstants.SubstructureNotifyMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        req.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            req.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public int getState(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return getStateImpl(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * New "NET" WM spec: _NET_WM_STATE/Atom[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    int getStateImpl(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        XAtomList net_wm_state = window.getNETWMState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (net_wm_state.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return Frame.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        int java_state = Frame.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (net_wm_state.contains(XA_NET_WM_STATE_MAXIMIZED_VERT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            java_state |= Frame.MAXIMIZED_VERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (net_wm_state.contains(XA_NET_WM_STATE_MAXIMIZED_HORZ)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            java_state |= Frame.MAXIMIZED_HORIZ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return java_state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public boolean isStateChange(XPropertyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        boolean res = doStateProtocol() && (e.get_atom() == XA_NET_WM_STATE.getAtom()) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            // Since state change happened, reset our cached state.  It will be re-read by getState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            XWindowPeer wpeer = (XWindowPeer)XToolkit.windowToXWindow(e.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            wpeer.setNETWMState(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Work around for 4775545.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void unshadeKludge(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        XAtomList net_wm_state = window.getNETWMState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        net_wm_state.remove(XA_NET_WM_STATE_SHADED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        window.setNETWMState(net_wm_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * XLayerProtocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public boolean supportsLayer(int layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return ((layer == LAYER_ALWAYS_ON_TOP) || (layer == LAYER_NORMAL)) && doLayerProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   171
    public void requestState(XWindow window, XAtom state, boolean isAdd) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   172
        XClientMessageEvent req = new XClientMessageEvent();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   173
        try {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   174
            req.set_type((int)XConstants.ClientMessage);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   175
            req.set_window(window.getWindow());
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   176
            req.set_message_type(XA_NET_WM_STATE.getAtom());
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   177
            req.set_format(32);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   178
            req.set_data(0, isAdd ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   179
            req.set_data(1, state.getAtom());
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   180
            // Fix for 6735584: req.data[2] must be set to 0 when only one property is changed
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   181
            req.set_data(2, 0);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   182
            log.fine("Setting _NET_STATE atom {0} on {1} for {2}", state, window, Boolean.valueOf(isAdd));
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   183
            XToolkit.awtLock();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   184
            try {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   185
                XlibWrapper.XSendEvent(XToolkit.getDisplay(),
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   186
                        XlibWrapper.RootWindow(XToolkit.getDisplay(), window.getScreenNumber()),
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   187
                        false,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   188
                        XConstants.SubstructureRedirectMask | XConstants.SubstructureNotifyMask,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   189
                        req.pData);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   190
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   191
            finally {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   192
                XToolkit.awtUnlock();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   193
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   194
        } finally {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   195
            req.dispose();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   196
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   197
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   198
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Helper function to set/reset one state in NET_WM_STATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * If window is showing then it uses ClientMessage, otherwise adjusts NET_WM_STATE list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param window Window which NET_WM_STATE property is being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param state State atom to be set/reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param reset Indicates operation, 'set' if false, 'reset' if true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private void setStateHelper(XWindowPeer window, XAtom state, boolean set) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   207
        log.finer("Window visibility is: withdrawn={0}, visible={1}, mapped={2} showing={3}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   208
                  Boolean.valueOf(window.isWithdrawn()), Boolean.valueOf(window.isVisible()),
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   209
                  Boolean.valueOf(window.isMapped()), Boolean.valueOf(window.isShowing()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (window.isShowing()) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2451
diff changeset
   211
            requestState(window, state, set);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            XAtomList net_wm_state = window.getNETWMState();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   214
            log.finer("Current state on {0} is {1}", window, net_wm_state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (!set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                net_wm_state.remove(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                net_wm_state.add(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   220
            log.fine("Setting states on {0} to {1}", window, net_wm_state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            window.setNETWMState(net_wm_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public void setLayer(XWindowPeer window, int layer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        setStateHelper(window, XA_NET_WM_STATE_ABOVE, layer == LAYER_ALWAYS_ON_TOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /* New "netwm" spec from www.freedesktop.org */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING");   /* like STRING but encoding is UTF-8 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    XAtom XA_NET_SUPPORTING_WM_CHECK = XAtom.get("_NET_SUPPORTING_WM_CHECK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    XAtom XA_NET_SUPPORTED = XAtom.get("_NET_SUPPORTED");      /* list of protocols (property of root) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    XAtom XA_NET_WM_NAME = XAtom.get("_NET_WM_NAME");  /* window property */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    XAtom XA_NET_WM_STATE = XAtom.get("_NET_WM_STATE");/* both window property and request */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * _NET_WM_STATE is a list of atoms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * NB: Standard spelling is "HORZ" (yes, without an 'I'), but KDE2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * uses misspelled "HORIZ" (see KDE bug #20229).  This was fixed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * KDE 2.2.  Under earlier versions of KDE2 horizontal and full
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * maximization doesn't work .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    XAtom XA_NET_WM_STATE_MAXIMIZED_HORZ = XAtom.get("_NET_WM_STATE_MAXIMIZED_HORZ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    XAtom XA_NET_WM_STATE_MAXIMIZED_VERT = XAtom.get("_NET_WM_STATE_MAXIMIZED_VERT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    XAtom XA_NET_WM_STATE_SHADED = XAtom.get("_NET_WM_STATE_SHADED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    XAtom XA_NET_WM_STATE_ABOVE = XAtom.get("_NET_WM_STATE_ABOVE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    XAtom XA_NET_WM_STATE_MODAL = XAtom.get("_NET_WM_STATE_MODAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    XAtom XA_NET_WM_STATE_FULLSCREEN = XAtom.get("_NET_WM_STATE_FULLSCREEN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    XAtom XA_NET_WM_STATE_BELOW = XAtom.get("_NET_WM_STATE_BELOW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    XAtom XA_NET_WM_STATE_HIDDEN = XAtom.get("_NET_WM_STATE_HIDDEN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    XAtom XA_NET_WM_STATE_SKIP_TASKBAR = XAtom.get("_NET_WM_STATE_SKIP_TASKBAR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    XAtom XA_NET_WM_STATE_SKIP_PAGER = XAtom.get("_NET_WM_STATE_SKIP_PAGER");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    XAtom XA_NET_WM_WINDOW_TYPE = XAtom.get("_NET_WM_WINDOW_TYPE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    XAtom XA_NET_WM_WINDOW_TYPE_DIALOG = XAtom.get("_NET_WM_WINDOW_TYPE_DIALOG");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   258
    XAtom XA_NET_WM_WINDOW_OPACITY = XAtom.get("_NET_WM_WINDOW_OPACITY");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   259
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
/* For _NET_WM_STATE ClientMessage requests */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    final static int _NET_WM_STATE_REMOVE      =0; /* remove/unset property */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    final static int _NET_WM_STATE_ADD         =1; /* add/set property      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    final static int _NET_WM_STATE_TOGGLE      =2; /* toggle property       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    boolean supportChecked = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    long NetWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    void detect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (supportChecked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            // TODO: How about detecting WM-restart or exit?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        NetWindow = checkAnchor(XA_NET_SUPPORTING_WM_CHECK, XAtom.XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        supportChecked = true;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   274
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("### " + this + " is active: " + (NetWindow != 0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    boolean active() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        detect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return NetWindow != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    boolean doStateProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_STATE);
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
   284
        stateLog.finer("doStateProtocol() returns " + res);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    boolean doLayerProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_STATE_ABOVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    boolean doModalityProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_STATE_MODAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   297
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   298
    boolean doOpacityProtocol() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   299
        boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_WINDOW_OPACITY);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   300
        return res;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   301
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1189
diff changeset
   302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    boolean isWMName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (!active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        String net_wm_name_string = getWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (net_wm_name_string == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2472
diff changeset
   311
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("### WM_NAME = " + net_wm_name_string);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return net_wm_name_string.startsWith(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    String net_wm_name_cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (!active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (net_wm_name_cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            return net_wm_name_cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * Check both UTF8_STRING and STRING.  We only call this function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * with ASCII names and UTF8 preserves ASCII bit-wise.  wm-spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * mandates UTF8_STRING for _NET_WM_NAME but at least sawfish-1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * still uses STRING.  (mmm, moving targets...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        String charSet = "UTF8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        byte[] net_wm_name = XA_NET_WM_NAME.getByteArrayProperty(NetWindow, XA_UTF8_STRING.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (net_wm_name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            net_wm_name = XA_NET_WM_NAME.getByteArrayProperty(NetWindow, XAtom.XA_STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            charSet = "ASCII";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (net_wm_name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            net_wm_name_cache = new String(net_wm_name, charSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            return net_wm_name_cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        } catch (java.io.UnsupportedEncodingException uex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Sets _NET_WM_ICON property on the window using the List of XIconInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * If icons is null or empty list, removes _NET_WM_ICON property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public void setWMIcons(XWindowPeer window, java.util.List<XIconInfo> icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (window == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        XAtom iconsAtom = XAtom.get("_NET_WM_ICON");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (icons == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            iconsAtom.DeleteProperty(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        int length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        for (XIconInfo ii : icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            length += ii.getRawLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        int cardinalSize = (XlibWrapper.dataModel == 32) ? 4 : 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int bufferSize = length * cardinalSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (bufferSize != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            long buffer = XlibWrapper.unsafe.allocateMemory(bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                long ptr = buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                for (XIconInfo ii : icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    int size = ii.getRawLength() * cardinalSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    if (XlibWrapper.dataModel == 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        XlibWrapper.copyIntArray(ptr, ii.getIntData(), size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        XlibWrapper.copyLongArray(ptr, ii.getLongData(), size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    ptr += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                iconsAtom.setAtomData(window.getWindow(), XAtom.XA_CARDINAL, buffer, bufferSize/Native.getCard32Size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                XlibWrapper.unsafe.freeMemory(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            iconsAtom.DeleteProperty(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public boolean isWMStateNetHidden(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (!doStateProtocol()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        XAtomList state = window.getNETWMState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return (state != null && state.size() != 0 && state.contains(XA_NET_WM_STATE_HIDDEN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
}