Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. |
3 |
* The contents of this file are made available under the terms |
4 |
* of the GNU Lesser General Public License (LGPL) Version 2.1 that |
5 |
* accompanies this distribution (lgpl-v21.txt). The LGPL is also |
6 |
* available at http://www.gnu.org/licenses/lgpl.html. If the version |
7 |
* of the LGPL at http://www.gnu.org is different to the version of |
8 |
* the LGPL accompanying this distribution and there is any conflict |
9 |
* between the two license versions, the terms of the LGPL accompanying |
10 |
* this distribution shall govern. |
11 |
* |
12 |
* Contributors: |
13 |
* IBM Corporation - initial API and implementation |
14 |
*******************************************************************************/ |
15 |
|
16 |
#include "swt.h" |
17 |
#include "ime.h" |
18 |
|
19 |
#define OS_NATIVE(func) Java_org_eclipse_swt_internal_gtk_IME_##func |
20 |
|
21 |
#ifndef NO__1GetKeyboardLanguages |
22 |
JNIEXPORT jint JNICALL OS_NATIVE(_1GetKeyboardLanguages) |
23 |
(JNIEnv *env, jclass that, jint arg0, jintArray arg1) |
24 |
{ |
25 |
jint *lparg1 = NULL; |
26 |
jint rc = -1; |
27 |
OS_NATIVE_ENTER(env, that, _1GetKeyboardLanguages_FUNC); |
28 |
#ifndef NO_IME |
29 |
if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail; |
30 |
{ |
31 |
/* For now, execute series of commmands */ |
32 |
int i = 0; |
33 |
char* p = NULL; |
34 |
char file_name[] = "/tmp/bidiXXX.tmp"; |
35 |
char command[100] = "dcop kxkb kxkb getLayoutsList > "; |
36 |
FILE* tmp_file = NULL; |
37 |
mkstemp(file_name); |
38 |
freopen("/dev/null", "w", stderr); |
39 |
system(strcat(command, file_name)); |
40 |
if ((tmp_file = fopen(file_name, "r+"))) { |
41 |
do { |
42 |
++rc; |
43 |
char* lang = (char*)malloc(20); |
44 |
if (!fgets(lang, 19, tmp_file)) { |
45 |
free(lang); |
46 |
break; |
47 |
} |
48 |
if ((p = strchr(lang, '\n'))) |
49 |
*p = '\0'; |
50 |
lparg1[i++] = (int)lang; |
51 |
} |
52 |
while (rc < 10); |
53 |
fclose(tmp_file); |
54 |
} |
55 |
remove(file_name); |
56 |
} |
57 |
if (rc <= 0) { |
58 |
static int initialized = 0; |
59 |
static void *handle = NULL; |
60 |
typedef Status (*FPTR)(Display*, unsigned long, XkbDescPtr); |
61 |
typedef void (*FPTR2)(XkbDescPtr, unsigned int, Bool); |
62 |
typedef Status (*FPTR3)(Display*, Atom*, int, char**); |
63 |
static FPTR fXkbGetControls = NULL; |
64 |
static FPTR2 fXkbFreeControls = NULL; |
65 |
static FPTR fXkbGetNames = NULL; |
66 |
static FPTR2 fXkbFreeNames = NULL; |
67 |
static FPTR3 fXGetAtomNames = NULL; |
68 |
if (!initialized) { |
69 |
/* TODO: Add XkbQueryExtension */ |
70 |
if (!handle) handle = dlopen(XKB_LIB, RTLD_LAZY); |
71 |
if (handle) { |
72 |
fXkbGetControls = (FPTR)dlsym(handle, "XkbGetControls"); |
73 |
fXkbFreeControls = (FPTR2)dlsym(handle, "XkbFreeControls"); |
74 |
fXkbGetNames = (FPTR)dlsym(handle, "XkbGetNames"); |
75 |
fXkbFreeNames = (FPTR2)dlsym(handle, "XkbFreeNames"); |
76 |
fXGetAtomNames = (FPTR3)dlsym(handle, "XGetAtomNames"); |
77 |
} |
78 |
initialized = 1; |
79 |
} |
80 |
if (fXkbGetControls && fXkbFreeControls && fXkbGetNames && fXkbFreeNames && fXGetAtomNames) { |
81 |
Display* dpy = (Display*)arg0; |
82 |
XkbDescRec desc; |
83 |
memset(&desc, 0, sizeof(desc)); |
84 |
desc.device_spec = XkbUseCoreKbd; |
85 |
desc.dpy = dpy; |
86 |
if ((*fXkbGetControls)(dpy, XkbGroupsWrapMask, &desc) == Success) { |
87 |
rc = desc.ctrls->num_groups; |
88 |
(*fXkbGetNames)(dpy, XkbGroupNamesMask, &desc); |
89 |
(*fXGetAtomNames)(dpy, desc.names->groups, rc, (char**)lparg1); |
90 |
(*fXkbFreeNames)(&desc, XkbGroupNamesMask, 1); |
91 |
} |
92 |
(*fXkbFreeControls)(&desc, XkbGroupsWrapMask, 1); |
93 |
} |
94 |
} |
95 |
fail: |
96 |
if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); |
97 |
#endif /* ifndef NO_IME */ |
98 |
OS_NATIVE_EXIT(env, that, _1GetKeyboardLanguages_FUNC); |
99 |
return rc; |
100 |
} |
101 |
#endif /* ifndef NO__1GetKeyboardLanguages */ |
102 |
|