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