Added support for AltGr characters. This resolves issue #11.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/12/head
Michele Calgaro 4 years ago
parent c4eebbfcf4
commit 85af0341dc
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -197,7 +197,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
caps->resize ( 63,30 ); caps->resize ( 63,30 );
caps->setText ( "Caps" ); caps->setText ( "Caps" );
caps->setToggleButton ( true ); 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); other_keys.append(caps);
caps->res(); caps->res();
@ -246,7 +246,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
lshift->resize ( 45,30 ); lshift->resize ( 45,30 );
lshift->setText ( "Shift" ); lshift->setText ( "Shift" );
lshift->setToggleButton ( true ); 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 ); mod_keys.append ( lshift );
lshift->res(); lshift->res();
@ -295,7 +295,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
rshift->resize ( 68,30 ); rshift->resize ( 68,30 );
rshift->setText ( "Shift" ); rshift->setText ( "Shift" );
rshift->setToggleButton ( true ); 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 ); mod_keys.append ( rshift );
rshift->res(); rshift->res();
@ -342,6 +342,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
ralt->setText ( "AltGr" ); ralt->setText ( "AltGr" );
ralt->setKeyCode ( 108 ); ralt->setKeyCode ( 108 );
ralt->setToggleButton ( true ); ralt->setToggleButton ( true );
connect ( ralt,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShiftCapsAltGr ( unsigned int ) ) );
mod_keys.append ( ralt ); mod_keys.append ( ralt );
ralt->res(); ralt->res();
@ -849,19 +850,20 @@ void MainWidget::updateNumlock()
} }
} }
void MainWidget::toggleShift(unsigned int keycode) void MainWidget::toggleShiftCapsAltGr(unsigned int keycode)
{ {
send_key(keycode); send_key(keycode);
updateShiftCaps(); updateShiftCapsAltGr();
} }
void MainWidget::updateShiftCaps() void MainWidget::updateShiftCapsAltGr()
{ {
bool shiftState = lshift->isOn() || rshift->isOn(); bool shiftState = lshift->isOn() || rshift->isOn();
bool capsState = caps->isOn(); bool capsState = caps->isOn();
bool altGrState = ralt->isOn();
for (unsigned a = 0; a < btns.size(); a++) 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); mod_keys[a]->setOn(false);
} }
// Make sure the key labels are correctly updated // Make sure the key labels are correctly updated
updateShiftCaps(); updateShiftCapsAltGr();
} }
void MainWidget::send_key(unsigned int keycode) void MainWidget::send_key(unsigned int keycode)
@ -926,7 +928,7 @@ void MainWidget::queryModState()
if (caps_state != caps->isOn()) if (caps_state != caps->isOn())
{ {
caps->setOn(caps_state); caps->setOn(caps_state);
updateShiftCaps(); updateShiftCapsAltGr();
} }
bool numl_state = keyState(XK_Num_Lock); bool numl_state = keyState(XK_Num_Lock);
@ -944,7 +946,7 @@ void MainWidget::mappingNotify(XMappingEvent *)
btns[a]->setupTexts(display); btns[a]->setupTexts(display);
} }
updateNumlock(); updateNumlock();
updateShiftCaps(); updateShiftCapsAltGr();
} }
KbdDock::KbdDock ( MainWidget *m ) KbdDock::KbdDock ( MainWidget *m )

@ -51,7 +51,7 @@ public:
public slots: public slots:
void keyPress(unsigned int keycode); void keyPress(unsigned int keycode);
void toggleNumlock(); void toggleNumlock();
void toggleShift(unsigned int keycode); void toggleShiftCapsAltGr(unsigned int keycode);
void toggleNumericPad(); void toggleNumericPad();
void toggleFontAutoRes(); void toggleFontAutoRes();
void toggleLock(); void toggleLock();
@ -73,7 +73,7 @@ protected:
private: private:
void updateFont(); void updateFont();
void updateNumlock(); void updateNumlock();
void updateShiftCaps(); void updateShiftCapsAltGr();
bool nresize; bool nresize;

@ -28,61 +28,112 @@ void VButton::setupTexts(Display *display)
{ {
// normal text // normal text
KeySym keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 0); KeySym keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 0);
TQChar c((uint)keysym2ucs(keysym_c)); TQChar nc((uint)keysym2ucs(keysym_c));
if (c == '&') if (nc == '&')
{ {
setText("&&"); setText("&&");
} }
else else
{ {
setText(c); setText(nc);
} }
// shift text // shift text
keysym_c = XkbKeycodeToKeysym(display, keycode, 0, 1); 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); 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 == '&') if (c == '&')
{ {
setShiftText("&&"); altGrShiftText = "&&";
} }
else 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 // Caps does not seem to make any difference when AltGr is pressed
if (caps && shift) if (shift)
{
TQPushButton::setText(capsShiftText);
}
else if (caps)
{
TQPushButton::setText(capsText);
}
else if (shift)
{ {
TQPushButton::setText(shiftText); TQPushButton::setText(altGrShiftText);
} }
else else
{ {
TQPushButton::setText(normalText); TQPushButton::setText(altGrText);
} }
} }
else else
{ {
// Non alpha button, only shift affects its state if (isAlpha)
if (shift)
{ {
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 else
{ {
TQPushButton::setText(normalText); // Non alpha button, only shift affects its state
if (shift)
{
TQPushButton::setText(shiftText);
}
else
{
TQPushButton::setText(normalText);
}
} }
} }
} }

@ -34,14 +34,16 @@ protected:
TQString normalText; TQString normalText;
TQString capsText; TQString capsText;
TQString shiftText; TQString shiftText;
TQString altGrText;
TQString capsShiftText; TQString capsShiftText;
TQString altGrShiftText;
TQRect orig_size; TQRect orig_size;
void timerEvent ( TQTimerEvent * ); void timerEvent ( TQTimerEvent * );
public slots: public slots:
void sendKey(); void sendKey();
void shiftCapsPressed(bool shift, bool caps); void shiftCapsAltGrPressed(bool shift, bool caps, bool altGrState);
protected slots: protected slots:
void enterEvent(TQEvent *e); void enterEvent(TQEvent *e);

Loading…
Cancel
Save