scx/c/xlib/key.c

129 lines
3.9 KiB
C
Raw Normal View History

2001-05-08 10:21:00 -04:00
#include "xlib.h"
2001-08-22 07:57:51 -04:00
#include "scheme48.h"
2001-05-08 10:21:00 -04:00
2001-08-22 07:57:51 -04:00
//#ifdef XLIB_RELEASE_5_OR_LATER
// I don't know if XDisplayKeycodes() was already there in X11R4.
// else: dpy->min_keycode dpy->max_keycode
2001-05-08 10:21:00 -04:00
2001-08-22 07:57:51 -04:00
s48_value scx_Display_Min_Keycode (s48_value d) {
int mink, maxk;
XDisplayKeycodes(SCX_EXTRACT_DISPLAY(d), &mink, &maxk);
return s48_enter_integer(mink);
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
s48_value scx_Display_Max_Keycode (s48_value d) {
int mink, maxk;
XDisplayKeycodes(SCX_EXTRACT_DISPLAY(d), &mink, &maxk);
return s48_enter_integer(maxk);
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
//#ifdef XLIB_RELEASE_5_OR_LATER
// I'm not sure if this works correctly in X11R4:
2001-05-08 10:21:00 -04:00
2001-08-22 07:57:51 -04:00
s48_value scx_Display_Keysyms_Per_Keycode (s48_value d) {
KeySym *ksyms;
int mink, maxk, ksyms_per_kode;
2001-05-08 10:21:00 -04:00
2001-08-22 07:57:51 -04:00
XDisplayKeycodes(SCX_EXTRACT_DISPLAY(d), &mink, &maxk);
ksyms = XGetKeyboardMapping(SCX_EXTRACT_DISPLAY(d), (KeyCode)mink,
maxk - mink + 1, &ksyms_per_kode);
XFree(ksyms);
2001-08-22 07:57:51 -04:00
return s48_enter_integer(ksyms_per_kode);
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
//#else
//static s48_value P_Display_Keysyms_Per_Keycode (d) s48_value d; {
// Check_Type (d, T_Display);
// // Force initialization:
// Disable_Interrupts;
// (void)XKeycodeToKeysym (DISPLAY(d)->dpy, DISPLAY(d)->dpy->min_keycode, 0);
// Enable_Interrupts;
// return s48_enter_integer (DISPLAY(d)->dpy->keysyms_per_keycode);
//}
//#endif
s48_value scx_String_To_Keysym (s48_value s) {
KeySym k = XStringToKeysym (s48_extract_string(s));
return k == NoSymbol ? S48_FALSE : s48_enter_integer ((unsigned long)k);
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
s48_value scx_Keysym_To_String (s48_value k) {
char* s = XKeysymToString ((KeySym)s48_extract_integer(k));
return s ? s48_enter_string(s) : S48_FALSE;
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
s48_value scx_Keycode_To_Keysym (s48_value d, s48_value k, s48_value index) {
KeySym ks;
//Disable_Interrupts;
ks = XKeycodeToKeysym(SCX_EXTRACT_DISPLAY(d),
(int)s48_extract_integer (k),
(int)s48_extract_integer (index));
//Enable_Interrupts;
if (ks == NoSymbol) return S48_FALSE;
else return s48_enter_integer((unsigned long)ks);
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
s48_value scx_Keysym_To_Keycode (s48_value d, s48_value k) {
KeyCode kc;
//Disable_Interrupts;
kc = XKeysymToKeycode (SCX_EXTRACT_DISPLAY(d),
(KeySym)s48_extract_integer(k));
//Enable_Interrupts;
return s48_enter_integer(kc);
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
s48_value scx_Lookup_String (s48_value d, s48_value k, s48_value mask) {
XKeyEvent e;
char buf[1024];
int len;
KeySym keysym_return;
XComposeStatus status_return;
e.display = SCX_EXTRACT_DISPLAY(d);
e.keycode = (int)s48_extract_integer(k);
e.state = Symbols_To_Bits(mask, State_Syms);
//Disable_Interrupts;
len = XLookupString (&e, buf, 1024, &keysym_return, &status_return);
//Enable_Interrupts;
return s48_enter_string(buf); //is there a 0 at buf[len] ?
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
s48_value scx_Rebind_Keysym (s48_value d, s48_value k, s48_value mods,
s48_value str) {
int i, n = S48_VECTOR_LENGTH(mods);
KeySym p[n];
for (i = 0; i < n; i++)
p[i] = (KeySym)s48_extract_integer(S48_VECTOR_REF(mods, i));
XRebindKeysym (SCX_EXTRACT_DISPLAY(d),
(KeySym)s48_extract_integer (k), p, n,
(unsigned char *)s48_extract_string(str),
S48_STRING_LENGTH(str));
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
s48_value scx_Refresh_Keyboard_Mapping (s48_value d, s48_value w,
s48_value event) {
static XMappingEvent fake;
2001-05-08 10:21:00 -04:00
2001-08-22 07:57:51 -04:00
fake.type = MappingNotify;
fake.display = SCX_EXTRACT_DISPLAY(d);
fake.window = SCX_EXTRACT_WINDOW(w);
fake.request = Symbol_To_Bit (event, Mapping_Syms);
XRefreshKeyboardMapping (&fake);
return S48_UNSPECIFIC;
2001-05-08 10:21:00 -04:00
}
2001-08-22 07:57:51 -04:00
scx_init_key () {
S48_EXPORT_FUNCTION(scx_Display_Min_Keycode);
S48_EXPORT_FUNCTION(scx_Display_Max_Keycode);
S48_EXPORT_FUNCTION(scx_Display_Keysyms_Per_Keycode);
S48_EXPORT_FUNCTION(scx_String_To_Keysym);
S48_EXPORT_FUNCTION(scx_Keysym_To_String);
S48_EXPORT_FUNCTION(scx_Keycode_To_Keysym);
S48_EXPORT_FUNCTION(scx_Keysym_To_Keycode);
S48_EXPORT_FUNCTION(scx_Lookup_String);
S48_EXPORT_FUNCTION(scx_Rebind_Keysym);
S48_EXPORT_FUNCTION(scx_Refresh_Keyboard_Mapping);
2001-05-08 10:21:00 -04:00
}