summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2021-03-25 10:01:12 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2021-03-26 13:18:54 +0900
commit85af0341dc94a5a65d3643f53d95c21d40017c1c (patch)
tree362b74dd24ca92b77265d8ff6c6a85c783258ce0
parentc4eebbfcf4a070aef2ee77726cc45d9eb62ee235 (diff)
downloadkvkbd-85af0341dc94a5a65d3643f53d95c21d40017c1c.tar.gz
kvkbd-85af0341dc94a5a65d3643f53d95c21d40017c1c.zip
Added support for AltGr characters. This resolves issue #11.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--src/MainWidget.cpp22
-rw-r--r--src/MainWidget.h4
-rw-r--r--src/VButton.cpp97
-rw-r--r--src/VButton.h4
4 files changed, 91 insertions, 36 deletions
diff --git a/src/MainWidget.cpp b/src/MainWidget.cpp
index c8558ae..076ebf7 100644
--- a/src/MainWidget.cpp
+++ b/src/MainWidget.cpp
@@ -197,7 +197,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
caps->resize ( 63,30 );
caps->setText ( "Caps" );
caps->setToggleButton ( true );
- connect ( caps,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift ( unsigned int ) ) );
+ connect ( caps,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShiftCapsAltGr ( unsigned int ) ) );
other_keys.append(caps);
caps->res();
@@ -246,7 +246,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
lshift->resize ( 45,30 );
lshift->setText ( "Shift" );
lshift->setToggleButton ( true );
- connect ( lshift,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift( unsigned int ) ) );
+ connect ( lshift,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShiftCapsAltGr( unsigned int ) ) );
mod_keys.append ( lshift );
lshift->res();
@@ -295,7 +295,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
rshift->resize ( 68,30 );
rshift->setText ( "Shift" );
rshift->setToggleButton ( true );
- connect ( rshift,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift( unsigned int ) ) );
+ connect ( rshift,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShiftCapsAltGr( unsigned int ) ) );
mod_keys.append ( rshift );
rshift->res();
@@ -342,6 +342,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
ralt->setText ( "AltGr" );
ralt->setKeyCode ( 108 );
ralt->setToggleButton ( true );
+ connect ( ralt,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShiftCapsAltGr ( unsigned int ) ) );
mod_keys.append ( ralt );
ralt->res();
@@ -849,19 +850,20 @@ void MainWidget::updateNumlock()
}
}
-void MainWidget::toggleShift(unsigned int keycode)
+void MainWidget::toggleShiftCapsAltGr(unsigned int keycode)
{
send_key(keycode);
- updateShiftCaps();
+ updateShiftCapsAltGr();
}
-void MainWidget::updateShiftCaps()
+void MainWidget::updateShiftCapsAltGr()
{
bool shiftState = lshift->isOn() || rshift->isOn();
bool capsState = caps->isOn();
+ bool altGrState = ralt->isOn();
for (unsigned a = 0; a < btns.size(); a++)
{
- btns[a]->shiftCapsPressed(shiftState, capsState);
+ btns[a]->shiftCapsAltGrPressed(shiftState, capsState, altGrState);
}
}
@@ -873,7 +875,7 @@ void MainWidget::keyPress(unsigned int a)
mod_keys[a]->setOn(false);
}
// Make sure the key labels are correctly updated
- updateShiftCaps();
+ updateShiftCapsAltGr();
}
void MainWidget::send_key(unsigned int keycode)
@@ -926,7 +928,7 @@ void MainWidget::queryModState()
if (caps_state != caps->isOn())
{
caps->setOn(caps_state);
- updateShiftCaps();
+ updateShiftCapsAltGr();
}
bool numl_state = keyState(XK_Num_Lock);
@@ -944,7 +946,7 @@ void MainWidget::mappingNotify(XMappingEvent *)
btns[a]->setupTexts(display);
}
updateNumlock();
- updateShiftCaps();
+ updateShiftCapsAltGr();
}
KbdDock::KbdDock ( MainWidget *m )
diff --git a/src/MainWidget.h b/src/MainWidget.h
index 7ea342a..126aeeb 100644
--- a/src/MainWidget.h
+++ b/src/MainWidget.h
@@ -51,7 +51,7 @@ public:
public slots:
void keyPress(unsigned int keycode);
void toggleNumlock();
- void toggleShift(unsigned int keycode);
+ void toggleShiftCapsAltGr(unsigned int keycode);
void toggleNumericPad();
void toggleFontAutoRes();
void toggleLock();
@@ -73,7 +73,7 @@ protected:
private:
void updateFont();
void updateNumlock();
- void updateShiftCaps();
+ void updateShiftCapsAltGr();
bool nresize;
diff --git a/src/VButton.cpp b/src/VButton.cpp
index 1959990..95d31e2 100644
--- a/src/VButton.cpp
+++ b/src/VButton.cpp
@@ -28,61 +28,112 @@ void VButton::setupTexts(Display *display)
{
// normal text
KeySym keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 0);
- TQChar c((uint)keysym2ucs(keysym_c));
- if (c == '&')
+ TQChar nc((uint)keysym2ucs(keysym_c));
+ if (nc == '&')
{
setText("&&");
}
else
{
- setText(c);
+ setText(nc);
}
// shift text
keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 1);
+ TQChar sc = (uint)keysym2ucs(keysym_c);
+ if (sc == '&')
+ {
+ setShiftText("&&");
+ }
+ else
+ {
+ setShiftText(sc);
+ }
+
+ // altGr text
+ keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 2);
+ TQChar c = (uint)keysym2ucs(keysym_c);
+ if (c == " ")
+ {
+ // use normal text in case altGr does not provide extra characters.
+ // This is required at least on US keyboards, where altGr works as Alt.
+ c = nc;
+ }
+ if (c == '&')
+ {
+ altGrText = "&&";
+ }
+ else
+ {
+ altGrText = c;
+ }
+
+ // altGr + shift text
+ keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 3);
c = (uint)keysym2ucs(keysym_c);
+ if (c == " ")
+ {
+ // use shift text in case altGr does not provide extra characters.
+ // This is required at least on US keyboards, where altGr works as Alt.
+ c = sc;
+ }
if (c == '&')
{
- setShiftText("&&");
+ altGrShiftText = "&&";
}
else
{
- setShiftText(c);
+ altGrShiftText = c;
}
}
-void VButton::shiftCapsPressed(bool shift, bool caps)
+void VButton::shiftCapsAltGrPressed(bool shift, bool caps, bool altGrState)
{
- if (isAlpha)
+ if (altGrState)
{
- // Alpha button, both shift and caps affect its state
- if (caps && shift)
- {
- TQPushButton::setText(capsShiftText);
- }
- else if (caps)
- {
- TQPushButton::setText(capsText);
- }
- else if (shift)
+ // Caps does not seem to make any difference when AltGr is pressed
+ if (shift)
{
- TQPushButton::setText(shiftText);
+ TQPushButton::setText(altGrShiftText);
}
else
{
- TQPushButton::setText(normalText);
+ TQPushButton::setText(altGrText);
}
}
else
{
- // Non alpha button, only shift affects its state
- if (shift)
+ if (isAlpha)
{
- TQPushButton::setText(shiftText);
+ // Alpha button, both shift and caps affect its state
+ if (caps && shift)
+ {
+ TQPushButton::setText(capsShiftText);
+ }
+ else if (caps)
+ {
+ TQPushButton::setText(capsText);
+ }
+ else if (shift)
+ {
+ TQPushButton::setText(shiftText);
+ }
+ else
+ {
+ TQPushButton::setText(normalText);
+ }
}
else
{
- TQPushButton::setText(normalText);
+ // Non alpha button, only shift affects its state
+ if (shift)
+ {
+ TQPushButton::setText(shiftText);
+ }
+ else
+ {
+ TQPushButton::setText(normalText);
+ }
}
}
}
diff --git a/src/VButton.h b/src/VButton.h
index 782eefa..86a58ee 100644
--- a/src/VButton.h
+++ b/src/VButton.h
@@ -34,14 +34,16 @@ protected:
TQString normalText;
TQString capsText;
TQString shiftText;
+ TQString altGrText;
TQString capsShiftText;
+ TQString altGrShiftText;
TQRect orig_size;
void timerEvent ( TQTimerEvent * );
public slots:
void sendKey();
- void shiftCapsPressed(bool shift, bool caps);
+ void shiftCapsAltGrPressed(bool shift, bool caps, bool altGrState);
protected slots:
void enterEvent(TQEvent *e);