2001-05-08 10:21:00 -04:00
|
|
|
#include "xlib.h"
|
|
|
|
|
|
|
|
#ifdef XLIB_RELEASE_5_OR_LATER
|
|
|
|
|
|
|
|
/* I don't know if XDisplayKeycodes() was already there in X11R4.
|
|
|
|
*/
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Display_Min_Keycode (d) s48_value d; {
|
2001-05-08 10:21:00 -04:00
|
|
|
int mink, maxk;
|
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
XDisplayKeycodes(DISPLAY(d)->dpy, &mink, &maxk);
|
2001-05-14 09:48:37 -04:00
|
|
|
return s48_enter_integer (mink);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Display_Max_Keycode (d) s48_value d; {
|
2001-05-08 10:21:00 -04:00
|
|
|
int mink, maxk;
|
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
XDisplayKeycodes(DISPLAY(d)->dpy, &mink, &maxk);
|
2001-05-14 09:48:37 -04:00
|
|
|
return s48_enter_integer (maxk);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Display_Min_Keycode (d) s48_value d; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (d, T_Display);
|
2001-05-14 09:48:37 -04:00
|
|
|
return s48_enter_integer (DISPLAY(d)->dpy->min_keycode);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Display_Max_Keycode (d) s48_value d; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (d, T_Display);
|
2001-05-14 09:48:37 -04:00
|
|
|
return s48_enter_integer (DISPLAY(d)->dpy->max_keycode);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XLIB_RELEASE_5_OR_LATER
|
|
|
|
|
|
|
|
/* I'm not sure if this works correctly in X11R4:
|
|
|
|
*/
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Display_Keysyms_Per_Keycode (d) s48_value d; {
|
2001-05-08 10:21:00 -04:00
|
|
|
KeySym *ksyms;
|
|
|
|
int mink, maxk, ksyms_per_kode;
|
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
XDisplayKeycodes(DISPLAY(d)->dpy, &mink, &maxk);
|
|
|
|
ksyms = XGetKeyboardMapping(DISPLAY(d)->dpy, (KeyCode)mink,
|
|
|
|
maxk - mink + 1, &ksyms_per_kode);
|
2001-05-14 09:48:37 -04:00
|
|
|
return s48_enter_integer (ksyms_per_kode);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Display_Keysyms_Per_Keycode (d) s48_value d; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (d, T_Display);
|
|
|
|
/* Force initialization: */
|
|
|
|
Disable_Interrupts;
|
|
|
|
(void)XKeycodeToKeysym (DISPLAY(d)->dpy, DISPLAY(d)->dpy->min_keycode, 0);
|
|
|
|
Enable_Interrupts;
|
2001-05-14 09:48:37 -04:00
|
|
|
return s48_enter_integer (DISPLAY(d)->dpy->keysyms_per_keycode);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_String_To_Keysym (s) s48_value s; {
|
2001-05-08 10:21:00 -04:00
|
|
|
KeySym k;
|
|
|
|
|
|
|
|
k = XStringToKeysym (Get_Strsym (s));
|
2001-05-14 09:48:37 -04:00
|
|
|
return k == NoSymbol ? S48_FALSE : s48_enter_integer ((unsigned long)k);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Keysym_To_String (k) s48_value k; {
|
2001-05-08 10:21:00 -04:00
|
|
|
register char *s;
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
s = XKeysymToString ((KeySym)s48_extract_integer (k));
|
|
|
|
return s ? Make_String (s, strlen (s)) : S48_FALSE;
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Keycode_To_Keysym (d, k, index) s48_value d, k, index; {
|
|
|
|
s48_value ret;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
Disable_Interrupts;
|
2001-05-14 09:48:37 -04:00
|
|
|
ret = s48_enter_integer ((unsigned long)XKeycodeToKeysym (DISPLAY(d)->dpy,
|
|
|
|
(int)s48_extract_integer (k), (int)s48_extract_integer (index)));
|
2001-05-08 10:21:00 -04:00
|
|
|
Enable_Interrupts;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Keysym_To_Keycode (d, k) s48_value d, k; {
|
|
|
|
s48_value ret;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
Disable_Interrupts;
|
2001-05-14 09:48:37 -04:00
|
|
|
ret = s48_enter_integer (XKeysymToKeycode (DISPLAY(d)->dpy,
|
|
|
|
(KeySym)s48_extract_integer (k)));
|
2001-05-08 10:21:00 -04:00
|
|
|
Enable_Interrupts;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Lookup_String (d, k, mask) s48_value d, k, mask; {
|
2001-05-08 10:21:00 -04:00
|
|
|
XKeyEvent e;
|
|
|
|
char buf[1024];
|
|
|
|
register len;
|
|
|
|
KeySym keysym_return;
|
|
|
|
XComposeStatus status_return;
|
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
e.display = DISPLAY(d)->dpy;
|
2001-05-14 09:48:37 -04:00
|
|
|
e.keycode = (int)s48_extract_integer (k);
|
2001-05-08 10:21:00 -04:00
|
|
|
e.state = Symbols_To_Bits (mask, 1, State_Syms);
|
|
|
|
Disable_Interrupts;
|
|
|
|
len = XLookupString (&e, buf, 1024, &keysym_return, &status_return);
|
|
|
|
Enable_Interrupts;
|
|
|
|
return Make_String (buf, len);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Rebind_Keysym (d, k, mods, str) s48_value d, k, mods, str; {
|
2001-05-08 10:21:00 -04:00
|
|
|
KeySym *p;
|
|
|
|
register i, n;
|
|
|
|
Alloca_Begin;
|
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
Check_Type (str, T_String);
|
|
|
|
Check_Type (mods, T_Vector);
|
2001-05-14 09:48:37 -04:00
|
|
|
n = S48_VECTOR_LENGTH(mods);
|
2001-05-08 10:21:00 -04:00
|
|
|
Alloca (p, KeySym*, n * sizeof (KeySym));
|
|
|
|
for (i = 0; i < n; i++)
|
2001-05-14 09:48:37 -04:00
|
|
|
p[i] = (KeySym)s48_extract_integer (VECTOR(mods)->data[i]);
|
|
|
|
XRebindKeysym (DISPLAY(d)->dpy, (KeySym)s48_extract_integer (k), p, n,
|
2001-05-08 10:21:00 -04:00
|
|
|
(unsigned char *)STRING(str)->data, STRING(str)->size);
|
|
|
|
Alloca_End;
|
|
|
|
return Void;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Refresh_Keyboard_Mapping (w, event) s48_value w, event; {
|
2001-05-08 10:21:00 -04:00
|
|
|
static XMappingEvent fake;
|
|
|
|
|
|
|
|
Check_Type (w, T_Window);
|
|
|
|
fake.type = MappingNotify;
|
|
|
|
fake.display = WINDOW(w)->dpy;
|
|
|
|
fake.window = WINDOW(w)->win;
|
|
|
|
fake.request = Symbols_To_Bits (event, 0, Mapping_Syms);
|
|
|
|
XRefreshKeyboardMapping (&fake);
|
|
|
|
return Void;
|
|
|
|
}
|
|
|
|
|
|
|
|
elk_init_xlib_key () {
|
|
|
|
Define_Primitive (P_Display_Min_Keycode, "display-min-keycode",
|
|
|
|
1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Display_Max_Keycode, "display-max-keycode",
|
|
|
|
1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Display_Keysyms_Per_Keycode,
|
|
|
|
"display-keysyms-per-keycode", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_String_To_Keysym, "string->keysym", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Keysym_To_String, "keysym->string", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Keycode_To_Keysym, "keycode->keysym", 3, 3, EVAL);
|
|
|
|
Define_Primitive (P_Keysym_To_Keycode, "keysym->keycode", 2, 2, EVAL);
|
|
|
|
Define_Primitive (P_Lookup_String, "lookup-string", 3, 3, EVAL);
|
|
|
|
Define_Primitive (P_Rebind_Keysym, "rebind-keysym", 4, 4, EVAL);
|
|
|
|
Define_Primitive (P_Refresh_Keyboard_Mapping,
|
|
|
|
"refresh-keyboard-mapping", 2, 2, EVAL);
|
|
|
|
}
|