Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created February 7, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchir/65f39ddb73f01107625338c26da84231 to your computer and use it in GitHub Desktop.
Save olegchir/65f39ddb73f01107625338c26da84231 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
static final int
UNDETERMINED_WM = 1,
NO_WM = 2,
OTHER_WM = 3,
OPENLOOK_WM = 4,
MOTIF_WM = 5,
CDE_WM = 6,
ENLIGHTEN_WM = 7,
KDE2_WM = 8,
SAWFISH_WM = 9,
ICE_WM = 10,
METACITY_WM = 11,
COMPIZ_WM = 12,
LG3D_WM = 13,
CWM_WM = 14,
MUTTER_WM = 15,
UNITY_COMPIZ_WM = 16;
public String toString() {
switch (WMID) {
case NO_WM:
return "NO WM";
case OTHER_WM:
return "Other WM";
case OPENLOOK_WM:
return "OPENLOOK";
case MOTIF_WM:
return "MWM";
case CDE_WM:
return "DTWM";
case ENLIGHTEN_WM:
return "Enlightenment";
case KDE2_WM:
return "KWM2";
case SAWFISH_WM:
return "Sawfish";
case ICE_WM:
return "IceWM";
case METACITY_WM:
return "Metacity";
case COMPIZ_WM:
return "Compiz";
case UNITY_COMPIZ_WM:
return "Unity Compiz";
case LG3D_WM:
return "LookingGlass";
case CWM_WM:
return "CWM";
case MUTTER_WM:
return "Mutter";
case UNDETERMINED_WM:
default:
return "Undetermined WM";
}
}
static int getWMID() {
if (insLog.isLoggable(PlatformLogger.Level.FINEST)) {
insLog.finest("awt_wmgr = " + awt_wmgr);
}
/*
* Ideally, we should support cases when a different WM is started
* during a Java app lifetime.
*/
if (awt_wmgr != XWM.UNDETERMINED_WM) {
return awt_wmgr;
}
XSetWindowAttributes substruct = new XSetWindowAttributes();
XToolkit.awtLock();
try {
if (isNoWM()) {
awt_wmgr = XWM.NO_WM;
return awt_wmgr;
}
// Initialize _NET protocol - used to detect Window Manager.
// Later, WM will initialize its own version of protocol
XNETProtocol l_net_protocol = g_net_protocol = new XNETProtocol();
l_net_protocol.detect();
if (log.isLoggable(PlatformLogger.Level.FINE) && l_net_protocol.active()) {
log.fine("_NET_WM_NAME is " + l_net_protocol.getWMName());
}
XWINProtocol win = g_win_protocol = new XWINProtocol();
win.detect();
/* actual check for IceWM to follow below */
boolean doIsIceWM = prepareIsIceWM(); /* and let IceWM to act */
/*
* Ok, some WM is out there. Check which one by testing for
* "distinguishing" atoms.
*/
if (isEnlightenment()) {
awt_wmgr = XWM.ENLIGHTEN_WM;
} else if (isMetacity()) {
awt_wmgr = XWM.METACITY_WM;
} else if (isMutter()) {
awt_wmgr = XWM.MUTTER_WM;
} else if (isSawfish()) {
awt_wmgr = XWM.SAWFISH_WM;
} else if (isKDE2()) {
awt_wmgr =XWM.KDE2_WM;
} else if (isCompiz()) {
awt_wmgr = XWM.COMPIZ_WM;
} else if (isLookingGlass()) {
awt_wmgr = LG3D_WM;
} else if (isCWM()) {
awt_wmgr = CWM_WM;
} else if (doIsIceWM && isIceWM()) {
awt_wmgr = XWM.ICE_WM;
} else if (isUnityCompiz()) {
awt_wmgr = XWM.UNITY_COMPIZ_WM;
}
/*
* We don't check for legacy WM when we already know that WM
* supports WIN or _NET wm spec.
*/
else if (l_net_protocol.active()) {
awt_wmgr = XWM.OTHER_WM;
} else if (win.active()) {
awt_wmgr = XWM.OTHER_WM;
}
/*
* Check for legacy WMs.
*/
else if (isCDE()) { /* XXX: must come before isMotif */
awt_wmgr = XWM.CDE_WM;
} else if (isMotif()) {
awt_wmgr = XWM.MOTIF_WM;
} else if (isOpenLook()) {
awt_wmgr = XWM.OPENLOOK_WM;
} else {
awt_wmgr = XWM.OTHER_WM;
}
return awt_wmgr;
} finally {
XToolkit.awtUnlock();
substruct.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment