提交 ece4d22e 编写于 作者: S son

6632140: minor refactoring for XWM

Summary: code cleanup and generificaion for XWM
Reviewed-by: anthony
上级 a984c3dd
/* /*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,15 +24,18 @@ ...@@ -24,15 +24,18 @@
*/ */
package sun.awt.X11; package sun.awt.X11;
import java.util.Vector; import java.awt.Color;
import java.awt.*; import java.awt.Dimension;
import java.awt.peer.*; import java.awt.Font;
import java.awt.event.*; import java.awt.FontMetrics;
import sun.awt.im.*; import java.awt.Frame;
import sun.awt.*; import java.awt.Graphics;
import java.util.logging.*; import java.awt.Insets;
import java.lang.reflect.Field; import java.awt.MenuBar;
import java.util.*; import java.awt.Rectangle;
import java.awt.peer.FramePeer;
import java.util.logging.Level;
import java.util.logging.Logger;
class XFramePeer extends XDecoratedPeer implements FramePeer, XConstants { class XFramePeer extends XDecoratedPeer implements FramePeer, XConstants {
private static Logger log = Logger.getLogger("sun.awt.X11.XFramePeer"); private static Logger log = Logger.getLogger("sun.awt.X11.XFramePeer");
...@@ -285,19 +288,20 @@ class XFramePeer extends XDecoratedPeer implements FramePeer, XConstants { ...@@ -285,19 +288,20 @@ class XFramePeer extends XDecoratedPeer implements FramePeer, XConstants {
* Let's see if this is a window state protocol message, and * Let's see if this is a window state protocol message, and
* if it is - decode a new state in terms of java constants. * if it is - decode a new state in terms of java constants.
*/ */
Integer newState = XWM.getWM().isStateChange(this, ev); if (!XWM.getWM().isStateChange(this, ev)) {
if (newState == null) { stateLog.finer("either not a state atom or state has not been changed");
return; return;
} }
int changed = state ^ newState.intValue(); final int newState = XWM.getWM().getState(this);
int changed = state ^ newState;
if (changed == 0) { if (changed == 0) {
stateLog.finer("State is the same: " + state); stateLog.finer("State is the same: " + state);
return; return;
} }
int old_state = state; int old_state = state;
state = newState.intValue(); state = newState;
if ((changed & Frame.ICONIFIED) != 0) { if ((changed & Frame.ICONIFIED) != 0) {
if ((state & Frame.ICONIFIED) != 0) { if ((state & Frame.ICONIFIED) != 0) {
......
/* /*
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,17 +26,15 @@ ...@@ -26,17 +26,15 @@
package sun.awt.X11; package sun.awt.X11;
import java.awt.*; import java.awt.Frame;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.LogManager;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol { final class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol
final static Logger log = Logger.getLogger("sun.awt.X11.XNETProtocol"); {
private final static Logger log = Logger.getLogger("sun.awt.X11.XNETProtocol");
private final static Logger iconLog = Logger.getLogger("sun.awt.X11.icon.XNETProtocol"); private final static Logger iconLog = Logger.getLogger("sun.awt.X11.icon.XNETProtocol");
private static Logger stateLog = Logger.getLogger("sun.awt.X11.states.XNETProtocol");
/** /**
* XStateProtocol * XStateProtocol
...@@ -276,6 +274,7 @@ class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol { ...@@ -276,6 +274,7 @@ class XNETProtocol extends XProtocol implements XStateProtocol, XLayerProtocol {
boolean doStateProtocol() { boolean doStateProtocol() {
boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_STATE); boolean res = active() && checkProtocol(XA_NET_SUPPORTED, XA_NET_WM_STATE);
stateLog.finer("doStateProtocol() returns " + res);
return res; return res;
} }
......
/* /*
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,11 +25,9 @@ ...@@ -25,11 +25,9 @@
package sun.awt.X11; package sun.awt.X11;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.InputEvent;
import java.awt.peer.*; import java.awt.event.MouseEvent;
import java.beans.PropertyChangeListener; import java.awt.datatransfer.Clipboard;
import sun.awt.*;
import java.util.*;
import java.awt.dnd.DragSource; import java.awt.dnd.DragSource;
import java.awt.dnd.DragGestureListener; import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureEvent;
...@@ -37,20 +35,27 @@ import java.awt.dnd.DragGestureRecognizer; ...@@ -37,20 +35,27 @@ import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.MouseDragGestureRecognizer; import java.awt.dnd.MouseDragGestureRecognizer;
import java.awt.dnd.InvalidDnDOperationException; import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.peer.DragSourceContextPeer; import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.image.*;
import java.security.*;
import java.awt.im.InputMethodHighlight; import java.awt.im.InputMethodHighlight;
import java.awt.im.spi.InputMethodDescriptor; import java.awt.im.spi.InputMethodDescriptor;
import java.awt.datatransfer.Clipboard; import java.awt.image.ColorModel;
import java.awt.peer.*;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIDefaults; import javax.swing.UIDefaults;
import java.util.logging.*; import sun.awt.*;
import sun.font.FontManager; import sun.font.FontManager;
import sun.misc.PerformanceLogger; import sun.misc.PerformanceLogger;
import sun.print.PrintJob2D; import sun.print.PrintJob2D;
import java.lang.reflect.*;
public class XToolkit extends UNIXToolkit implements Runnable, XConstants { public final class XToolkit extends UNIXToolkit implements Runnable, XConstants
{
private static Logger log = Logger.getLogger("sun.awt.X11.XToolkit"); private static Logger log = Logger.getLogger("sun.awt.X11.XToolkit");
private static Logger eventLog = Logger.getLogger("sun.awt.X11.event.XToolkit"); private static Logger eventLog = Logger.getLogger("sun.awt.X11.event.XToolkit");
private static final Logger timeoutTaskLog = Logger.getLogger("sun.awt.X11.timeoutTask.XToolkit"); private static final Logger timeoutTaskLog = Logger.getLogger("sun.awt.X11.timeoutTask.XToolkit");
...@@ -1871,9 +1876,7 @@ public class XToolkit extends UNIXToolkit implements Runnable, XConstants { ...@@ -1871,9 +1876,7 @@ public class XToolkit extends UNIXToolkit implements Runnable, XConstants {
} }
public boolean isAlwaysOnTopSupported() { public boolean isAlwaysOnTopSupported() {
Iterator iter = XWM.getWM().getProtocols(XLayerProtocol.class).iterator(); for (XLayerProtocol proto : XWM.getWM().getProtocols(XLayerProtocol.class)) {
while (iter.hasNext()) {
XLayerProtocol proto = (XLayerProtocol)iter.next();
if (proto.supportsLayer(XLayerProtocol.LAYER_ALWAYS_ON_TOP)) { if (proto.supportsLayer(XLayerProtocol.LAYER_ALWAYS_ON_TOP)) {
return true; return true;
} }
......
/* /*
* Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,20 +31,23 @@ ...@@ -31,20 +31,23 @@
package sun.awt.X11; package sun.awt.X11;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import java.util.regex.*; import java.awt.Insets;
import java.awt.Frame; import java.awt.Frame;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.util.*; import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.awt.Insets; import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* Class incapsulating knowledge about window managers in general * Class incapsulating knowledge about window managers in general
* Descendants should provide some information about specific window manager. * Descendants should provide some information about specific window manager.
*/ */
class XWM implements MWMConstants, XUtilConstants { final class XWM implements MWMConstants, XUtilConstants
{
private final static Logger log = Logger.getLogger("sun.awt.X11.XWM"); private final static Logger log = Logger.getLogger("sun.awt.X11.XWM");
private final static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XWM"); private final static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XWM");
...@@ -1026,21 +1029,21 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1026,21 +1029,21 @@ class XWM implements MWMConstants, XUtilConstants {
/*****************************************************************************\ /*****************************************************************************\
* Protocols support * Protocols support
*/ */
HashMap<Class<?>, Collection<XProtocol>> protocolsMap = new HashMap<Class<?>, Collection<XProtocol>>(); private HashMap<Class<?>, Collection<?>> protocolsMap = new HashMap<Class<?>, Collection<?>>();
/** /**
* Returns all protocols supporting given protocol interface * Returns all protocols supporting given protocol interface
*/ */
Collection<XProtocol> getProtocols(Class protocolInterface) { <T> Collection<T> getProtocols(Class<T> protocolInterface) {
Collection<XProtocol> res = protocolsMap.get(protocolInterface); Collection<T> res = (Collection<T>) protocolsMap.get(protocolInterface);
if (res != null) { if (res != null) {
return (Collection<XProtocol>)res; return res;
} else { } else {
return new LinkedList<XProtocol>(); return new LinkedList<T>();
} }
} }
void addProtocol(Class protocolInterface, XProtocol protocol) { private <T> void addProtocol(Class<T> protocolInterface, T protocol) {
Collection<XProtocol> protocols = getProtocols(protocolInterface); Collection<T> protocols = getProtocols(protocolInterface);
protocols.add(protocol); protocols.add(protocol);
protocolsMap.put(protocolInterface, protocols); protocolsMap.put(protocolInterface, protocols);
} }
...@@ -1085,9 +1088,7 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1085,9 +1088,7 @@ class XWM implements MWMConstants, XUtilConstants {
} }
/* FALLTROUGH */ /* FALLTROUGH */
case Frame.MAXIMIZED_BOTH: case Frame.MAXIMIZED_BOTH:
Iterator iter = getProtocols(XStateProtocol.class).iterator(); for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
if (proto.supportsState(state)) { if (proto.supportsState(state)) {
return true; return true;
} }
...@@ -1105,10 +1106,8 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1105,10 +1106,8 @@ class XWM implements MWMConstants, XUtilConstants {
int getExtendedState(XWindowPeer window) { int getExtendedState(XWindowPeer window) {
Iterator iter = getProtocols(XStateProtocol.class).iterator();
int state = 0; int state = 0;
while (iter.hasNext()) { for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
XStateProtocol proto = (XStateProtocol)iter.next();
state |= proto.getState(window); state |= proto.getState(window);
} }
if (state != 0) { if (state != 0) {
...@@ -1127,18 +1126,17 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1127,18 +1126,17 @@ class XWM implements MWMConstants, XUtilConstants {
/* /*
* Check if property change is a window state protocol message. * Check if property change is a window state protocol message.
* If it is - return the new state as Integer, otherwise return null
*/ */
Integer isStateChange(XDecoratedPeer window, XPropertyEvent e) { boolean isStateChange(XDecoratedPeer window, XPropertyEvent e) {
if (!window.isShowing()) { if (!window.isShowing()) {
stateLog.finer("Window is not showing"); stateLog.finer("Window is not showing");
return null; return false;
} }
int wm_state = window.getWMState(); int wm_state = window.getWMState();
if (wm_state == XlibWrapper.WithdrawnState) { if (wm_state == XlibWrapper.WithdrawnState) {
stateLog.finer("WithdrawnState"); stateLog.finer("WithdrawnState");
return null; return false;
} else { } else {
stateLog.finer("Window WM_STATE is " + wm_state); stateLog.finer("Window WM_STATE is " + wm_state);
} }
...@@ -1147,26 +1145,26 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1147,26 +1145,26 @@ class XWM implements MWMConstants, XUtilConstants {
is_state_change = true; is_state_change = true;
} }
Iterator iter = getProtocols(XStateProtocol.class).iterator(); for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
is_state_change |= proto.isStateChange(e); is_state_change |= proto.isStateChange(e);
stateLog.finest(proto + ": is state changed = " + is_state_change);
}
return is_state_change;
} }
int res = 0;
if (is_state_change) { /*
* Returns current state (including extended) of a given window.
*/
int getState(XDecoratedPeer window) {
int res = 0;
final int wm_state = window.getWMState();
if (wm_state == XlibWrapper.IconicState) { if (wm_state == XlibWrapper.IconicState) {
res = Frame.ICONIFIED; res = Frame.ICONIFIED;
} else { } else {
res = Frame.NORMAL; res = Frame.NORMAL;
} }
res |= getExtendedState(window); res |= getExtendedState(window);
} return res;
if (is_state_change) {
return Integer.valueOf(res);
} else {
return null;
}
} }
/*****************************************************************************\ /*****************************************************************************\
...@@ -1180,9 +1178,7 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1180,9 +1178,7 @@ class XWM implements MWMConstants, XUtilConstants {
* in XLayerProtocol * in XLayerProtocol
*/ */
void setLayer(XWindowPeer window, int layer) { void setLayer(XWindowPeer window, int layer) {
Iterator iter = getProtocols(XLayerProtocol.class).iterator(); for (XLayerProtocol proto : getProtocols(XLayerProtocol.class)) {
while (iter.hasNext()) {
XLayerProtocol proto = (XLayerProtocol)iter.next();
if (proto.supportsLayer(layer)) { if (proto.supportsLayer(layer)) {
proto.setLayer(window, layer); proto.setLayer(window, layer);
} }
...@@ -1191,9 +1187,7 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1191,9 +1187,7 @@ class XWM implements MWMConstants, XUtilConstants {
} }
void setExtendedState(XWindowPeer window, int state) { void setExtendedState(XWindowPeer window, int state) {
Iterator iter = getProtocols(XStateProtocol.class).iterator(); for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
if (proto.supportsState(state)) { if (proto.supportsState(state)) {
proto.setState(window, state); proto.setState(window, state);
break; break;
...@@ -1239,9 +1233,7 @@ class XWM implements MWMConstants, XUtilConstants { ...@@ -1239,9 +1233,7 @@ class XWM implements MWMConstants, XUtilConstants {
void unshadeKludge(XDecoratedPeer window) { void unshadeKludge(XDecoratedPeer window) {
assert(window.isShowing()); assert(window.isShowing());
Iterator iter = getProtocols(XStateProtocol.class).iterator(); for (XStateProtocol proto : getProtocols(XStateProtocol.class)) {
while (iter.hasNext()) {
XStateProtocol proto = (XStateProtocol)iter.next();
proto.unshadeKludge(window); proto.unshadeKludge(window);
} }
XToolkit.XSync(); XToolkit.XSync();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册