1 /*
2  * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package sun.awt.X11;
27 
28 import java.awt.*;
29 
30 /**
31  * This class represent focus holder window implementation. When toplevel requests or receives focus
32  * it instead sets focus to this proxy. This proxy is mapped but invisible(it is kept at (-1,-1))
33  * and therefore X doesn't control focus after we have set it to proxy.
34  */
35 public class XFocusProxyWindow extends XBaseWindow {
36     XWindowPeer owner;
37 
XFocusProxyWindow(XWindowPeer owner)38     public XFocusProxyWindow(XWindowPeer owner) {
39         super(new XCreateWindowParams(new Object[] {
40             BOUNDS, new Rectangle(-1, -1, 1, 1),
41             PARENT_WINDOW, new Long(owner.getWindow()),
42             EVENT_MASK, new Long(XConstants.FocusChangeMask | XConstants.KeyPressMask | XConstants.KeyReleaseMask)
43         }));
44         this.owner = owner;
45     }
46 
postInit(XCreateWindowParams params)47     public void postInit(XCreateWindowParams params){
48         super.postInit(params);
49         setWMClass(getWMClass());
50         xSetVisible(true);
51     }
52 
getWMName()53     protected String getWMName() {
54         return "FocusProxy";
55     }
getWMClass()56     protected String[] getWMClass() {
57         return new String[] {"Focus-Proxy-Window", "FocusProxy"};
58     }
59 
getOwner()60     public XWindowPeer getOwner() {
61         return owner;
62     }
63 
dispatchEvent(XEvent ev)64     public void dispatchEvent(XEvent ev) {
65         int type = ev.get_type();
66         switch (type)
67         {
68           case XConstants.FocusIn:
69           case XConstants.FocusOut:
70               handleFocusEvent(ev);
71               break;
72         }
73         super.dispatchEvent(ev);
74     }
75 
handleFocusEvent(XEvent xev)76     public void handleFocusEvent(XEvent xev) {
77         owner.handleFocusEvent(xev);
78     }
79 
handleKeyPress(XEvent xev)80     public void handleKeyPress(XEvent xev) {
81         owner.handleKeyPress(xev);
82     }
83 
handleKeyRelease(XEvent xev)84     public void handleKeyRelease(XEvent xev) {
85         owner.handleKeyRelease(xev);
86     }
87 }
88