KRFB: additional keys entry with replacing old ones at achieving the limit

Signed-off-by: Roman Savochenko <roman@home.home>
feat/krfb-newenterkeys
Roman Savochenko 1 year ago
parent f8b3eca91d
commit c22796fda9

@ -185,14 +185,13 @@ const int KeyboardEvent::LEFTSHIFT = 1;
const int KeyboardEvent::RIGHTSHIFT = 2; const int KeyboardEvent::RIGHTSHIFT = 2;
const int KeyboardEvent::ALTGR = 4; const int KeyboardEvent::ALTGR = 4;
char KeyboardEvent::ModifierState; char KeyboardEvent::ModifierState;
KeySym KeyboardEvent::added_keysyms[0x100];
static KeySym added_keysyms[0x100];
KeyboardEvent::KeyboardEvent(bool d, KeySym k) : KeyboardEvent::KeyboardEvent(bool d, KeySym k) :
down(d), down(d),
keySym(k) { keySym(k) {
if(k && !IsModifierKey(k)) add_keysym(k); if(k && !IsModifierKey(k) && XKeysymToKeycode(dpy,k) == NoSymbol) add_keysym(k);
} }
void KeyboardEvent::initKeycodes() { void KeyboardEvent::initKeycodes() {
@ -244,17 +243,18 @@ int KeyboardEvent::add_keysym( KeySym keysym )
int minkey, maxkey, syms_per_keycode, kc, ret = 0; int minkey, maxkey, syms_per_keycode, kc, ret = 0;
XDisplayKeycodes(dpy, &minkey, &maxkey); XDisplayKeycodes(dpy, &minkey, &maxkey);
repeate:
KeySym *keymap = XGetKeyboardMapping(dpy, minkey, (maxkey-minkey+1), &syms_per_keycode); KeySym *keymap = XGetKeyboardMapping(dpy, minkey, (maxkey-minkey+1), &syms_per_keycode);
bool is_empty = true;
for(int kc = minkey+1; kc <= maxkey; kc++) { for(int kc = minkey+1; kc <= maxkey; kc++) {
int j, didmsg = 0, is_empty = 1;
char *str;
KeySym newks[8]; KeySym newks[8];
for(int n = 0; n < syms_per_keycode; n++) { is_empty = true;
for(int n = 0; n < syms_per_keycode; n++)
if(keymap[(kc-minkey)*syms_per_keycode+n] != NoSymbol) if(keymap[(kc-minkey)*syms_per_keycode+n] != NoSymbol)
{ is_empty = 0; break; } { is_empty = false; break; }
}
if(!is_empty) continue; if(!is_empty) continue;
for(int i = 0; i < 8; i++) newks[i] = NoSymbol; for(int i = 0; i < 8; i++) newks[i] = NoSymbol;
@ -270,12 +270,36 @@ int KeyboardEvent::add_keysym( KeySym keysym )
ret = kc; ret = kc;
break; break;
} }
XFree(keymap); XFree(keymap);
if(!is_empty) { delete_added_keycodes(); goto repeate; }
return ret; return ret;
} }
void KeyboardEvent::delete_added_keycodes( )
{
for(int kc = 0; kc < 0x100; kc++)
if(added_keysyms[kc] != NoSymbol) {
added_keysyms[kc] = NoSymbol;
int minkey, maxkey, syms_per_keycode, i;
KeySym *keymap;
KeySym ksym, newks[8];
char *str;
XDisplayKeycodes(dpy, &minkey, &maxkey);
keymap = XGetKeyboardMapping(dpy, minkey, (maxkey - minkey + 1), &syms_per_keycode);
for (i = 0; i < 8; i++) newks[i] = NoSymbol;
XChangeKeyboardMapping(dpy, kc, syms_per_keycode, newks, 1);
XFree(keymap);
XFlush(dpy);
}
}
/* this function adjusts the modifiers according to mod (as from modifiers) and ModifierState */ /* this function adjusts the modifiers according to mod (as from modifiers) and ModifierState */
void KeyboardEvent::tweakModifiers(signed char mod, bool down) { void KeyboardEvent::tweakModifiers(signed char mod, bool down) {
@ -433,6 +457,8 @@ RFBController::RFBController(Configuration *c) :
RFBController::~RFBController() RFBController::~RFBController()
{ {
KeyboardEvent::delete_added_keycodes();
stopServer(); stopServer();
} }

@ -68,13 +68,15 @@ class KeyboardEvent : public VNCEvent {
static const int RIGHTSHIFT; static const int RIGHTSHIFT;
static const int ALTGR; static const int ALTGR;
static char ModifierState; static char ModifierState;
static KeySym added_keysyms[0x100];
static void tweakModifiers(signed char mod, bool down); static void tweakModifiers(signed char mod, bool down);
public: public:
static void initKeycodes(); static void initKeycodes();
KeyboardEvent(bool d, KeySym k); KeyboardEvent(bool d, KeySym k);
int add_keysym( KeySym keysym ); static int add_keysym( KeySym keysym );
static void delete_added_keycodes( );
virtual void exec(); virtual void exec();
}; };

Loading…
Cancel
Save