summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Savochenko <[email protected]>2023-11-19 17:06:47 +0200
committerRoman Savochenko <[email protected]>2023-11-19 17:06:47 +0200
commitc22796fda9743433793c8b0d19d5a20d254445fb (patch)
treec71ed147b869979ef9ad2d565440d825f44cf80d
parentf8b3eca91d185da64eacfb901522a1fe65de1731 (diff)
downloadtdenetwork-feat/krfb-newenterkeys.tar.gz
tdenetwork-feat/krfb-newenterkeys.zip
KRFB: additional keys entry with replacing old ones at achieving the limitfeat/krfb-newenterkeys
Signed-off-by: Roman Savochenko <[email protected]>
-rw-r--r--krfb/krfb/rfbcontroller.cpp44
-rw-r--r--krfb/krfb/rfbcontroller.h4
2 files changed, 38 insertions, 10 deletions
diff --git a/krfb/krfb/rfbcontroller.cpp b/krfb/krfb/rfbcontroller.cpp
index fe6aee94..209af979 100644
--- a/krfb/krfb/rfbcontroller.cpp
+++ b/krfb/krfb/rfbcontroller.cpp
@@ -185,14 +185,13 @@ const int KeyboardEvent::LEFTSHIFT = 1;
const int KeyboardEvent::RIGHTSHIFT = 2;
const int KeyboardEvent::ALTGR = 4;
char KeyboardEvent::ModifierState;
-
-static KeySym added_keysyms[0x100];
+KeySym KeyboardEvent::added_keysyms[0x100];
KeyboardEvent::KeyboardEvent(bool d, KeySym k) :
down(d),
keySym(k) {
- if(k && !IsModifierKey(k)) add_keysym(k);
+ if(k && !IsModifierKey(k) && XKeysymToKeycode(dpy,k) == NoSymbol) add_keysym(k);
}
void KeyboardEvent::initKeycodes() {
@@ -244,17 +243,18 @@ int KeyboardEvent::add_keysym( KeySym keysym )
int minkey, maxkey, syms_per_keycode, kc, ret = 0;
XDisplayKeycodes(dpy, &minkey, &maxkey);
+
+ repeate:
KeySym *keymap = XGetKeyboardMapping(dpy, minkey, (maxkey-minkey+1), &syms_per_keycode);
+ bool is_empty = true;
for(int kc = minkey+1; kc <= maxkey; kc++) {
- int j, didmsg = 0, is_empty = 1;
- char *str;
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)
- { is_empty = 0; break; }
- }
+ { is_empty = false; break; }
if(!is_empty) continue;
for(int i = 0; i < 8; i++) newks[i] = NoSymbol;
@@ -270,12 +270,36 @@ int KeyboardEvent::add_keysym( KeySym keysym )
ret = kc;
break;
}
-
XFree(keymap);
+ if(!is_empty) { delete_added_keycodes(); goto repeate; }
+
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 */
void KeyboardEvent::tweakModifiers(signed char mod, bool down) {
@@ -433,6 +457,8 @@ RFBController::RFBController(Configuration *c) :
RFBController::~RFBController()
{
+ KeyboardEvent::delete_added_keycodes();
+
stopServer();
}
diff --git a/krfb/krfb/rfbcontroller.h b/krfb/krfb/rfbcontroller.h
index f762d2d1..6586593f 100644
--- a/krfb/krfb/rfbcontroller.h
+++ b/krfb/krfb/rfbcontroller.h
@@ -68,13 +68,15 @@ class KeyboardEvent : public VNCEvent {
static const int RIGHTSHIFT;
static const int ALTGR;
static char ModifierState;
+ static KeySym added_keysyms[0x100];
static void tweakModifiers(signed char mod, bool down);
public:
static void initKeycodes();
KeyboardEvent(bool d, KeySym k);
- int add_keysym( KeySym keysym );
+ static int add_keysym( KeySym keysym );
+ static void delete_added_keycodes( );
virtual void exec();
};