virtualkeyboard: fixes; input_server now displays keyboard

This commit is contained in:
Freeman Lou 2014-01-03 14:31:58 +00:00 committed by François Revol
parent 2e4c86a4d2
commit a9fd76aefc
8 changed files with 61 additions and 82 deletions

View File

@ -1,23 +1,18 @@
SubDir HAIKU_TOP src apps virtualkeyboard ;
SubDir HAIKU_TOP src add-ons input_server devices virtualkeyboard ;
UsePrivateHeaders interface shared ;
UsePrivateHeaders input interface shared tracker ;
UsePrivateSystemHeaders ;
Addon <input> VirtualKeyboard :
AddResources <input>virtualkeyboard : VirtualKeyboard.rdef ;
Addon <input>virtualkeyboard :
KeyboardLayout.cpp
KeyboardLayoutView.cpp
Keymap.cpp
KeymapListItem.cpp
VirtualKeyboardInputDevice.cpp
VirtualKeyboardWindow.cpp
: be tracker input_server localestub libshared.a $(TARGET_LIBSTDC++)
;
DoCatalogs Sudoku :
x-vnd.Haiku-Sudoku
:
KeyboardLayout.cpp
KeyboardLayoutView.cpp
Keymap.cpp
KeymapListItem.cpp
VirtualKeyboardWindow.cpp
;

View File

@ -26,7 +26,8 @@ static const rgb_color kDeadKeyColor = {152, 203, 255, 255};
static const rgb_color kLitIndicatorColor = {116, 212, 83, 255};
KeyboardLayoutView::KeyboardLayoutView(const char* name)
KeyboardLayoutView::KeyboardLayoutView(const char* name,
BInputServerDevice* dev)
:
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
fOffscreenBitmap(NULL),
@ -37,7 +38,8 @@ KeyboardLayoutView::KeyboardLayoutView(const char* name)
fButtons(0),
fDragKey(NULL),
fDropTarget(NULL),
fOldSize(0, 0)
fOldSize(0, 0),
fDevice(dev)
{
fLayout = new KeyboardLayout;
memset(fKeyState, 0, sizeof(fKeyState));
@ -229,8 +231,7 @@ KeyboardLayoutView::MouseUp(BPoint point)
_InvalidateKey(key);
if (fDragKey == NULL && fKeymap != NULL) {
// Send fake key down message to target
_SendFakeKeyDown(key);
_SendKeyDown(key);
}
}
}
@ -373,7 +374,7 @@ KeyboardLayoutView::MessageReceived(BMessage* message)
}
} else {
// Send the old key to the target, so it's not lost entirely
_SendFakeKeyDown(fDropTarget);
_SendKeyDown(fDropTarget);
fKeymap->SetKey(fDropTarget->code, fModifiers, fDeadKey,
(const char*)data, dataSize);
@ -1074,7 +1075,7 @@ KeyboardLayoutView::_EvaluateDropTarget(BPoint point)
void
KeyboardLayoutView::_SendFakeKeyDown(const Key* key)
KeyboardLayoutView::_SendKeyDown(const Key* key)
{
BMessage message(B_KEY_DOWN);
message.AddInt64("when", system_time());
@ -1099,6 +1100,6 @@ KeyboardLayoutView::_SendFakeKeyDown(const Key* key)
message.AddInt8("byte", string[0]);
delete[] string;
}
fTarget.SendMessage(&message);
fDevice->EnqueueMessage(&message);
}

View File

@ -6,6 +6,7 @@
#define KEYBOARD_LAYOUT_VIEW_H
#include <InputServerDevice.h>
#include <Messenger.h>
#include <View.h>
@ -17,7 +18,8 @@ class Keymap;
class KeyboardLayoutView : public BView {
public:
KeyboardLayoutView(const char* name);
KeyboardLayoutView(const char* name,
BInputServerDevice* dev);
~KeyboardLayoutView();
void SetKeyboardLayout(KeyboardLayout* layout);
@ -90,8 +92,8 @@ private:
BRect _FrameFor(const Key* key);
void _SetFontSize(BView* view, key_kind keyKind);
void _EvaluateDropTarget(BPoint point);
void _SendFakeKeyDown(const Key* key);
void _SendKeyDown(const Key* key);
BBitmap* fOffscreenBitmap;
BView* fOffscreenView;
@ -119,6 +121,9 @@ private:
BPoint fOffset;
float fFactor;
float fGap;
BInputServerDevice* fDevice;
};

View File

@ -1,38 +1 @@
resource app_signature "application/x-vnd.VirtualKeyboard";
resource app_name_catalog_entry "x-vnd.VirtualKeyboard:System name:VirtualKeyboard";
resource app_version {
major = 1,
middle = 0,
minor = 0,
variety = 1,
internal = 0,
short_info = "VirtualKeybaord",
long_info = "An on-screen keyboard for Haiku"
};
resource vector_icon {
$"6E63696605020016023910813A2974BB43733A501C4B20D94AA7F400E9FFB902"
$"001602B82588B66C3639EE80BB7BCD4B41FC4B6A3B0066FF9002011603BC39E2"
$"364286B516B5BB0AE64B8EF94A7E0500FF56E5FFC1050004006D0E0A04525E5C"
$"CAE766C6EB5E4B0A0442544648524E525C0A04525C524E5C445E500A04464852"
$"4E5C44503E0A02B8DABA5FB913BA320A02BA25B92DB942BA0F0803B70BBCFDB8"
$"C7BB84B7BBBB82000CC151BD52C151BD52C151BD52C0B0BDBEC0B0BDBEC105BD"
$"83C0EEBD21C116BD40C0C6BD01C00CBD38C022BD28BFCCBD68BFEBBDBDBFCBBD"
$"A7C016BDDBC08ABDBEC08ABDBEC072BDD0C080BE0CC065BDF9C0ADBE2CC19CBD"
$"CEC15EBE0BC20ABD6244BCC9C1A4BCF5C0ABBC64BF88BD14BFD6BCC6BEE4BDB8"
$"BFE6BE44BFB33CC052BE81C100BE6EC0E2BE7AC100BE6E0406FA0FBD8FC04CBC"
$"96BFB3BD553FBCDC3FBDCE3FBE873FBE3BBF8DBED4BF27BE94BE7ABEDABEB4BE"
$"4EBE41BDB5BE94BDCFBE7ABDB5BE940802C63340C74DC0670802C5C6C01FC6D8"
$"C0CB0802C791BFECC5F9C0E50802C58DC0A5C712BFA00007C361C29EC361C29E"
$"C33FC2BBC39AC332C35FC30EC3D5C357C496C30FC468C33EC4C4C2E1C463C25D"
$"C4D4C29EC4D4C29EC537C245C515C26DC558C21DC50AC1AA4EC1DDC4C1C177C4"
$"4945C461C1A9C449450E0A030303020130001001178322040A0001012000100A"
$"0101022000100A0201032000100A030303020130101801178322040A00010120"
$"10180A0101022010180A0201032010180A040100000A03030302011001178322"
$"040A000101000A010102000A020103000A030A0D090A0B0C0807060504100117"
$"812204"
};
resource app_signature "application/x-vnd.Haiku-VirtualKeyboardInputServerDevice";

View File

@ -4,6 +4,8 @@
*/
#include "VirtualKeyboardInputDevice.h"
#include <InterfaceDefs.h>
extern "C" BInputServerDevice*
instantiate_input_device()
{
@ -15,23 +17,24 @@ VirtualKeyboardInputDevice::VirtualKeyboardInputDevice()
:
BInputServerDevice()
{
fKeyboardWindow = new VirtualKeyboardWindow();
fKeyboardWindow = new VirtualKeyboardWindow(this);
}
status_t
VirtualKeyboardInputDevice::SystemShuttingDown()
VirtualKeyboardInputDevice::~VirtualKeyboardInputDevice()
{
if (fKeyboardWindow)
fKeyboardWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
return B_OK;
}
status_t
VirtualKeyboardInputDevice::InitCheck()
{
return BInputServerDevice::InitCheck();
static input_device_ref keyboard = {"VirtualKeyboard",
B_KEYBOARD_DEVICE, (void*) this};
static input_device_ref* devices[2] = {&keyboard, NULL};
RegisterDevices(devices);
return B_OK;
}
@ -39,5 +42,16 @@ status_t
VirtualKeyboardInputDevice::Start(const char* name, void* cookie)
{
fKeyboardWindow->Show();
return B_OK;
}
status_t
VirtualKeyboardInputDevice::Stop(const char* name, void* cookie)
{
if (fKeyboardWindow) {
fKeyboardWindow->Quit();
fKeyboardWindow = NULL;
}
return B_OK;
}

View File

@ -9,19 +9,17 @@
#include "VirtualKeyboardWindow.h"
class VirtualKeyboardInputDevice : public BInputServerDevice {
public:
VirtualKeyboardInputDevice();
virtual status_t InitCheck();
virtual status_t Start(const char* name, void* cookie);
virtual status_t Stop(const char* name, void* cookie);
virtual status_t Control(const char* name, void* cookie,
uint32 command, BMessage* message);
virtual status_t SystemShuttingDown();
VirtualKeyboardInputDevice();
~VirtualKeyboardInputDevice();
virtual status_t InitCheck();
virtual status_t Start(const char* name, void* cookie);
virtual status_t Stop(const char* name, void* cookie);
private:
friend class VirtualKeyboardWindow;
VirtualKeyboardWindow* fKeyboardWindow;
VirtualKeyboardWindow* fKeyboardWindow;
};

View File

@ -30,11 +30,12 @@ compare_key_list_items(const void* a, const void* b)
}
VirtualKeyboardWindow::VirtualKeyboardWindow()
VirtualKeyboardWindow::VirtualKeyboardWindow(BInputServerDevice* dev)
:
BWindow(BRect(0,0,0,0),"Virtual Keyboard",
B_NO_BORDER_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL,
B_WILL_ACCEPT_FIRST_CLICK | B_AVOID_FRONT)
B_WILL_ACCEPT_FIRST_CLICK | B_AVOID_FOCUS),
fDevice(dev)
{
BScreen screen;
BRect screenRect(screen.Frame());
@ -57,7 +58,7 @@ VirtualKeyboardWindow::VirtualKeyboardWindow()
static_cast<KeymapListItem*>(fMapListView->FirstItem());
fCurrentKeymap.Load(current->EntryRef());
fKeyboardView = new KeyboardLayoutView("Keyboard");
fKeyboardView = new KeyboardLayoutView("Keyboard",fDevice);
fKeyboardView->GetKeyboardLayout()->SetDefault();
fKeyboardView->SetEditable(false);
fKeyboardView->SetKeymap(&fCurrentKeymap);

View File

@ -5,6 +5,7 @@
#ifndef VIRTUAL_KEYBOARD_WINDOW_H
#define VIRTUAL_KEYBOARD_WINDOW_H
#include <InputServerDevice.h>
#include <Window.h>
#include <vector.h>
@ -19,7 +20,7 @@ class BMenu;
class VirtualKeyboardWindow : public BWindow{
public:
VirtualKeyboardWindow();
VirtualKeyboardWindow(BInputServerDevice* dev);
virtual void MessageReceived(BMessage* message);
private:
@ -28,6 +29,7 @@ private:
BMenu* fFontMenu;
BMenu* fLayoutMenu;
Keymap fCurrentKeymap;
BInputServerDevice* fDevice;
private:
void _LoadLayouts(BMenu* menu);