Commit e0ee3669 authored by Anatoly Mihalchenko's avatar Anatoly Mihalchenko

Virtual keyboard improvement

parent ca020305
...@@ -299,6 +299,7 @@ ...@@ -299,6 +299,7 @@
<file>images/virtual.keyboard/41/right-active.png</file> <file>images/virtual.keyboard/41/right-active.png</file>
<file>images/virtual.keyboard/41/backspace.png</file> <file>images/virtual.keyboard/41/backspace.png</file>
<file>images/virtual.keyboard/41/capslock.png</file> <file>images/virtual.keyboard/41/capslock.png</file>
<file>images/virtual.keyboard/41/shift.png</file>
<file>images/virtual.keyboard/41/tab.png</file> <file>images/virtual.keyboard/41/tab.png</file>
<file>images/virtual.keyboard/29/centre-passive.png</file> <file>images/virtual.keyboard/29/centre-passive.png</file>
<file>images/virtual.keyboard/29/left-passive.png</file> <file>images/virtual.keyboard/29/left-passive.png</file>
...@@ -308,6 +309,7 @@ ...@@ -308,6 +309,7 @@
<file>images/virtual.keyboard/29/right-active.png</file> <file>images/virtual.keyboard/29/right-active.png</file>
<file>images/virtual.keyboard/29/backspace.png</file> <file>images/virtual.keyboard/29/backspace.png</file>
<file>images/virtual.keyboard/29/capslock.png</file> <file>images/virtual.keyboard/29/capslock.png</file>
<file>images/virtual.keyboard/29/shift.png</file>
<file>images/virtual.keyboard/29/tab.png</file> <file>images/virtual.keyboard/29/tab.png</file>
<file>images/toolPalette/cacheTool.png</file> <file>images/toolPalette/cacheTool.png</file>
<file>images/libpalette/FlashCategory.svg</file> <file>images/libpalette/FlashCategory.svg</file>
......
...@@ -57,4 +57,5 @@ UBKeyboardLocale** UBPlatformUtils::getKeyboardLayouts(int& nCount) ...@@ -57,4 +57,5 @@ UBKeyboardLocale** UBPlatformUtils::getKeyboardLayouts(int& nCount)
{ {
nCount = nKeyboardLayouts; nCount = nKeyboardLayouts;
return keyboardLayouts; return keyboardLayouts;
} }
\ No newline at end of file
...@@ -23,30 +23,82 @@ class QMainWindow; ...@@ -23,30 +23,82 @@ class QMainWindow;
#define SYMBOL_KEYS_COUNT 47 #define SYMBOL_KEYS_COUNT 47
struct KEYCODE{
KEYCODE()
:symbol(0)
,code(0)
,modifier(0)
{}
KEYCODE(int _symbol)
:symbol(_symbol)
,code(0)
,modifier(0)
{}
KEYCODE(int _symbol,
unsigned char _code,
int _modifier)
:symbol(_symbol)
,code(_code)
,modifier(_modifier)
{}
bool empty() const
{
return symbol == 0;
}
int symbol;
unsigned char code;
int modifier;
};
struct KEYBT struct KEYBT
{ {
const QChar symbol1; QChar symbol1;
const int code1; QChar symbol2;
const QChar symbol2; bool capsLockSwitch;
const int code2; int modifier1;
int modifier2;
KEYBT(unsigned int _symbol1, KEYCODE codes[8];
unsigned int _symbol2):
symbol1(_symbol1), KEYBT( QChar _symbol1,
code1(_symbol1), QChar _symbol2,
symbol2(_symbol2), bool _capsLockSwitch,
code2(_symbol2){} int _modifier1,
int _modifier2,
KEYCODE c1 = 0,
KEYBT(QChar _symbol1, KEYCODE c2 = 0,
int _code1, KEYCODE c3 = 0,
QChar _symbol2, KEYCODE c4 = 0,
int _code2): KEYCODE c5 = 0,
symbol1(_symbol1), KEYCODE c6 = 0,
code1(_code1), KEYCODE c7 = 0,
symbol2(_symbol2), KEYCODE c8 = 0)
code2(_code2){} :symbol1(_symbol1)
}; ,symbol2(_symbol2)
,capsLockSwitch(_capsLockSwitch)
,modifier1(_modifier1)
,modifier2(_modifier2)
{
codes[0] = c1;
codes[1] = c2;
codes[2] = c3;
codes[3] = c4;
codes[4] = c5;
codes[5] = c6;
codes[6] = c7;
codes[7] = c8;
}
~KEYBT()
{}
};
class UBKeyboardLocale class UBKeyboardLocale
{ {
...@@ -63,7 +115,7 @@ struct KEYBT ...@@ -63,7 +115,7 @@ struct KEYBT
const QString& _name, const QString& _name,
const QString& _id, const QString& _id,
QIcon* _icon, QIcon* _icon,
const KEYBT _symbols[]) KEYBT _symbols[])
:fullName(_fullName),name(_name), id(_id), icon(_icon), :fullName(_fullName),name(_name), id(_id), icon(_icon),
constSymbols(_symbols), varSymbols(NULL) constSymbols(_symbols), varSymbols(NULL)
{} {}
...@@ -74,12 +126,12 @@ struct KEYBT ...@@ -74,12 +126,12 @@ struct KEYBT
const QString name; const QString name;
const QString id; const QString id;
QIcon* icon; QIcon* icon;
const KEYBT* operator[] (int index) const KEYBT* operator[] (int index) const
{ {
return (varSymbols==NULL)? constSymbols + index : varSymbols[index]; return (varSymbols==NULL)? constSymbols + index : varSymbols[index];
} }
private: private:
const KEYBT* constSymbols; KEYBT* constSymbols;
KEYBT** varSymbols; KEYBT** varSymbols;
}; };
......
This diff is collapsed.
...@@ -10,8 +10,12 @@ ...@@ -10,8 +10,12 @@
#import <Foundation/NSAutoreleasePool.h> #import <Foundation/NSAutoreleasePool.h>
#import <Carbon/Carbon.h> #import <Carbon/Carbon.h>
#import <APELite.h> #import <APELite.h>
/*
// commented because Sankore crashes on Java Script. It seems to backends dependencies.
#import <WebKit/WebKit.h> #import <WebKit/WebKit.h>
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
*/
NSString* bundleShortVersion(NSBundle *bundle) NSString* bundleShortVersion(NSBundle *bundle)
...@@ -409,14 +413,15 @@ KEYBT* createKeyBt(const UCKeyboardLayout* keyLayout, int vkk) ...@@ -409,14 +413,15 @@ KEYBT* createKeyBt(const UCKeyboardLayout* keyLayout, int vkk)
UInt32 deadKeyState = 0L; UInt32 deadKeyState = 0L;
UInt32 kbdType = kKeyboardISO; UInt32 kbdType = kKeyboardISO;
UniCharCount cnt1, cnt2; UniCharCount cnt1, cnt2, cnt3;
UniChar unicodeString1[100], unicodeString2[100]; UniChar unicodeString1[100], unicodeString2[100], unicodeString3[100];
UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, 0, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt1, unicodeString1); UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, 0, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt1, unicodeString1);
UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, (shiftKey >> 8) & 0xff, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt2, unicodeString2); UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, (shiftKey >> 8) & 0xff, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt2, unicodeString2);
UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, (alphaLock >> 8) & 0xff, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt2, unicodeString3);
return new KEYBT(unicodeString1[0], vkk, unicodeString2[0], vkk); return new KEYBT(unicodeString1[0], unicodeString2[0], unicodeString1[0] != unicodeString3[0], 0,0, KEYCODE(0, vkk, 0), KEYCODE(0, vkk, 1));
} }
void UBPlatformUtils::initializeKeyboardLayouts() void UBPlatformUtils::initializeKeyboardLayouts()
...@@ -543,13 +548,14 @@ void UBPlatformUtils::destroyKeyboardLayouts() ...@@ -543,13 +548,14 @@ void UBPlatformUtils::destroyKeyboardLayouts()
QString UBPlatformUtils::urlFromClipboard() QString UBPlatformUtils::urlFromClipboard()
{ {
QString qsRet; QString qsRet;
/*
// commented because Sankore crashes on Java Script. It seems to backends dependencies.
NSPasteboard* pPasteboard = [NSPasteboard pasteboardWithName:@"Apple CFPasteboard drag"]; NSPasteboard* pPasteboard = [NSPasteboard pasteboardWithName:@"Apple CFPasteboard drag"];
WebArchive* pArchive = [[WebArchive alloc] initWithData:[pPasteboard dataForType:@"com.apple.webarchive"]]; WebArchive* pArchive = [[WebArchive alloc] initWithData:[pPasteboard dataForType:@"com.apple.webarchive"]];
qsRet = [[[[pArchive mainResource] URL] absoluteString] UTF8String]; qsRet = [[[[pArchive mainResource] URL] absoluteString] UTF8String];
[pArchive release]; [pArchive release];
*/
return qsRet; return qsRet;
} }
This diff is collapsed.
...@@ -38,11 +38,16 @@ UBKeyboardPalette::UBKeyboardPalette(QWidget *parent) ...@@ -38,11 +38,16 @@ UBKeyboardPalette::UBKeyboardPalette(QWidget *parent)
setGrip(false); setGrip(false);
capsLock = false; capsLock = false;
shift = false;
languagePopupActive = false; languagePopupActive = false;
keyboardActive = false; keyboardActive = false;
nSpecialModifierIndex = 0;
specialModifier = 0;
btnWidth = btnHeight = 16; btnWidth = btnHeight = 16;
strSize = "16x16"; strSize = "16x16";
currBtnImages = new BTNImages("16", btnWidth, btnHeight); currBtnImages = new BTNImages("16", btnWidth, btnHeight);
storage = NULL;
buttons = new UBKeyButton*[47]; buttons = new UBKeyButton*[47];
for (int i=0; i<47; i++) for (int i=0; i<47; i++)
...@@ -77,7 +82,7 @@ void UBKeyboardPalette::init() ...@@ -77,7 +82,7 @@ void UBKeyboardPalette::init()
//------------------------------// //------------------------------//
UBPlatformUtils::setWindowNonActivableFlag(this, true); UBPlatformUtils::setWindowNonActivableFlag(this, true);
} }
void UBKeyboardPalette::showKeyboard(bool show) void UBKeyboardPalette::showKeyboard(bool show)
...@@ -143,6 +148,8 @@ UBKeyboardPalette::~UBKeyboardPalette() ...@@ -143,6 +148,8 @@ UBKeyboardPalette::~UBKeyboardPalette()
delete currBtnImages; delete currBtnImages;
currBtnImages = NULL; currBtnImages = NULL;
} }
onActivated(false);
} }
QSize UBKeyboardPalette::sizeHint () const QSize UBKeyboardPalette::sizeHint () const
...@@ -302,8 +309,10 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event) ...@@ -302,8 +309,10 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event)
//------------------- //-------------------
// // Row 3 Stub // // Row 3 Stub
// ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth, btnHeight);
// offX += btnWidth; // button Enter
ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth * 1, btnHeight);
offX += btnWidth*1;
// buttons [a]..[\] // buttons [a]..[\]
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
...@@ -313,8 +322,8 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event) ...@@ -313,8 +322,8 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event)
} }
// button Enter // button Enter
ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth * 3, btnHeight); ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth * 2, btnHeight);
offX += btnWidth*3; offX += btnWidth*2;
//------------------------------------------------ //------------------------------------------------
// set geometry (position) for row 4 // set geometry (position) for row 4
...@@ -353,6 +362,11 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event) ...@@ -353,6 +362,11 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event)
//------------------------------------------------ //------------------------------------------------
} }
void UBKeyboardPalette::onDeactivated()
{
onActivated(false);
}
//-----------------------------------------------------------------------// //-----------------------------------------------------------------------//
// BTNImages Class // BTNImages Class
...@@ -415,6 +429,11 @@ UBKeyboardButton::~UBKeyboardButton() ...@@ -415,6 +429,11 @@ UBKeyboardButton::~UBKeyboardButton()
} }
} }
bool UBKeyboardButton::isPressed()
{
return bPressed;
}
void UBKeyboardButton::paintEvent(QPaintEvent*) void UBKeyboardButton::paintEvent(QPaintEvent*)
{ {
...@@ -437,7 +456,7 @@ void UBKeyboardButton::paintEvent(QPaintEvent*) ...@@ -437,7 +456,7 @@ void UBKeyboardButton::paintEvent(QPaintEvent*)
//-------------------------- //--------------------------
if (bPressed) if (isPressed())
{ {
painter.drawImage( 0,0, m_parent->currBtnImages->m_btnLeftActive, 0,0, m_parent->currBtnImages->m_btnLeftActive.width(), m_parent->currBtnImages->m_btnLeftActive.height() ); painter.drawImage( 0,0, m_parent->currBtnImages->m_btnLeftActive, 0,0, m_parent->currBtnImages->m_btnLeftActive.width(), m_parent->currBtnImages->m_btnLeftActive.height() );
painter.drawImage( QRect(m_parent->currBtnImages->m_btnLeftActive.width(), 0, width() - m_parent->currBtnImages->m_btnLeftActive.width() - m_parent->currBtnImages->m_btnRightActive.width(), height()), m_parent->currBtnImages->m_btnCenterActive ); painter.drawImage( QRect(m_parent->currBtnImages->m_btnLeftActive.width(), 0, width() - m_parent->currBtnImages->m_btnLeftActive.width() - m_parent->currBtnImages->m_btnRightActive.width(), height()), m_parent->currBtnImages->m_btnCenterActive );
...@@ -471,7 +490,7 @@ void UBKeyboardButton::leaveEvent ( QEvent*) ...@@ -471,7 +490,7 @@ void UBKeyboardButton::leaveEvent ( QEvent*)
void UBKeyboardButton::mousePressEvent ( QMouseEvent * event) void UBKeyboardButton::mousePressEvent ( QMouseEvent * event)
{ {
event->accept(); event->accept();
bPressed = true; bPressed = true;
update(); update();
this->onPress(); this->onPress();
...@@ -492,10 +511,55 @@ UBKeyButton::UBKeyButton(UBKeyboardPalette* parent) ...@@ -492,10 +511,55 @@ UBKeyButton::UBKeyButton(UBKeyboardPalette* parent)
UBKeyButton::~UBKeyButton() UBKeyButton::~UBKeyButton()
{} {}
bool UBKeyButton::shifted()
{
bool b = keyboard->shift;
if (keybt->capsLockSwitch && keyboard->capsLock)
b = !b;
return b;
}
void UBKeyButton::onPress() void UBKeyButton::onPress()
{ {
if (keybt!=NULL) if (keybt!=NULL)
sendUnicodeSymbol(keybt->code1, keybt->code2, capsLock()); {
int codeIndex = keyboard->nSpecialModifierIndex * 2 + shifted();
if (keyboard->nSpecialModifierIndex)
{
if (keybt->codes[codeIndex].empty())
{
sendUnicodeSymbol(keyboard->specialModifier);
sendUnicodeSymbol(keybt->codes[shifted()]);
}
else
{
sendUnicodeSymbol(keybt->codes[codeIndex]);
}
keyboard->nSpecialModifierIndex = 0;
}
else
{
int nSpecialModifierIndex = shifted()? keybt->modifier2 : keybt->modifier1;
if (nSpecialModifierIndex)
{
keyboard->nSpecialModifierIndex = nSpecialModifierIndex;
keyboard->specialModifier = keybt->codes[codeIndex];
}
else
{
sendUnicodeSymbol(keybt->codes[codeIndex]);
}
}
}
if (keyboard->shift)
{
keyboard->shift = false;
keyboard->update();
}
} }
void UBKeyButton::onRelease() void UBKeyButton::onRelease()
...@@ -505,7 +569,7 @@ void UBKeyButton::paintContent(QPainter& painter) ...@@ -505,7 +569,7 @@ void UBKeyButton::paintContent(QPainter& painter)
{ {
if (keybt) if (keybt)
{ {
QString text(QChar(capsLock() ? keybt->symbol2 : keybt->symbol1)); QString text(QChar(shifted() ? keybt->symbol2 : keybt->symbol1));
QRect textRect(rect().x()+2, rect().y()+2, rect().width()-4, rect().height()-4); QRect textRect(rect().x()+2, rect().y()+2, rect().width()-4, rect().height()-4);
painter.drawText(textRect, Qt::AlignCenter, text); painter.drawText(textRect, Qt::AlignCenter, text);
} }
...@@ -565,6 +629,11 @@ void UBCapsLockButton::onPress() ...@@ -565,6 +629,11 @@ void UBCapsLockButton::onPress()
void UBCapsLockButton::onRelease() void UBCapsLockButton::onRelease()
{} {}
bool UBCapsLockButton::isPressed()
{
return keyboard->capsLock;
}
void UBCapsLockButton::paintContent(QPainter& painter) void UBCapsLockButton::paintContent(QPainter& painter)
{ {
if(imgContent != NULL) if(imgContent != NULL)
...@@ -576,6 +645,40 @@ void UBCapsLockButton::paintContent(QPainter& painter) ...@@ -576,6 +645,40 @@ void UBCapsLockButton::paintContent(QPainter& painter)
painter.drawText(rect(), Qt::AlignCenter, "^"); painter.drawText(rect(), Qt::AlignCenter, "^");
} }
UBShiftButton::UBShiftButton(UBKeyboardPalette* parent, const QString _contentImagePath)
:UBKeyboardButton(parent, _contentImagePath)
{}
UBShiftButton::~UBShiftButton()
{}
void UBShiftButton::onPress()
{
keyboard->shift = !keyboard->shift;
keyboard->update();
}
void UBShiftButton::onRelease()
{}
bool UBShiftButton::isPressed()
{
return keyboard->shift;
}
void UBShiftButton::paintContent(QPainter& painter)
{
if(imgContent != NULL)
{
painter.drawImage(( rect().width() - imgContent->m_btnContent.width() ) / 2, ( rect().height() - imgContent->m_btnContent.height() ) / 2,
imgContent->m_btnContent, 0,0, imgContent->m_btnContent.width(), imgContent->m_btnContent.height());
}
else
painter.drawText(rect(), Qt::AlignCenter, "^");
}
UBLocaleButton::UBLocaleButton(UBKeyboardPalette* parent) UBLocaleButton::UBLocaleButton(UBKeyboardPalette* parent)
:UBKeyboardButton(parent) :UBKeyboardButton(parent)
......
...@@ -64,7 +64,9 @@ class UBKeyboardPalette : public UBActionPalette ...@@ -64,7 +64,9 @@ class UBKeyboardPalette : public UBActionPalette
friend class UBKeyboardButton; friend class UBKeyboardButton;
friend class UBCapsLockButton; friend class UBCapsLockButton;
friend class UBShiftButton;
friend class UBLocaleButton; friend class UBLocaleButton;
friend class UBKeyButton;
public: public:
UBKeyboardPalette(QWidget *parent); UBKeyboardPalette(QWidget *parent);
...@@ -97,10 +99,14 @@ private slots: ...@@ -97,10 +99,14 @@ private slots:
protected: protected:
bool capsLock; bool capsLock;
bool shift;
int nCurrentLocale; int nCurrentLocale;
int nLocalesCount; int nLocalesCount;
UBKeyboardLocale** locales; UBKeyboardLocale** locales;
int nSpecialModifierIndex;
KEYCODE specialModifier;
QString strSize; QString strSize;
int btnWidth; int btnWidth;
int btnHeight; int btnHeight;
...@@ -113,7 +119,7 @@ protected: ...@@ -113,7 +119,7 @@ protected:
virtual void paintEvent(QPaintEvent *event); virtual void paintEvent(QPaintEvent *event);
virtual void moveEvent ( QMoveEvent * event ); virtual void moveEvent ( QMoveEvent * event );
void sendKeyEvent(const KEYBT& keybt); void sendKeyEvent(KEYCODE keyCode);
void setLocale(int nLocale); void setLocale(int nLocale);
...@@ -170,11 +176,11 @@ protected: ...@@ -170,11 +176,11 @@ protected:
virtual void onRelease() = 0; virtual void onRelease() = 0;
virtual void paintContent(QPainter& painter) = 0; virtual void paintContent(QPainter& painter) = 0;
bool capsLock(){return keyboard->capsLock;} virtual bool isPressed();
UBKeyboardPalette* keyboard; UBKeyboardPalette* keyboard;
void sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift); void sendUnicodeSymbol(KEYCODE keycode);
void sendControlSymbol(int nSymbol); void sendControlSymbol(int nSymbol);
private: private:
...@@ -197,6 +203,7 @@ public: ...@@ -197,6 +203,7 @@ public:
virtual void paintContent(QPainter& painter); virtual void paintContent(QPainter& painter);
private: private:
bool shifted();
const KEYBT* keybt; const KEYBT* keybt;
}; };
...@@ -229,8 +236,28 @@ public: ...@@ -229,8 +236,28 @@ public:
virtual void onPress(); virtual void onPress();
virtual void onRelease(); virtual void onRelease();
virtual void paintContent(QPainter& painter); virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
};
class UBShiftButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBShiftButton(UBKeyboardPalette* parent, const QString _contentImagePath);
~UBShiftButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
}; };
class UBLocaleButton : public UBKeyboardButton class UBLocaleButton : public UBKeyboardButton
{ {
Q_OBJECT Q_OBJECT
......
...@@ -70,22 +70,59 @@ void x11SendKey(Display *display, int keyCode, int modifiers) ...@@ -70,22 +70,59 @@ void x11SendKey(Display *display, int keyCode, int modifiers)
// Send a fake key release event to the window. // Send a fake key release event to the window.
event = createKeyEvent(display, winFocus, winRoot, false, keyCode, modifiers); event = createKeyEvent(display, winFocus, winRoot, false, keyCode, modifiers);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event); XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
} }
void UBKeyboardButton::sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift) void traceKeyCodes()
{ {
unsigned int nSymbol = shift ? nSymbol2 : nSymbol1; Display *display = XOpenDisplay(0);
if(display == NULL)
return;
int min_keycodes, max_keycodes, byte_per_code;
XDisplayKeycodes(display, &min_keycodes, &max_keycodes);
KeySym* keySyms = XGetKeyboardMapping(display, min_keycodes,
max_keycodes - min_keycodes, &byte_per_code);
qDebug() << "Codes table, min_keycodes: " << min_keycodes << ", max_keycodes: "
<< max_keycodes << ", bytes_per_code:" << byte_per_code;
for(int i=0; i<max_keycodes - min_keycodes; i++)
{
QString str;
for(int j=0; j<byte_per_code;j++)
{
str += QString::number(keySyms[i*byte_per_code + j], 16);
str += ":";
}
qDebug() << i << ":" << str;
}
XFree(keySyms);
XCloseDisplay(display);
}
void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{
// Obtain the X11 display. // Obtain the X11 display.
Display *display = XOpenDisplay(0); Display *display = XOpenDisplay(0);
if(display == NULL) if(display == NULL)
return; return;
KeyCode keyCode = XKeysymToKeycode(display, nSymbol); if (!keycode.empty())
if (keyCode != NoSymbol)
{ {
x11SendKey(display, keyCode, shift); int modifier = keycode.modifier;
if (keycode.modifier==2) modifier = 0x2000;
if (keycode.modifier==3) modifier = 0x2001;
if (keycode.modifier==4) modifier = 0x4000;
if (keycode.modifier==5) modifier = 0x4001;
//modifiers 6 and 7 seems are not available.... They are reassigned in layout creationtime
//if (keycode.modifier==6) modifier = 0x6000;
//if (keycode.modifier==7) modifier = 0x6001;
x11SendKey(display, keycode.code + keyboard->min_keycodes , modifier);
} }
XCloseDisplay(display); XCloseDisplay(display);
...@@ -111,16 +148,17 @@ void UBKeyboardButton::sendControlSymbol(int nSymbol) ...@@ -111,16 +148,17 @@ void UBKeyboardButton::sendControlSymbol(int nSymbol)
void UBKeyboardPalette::createCtrlButtons() void UBKeyboardPalette::createCtrlButtons()
{ {
ctrlButtons = new UBKeyboardButton*[8]; ctrlButtons = new UBKeyboardButton*[9];
ctrlButtons[0] = new UBCntrlButton(this, "<-", XK_BackSpace); ctrlButtons[0] = new UBCntrlButton(this, XK_BackSpace, "backspace");
ctrlButtons[1] = new UBCntrlButton(this, "<->", XK_Tab); ctrlButtons[1] = new UBCntrlButton(this, XK_Tab, "tab");
ctrlButtons[2] = new UBCntrlButton(this, tr("Enter"), XK_Return); ctrlButtons[2] = new UBCapsLockButton(this, "capslock");
ctrlButtons[3] = new UBCapsLockButton(this, "capslock"); ctrlButtons[3] = new UBCntrlButton(this, tr("Enter"), XK_Return);
ctrlButtons[4] = new UBCapsLockButton(this, "capslock"); ctrlButtons[4] = new UBShiftButton(this, "shift");
ctrlButtons[5] = new UBLocaleButton(this); ctrlButtons[5] = new UBShiftButton(this, "shift");
ctrlButtons[6] = new UBCntrlButton(this, "", XK_space); ctrlButtons[6] = new UBLocaleButton(this);
ctrlButtons[7] = new UBLocaleButton(this); ctrlButtons[7] = new UBCntrlButton(this, "", XK_space);
ctrlButtons[8] = new UBLocaleButton(this);
} }
...@@ -128,90 +166,114 @@ void UBKeyboardPalette::onActivated(bool activated) ...@@ -128,90 +166,114 @@ void UBKeyboardPalette::onActivated(bool activated)
{ {
if (activated) if (activated)
{ {
if (storage)
{
qDebug() << "Keybard already activated....";
return;
}
Display *display = XOpenDisplay(0); Display *display = XOpenDisplay(0);
if(display == NULL) if(display == NULL)
return; return;
XDisplayKeycodes(display, &this->min_keycodes, &this->max_keycodes); XDisplayKeycodes(display, &this->min_keycodes, &this->max_keycodes);
KeySym* keySyms = XGetKeyboardMapping(display, min_keycodes, KeySym* keySyms = XGetKeyboardMapping(display, min_keycodes,
max_keycodes - min_keycodes, &this->byte_per_code); max_keycodes - min_keycodes, &byte_per_code);
storage = keySyms; storage = keySyms;
XCloseDisplay(display); XCloseDisplay(display);
qDebug() << "------------ ORIGINAL --------------------------------------------------";
traceKeyCodes();
onLocaleChanged(locales[nCurrentLocale]); onLocaleChanged(locales[nCurrentLocale]);
qDebug() << "------------ CUSTOM ------------------------------------------------";
traceKeyCodes();
qDebug() << "----------------------------------------------------------------------";
} }
else else
{ {
Display *display = XOpenDisplay(0); Display *display = XOpenDisplay(0);
if(display == NULL) if(display == NULL)
return; {
qDebug() << "Keybard not activated....";
return;
}
KeySym* keySyms = (KeySym*)storage; KeySym* keySyms = (KeySym*)storage;
if (keySyms!=NULL) if (keySyms!=NULL)
{ {
qDebug() << "Default key table restored.....";
XChangeKeyboardMapping(display, min_keycodes, byte_per_code, XChangeKeyboardMapping(display, min_keycodes, byte_per_code,
keySyms, max_keycodes - min_keycodes); keySyms, max_keycodes - min_keycodes);
XFree(keySyms); XFree(keySyms);
} storage = NULL;
}
XCloseDisplay(display); XCloseDisplay(display);
} }
} }
void UBKeyboardPalette::onDeactivated()
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale)
{ {
Display *display = XOpenDisplay(0); Display *display = XOpenDisplay(0);
if(display == NULL) if(display == NULL)
return; return;
KeySym* keySyms = (KeySym*)storage; int byte_per_code;
if (keySyms!=NULL) { KeySym* keySyms = XGetKeyboardMapping(display, min_keycodes,
XChangeKeyboardMapping(display, min_keycodes, byte_per_code, max_keycodes - min_keycodes, &byte_per_code);
keySyms, max_keycodes - min_keycodes);
}
XCloseDisplay(display);
}
void setSymbolsFromButton(Display *display, for(int i=0; i<SYMBOL_KEYS_COUNT; i++)
const UBKeyboardLocale& locale,
int byte_per_code,
int nFromSymbol,
int nFromButton,
int count)
{
KeySym* keySyms = new KeySym[count * byte_per_code];
for(int i = 0; i < count; i++)
{ {
keySyms[byte_per_code * i + 0] = // loop by keybt
keySyms[byte_per_code * i + 2] = locale[nFromButton + i]->code1; for(int j=0; j<8; j++)
{
keySyms[byte_per_code * i + 1] = KEYCODE& kc = (*locale)[i]->codes[j];
keySyms[byte_per_code * i + 3] = locale[nFromButton + i]->code2; if (!kc.empty())
{
for(int j=4; j<byte_per_code; j++) if (kc.modifier <= 5)
keySyms[byte_per_code * i + j] = NoSymbol; keySyms[kc.code * byte_per_code + kc.modifier] = kc.symbol;
}
}
} }
XChangeKeyboardMapping(display, nFromSymbol, byte_per_code, keySyms, count); //Now look for modifiers > 5 and reassign them to free places
delete [] keySyms; for(int i=0; i<SYMBOL_KEYS_COUNT; i++)
} {
// loop by keybt
for(int j=0; j<8; j++)
{
KEYCODE& kc = (*locale)[i]->codes[j];
if (!kc.empty())
{
if (kc.modifier > 5)
{
for(int i1=0; i1<SYMBOL_KEYS_COUNT; i1++)
for(int j1=0; j1<=5; j1++)
if (keySyms[i1 * byte_per_code + j1]==NoSymbol)
{
kc.code =i1;
kc.modifier =j1;
break;
}
}
keySyms[kc.code * byte_per_code + kc.modifier] = kc.symbol;
}
}
}
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale)
{
Display *display = XOpenDisplay(0);
if(display == NULL)
return;
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 41, 0, 1); XChangeKeyboardMapping(display, min_keycodes, byte_per_code, keySyms, max_keycodes - min_keycodes);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 2, 1, 12); XFree(keySyms);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 16, 13, 12);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 30, 25, 11);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 44, 37, 10);
XCloseDisplay(display); XCloseDisplay(display);
} }
...@@ -22,15 +22,13 @@ ...@@ -22,15 +22,13 @@
#include <QMap> #include <QMap>
#include <QString> #include <QString>
void UBKeyboardButton::sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift) void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{ {
unsigned int nSymbol = (shift)? nSymbol2 : nSymbol1; if (keycode.modifier)
if (shift)
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, true)); CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, true));
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, nSymbol, true)); CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, keycode.code, true));
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, nSymbol, false)); CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, keycode.code, false));
if (shift) if (keycode.modifier)
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, false)); CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, false));
} }
...@@ -46,16 +44,17 @@ void UBKeyboardButton::sendControlSymbol(int nSymbol) ...@@ -46,16 +44,17 @@ void UBKeyboardButton::sendControlSymbol(int nSymbol)
void UBKeyboardPalette::createCtrlButtons() void UBKeyboardPalette::createCtrlButtons()
{ {
ctrlButtons = new UBKeyboardButton*[7]; ctrlButtons = new UBKeyboardButton*[9];
ctrlButtons[0] = new UBCntrlButton(this, "<-", 51); ctrlButtons[0] = new UBCntrlButton(this, 51, "backspace");
ctrlButtons[1] = new UBCntrlButton(this, "<->", 48); ctrlButtons[1] = new UBCntrlButton(this, 48, "tab");
ctrlButtons[2] = new UBCntrlButton(this, tr("Enter"), 76); ctrlButtons[2] = new UBCapsLockButton(this, "capslock");
ctrlButtons[3] = new UBCapsLockButton(this, "capslock"); ctrlButtons[3] = new UBCntrlButton(this, tr("Enter"), 76);
ctrlButtons[4] = new UBCapsLockButton(this, "capslock"); ctrlButtons[4] = new UBShiftButton(this, "shift");
ctrlButtons[5] = new UBLocaleButton(this); ctrlButtons[5] = new UBShiftButton(this, "shift");
ctrlButtons[6] = new UBCntrlButton(this, "", 49); ctrlButtons[6] = new UBLocaleButton(this);
ctrlButtons[7] = new UBLocaleButton(this); ctrlButtons[7] = new UBCntrlButton(this, "", 49);
ctrlButtons[8] = new UBLocaleButton(this);
} }
void SetMacLocaleByIdentifier(const QString& id) void SetMacLocaleByIdentifier(const QString& id)
...@@ -102,10 +101,7 @@ void UBKeyboardPalette::onActivated(bool activated) ...@@ -102,10 +101,7 @@ void UBKeyboardPalette::onActivated(bool activated)
SetMacLocaleByIdentifier(activeLocale); SetMacLocaleByIdentifier(activeLocale);
} }
} }
void UBKeyboardPalette::onDeactivated()
{
SetMacLocaleByIdentifier(activeLocale);
}
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale) void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale)
{ {
SetMacLocaleByIdentifier(locale->id); SetMacLocaleByIdentifier(locale->id);
......
...@@ -8,21 +8,19 @@ ...@@ -8,21 +8,19 @@
#include "core/memcheck.h" #include "core/memcheck.h"
void UBKeyboardButton::sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift) void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{ {
unsigned int nSymbol = shift? nSymbol2 : nSymbol1;
INPUT input[2]; INPUT input[2];
input[0].type = INPUT_KEYBOARD; input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0; input[0].ki.wVk = 0;
input[0].ki.wScan = nSymbol; input[0].ki.wScan = keycode.symbol;
input[0].ki.dwFlags = KEYEVENTF_UNICODE; input[0].ki.dwFlags = KEYEVENTF_UNICODE;
input[0].ki.time = 0; input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0; input[0].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD; input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0; input[1].ki.wVk = 0;
input[1].ki.wScan = nSymbol; input[1].ki.wScan = keycode.symbol;
input[1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP; input[1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
input[1].ki.time = 0; input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0; input[1].ki.dwExtraInfo = 0;
...@@ -57,11 +55,10 @@ void UBKeyboardPalette::createCtrlButtons() ...@@ -57,11 +55,10 @@ void UBKeyboardPalette::createCtrlButtons()
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x08, "backspace");// Backspace ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x08, "backspace");// Backspace
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x09, "tab"); // Tab ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x09, "tab"); // Tab
// ctrlButtons[ctrlID++] = new UBKeyButton(this); // Row 2 Stub ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Shift
// ctrlButtons[ctrlID++] = new UBKeyButton(this); // Row 3 Stub
ctrlButtons[ctrlID++] = new UBCntrlButton(this, tr("Enter"), 0x0d); // Enter ctrlButtons[ctrlID++] = new UBCntrlButton(this, tr("Enter"), 0x0d); // Enter
ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Caps Lock ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Caps Lock ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
ctrlButtons[ctrlID++] = new UBCntrlButton(this, "", 0x20); // Space ctrlButtons[ctrlID++] = new UBCntrlButton(this, "", 0x20); // Space
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
...@@ -69,10 +66,6 @@ void UBKeyboardPalette::createCtrlButtons() ...@@ -69,10 +66,6 @@ void UBKeyboardPalette::createCtrlButtons()
void UBKeyboardPalette::onActivated(bool) void UBKeyboardPalette::onActivated(bool)
{ {
}
void UBKeyboardPalette::onDeactivated()
{
} }
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* ) void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* )
{} {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment