< prev index next >

src/solaris/classes/sun/awt/X11/XWINProtocol.java

Print this page
rev 1571 : 8010297: Missing isLoggable() checks in logging code
Summary: Add isLoggable() checks
Reviewed-by: anthony, mchung, serb
Contributed-by: Laurent Bourges <bourges.laurent@gmail.com>


  47             /*
  48              * Request state transition from a Gnome WM (_WIN protocol) by sending
  49              * _WIN_STATE ClientMessage to root window.
  50              */
  51             long win_state = 0;
  52 
  53             if ( (state & Frame.MAXIMIZED_VERT) != 0) {
  54                 win_state |= WIN_STATE_MAXIMIZED_VERT;
  55             }
  56             if ( (state & Frame.MAXIMIZED_HORIZ) != 0) {
  57                 win_state |= WIN_STATE_MAXIMIZED_HORIZ;
  58             }
  59 
  60             XClientMessageEvent req = new XClientMessageEvent();
  61             req.set_type(XlibWrapper.ClientMessage);
  62             req.set_window(window.getWindow());
  63             req.set_message_type(XA_WIN_STATE.getAtom());
  64             req.set_format(32);
  65             req.set_data(0, (WIN_STATE_MAXIMIZED_HORIZ | WIN_STATE_MAXIMIZED_VERT));
  66             req.set_data(1, win_state);
  67             if (log.isLoggable(Level.FINE)) log.fine("Sending WIN_STATE to root to change the state to " + win_state);


  68             try {
  69                 XToolkit.awtLock();
  70                 XlibWrapper.XSendEvent(XToolkit.getDisplay(),
  71                         XlibWrapper.RootWindow(XToolkit.getDisplay(),
  72                             window.getScreenNumber()),
  73                         false,
  74                         XlibWrapper.SubstructureRedirectMask | XlibWrapper.SubstructureNotifyMask,
  75                         req.pData);
  76             }
  77             finally {
  78                 XToolkit.awtUnlock();
  79             }
  80             req.dispose();
  81         } else {
  82             /*
  83              * Specify initial state for a Gnome WM (_WIN protocol) by setting
  84              * WIN_STATE property on the window to the desired state before
  85              * mapping it.
  86              */
  87             /* Be careful to not wipe out state bits we don't understand */


  95              * pay attention.
  96              */
  97             if ((state & Frame.ICONIFIED) != 0) {
  98                 win_state |= WIN_STATE_MINIMIZED;
  99             } else {
 100                 win_state &= ~WIN_STATE_MINIMIZED;
 101             }
 102 
 103             if ((state & Frame.MAXIMIZED_VERT) != 0) {
 104                 win_state |= WIN_STATE_MAXIMIZED_VERT;
 105             } else {
 106                 win_state &= ~WIN_STATE_MAXIMIZED_VERT;
 107             }
 108 
 109             if ((state & Frame.MAXIMIZED_HORIZ) != 0) {
 110                 win_state |= WIN_STATE_MAXIMIZED_HORIZ;
 111             } else {
 112                 win_state &= ~WIN_STATE_MAXIMIZED_HORIZ;
 113             }
 114             if ((old_win_state ^ win_state) != 0) {
 115                 if (log.isLoggable(Level.FINE)) log.fine("Setting WIN_STATE on " + window + " to change the state to " + win_state);


 116                 XA_WIN_STATE.setCard32Property(window, win_state);
 117             }
 118         }
 119     }
 120 
 121     public int getState(XWindowPeer window) {
 122         long win_state = XA_WIN_STATE.getCard32Property(window);
 123         int java_state = Frame.NORMAL;
 124         if ((win_state & WIN_STATE_MAXIMIZED_VERT) != 0) {
 125             java_state |= Frame.MAXIMIZED_VERT;
 126         }
 127         if ((win_state & WIN_STATE_MAXIMIZED_HORIZ) != 0) {
 128             java_state |= Frame.MAXIMIZED_HORIZ;
 129         }
 130         return java_state;
 131     }
 132 
 133     public boolean isStateChange(XPropertyEvent e) {
 134         return doStateProtocol() && e.get_atom() == XA_WIN_STATE.getAtom();
 135     }


 140             return;
 141         }
 142         win_state &= ~WIN_STATE_SHADED;
 143         XA_WIN_STATE.setCard32Property(window, win_state);
 144     }
 145 
 146     public boolean supportsLayer(int layer) {
 147         return ((layer == LAYER_ALWAYS_ON_TOP) || (layer == LAYER_NORMAL)) && doLayerProtocol();
 148     }
 149 
 150     public void setLayer(XWindowPeer window, int layer) {
 151         if (window.isShowing()) {
 152             XClientMessageEvent req = new XClientMessageEvent();
 153             req.set_type(XlibWrapper.ClientMessage);
 154             req.set_window(window.getWindow());
 155             req.set_message_type(XA_WIN_LAYER.getAtom());
 156             req.set_format(32);
 157             req.set_data(0, layer == LAYER_NORMAL ? WIN_LAYER_NORMAL : WIN_LAYER_ONTOP);
 158             req.set_data(1, 0);
 159             req.set_data(2, 0);
 160             if (log.isLoggable(Level.FINE)) log.fine("Setting layer " + layer + " by root message : " + req);


 161             XToolkit.awtLock();
 162             try {
 163                 XlibWrapper.XSendEvent(XToolkit.getDisplay(),
 164                         XlibWrapper.RootWindow(XToolkit.getDisplay(),
 165                             window.getScreenNumber()),
 166                         false,
 167                         /*XlibWrapper.SubstructureRedirectMask | */XlibWrapper.SubstructureNotifyMask,
 168                         req.pData);
 169             }
 170             finally {
 171                 XToolkit.awtUnlock();
 172             }
 173             req.dispose();
 174         } else {
 175             if (log.isLoggable(Level.FINE)) log.fine("Setting layer property to " + layer);


 176             XA_WIN_LAYER.setCard32Property(window, layer == LAYER_NORMAL ? WIN_LAYER_NORMAL : WIN_LAYER_ONTOP);
 177         }
 178     }
 179 
 180     XAtom XA_WIN_LAYER = XAtom.get("_WIN_LAYER");
 181 
 182 /* _WIN_STATE bits */
 183     final static int WIN_STATE_STICKY          =(1<<0); /* everyone knows sticky            */
 184     final static int WIN_STATE_MINIMIZED       =(1<<1); /* Reserved - definition is unclear */
 185     final static int WIN_STATE_MAXIMIZED_VERT  =(1<<2); /* window in maximized V state      */
 186     final static int WIN_STATE_MAXIMIZED_HORIZ =(1<<3); /* window in maximized H state      */
 187     final static int WIN_STATE_HIDDEN          =(1<<4); /* not on taskbar but window visible*/
 188     final static int WIN_STATE_SHADED          =(1<<5); /* shaded (MacOS / Afterstep style) */
 189 /* _WIN_LAYER values */
 190     final static int WIN_LAYER_ONTOP = 6;
 191     final static int WIN_LAYER_NORMAL = 4;
 192 
 193     long WinWindow = 0;
 194     boolean supportChecked = false;
 195     void detect() {
 196         if (supportChecked) {
 197             return;
 198         }
 199         WinWindow = checkAnchor(XA_WIN_SUPPORTING_WM_CHECK, XAtom.XA_CARDINAL);
 200         supportChecked = true;
 201         if (log.isLoggable(Level.FINE)) log.fine("### " + this + " is active: " + (WinWindow != 0));


 202     }
 203 
 204     boolean active() {
 205         detect();
 206         return WinWindow != 0;
 207     }
 208     boolean doStateProtocol() {
 209         boolean res = active() && checkProtocol(XA_WIN_PROTOCOLS, XA_WIN_STATE);
 210         if (log.isLoggable(Level.FINE)) log.fine("### " + this + " supports state: " + res);


 211         return res;
 212     }
 213 
 214     boolean doLayerProtocol() {
 215         boolean res = active() && checkProtocol(XA_WIN_PROTOCOLS, XA_WIN_LAYER);
 216         if (log.isLoggable(Level.FINE)) log.fine("### " + this + " supports layer: " + res);


 217         return res;
 218     }
 219 }


  47             /*
  48              * Request state transition from a Gnome WM (_WIN protocol) by sending
  49              * _WIN_STATE ClientMessage to root window.
  50              */
  51             long win_state = 0;
  52 
  53             if ( (state & Frame.MAXIMIZED_VERT) != 0) {
  54                 win_state |= WIN_STATE_MAXIMIZED_VERT;
  55             }
  56             if ( (state & Frame.MAXIMIZED_HORIZ) != 0) {
  57                 win_state |= WIN_STATE_MAXIMIZED_HORIZ;
  58             }
  59 
  60             XClientMessageEvent req = new XClientMessageEvent();
  61             req.set_type(XlibWrapper.ClientMessage);
  62             req.set_window(window.getWindow());
  63             req.set_message_type(XA_WIN_STATE.getAtom());
  64             req.set_format(32);
  65             req.set_data(0, (WIN_STATE_MAXIMIZED_HORIZ | WIN_STATE_MAXIMIZED_VERT));
  66             req.set_data(1, win_state);
  67             if (log.isLoggable(Level.FINE)) {
  68                 log.fine("Sending WIN_STATE to root to change the state to " + win_state);
  69             }
  70             try {
  71                 XToolkit.awtLock();
  72                 XlibWrapper.XSendEvent(XToolkit.getDisplay(),
  73                         XlibWrapper.RootWindow(XToolkit.getDisplay(),
  74                             window.getScreenNumber()),
  75                         false,
  76                         XlibWrapper.SubstructureRedirectMask | XlibWrapper.SubstructureNotifyMask,
  77                         req.pData);
  78             }
  79             finally {
  80                 XToolkit.awtUnlock();
  81             }
  82             req.dispose();
  83         } else {
  84             /*
  85              * Specify initial state for a Gnome WM (_WIN protocol) by setting
  86              * WIN_STATE property on the window to the desired state before
  87              * mapping it.
  88              */
  89             /* Be careful to not wipe out state bits we don't understand */


  97              * pay attention.
  98              */
  99             if ((state & Frame.ICONIFIED) != 0) {
 100                 win_state |= WIN_STATE_MINIMIZED;
 101             } else {
 102                 win_state &= ~WIN_STATE_MINIMIZED;
 103             }
 104 
 105             if ((state & Frame.MAXIMIZED_VERT) != 0) {
 106                 win_state |= WIN_STATE_MAXIMIZED_VERT;
 107             } else {
 108                 win_state &= ~WIN_STATE_MAXIMIZED_VERT;
 109             }
 110 
 111             if ((state & Frame.MAXIMIZED_HORIZ) != 0) {
 112                 win_state |= WIN_STATE_MAXIMIZED_HORIZ;
 113             } else {
 114                 win_state &= ~WIN_STATE_MAXIMIZED_HORIZ;
 115             }
 116             if ((old_win_state ^ win_state) != 0) {
 117                 if (log.isLoggable(Level.FINE)) {
 118                     log.fine("Setting WIN_STATE on " + window + " to change the state to " + win_state);
 119                 }
 120                 XA_WIN_STATE.setCard32Property(window, win_state);
 121             }
 122         }
 123     }
 124 
 125     public int getState(XWindowPeer window) {
 126         long win_state = XA_WIN_STATE.getCard32Property(window);
 127         int java_state = Frame.NORMAL;
 128         if ((win_state & WIN_STATE_MAXIMIZED_VERT) != 0) {
 129             java_state |= Frame.MAXIMIZED_VERT;
 130         }
 131         if ((win_state & WIN_STATE_MAXIMIZED_HORIZ) != 0) {
 132             java_state |= Frame.MAXIMIZED_HORIZ;
 133         }
 134         return java_state;
 135     }
 136 
 137     public boolean isStateChange(XPropertyEvent e) {
 138         return doStateProtocol() && e.get_atom() == XA_WIN_STATE.getAtom();
 139     }


 144             return;
 145         }
 146         win_state &= ~WIN_STATE_SHADED;
 147         XA_WIN_STATE.setCard32Property(window, win_state);
 148     }
 149 
 150     public boolean supportsLayer(int layer) {
 151         return ((layer == LAYER_ALWAYS_ON_TOP) || (layer == LAYER_NORMAL)) && doLayerProtocol();
 152     }
 153 
 154     public void setLayer(XWindowPeer window, int layer) {
 155         if (window.isShowing()) {
 156             XClientMessageEvent req = new XClientMessageEvent();
 157             req.set_type(XlibWrapper.ClientMessage);
 158             req.set_window(window.getWindow());
 159             req.set_message_type(XA_WIN_LAYER.getAtom());
 160             req.set_format(32);
 161             req.set_data(0, layer == LAYER_NORMAL ? WIN_LAYER_NORMAL : WIN_LAYER_ONTOP);
 162             req.set_data(1, 0);
 163             req.set_data(2, 0);
 164             if (log.isLoggable(Level.FINE)) {
 165                 log.fine("Setting layer " + layer + " by root message : " + req);
 166             }
 167             XToolkit.awtLock();
 168             try {
 169                 XlibWrapper.XSendEvent(XToolkit.getDisplay(),
 170                         XlibWrapper.RootWindow(XToolkit.getDisplay(),
 171                             window.getScreenNumber()),
 172                         false,
 173                         /*XlibWrapper.SubstructureRedirectMask | */XlibWrapper.SubstructureNotifyMask,
 174                         req.pData);
 175             }
 176             finally {
 177                 XToolkit.awtUnlock();
 178             }
 179             req.dispose();
 180         } else {
 181             if (log.isLoggable(Level.FINE)) {
 182                 log.fine("Setting layer property to " + layer);
 183             }
 184             XA_WIN_LAYER.setCard32Property(window, layer == LAYER_NORMAL ? WIN_LAYER_NORMAL : WIN_LAYER_ONTOP);
 185         }
 186     }
 187 
 188     XAtom XA_WIN_LAYER = XAtom.get("_WIN_LAYER");
 189 
 190 /* _WIN_STATE bits */
 191     final static int WIN_STATE_STICKY          =(1<<0); /* everyone knows sticky            */
 192     final static int WIN_STATE_MINIMIZED       =(1<<1); /* Reserved - definition is unclear */
 193     final static int WIN_STATE_MAXIMIZED_VERT  =(1<<2); /* window in maximized V state      */
 194     final static int WIN_STATE_MAXIMIZED_HORIZ =(1<<3); /* window in maximized H state      */
 195     final static int WIN_STATE_HIDDEN          =(1<<4); /* not on taskbar but window visible*/
 196     final static int WIN_STATE_SHADED          =(1<<5); /* shaded (MacOS / Afterstep style) */
 197 /* _WIN_LAYER values */
 198     final static int WIN_LAYER_ONTOP = 6;
 199     final static int WIN_LAYER_NORMAL = 4;
 200 
 201     long WinWindow = 0;
 202     boolean supportChecked = false;
 203     void detect() {
 204         if (supportChecked) {
 205             return;
 206         }
 207         WinWindow = checkAnchor(XA_WIN_SUPPORTING_WM_CHECK, XAtom.XA_CARDINAL);
 208         supportChecked = true;
 209         if (log.isLoggable(Level.FINE)) {
 210             log.fine("### " + this + " is active: " + (WinWindow != 0));
 211         }
 212     }
 213 
 214     boolean active() {
 215         detect();
 216         return WinWindow != 0;
 217     }
 218     boolean doStateProtocol() {
 219         boolean res = active() && checkProtocol(XA_WIN_PROTOCOLS, XA_WIN_STATE);
 220         if (log.isLoggable(Level.FINE)) {
 221             log.fine("### " + this + " supports state: " + res);
 222         }
 223         return res;
 224     }
 225 
 226     boolean doLayerProtocol() {
 227         boolean res = active() && checkProtocol(XA_WIN_PROTOCOLS, XA_WIN_LAYER);
 228         if (log.isLoggable(Level.FINE)) {
 229             log.fine("### " + this + " supports layer: " + res);
 230         }
 231         return res;
 232     }
 233 }
< prev index next >