2
|
1 |
/*
|
|
2 |
* Copyright 2003-2005 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.awt.X11;
|
|
27 |
|
|
28 |
import sun.misc.Unsafe;
|
|
29 |
|
|
30 |
import java.util.logging.*;
|
|
31 |
import java.awt.AWTKeyStroke;
|
|
32 |
import java.awt.event.InputEvent;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Common class for all XEmbed protocol participating classes.
|
|
36 |
* Contains constant definitions and helper routines.
|
|
37 |
*/
|
|
38 |
public class XEmbedHelper {
|
|
39 |
private static final Logger xembedLog = Logger.getLogger("sun.awt.X11.xembed");
|
|
40 |
final static Unsafe unsafe = Unsafe.getUnsafe();
|
|
41 |
|
|
42 |
final static int XEMBED_VERSION = 0,
|
|
43 |
XEMBED_MAPPED = (1 << 0);
|
|
44 |
/* XEMBED messages */
|
|
45 |
final static int XEMBED_EMBEDDED_NOTIFY = 0;
|
|
46 |
final static int XEMBED_WINDOW_ACTIVATE = 1;
|
|
47 |
final static int XEMBED_WINDOW_DEACTIVATE = 2;
|
|
48 |
final static int XEMBED_REQUEST_FOCUS =3;
|
|
49 |
final static int XEMBED_FOCUS_IN = 4;
|
|
50 |
final static int XEMBED_FOCUS_OUT = 5;
|
|
51 |
final static int XEMBED_FOCUS_NEXT = 6;
|
|
52 |
final static int XEMBED_FOCUS_PREV = 7;
|
|
53 |
/* 8-9 were used for XEMBED_GRAB_KEY/XEMBED_UNGRAB_KEY */
|
|
54 |
final static int XEMBED_GRAB_KEY = 8;
|
|
55 |
final static int XEMBED_UNGRAB_KEY = 9;
|
|
56 |
final static int XEMBED_MODALITY_ON = 10;
|
|
57 |
final static int XEMBED_MODALITY_OFF = 11;
|
|
58 |
final static int XEMBED_REGISTER_ACCELERATOR = 12;
|
|
59 |
final static int XEMBED_UNREGISTER_ACCELERATOR= 13;
|
|
60 |
final static int XEMBED_ACTIVATE_ACCELERATOR = 14;
|
|
61 |
|
|
62 |
final static int NON_STANDARD_XEMBED_GTK_GRAB_KEY = 108;
|
|
63 |
final static int NON_STANDARD_XEMBED_GTK_UNGRAB_KEY = 109;
|
|
64 |
|
|
65 |
// A detail code is required for XEMBED_FOCUS_IN. The following values are valid:
|
|
66 |
/* Details for XEMBED_FOCUS_IN: */
|
|
67 |
final static int XEMBED_FOCUS_CURRENT = 0;
|
|
68 |
final static int XEMBED_FOCUS_FIRST = 1;
|
|
69 |
final static int XEMBED_FOCUS_LAST = 2;
|
|
70 |
|
|
71 |
// Modifiers bits
|
|
72 |
final static int XEMBED_MODIFIER_SHIFT = (1 << 0);
|
|
73 |
final static int XEMBED_MODIFIER_CONTROL = (1 << 1);
|
|
74 |
final static int XEMBED_MODIFIER_ALT = (1 << 2);
|
|
75 |
final static int XEMBED_MODIFIER_SUPER = (1 << 3);
|
|
76 |
final static int XEMBED_MODIFIER_HYPER = (1 << 4);
|
|
77 |
|
|
78 |
static XAtom XEmbedInfo;
|
|
79 |
static XAtom XEmbed;
|
|
80 |
|
|
81 |
XEmbedHelper() {
|
|
82 |
if (XEmbed == null) {
|
|
83 |
XEmbed = XAtom.get("_XEMBED");
|
|
84 |
if (xembedLog.isLoggable(Level.FINER)) xembedLog.finer("Created atom " + XEmbed.toString());
|
|
85 |
}
|
|
86 |
if (XEmbedInfo == null) {
|
|
87 |
XEmbedInfo = XAtom.get("_XEMBED_INFO");
|
|
88 |
if (xembedLog.isLoggable(Level.FINER)) xembedLog.finer("Created atom " + XEmbedInfo.toString());
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
void sendMessage(long window, int message) {
|
|
93 |
sendMessage(window, message, 0, 0, 0);
|
|
94 |
}
|
|
95 |
void sendMessage(long window, int message, long detail, long data1, long data2) {
|
|
96 |
XClientMessageEvent msg = new XClientMessageEvent();
|
|
97 |
msg.set_type((int)XlibWrapper.ClientMessage);
|
|
98 |
msg.set_window(window);
|
|
99 |
msg.set_message_type(XEmbed.getAtom());
|
|
100 |
msg.set_format(32);
|
|
101 |
msg.set_data(0, XToolkit.getCurrentServerTime());
|
|
102 |
msg.set_data(1, message);
|
|
103 |
msg.set_data(2, detail);
|
|
104 |
msg.set_data(3, data1);
|
|
105 |
msg.set_data(4, data2);
|
|
106 |
XToolkit.awtLock();
|
|
107 |
try {
|
|
108 |
if (xembedLog.isLoggable(Level.FINE)) xembedLog.fine("Sending " + XEmbedMessageToString(msg));
|
|
109 |
XlibWrapper.XSendEvent(XToolkit.getDisplay(), window, false, XlibWrapper.NoEventMask, msg.pData);
|
|
110 |
}
|
|
111 |
finally {
|
|
112 |
XToolkit.awtUnlock();
|
|
113 |
}
|
|
114 |
msg.dispose();
|
|
115 |
}
|
|
116 |
|
|
117 |
static String msgidToString(int msg_id) {
|
|
118 |
switch (msg_id) {
|
|
119 |
case XEMBED_EMBEDDED_NOTIFY:
|
|
120 |
return "XEMBED_EMBEDDED_NOTIFY";
|
|
121 |
case XEMBED_WINDOW_ACTIVATE:
|
|
122 |
return "XEMBED_WINDOW_ACTIVATE";
|
|
123 |
case XEMBED_WINDOW_DEACTIVATE:
|
|
124 |
return "XEMBED_WINDOW_DEACTIVATE";
|
|
125 |
case XEMBED_FOCUS_IN:
|
|
126 |
return "XEMBED_FOCUS_IN";
|
|
127 |
case XEMBED_FOCUS_OUT:
|
|
128 |
return "XEMBED_FOCUS_OUT";
|
|
129 |
case XEMBED_REQUEST_FOCUS:
|
|
130 |
return "XEMBED_REQUEST_FOCUS";
|
|
131 |
case XEMBED_FOCUS_NEXT:
|
|
132 |
return "XEMBED_FOCUS_NEXT";
|
|
133 |
case XEMBED_FOCUS_PREV:
|
|
134 |
return "XEMBED_FOCUS_PREV";
|
|
135 |
case XEMBED_MODALITY_ON:
|
|
136 |
return "XEMBED_MODALITY_ON";
|
|
137 |
case XEMBED_MODALITY_OFF:
|
|
138 |
return "XEMBED_MODALITY_OFF";
|
|
139 |
case XEMBED_REGISTER_ACCELERATOR:
|
|
140 |
return "XEMBED_REGISTER_ACCELERATOR";
|
|
141 |
case XEMBED_UNREGISTER_ACCELERATOR:
|
|
142 |
return "XEMBED_UNREGISTER_ACCELERATOR";
|
|
143 |
case XEMBED_ACTIVATE_ACCELERATOR:
|
|
144 |
return "XEMBED_ACTIVATE_ACCELERATOR";
|
|
145 |
case XEMBED_GRAB_KEY:
|
|
146 |
return "XEMBED_GRAB_KEY";
|
|
147 |
case XEMBED_UNGRAB_KEY:
|
|
148 |
return "XEMBED_UNGRAB_KEY";
|
|
149 |
case NON_STANDARD_XEMBED_GTK_UNGRAB_KEY:
|
|
150 |
return "NON_STANDARD_XEMBED_GTK_UNGRAB_KEY";
|
|
151 |
case NON_STANDARD_XEMBED_GTK_GRAB_KEY:
|
|
152 |
return "NON_STANDARD_XEMBED_GTK_GRAB_KEY";
|
|
153 |
case XConstants.KeyPress | XEmbedServerTester.SYSTEM_EVENT_MASK:
|
|
154 |
return "KeyPress";
|
|
155 |
case XConstants.MapNotify | XEmbedServerTester.SYSTEM_EVENT_MASK:
|
|
156 |
return "MapNotify";
|
|
157 |
case XConstants.PropertyNotify | XEmbedServerTester.SYSTEM_EVENT_MASK:
|
|
158 |
return "PropertyNotify";
|
|
159 |
default:
|
|
160 |
return "unknown XEMBED id " + msg_id;
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
static String focusIdToString(int focus_id) {
|
|
165 |
switch(focus_id) {
|
|
166 |
case XEMBED_FOCUS_CURRENT:
|
|
167 |
return "XEMBED_FOCUS_CURRENT";
|
|
168 |
case XEMBED_FOCUS_FIRST:
|
|
169 |
return "XEMBED_FOCUS_FIRST";
|
|
170 |
case XEMBED_FOCUS_LAST:
|
|
171 |
return "XEMBED_FOCUS_LAST";
|
|
172 |
default:
|
|
173 |
return "unknown focus id " + focus_id;
|
|
174 |
}
|
|
175 |
}
|
|
176 |
|
|
177 |
static String XEmbedMessageToString(XClientMessageEvent msg) {
|
|
178 |
return ("XEmbed message to " + Long.toHexString(msg.get_window()) + ": " + msgidToString((int)msg.get_data(1)) +
|
|
179 |
", detail: " + msg.get_data(2) +
|
|
180 |
", data:[" + msg.get_data(3) + "," + msg.get_data(4) + "]");
|
|
181 |
|
|
182 |
}
|
|
183 |
|
|
184 |
|
|
185 |
/**
|
|
186 |
* Converts XEMBED modifiers mask into AWT InputEvent mask
|
|
187 |
*/
|
|
188 |
int getModifiers(int state) {
|
|
189 |
int mods = 0;
|
|
190 |
if ((state & XEMBED_MODIFIER_SHIFT) != 0) {
|
|
191 |
mods |= InputEvent.SHIFT_DOWN_MASK;
|
|
192 |
}
|
|
193 |
if ((state & XEMBED_MODIFIER_CONTROL) != 0) {
|
|
194 |
mods |= InputEvent.CTRL_DOWN_MASK;
|
|
195 |
}
|
|
196 |
if ((state & XEMBED_MODIFIER_ALT) != 0) {
|
|
197 |
mods |= InputEvent.ALT_DOWN_MASK;
|
|
198 |
}
|
|
199 |
// FIXME: What is super/hyper?
|
|
200 |
// FIXME: Experiments show that SUPER is ALT. So what is Alt then?
|
|
201 |
if ((state & XEMBED_MODIFIER_SUPER) != 0) {
|
|
202 |
mods |= InputEvent.ALT_DOWN_MASK;
|
|
203 |
}
|
|
204 |
// if ((state & XEMBED_MODIFIER_HYPER) != 0) {
|
|
205 |
// mods |= InputEvent.DOWN_MASK;
|
|
206 |
// }
|
|
207 |
return mods;
|
|
208 |
}
|
|
209 |
|
|
210 |
// Shouldn't be called on Toolkit thread.
|
|
211 |
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
|
|
212 |
XBaseWindow.checkSecurity();
|
|
213 |
|
|
214 |
int keycode;
|
|
215 |
|
|
216 |
XToolkit.awtLock();
|
|
217 |
try {
|
|
218 |
keycode = XWindow.getAWTKeyCodeForKeySym((int)keysym);
|
|
219 |
} finally {
|
|
220 |
XToolkit.awtUnlock();
|
|
221 |
}
|
|
222 |
|
|
223 |
int modifiers = getModifiers((int)state);
|
|
224 |
return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
|
|
225 |
}
|
|
226 |
}
|