jdk/src/java.desktop/unix/classes/sun/awt/X11/XWM.java
author chegar
Wed, 11 Nov 2015 09:19:12 +0000
changeset 33674 566777f73c32
parent 32865 f9cb6e427f9e
child 34405 d152b09f62ba
permissions -rw-r--r--
8140606: Update library code to use internal Unsafe Reviewed-by: alanb, mchung, psandoz, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24191
75ee64f51cb4 8039861: Fix fallthrough lint warnings in awt
darcy
parents: 20141
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: 4214
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: 4214
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: 4214
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4214
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * Ported from awt_wm.c, SCCS v1.11, author Valeriy Ushakov
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Author: Denis Mikhalkin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 12829
diff changeset
    33
import sun.awt.IconInfo;
33674
566777f73c32 8140606: Update library code to use internal Unsafe
chegar
parents: 32865
diff changeset
    34
import jdk.internal.misc.Unsafe;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    35
import java.awt.Insets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Rectangle;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    38
import java.util.Collection;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    39
import java.util.HashMap;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    40
import java.util.LinkedList;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    41
import java.util.regex.Matcher;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    42
import java.util.regex.Pattern;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    43
import sun.util.logging.PlatformLogger;
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    44
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Class incapsulating knowledge about window managers in general
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Descendants should provide some information about specific window manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
    50
final class XWM
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    51
{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    53
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWM");
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    54
    private static final PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XWM");
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    55
    private static final PlatformLogger stateLog = PlatformLogger.getLogger("sun.awt.X11.states.XWM");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static final XAtom XA_MWM_HINTS = new XAtom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/* Good old ICCCM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static XAtom XA_WM_STATE = new XAtom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING");    /* like STRING but encoding is UTF-8 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/* Currently we only care about max_v and max_h in _NET_WM_STATE */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    69
    static final int AWT_NET_N_KNOWN_STATES=2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/* Enlightenment */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    72
    static final XAtom XA_E_FRAME_SIZE = new XAtom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/* KWin (KDE2) */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    75
    static final XAtom XA_KDE_NET_WM_FRAME_STRUT = new XAtom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/* KWM (KDE 1.x) OBSOLETE??? */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    78
    static final XAtom XA_KWM_WIN_ICONIFIED = new XAtom();
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    79
    static final XAtom XA_KWM_WIN_MAXIMIZED = new XAtom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
/* OpenLook */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    82
    static final XAtom XA_OL_DECOR_DEL = new XAtom();
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    83
    static final XAtom XA_OL_DECOR_HEADER = new XAtom();
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    84
    static final XAtom XA_OL_DECOR_RESIZE = new XAtom();
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    85
    static final XAtom XA_OL_DECOR_PIN = new XAtom();
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    86
    static final XAtom XA_OL_DECOR_CLOSE = new XAtom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
/* EWMH */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    89
    static final XAtom XA_NET_FRAME_EXTENTS = new XAtom();
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    90
    static final XAtom XA_NET_REQUEST_FRAME_EXTENTS = new XAtom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 27284
diff changeset
    92
    static final int
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        UNDETERMINED_WM = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        NO_WM = 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        OTHER_WM = 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        OPENLOOK_WM = 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        MOTIF_WM = 5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        CDE_WM = 6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        ENLIGHTEN_WM = 7,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        KDE2_WM = 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        SAWFISH_WM = 9,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        ICE_WM = 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        METACITY_WM = 11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        COMPIZ_WM = 12,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   105
        LG3D_WM = 13,
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   106
        CWM_WM = 14,
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   107
        MUTTER_WM = 15;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        switch  (WMID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
          case NO_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
              return "NO WM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
          case OTHER_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
              return "Other WM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
          case OPENLOOK_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
              return "OPENLOOK";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
          case MOTIF_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
              return "MWM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
          case CDE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
              return "DTWM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
          case ENLIGHTEN_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
              return "Enlightenment";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
          case KDE2_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
              return "KWM2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
          case SAWFISH_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
              return "Sawfish";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
          case ICE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
              return "IceWM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
          case METACITY_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
              return "Metacity";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
          case COMPIZ_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
              return "Compiz";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
          case LG3D_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
              return "LookingGlass";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   134
          case CWM_WM:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   135
              return "CWM";
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   136
          case MUTTER_WM:
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   137
              return "Mutter";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
          case UNDETERMINED_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
              return "Undetermined WM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    int WMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    static final Insets zeroInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    static final Insets defaultInsets = new Insets(25, 5, 5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    XWM(int WMID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this.WMID = WMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        initializeProtocols();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   152
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   153
            log.fine("Window manager: " + toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   154
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    int getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return WMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    static Insets normalize(Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (insets.top > 64 || insets.top < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            insets.top = 28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (insets.left > 32 || insets.left < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            insets.left = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (insets.right > 32 || insets.right < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            insets.right = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (insets.bottom > 32 || insets.bottom < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            insets.bottom = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    static XNETProtocol g_net_protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    static XWINProtocol g_win_protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    static boolean isNetWMName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (g_net_protocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return g_net_protocol.isWMName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    static void initAtoms() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        final Object[][] atomInitList ={
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            { XA_WM_STATE,                      "WM_STATE"                  },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            { XA_KDE_NET_WM_FRAME_STRUT,    "_KDE_NET_WM_FRAME_STRUT"       },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            { XA_E_FRAME_SIZE,              "_E_FRAME_SIZE"                 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            { XA_KWM_WIN_ICONIFIED,          "KWM_WIN_ICONIFIED"             },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            { XA_KWM_WIN_MAXIMIZED,          "KWM_WIN_MAXIMIZED"             },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            { XA_OL_DECOR_DEL,               "_OL_DECOR_DEL"                 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            { XA_OL_DECOR_HEADER,            "_OL_DECOR_HEADER"              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            { XA_OL_DECOR_RESIZE,            "_OL_DECOR_RESIZE"              },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            { XA_OL_DECOR_PIN,               "_OL_DECOR_PIN"                 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            { XA_OL_DECOR_CLOSE,             "_OL_DECOR_CLOSE"               },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            { XA_MWM_HINTS,                  "_MOTIF_WM_HINTS"               },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            { XA_NET_FRAME_EXTENTS,          "_NET_FRAME_EXTENTS"            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            { XA_NET_REQUEST_FRAME_EXTENTS,  "_NET_REQUEST_FRAME_EXTENTS"    },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        String[] names = new String[atomInitList.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        for (int index = 0; index < names.length; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            names[index] = (String)atomInitList[index][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        int atomSize = XAtom.getAtomSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        long atoms = unsafe.allocateMemory(names.length*atomSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            int status = XlibWrapper.XInternAtoms(XToolkit.getDisplay(), names, false, atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if (status == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            for (int atom = 0, atomPtr = 0; atom < names.length; atom++, atomPtr += atomSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                ((XAtom)(atomInitList[atom][0])).setValues(XToolkit.getDisplay(), names[atom], XAtom.getAtom(atoms + atomPtr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            unsafe.freeMemory(atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * MUST BE CALLED UNDER AWTLOCK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * If *any* window manager is running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * According to ICCCM 2.0 section 4.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * WM will acquire ownership of a selection named WM_Sn, where n is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * the screen number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * No selection owner, but, perhaps it is not ICCCM compliant WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * (e.g. CDE/Sawfish).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Try selecting for SubstructureRedirect, that only one client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * can select for, and if the request fails, than some other WM is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * already running.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * We also treat eXcursion as NO_WM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    private static boolean isNoWM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
         * Quick checks for specific servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        String vendor_string = XlibWrapper.ServerVendor(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (vendor_string.indexOf("eXcursion") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             * Use NO_WM since in all other aspects eXcursion is like not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
             * having a window manager running. I.e. it does not reparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
             * top level shells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
             */
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   258
            if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                insLog.finer("eXcursion means NO_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        XSetWindowAttributes substruct = new XSetWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
             * Let's check an owner of WM_Sn selection for the default screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            final long default_screen_number =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                XlibWrapper.DefaultScreen(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            final String selection_name = "WM_S" + default_screen_number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            long selection_owner =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                XlibWrapper.XGetSelectionOwner(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                               XAtom.get(selection_name).getAtom());
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   276
            if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                insLog.finer("selection owner of " + selection_name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                             + " is " + selection_owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (selection_owner != XConstants.None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            winmgr_running = false;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   286
            substruct.set_event_mask(XConstants.SubstructureRedirectMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
   288
            XErrorHandlerUtil.WITH_XERROR_HANDLER(detectWMHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                                XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   291
                                                XConstants.CWEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                                substruct.pData);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
   293
            XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
             * If no WM is running then our selection for SubstructureRedirect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
             * succeeded and needs to be undone (hey we are *not* a WM ;-).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (!winmgr_running) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                substruct.set_event_mask(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                                    XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   303
                                                    XConstants.CWEventMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                                    substruct.pData);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   305
                if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    insLog.finer("It looks like there is no WM thus NO_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            return !winmgr_running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            substruct.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    static XAtom XA_ENLIGHTENMENT_COMMS = new XAtom("ENLIGHTENMENT_COMMS", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Helper function for isEnlightenment().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Enlightenment uses STRING property for its comms window id.  Gaaa!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * The property is ENLIGHTENMENT_COMMS, STRING/8 and the string format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * is "WINID %8x".  Gee, I haven't been using scanf for *ages*... :-)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    static long getECommsWindowIDProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (!XA_ENLIGHTENMENT_COMMS.isInterned()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            new WindowPropertyGetter(window, XA_ENLIGHTENMENT_COMMS, 0, 14, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                     XAtom.XA_STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   333
            int status = getter.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   334
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                return 0;
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 (getter.getActualType() != XAtom.XA_STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                || getter.getActualFormat() != 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                || getter.getNumberOfItems() != 14 || getter.getBytesAfter() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            // Convert data to String, ASCII
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            byte[] bytes = XlibWrapper.getStringBytes(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            String id = new String(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   349
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   350
                log.finer("ENLIGHTENMENT_COMMS is " + id);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   351
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            // Parse WINID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            Pattern winIdPat = Pattern.compile("WINID\\s+(\\p{XDigit}{0,8})");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                Matcher match = winIdPat.matcher(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                if (match.matches()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   358
                    if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   359
                        log.finest("Match group count: " + match.groupCount());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   360
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    String longId = match.group(1);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   362
                    if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   363
                        log.finest("Match group 1 " + longId);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   364
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    long winid = Long.parseLong(longId, 16);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   366
                    if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   367
                        log.finer("Enlightenment communication window " + winid);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   368
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    return winid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    log.finer("ENLIGHTENMENT_COMMS has wrong format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            } catch (Exception e) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   375
                if (log.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Is Enlightenment WM running?  Congruent to awt_wm_checkAnchor, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * uses STRING property peculiar to Enlightenment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    static boolean isEnlightenment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        long root_xref = getECommsWindowIDProperty(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (root_xref == 0) {
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        long self_xref = getECommsWindowIDProperty(root_xref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (self_xref != root_xref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Is CDE running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * XXX: This is hairy...  CDE is MWM as well.  It seems we simply test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * for default setup and will be bitten if user changes things...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Check for _DT_SM_WINDOW_INFO(_DT_SM_WINDOW_INFO) on root.  Take the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * second element of the property and check for presence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * _DT_SM_STATE_INFO(_DT_SM_STATE_INFO) on that window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * XXX: Any header that defines this structures???
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    static final XAtom XA_DT_SM_WINDOW_INFO = new XAtom("_DT_SM_WINDOW_INFO", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    static final XAtom XA_DT_SM_STATE_INFO = new XAtom("_DT_SM_STATE_INFO", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    static boolean isCDE() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (!XA_DT_SM_WINDOW_INFO.isInterned()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   421
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   422
                log.finer("{0} is not interned", XA_DT_SM_WINDOW_INFO);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   423
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            new WindowPropertyGetter(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                     XA_DT_SM_WINDOW_INFO, 0, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                     false, XA_DT_SM_WINDOW_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   433
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                log.finer("Getting of _DT_SM_WINDOW_INFO is not successfull");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (getter.getActualType() != XA_DT_SM_WINDOW_INFO.getAtom()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                || getter.getActualFormat() != 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                || getter.getNumberOfItems() != 2 || getter.getBytesAfter() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                log.finer("Wrong format of _DT_SM_WINDOW_INFO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            long wmwin = Native.getWindow(getter.getData(), 1); //unsafe.getInt(getter.getData()+4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            if (wmwin == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                log.fine("WARNING: DT_SM_WINDOW_INFO exists but returns zero windows");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            /* Now check that this window has _DT_SM_STATE_INFO (ignore contents) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if (!XA_DT_SM_STATE_INFO.isInterned()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   454
                if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   455
                    log.finer("{0} is not interned", XA_DT_SM_STATE_INFO);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   456
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            WindowPropertyGetter getter2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                new WindowPropertyGetter(wmwin, XA_DT_SM_STATE_INFO, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                         false, XA_DT_SM_STATE_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   463
                status = getter2.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   466
                if (status != XConstants.Success || getter2.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    log.finer("Getting of _DT_SM_STATE_INFO is not successfull");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if (getter2.getActualType() != XA_DT_SM_STATE_INFO.getAtom()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    || getter2.getActualFormat() != 32)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    log.finer("Wrong format of _DT_SM_STATE_INFO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                getter2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Is MWM running?  (Note that CDE will test positive as well).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Check for _MOTIF_WM_INFO(_MOTIF_WM_INFO) on root.  Take the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * second element of the property and check for presence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * _DT_SM_STATE_INFO(_DT_SM_STATE_INFO) on that window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    static final XAtom XA_MOTIF_WM_INFO = new XAtom("_MOTIF_WM_INFO", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    static final XAtom XA_DT_WORKSPACE_CURRENT = new XAtom("_DT_WORKSPACE_CURRENT", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    static boolean isMotif() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (!(XA_MOTIF_WM_INFO.isInterned()/* && XA_DT_WORKSPACE_CURRENT.isInterned()*/) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            new WindowPropertyGetter(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                                     XA_MOTIF_WM_INFO, 0,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   504
                                     MWMConstants.PROP_MOTIF_WM_INFO_ELEMENTS,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                     false, XA_MOTIF_WM_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            int status = getter.execute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   509
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (getter.getActualType() != XA_MOTIF_WM_INFO.getAtom()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                || getter.getActualFormat() != 32
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   515
                || getter.getNumberOfItems() != MWMConstants.PROP_MOTIF_WM_INFO_ELEMENTS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                || getter.getBytesAfter() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            long wmwin = Native.getLong(getter.getData(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if (wmwin != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                if (XA_DT_WORKSPACE_CURRENT.isInterned()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    /* Now check that this window has _DT_WORKSPACE_CURRENT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    XAtom[] curws = XA_DT_WORKSPACE_CURRENT.getAtomListProperty(wmwin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    if (curws.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    // No DT_WORKSPACE, however in our tests MWM sometimes can be without desktop -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    // and that is still MWM.  So simply check for the validity of this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    // (through WM_STATE property).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    WindowPropertyGetter state_getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                        new WindowPropertyGetter(wmwin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                                 XA_WM_STATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                                 0, 1, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                                 XA_WM_STATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   540
                        if (state_getter.execute() == XConstants.Success &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                            state_getter.getData() != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                            state_getter.getActualType() == XA_WM_STATE.getAtom())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        state_getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * Is Sawfish running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    static boolean isSawfish() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return isNetWMName("Sawfish");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Is KDE2 (KWin) running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    static boolean isKDE2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return isNetWMName("KWin");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    static boolean isCompiz() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return isNetWMName("compiz");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    static boolean isLookingGlass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        return isNetWMName("LG3D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   579
    static boolean isCWM() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   580
        return isNetWMName("CWM");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   581
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   582
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Is Metacity running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    static boolean isMetacity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return isNetWMName("Metacity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
//         || (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
//             XA_NET_SUPPORTING_WM_CHECK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
//             getIntProperty(XToolkit.getDefaultRootWindow(), XA_NET_SUPPORTING_WM_CHECK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
//                            getIntProperty(XToolkit.getDefaultRootWindow(), XAtom.XA_CARDINAL)) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   594
    static boolean isMutter() {
20141
2ed60881f2a1 8024863: X11: Support GNOME Shell as mutter
omajid
parents: 18275
diff changeset
   595
        return isNetWMName("Mutter") || isNetWMName("GNOME Shell");
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   596
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   597
27284
98699328cef3 8058197: AWT fails on generic non-reparenting window managers
azvegint
parents: 25859
diff changeset
   598
    static int awtWMNonReparenting = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    static boolean isNonReparentingWM() {
27284
98699328cef3 8058197: AWT fails on generic non-reparenting window managers
azvegint
parents: 25859
diff changeset
   600
        if (awtWMNonReparenting == -1) {
98699328cef3 8058197: AWT fails on generic non-reparenting window managers
azvegint
parents: 25859
diff changeset
   601
            awtWMNonReparenting = (XToolkit.getEnv("_JAVA_AWT_WM_NONREPARENTING") != null) ? 1 : 0;
98699328cef3 8058197: AWT fails on generic non-reparenting window managers
azvegint
parents: 25859
diff changeset
   602
        }
98699328cef3 8058197: AWT fails on generic non-reparenting window managers
azvegint
parents: 25859
diff changeset
   603
        return (awtWMNonReparenting == 1 || XWM.getWMID() == XWM.COMPIZ_WM
98699328cef3 8058197: AWT fails on generic non-reparenting window managers
azvegint
parents: 25859
diff changeset
   604
                || XWM.getWMID() == XWM.LG3D_WM || XWM.getWMID() == XWM.CWM_WM);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Prepare IceWM check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * The only way to detect IceWM, seems to be by setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * _ICEWM_WINOPTHINT(_ICEWM_WINOPTHINT/8) on root and checking if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * was immediately deleted by IceWM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * But messing with PropertyNotify here is way too much trouble, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * approximate the check by setting the property in this function and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * checking if it still exists later on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Gaa, dirty dances...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    static final XAtom XA_ICEWM_WINOPTHINT = new XAtom("_ICEWM_WINOPTHINT", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    static final char opt[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        'A','W','T','_','I','C','E','W','M','_','T','E','S','T','\0',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        'a','l','l','W','o','r','k','s','p','a','c','e','s','\0',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        '0','\0'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    static boolean prepareIsIceWM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
         * Choose something innocuous: "AWT_ICEWM_TEST allWorkspaces 0".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         * IceWM expects "class\0option\0arg\0" with zero bytes as delimiters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (!XA_ICEWM_WINOPTHINT.isInterned()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   633
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   634
                log.finer("{0} is not interned", XA_ICEWM_WINOPTHINT);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   635
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        try {
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
   641
            XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.VerifyChangePropertyHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            XlibWrapper.XChangePropertyS(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                         XA_ICEWM_WINOPTHINT.getAtom(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                         XA_ICEWM_WINOPTHINT.getAtom(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   645
                                         8, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                                         new String(opt));
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
   647
            XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
   649
            if ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 16839
diff changeset
   650
                (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                log.finer("Erorr getting XA_ICEWM_WINOPTHINT property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            log.finer("Prepared for IceWM detection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Is IceWM running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * Note well: Only call this if awt_wm_prepareIsIceWM succeeded, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * false positive will be reported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    static boolean isIceWM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        if (!XA_ICEWM_WINOPTHINT.isInterned()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   669
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   670
                log.finer("{0} is not interned", XA_ICEWM_WINOPTHINT);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   671
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            new WindowPropertyGetter(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                                     XA_ICEWM_WINOPTHINT, 0, 0xFFFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                     true, XA_ICEWM_WINOPTHINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   681
            boolean res = (status == XConstants.Success && getter.getActualType() != 0);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   682
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   683
                log.finer("Status getting XA_ICEWM_WINOPTHINT: " + !res);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   684
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            return !res || isNetWMName("IceWM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * Is OpenLook WM running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * This one is pretty lame, but the only property peculiar to OLWM is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * _SUN_WM_PROTOCOLS(ATOM[]).  Fortunately, olwm deletes it on exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    static final XAtom XA_SUN_WM_PROTOCOLS = new XAtom("_SUN_WM_PROTOCOLS", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    static boolean isOpenLook() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        if (!XA_SUN_WM_PROTOCOLS.isInterned()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        XAtom[] list = XA_SUN_WM_PROTOCOLS.getAtomListProperty(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        return (list.length != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Temporary error handler that checks if selecting for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * SubstructureRedirect failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   711
    private static boolean winmgr_running = false;
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   712
    private static XErrorHandler detectWMHandler = new XErrorHandler.XBaseErrorHandler() {
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   713
        @Override
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   714
        public int handleError(long display, XErrorEvent err) {
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   715
            if ((err.get_request_code() == XProtocolConstants.X_ChangeWindowAttributes) &&
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   716
                (err.get_error_code() == XConstants.BadAccess))
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   717
            {
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   718
                winmgr_running = true;
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   719
                return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            }
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   721
            return super.handleError(display, err);
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   722
        }
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 2472
diff changeset
   723
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Make an educated guess about running window manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * XXX: ideally, we should detect wm restart.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    static int awt_wmgr = XWM.UNDETERMINED_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    static XWM wm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    static XWM getWM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        if (wm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            wm = new XWM(awt_wmgr = getWMID()/*XWM.OTHER_WM*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        return wm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    static int getWMID() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   738
        if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            insLog.finest("awt_wmgr = " + awt_wmgr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         * Ideally, we should support cases when a different WM is started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * during a Java app lifetime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (awt_wmgr != XWM.UNDETERMINED_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            return awt_wmgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        XSetWindowAttributes substruct = new XSetWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            if (isNoWM()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                awt_wmgr = XWM.NO_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                return awt_wmgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            // Initialize _NET protocol - used to detect Window Manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            // Later, WM will initialize its own version of protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            XNETProtocol l_net_protocol = g_net_protocol = new XNETProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            l_net_protocol.detect();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   762
            if (log.isLoggable(PlatformLogger.Level.FINE) && l_net_protocol.active()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                log.fine("_NET_WM_NAME is " + l_net_protocol.getWMName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            XWINProtocol win = g_win_protocol = new XWINProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            win.detect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            /* actual check for IceWM to follow below */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            boolean doIsIceWM = prepareIsIceWM(); /* and let IceWM to act */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
             * Ok, some WM is out there.  Check which one by testing for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
             * "distinguishing" atoms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            if (isEnlightenment()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                awt_wmgr = XWM.ENLIGHTEN_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            } else if (isMetacity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                awt_wmgr = XWM.METACITY_WM;
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   779
            } else if (isMutter()) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12047
diff changeset
   780
                awt_wmgr = XWM.MUTTER_WM;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            } else if (isSawfish()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                awt_wmgr = XWM.SAWFISH_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            } else if (isKDE2()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                awt_wmgr =XWM.KDE2_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            } else if (isCompiz()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                awt_wmgr = XWM.COMPIZ_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            } else if (isLookingGlass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                awt_wmgr = LG3D_WM;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   789
            } else if (isCWM()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   790
                awt_wmgr = CWM_WM;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            } else if (doIsIceWM && isIceWM()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                awt_wmgr = XWM.ICE_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
             * We don't check for legacy WM when we already know that WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
             * supports WIN or _NET wm spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            else if (l_net_protocol.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                awt_wmgr = XWM.OTHER_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            } else if (win.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                awt_wmgr = XWM.OTHER_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
             * Check for legacy WMs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            else if (isCDE()) { /* XXX: must come before isMotif */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                awt_wmgr = XWM.CDE_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            } else if (isMotif()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                awt_wmgr = XWM.MOTIF_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            } else if (isOpenLook()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                awt_wmgr = XWM.OPENLOOK_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                awt_wmgr = XWM.OTHER_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            return awt_wmgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            substruct.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
/*****************************************************************************\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
 * Size and decoration hints ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
\*****************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * Remove size hints specified by the mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * XXX: Why do we need this in the first place???
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    static void removeSizeHints(XDecoratedPeer window, long mask) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   836
        mask &= XUtilConstants.PMaxSize | XUtilConstants.PMinSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            XSizeHints hints = window.getHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            if ((hints.get_flags() & mask) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            hints.set_flags(hints.get_flags() & ~mask);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   846
            if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   847
                insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(hints.get_flags()));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   848
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                                          window.getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                                          hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * If MWM_DECOR_ALL bit is set, then the rest of the bit-mask is taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * to be subtracted from the decorations.  Normalize decoration spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * so that we can map motif decor to something else bit-by-bit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * rest of the code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    static int normalizeMotifDecor(int decorations) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   864
        if ((decorations & MWMConstants.MWM_DECOR_ALL) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            return decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   867
        int d = MWMConstants.MWM_DECOR_BORDER | MWMConstants.MWM_DECOR_RESIZEH
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   868
            | MWMConstants.MWM_DECOR_TITLE
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   869
            | MWMConstants.MWM_DECOR_MENU | MWMConstants.MWM_DECOR_MINIMIZE
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   870
            | MWMConstants.MWM_DECOR_MAXIMIZE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        d &= ~decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * If MWM_FUNC_ALL bit is set, then the rest of the bit-mask is taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * to be subtracted from the functions.  Normalize function spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * so that we can map motif func to something else bit-by-bit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * rest of the code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    static int normalizeMotifFunc(int functions) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   882
        if ((functions & MWMConstants.MWM_FUNC_ALL) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            return functions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   885
        int f = MWMConstants.MWM_FUNC_RESIZE |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   886
                MWMConstants.MWM_FUNC_MOVE |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   887
                MWMConstants.MWM_FUNC_MAXIMIZE |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   888
                MWMConstants.MWM_FUNC_MINIMIZE |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   889
                MWMConstants.MWM_FUNC_CLOSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        f &= ~functions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * Infer OL properties from MWM decorations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * Use _OL_DECOR_DEL(ATOM[]) to remove unwanted ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    static void setOLDecor(XWindow window, boolean resizable, int decorations) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        if (window == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        XAtomList decorDel = new XAtomList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        decorations = normalizeMotifDecor(decorations);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   905
        if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   906
            insLog.finer("Setting OL_DECOR to " + Integer.toBinaryString(decorations));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   907
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   908
        if ((decorations & MWMConstants.MWM_DECOR_TITLE) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            decorDel.add(XA_OL_DECOR_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   911
        if ((decorations & (MWMConstants.MWM_DECOR_RESIZEH | MWMConstants.MWM_DECOR_MAXIMIZE)) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            decorDel.add(XA_OL_DECOR_RESIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   914
        if ((decorations & (MWMConstants.MWM_DECOR_MENU |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   915
                            MWMConstants.MWM_DECOR_MAXIMIZE |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   916
                            MWMConstants.MWM_DECOR_MINIMIZE)) == 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            decorDel.add(XA_OL_DECOR_CLOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        if (decorDel.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            insLog.finer("Deleting OL_DECOR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            XA_OL_DECOR_DEL.DeleteProperty(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   924
            if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   925
                insLog.finer("Setting OL_DECOR to " + decorDel);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   926
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            XA_OL_DECOR_DEL.setAtomListProperty(window, decorDel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Set MWM decorations.  Set MWM functions depending on resizability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 439
diff changeset
   934
    static void setMotifDecor(XWindow window, boolean resizable, int decorations, int functions) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        /* Apparently some WMs don't implement MWM_*_ALL semantic correctly */
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   936
        if ((decorations & MWMConstants.MWM_DECOR_ALL) != 0
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   937
            && (decorations != MWMConstants.MWM_DECOR_ALL))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            decorations = normalizeMotifDecor(decorations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   941
        if ((functions & MWMConstants.MWM_FUNC_ALL) != 0
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   942
            && (functions != MWMConstants.MWM_FUNC_ALL))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            functions = normalizeMotifFunc(functions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        PropMwmHints hints = window.getMWMHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   948
        hints.set_flags(hints.get_flags() |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   949
                        MWMConstants.MWM_HINTS_FUNCTIONS |
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   950
                        MWMConstants.MWM_HINTS_DECORATIONS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        hints.set_functions(functions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        hints.set_decorations(decorations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   954
        if (stateLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   955
            stateLog.finer("Setting MWM_HINTS to " + hints);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
   956
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        window.setMWMHints(hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * Under some window managers if shell is already mapped, we MUST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * unmap and later remap in order to effect the changes we make in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * window manager decorations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * N.B.  This unmapping / remapping of the shell exposes a bug in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * X/Motif or the Motif Window Manager.  When you attempt to map a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * widget which is positioned (partially) off-screen, the window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * relocated to be entirely on screen. Good idea.  But if both the x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * and the y coordinates are less than the origin (0,0), the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * (re)map will move the window to the origin, and any subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * (re)map will relocate the window at some other point on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * I have written a short Motif test program to discover this bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * This should occur infrequently and it does not cause any real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * problem.  So for now we'll let it be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    static boolean needRemap(XDecoratedPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        // Don't remap EmbeddedFrame,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        // e.g. for TrayIcon it causes problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        return !window.isEmbedded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * Set decoration hints on the shell to wdata->decor adjusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * appropriately if not resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    static void setShellDecor(XDecoratedPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        int decorations = window.getDecorations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        int functions = window.getFunctions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        boolean resizable = window.isResizable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        if (!resizable) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   992
            if ((decorations & MWMConstants.MWM_DECOR_ALL) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   993
                decorations |= MWMConstants.MWM_DECOR_RESIZEH | MWMConstants.MWM_DECOR_MAXIMIZE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
   995
                decorations &= ~(MWMConstants.MWM_DECOR_RESIZEH | MWMConstants.MWM_DECOR_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        setMotifDecor(window, resizable, decorations, functions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        setOLDecor(window, resizable, decorations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        /* Some WMs need remap to redecorate the window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        if (window.isShowing() && needRemap(window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
             * Do the re/mapping at the Xlib level.  Since we essentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
             * work around a WM bug we don't want this hack to be exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
             * to Intrinsics (i.e. don't mess with grabs, callbacks etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            window.xSetVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            window.xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * Make specified shell resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    static void setShellResizable(XDecoratedPeer window) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1018
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1019
            insLog.fine("Setting shell resizable " + window);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1020
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            Rectangle shellBounds = window.getShellBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            shellBounds.translate(-window.currentInsets.left, -window.currentInsets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            window.updateSizeHints(window.getDimensions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            requestWMExtents(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                                          shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            /* REMINDER: will need to revisit when setExtendedStateBounds is added */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            //We need to update frame's minimum size, not to reset it
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1032
            removeSizeHints(window, XUtilConstants.PMaxSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            window.updateMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            /* Restore decorations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            setShellDecor(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * Make specified shell non-resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * If justChangeSize is false, update decorations as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @param shellBounds bounds of the shell window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    static void setShellNotResizable(XDecoratedPeer window, WindowDimensions newDimensions, Rectangle shellBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                                     boolean justChangeSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1050
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1051
            insLog.fine("Setting non-resizable shell " + window + ", dimensions " + newDimensions +
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1052
                        ", shellBounds " + shellBounds +", just change size: " + justChangeSize);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1053
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            /* Fix min/max size hints at the specified values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            if (!shellBounds.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                window.updateSizeHints(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                requestWMExtents(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                                              shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            if (!justChangeSize) {  /* update decorations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                setShellDecor(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
/*****************************************************************************\
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
 * Protocols support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
 */
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1075
    private HashMap<Class<?>, Collection<?>> protocolsMap = new HashMap<Class<?>, Collection<?>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * Returns all protocols supporting given protocol interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     */
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1079
    <T> Collection<T> getProtocols(Class<T> protocolInterface) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24191
diff changeset
  1080
        @SuppressWarnings("unchecked")
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1081
        Collection<T> res = (Collection<T>) protocolsMap.get(protocolInterface);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        if (res != null) {
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1083
            return res;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        } else {
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1085
            return new LinkedList<T>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1089
    private <T> void addProtocol(Class<T> protocolInterface, T protocol) {
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1090
        Collection<T> protocols = getProtocols(protocolInterface);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        protocols.add(protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        protocolsMap.put(protocolInterface, protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    boolean supportsDynamicLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        int wm = getWMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        switch (wm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
          case XWM.ENLIGHTEN_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
          case XWM.KDE2_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
          case XWM.SAWFISH_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
          case XWM.ICE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
          case XWM.METACITY_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
          case XWM.OPENLOOK_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
          case XWM.MOTIF_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
          case XWM.CDE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
              return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
              return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * Check if state is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * Note that a compound state is always reported as not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * Note also that MAXIMIZED_BOTH is considered not a compound state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * Therefore, a compound state is just ICONIFIED | anything else.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     */
24191
75ee64f51cb4 8039861: Fix fallthrough lint warnings in awt
darcy
parents: 20141
diff changeset
  1121
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    boolean supportsExtendedState(int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
          case Frame.MAXIMIZED_VERT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
          case Frame.MAXIMIZED_HORIZ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
              /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
               * WMs that talk NET/WIN protocol, but do not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
               * unidirectional maximization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
               */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
              if (getWMID() == METACITY_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                  /* "This is a deliberate policy decision." -hp */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
              /* FALLTROUGH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
          case Frame.MAXIMIZED_BOTH:
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1136
              for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                  if (proto.supportsState(state)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                      return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
              }
24191
75ee64f51cb4 8039861: Fix fallthrough lint warnings in awt
darcy
parents: 20141
diff changeset
  1141
              /* FALLTROUGH */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
              return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
/*****************************************************************************\
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
 * Reading state from different protocols
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
\*****************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    int getExtendedState(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        int state = 0;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1156
        for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            state |= proto.getState(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        if (state != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            return Frame.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
/*****************************************************************************\
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
 * Notice window state change when WM changes a property on the window ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
\*****************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * Check if property change is a window state protocol message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     */
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1176
    boolean isStateChange(XDecoratedPeer window, XPropertyEvent e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        if (!window.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            stateLog.finer("Window is not showing");
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1179
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        int wm_state = window.getWMState();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1183
        if (wm_state == XUtilConstants.WithdrawnState) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            stateLog.finer("WithdrawnState");
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1185
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1187
            if (stateLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1188
                stateLog.finer("Window WM_STATE is " + wm_state);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1189
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        boolean is_state_change = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        if (e.get_atom() == XA_WM_STATE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            is_state_change = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1196
        for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            is_state_change |= proto.isStateChange(e);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1198
            if (stateLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1199
                stateLog.finest(proto + ": is state changed = " + is_state_change);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1200
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        }
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1202
        return is_state_change;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1203
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1205
    /*
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1206
     * Returns current state (including extended) of a given window.
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1207
     */
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1208
    int getState(XDecoratedPeer window) {
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1209
        int res = 0;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1210
        final int wm_state = window.getWMState();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1211
        if (wm_state == XUtilConstants.IconicState) {
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1212
            res = Frame.ICONIFIED;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1213
        } else {
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1214
            res = Frame.NORMAL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1216
        res |= getExtendedState(window);
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1217
        return res;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
/*****************************************************************************\
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
 * Setting/changing window state ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
\*****************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * Moves window to the specified layer, layer is one of the constants defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * in XLayerProtocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    void setLayer(XWindowPeer window, int layer) {
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1231
        for (XLayerProtocol proto : getProtocols(XLayerProtocol.class)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            if (proto.supportsLayer(layer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                proto.setLayer(window, layer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    void setExtendedState(XWindowPeer window, int state) {
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1240
        for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            if (proto.supportsState(state)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                proto.setState(window, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        if (!window.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
             * Purge KWM bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
             * Not really tested with KWM, only with WindowMaker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                                            window.getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                                            XA_KWM_WIN_ICONIFIED.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                                            window.getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                                            XA_KWM_WIN_MAXIMIZED.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * Work around for 4775545.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * If WM exits while the top-level is shaded, the shaded hint remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * on the top-level properties.  When WM restarts and sees the shaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * window it can reparent it into a "pre-shaded" decoration frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * (Metacity does), and our insets logic will go crazy, b/c it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * see a huge nagative bottom inset.  There's no clean solution for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * this, so let's just be weasels and drop the shaded hint if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * detect that WM exited.  NB: we are in for a race condition with WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * restart here.  NB2: e.g. WindowMaker saves the state in a private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * property that this code knows nothing about, so this workaround is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * not effective; other WMs might play similar tricks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    void unshadeKludge(XDecoratedPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        assert(window.isShowing());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
  1286
        for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            proto.unshadeKludge(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    static boolean inited = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    static void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        if (inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        initAtoms();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        getWM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        inited = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    void initializeProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        XNETProtocol net_protocol = g_net_protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        if (net_protocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            if (!net_protocol.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                net_protocol = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                if (net_protocol.doStateProtocol()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                    addProtocol(XStateProtocol.class, net_protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                if (net_protocol.doLayerProtocol()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                    addProtocol(XLayerProtocol.class, net_protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        XWINProtocol win = g_win_protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        if (win != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            if (win.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                if (win.doStateProtocol()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                    addProtocol(XStateProtocol.class, win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                if (win.doLayerProtocol()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                    addProtocol(XLayerProtocol.class, win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24191
diff changeset
  1331
    HashMap<Class<?>, Insets> storedInsets = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    Insets guessInsets(XDecoratedPeer window) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24191
diff changeset
  1333
        Insets res = storedInsets.get(window.getClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        if (res == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            switch (WMID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
              case ENLIGHTEN_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                  res = new Insets(19, 4, 4, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
              case CDE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                  res = new Insets(28, 6, 6, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
              case NO_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
              case LG3D_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                  res = zeroInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
              case MOTIF_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
              case OPENLOOK_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                  res = defaultInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1352
        if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1353
            insLog.finest("WM guessed insets: " + res);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1354
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * Some buggy WMs ignore window gravity when processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * ConfigureRequest and position window as if the gravity is Static.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * We work around this in MWindowPeer.pReshape().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * Starting with 1.5 we have introduced an Environment variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * _JAVA_AWT_WM_STATIC_GRAVITY that can be set to indicate to Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * explicitly that the WM has this behaviour, example is FVWM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    static int awtWMStaticGravity = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    static boolean configureGravityBuggy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        if (awtWMStaticGravity == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            awtWMStaticGravity = (XToolkit.getEnv("_JAVA_AWT_WM_STATIC_GRAVITY") != null) ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        if (awtWMStaticGravity == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        switch(getWMID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
          case XWM.ICE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
              /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
               * See bug #228981 at IceWM's SourceForge pages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
               * Latest stable version 1.0.8-6 still has this problem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
               */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
              /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
               * Version 1.2.2 doesn't have this problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
               */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
              // Detect IceWM version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
              if (g_net_protocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                  String wm_name = g_net_protocol.getWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                  Pattern pat = Pattern.compile("^IceWM (\\d+)\\.(\\d+)\\.(\\d+).*$");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                  try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                      Matcher match = pat.matcher(wm_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                      if (match.matches()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                          int v1 = Integer.parseInt(match.group(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                          int v2 = Integer.parseInt(match.group(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                          int v3 = Integer.parseInt(match.group(3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                          return !(v1 > 1 || (v1 == 1 && (v2 > 2 || (v2 == 2 && v3 >=2))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                  } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                      return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
          case XWM.ENLIGHTEN_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
              /* At least E16 is buggy. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
              return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * @return if WM implements the insets property - returns insets with values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * specified in that property, null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    public static Insets getInsetsFromExtents(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        if (window == XConstants.None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        XNETProtocol net_protocol = getWM().getNETProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        if (net_protocol != null && net_protocol.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            Insets insets = getInsetsFromProp(window, XA_NET_FRAME_EXTENTS);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1423
            if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1424
                insLog.fine("_NET_FRAME_EXTENTS: {0}", insets);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1425
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        switch(getWMID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
          case XWM.KDE2_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
              return getInsetsFromProp(window, XA_KDE_NET_WM_FRAME_STRUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
          case XWM.ENLIGHTEN_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
              return getInsetsFromProp(window, XA_E_FRAME_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
              return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * Helper function reads property of type CARDINAL[4] = { left, right, top, bottom }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * and converts it to Insets object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    public static Insets getInsetsFromProp(long window, XAtom atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        if (window == XConstants.None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            new WindowPropertyGetter(window, atom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                                     0, 4, false, XAtom.XA_CARDINAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1454
            if (getter.execute() != XConstants.Success
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                || getter.getData() == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                || getter.getActualType() != XAtom.XA_CARDINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                || getter.getActualFormat() != 32)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                return new Insets((int)Native.getCard32(getter.getData(), 2), // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                                  (int)Native.getCard32(getter.getData(), 0), // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                                  (int)Native.getCard32(getter.getData(), 3), // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                                  (int)Native.getCard32(getter.getData(), 1)); // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * Asks WM to fill Frame Extents (insets) for the window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    public static void requestWMExtents(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        if (window == XConstants.None) { // not initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        log.fine("Requesting FRAME_EXTENTS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        XClientMessageEvent msg = new XClientMessageEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        msg.zero();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1483
        msg.set_type(XConstants.ClientMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        msg.set_display(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        msg.set_window(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        msg.set_format(32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            XNETProtocol net_protocol = getWM().getNETProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            if (net_protocol != null && net_protocol.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                msg.set_message_type(XA_NET_REQUEST_FRAME_EXTENTS.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1493
                                       false,
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1494
                                       XConstants.SubstructureRedirectMask | XConstants.SubstructureNotifyMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                                       msg.getPData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            if (getWMID() == XWM.KDE2_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                msg.set_message_type(XA_KDE_NET_WM_FRAME_STRUT.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1500
                                       false,
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 107
diff changeset
  1501
                                       XConstants.SubstructureRedirectMask | XConstants.SubstructureNotifyMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                                       msg.getPData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            // XXX: should we wait for response? XIfEvent() would be useful here :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            msg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    /* syncTopLEvelPos() is necessary to insure that the window manager has in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * fact moved us to our final position relative to the reParented WM window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * We have noted a timing window which our shell has not been moved so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * screw up the insets thinking they are 0,0.  Wait (for a limited period of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     * time to let the WM hava a chance to move us.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * @param window window ID of the shell, assuming it is the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * which will NOT have zero coordinates after the complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * reparenting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    boolean syncTopLevelPos(long window, XWindowAttributes attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        int tries = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), window, attrs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                if (attrs.get_x() != 0 || attrs.get_y() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                tries++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            } while (tries < 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    Insets getInsets(XDecoratedPeer win, long window, long parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
         * Unfortunately the concept of "insets" borrowed to AWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
         * from Win32 is *absolutely*, *unbelievably* foreign to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
         * X11.  Few WMs provide the size of frame decor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
         * (i.e. insets) in a property they set on the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
         * window, so we check if we can get away with just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
         * peeking at it.  [Future versions of wm-spec might add a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
         * standardized hint for this].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
         * Otherwise we do some special casing.  Actually the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
         * fallback code ("default" case) seems to cover most of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
         * the existing WMs (modulo Reparent/Configure order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
         * perhaps?).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
         * Fallback code tries to account for the two most common cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
         * . single reparenting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
         *       parent window is the WM frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
         *       [twm, olwm, sawfish]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
         * . double reparenting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
         *       parent is a lining exactly the size of the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
         *       grandpa is the WM frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
         *       [mwm, e!, kwin, fvwm2 ... ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        Insets correctWM = XWM.getInsetsFromExtents(window);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1566
        if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1567
            insLog.finer("Got insets from property: {0}", correctWM);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1568
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        if (correctWM == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            correctWM = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            correctWM.top = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            correctWM.left = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            XWindowAttributes lwinAttr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            XWindowAttributes pattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                switch (XWM.getWMID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                  /* should've been done in awt_wm_getInsetsFromProp */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                  case XWM.ENLIGHTEN_WM: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                      /* enlightenment does double reparenting */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                      syncTopLevelPos(parent, lwinAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                      correctWM.left = lwinAttr.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                      correctWM.top = lwinAttr.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                       * Now get the actual dimensions of the parent window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                       * resolve the difference.  We can't rely on the left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                       * to be equal to right or bottom...  Enlightment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                       * breaks that assumption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                      XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                                                       XlibUtil.getParentWindow(parent),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                                                       pattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                      correctWM.right = pattr.get_width() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                          (lwinAttr.get_width() + correctWM.left);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                      correctWM.bottom = pattr.get_height() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                          (lwinAttr.get_height() + correctWM.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                  case XWM.ICE_WM: // for 1.2.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                  case XWM.KDE2_WM: /* should've been done in getInsetsFromProp */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                  case XWM.CDE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                  case XWM.MOTIF_WM: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                      /* these are double reparenting too */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                      if (syncTopLevelPos(parent, lwinAttr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                          correctWM.top = lwinAttr.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                          correctWM.left = lwinAttr.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                          correctWM.right = correctWM.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                          correctWM.bottom = correctWM.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                          return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                  case XWM.SAWFISH_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                  case XWM.OPENLOOK_WM: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                      /* single reparenting */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                      syncTopLevelPos(window, lwinAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                      correctWM.top    = lwinAttr.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                      correctWM.left   = lwinAttr.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                      correctWM.right  = correctWM.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                      correctWM.bottom = correctWM.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                  case XWM.OTHER_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                  default: {                /* this is very similar to the E! case above */
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1629
                      if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1630
                          insLog.finest("Getting correct insets for OTHER_WM/default, parent: {0}", parent);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1631
                      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                      syncTopLevelPos(parent, lwinAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                      int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                                                                    window, lwinAttr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                      status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                                                                parent, pattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                      if (lwinAttr.get_root() == parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                          insLog.finest("our parent is root so insets should be zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                          correctWM = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                       * Check for double-reparenting WM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                       *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                       * If the parent is exactly the same size as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                       * top-level assume taht it's the "lining" window and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                       * that the grandparent is the actual frame (NB: we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                       * have already handled undecorated windows).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                       *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                       * XXX: what about timing issues that syncTopLevelPos
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                       * is supposed to work around?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                      if (lwinAttr.get_x() == 0 && lwinAttr.get_y() == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                          && lwinAttr.get_width()+2*lwinAttr.get_border_width() == pattr.get_width()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                          && lwinAttr.get_height()+2*lwinAttr.get_border_width() == pattr.get_height())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                      {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1658
                          if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1659
                              insLog.finest("Double reparenting detected, pattr({2})={0}, lwinAttr({3})={1}",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
  1660
                                        lwinAttr, pattr, parent, window);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1661
                          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                          lwinAttr.set_x(pattr.get_x());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                          lwinAttr.set_y(pattr.get_y());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                          lwinAttr.set_border_width(lwinAttr.get_border_width()+pattr.get_border_width());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                          final long grand_parent = XlibUtil.getParentWindow(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                          if (grand_parent == lwinAttr.get_root()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                              // This is not double-reparenting in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                              // general sense - we simply don't have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                              // correct insets - return null to try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                              // get insets later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                              return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                              parent = grand_parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                              XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                                                               parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                                                               pattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                       * XXX: To be absolutely correct, we'd need to take
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                       * parent's border-width into account too, but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                       * rest of the code is happily unaware about border
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                       * widths and inner/outer distinction, so for the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                       * being, just ignore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                       */
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
  1688
                      if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1689
                          insLog.finest("Attrs before calculation: pattr({2})={0}, lwinAttr({3})={1}",
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
  1690
                                    lwinAttr, pattr, parent, window);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 12829
diff changeset
  1691
                      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                      correctWM = new Insets(lwinAttr.get_y() + lwinAttr.get_border_width(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                                             lwinAttr.get_x() + lwinAttr.get_border_width(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                                             pattr.get_height() - (lwinAttr.get_y() + lwinAttr.get_height() + 2*lwinAttr.get_border_width()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                                             pattr.get_width() -  (lwinAttr.get_x() + lwinAttr.get_width() + 2*lwinAttr.get_border_width()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                  } /* default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                } /* switch (runningWM) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                lwinAttr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                pattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        if (storedInsets.get(win.getClass()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            storedInsets.put(win.getClass(), correctWM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        return correctWM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    boolean isDesktopWindow( long w ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        if (g_net_protocol != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            XAtomList wtype = XAtom.get("_NET_WM_WINDOW_TYPE").getAtomListPropertyList( w );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            return wtype.contains( XAtom.get("_NET_WM_WINDOW_TYPE_DESKTOP") );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    public XNETProtocol getNETProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        return g_net_protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * Sets _NET_WN_ICON property on the window using the arrays of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * raster-data for icons. If icons is null, removes _NET_WM_ICON
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * This method invokes XNETProtocol.setWMIcon() for WMs that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * support NET protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * @return true if hint was modified successfully, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     */
18241
3e009b5be123 8003559: Update display of applet windows
leonidr
parents: 12829
diff changeset
  1731
    public boolean setNetWMIcon(XWindowPeer window, java.util.List<IconInfo> icons) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        if (g_net_protocol != null && g_net_protocol.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            g_net_protocol.setWMIcons(window, icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            return getWMID() != ICE_WM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
}