* Cleanup, no functional change.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33958 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -5,61 +5,60 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Jeremy Friesner
|
* Jeremy Friesner
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "KeyCommandMap.h"
|
#include "KeyCommandMap.h"
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
#include <OS.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <NodeMonitor.h>
|
|
||||||
#include <Entry.h>
|
|
||||||
#include <WindowScreen.h>
|
|
||||||
#include <MessageFilter.h>
|
|
||||||
#include <Beep.h>
|
#include <Beep.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <File.h>
|
||||||
|
#include <MessageFilter.h>
|
||||||
|
#include <NodeMonitor.h>
|
||||||
|
#include <OS.h>
|
||||||
|
#include <WindowScreen.h>
|
||||||
|
|
||||||
|
|
||||||
#include "ShortcutsFilterConstants.h"
|
|
||||||
#include "BitFieldTesters.h"
|
#include "BitFieldTesters.h"
|
||||||
#include "CommandActuators.h"
|
#include "CommandActuators.h"
|
||||||
|
#include "ShortcutsFilterConstants.h"
|
||||||
|
|
||||||
|
|
||||||
#define FILE_UPDATED 'fiUp'
|
#define FILE_UPDATED 'fiUp'
|
||||||
|
|
||||||
|
|
||||||
class hks {
|
class hks {
|
||||||
public:
|
public:
|
||||||
hks(int32 key, BitFieldTester* t, CommandActuator* act, const BMessage& a)
|
hks(int32 key, BitFieldTester* tester, CommandActuator* actuator,
|
||||||
|
const BMessage& actuatorMessage)
|
||||||
:
|
:
|
||||||
fKey(key),
|
fKey(key),
|
||||||
fTester(t),
|
fTester(tester),
|
||||||
fActuator(act),
|
fActuator(actuator),
|
||||||
fActuatorMessage(a)
|
fActuatorMessage(actuatorMessage)
|
||||||
{
|
{
|
||||||
// empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~hks()
|
||||||
~hks()
|
|
||||||
{
|
{
|
||||||
delete fActuator;
|
delete fActuator;
|
||||||
delete fTester;
|
delete fTester;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 GetKey() const {return fKey;}
|
int32 GetKey() const
|
||||||
bool DoModifiersMatch(uint32 bits) const
|
{ return fKey; }
|
||||||
{
|
bool DoModifiersMatch(uint32 bits) const
|
||||||
return fTester->IsMatching(bits);
|
{ return fTester->IsMatching(bits); }
|
||||||
}
|
const BMessage& GetActuatorMsg() const
|
||||||
const BMessage& GetActuatorMsg() const {return fActuatorMessage;}
|
{ return fActuatorMessage; }
|
||||||
CommandActuator* GetActuator() {return fActuator;}
|
CommandActuator* GetActuator()
|
||||||
|
{ return fActuator; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 fKey;
|
int32 fKey;
|
||||||
BitFieldTester* fTester;
|
BitFieldTester* fTester;
|
||||||
CommandActuator* fActuator;
|
CommandActuator* fActuator;
|
||||||
const BMessage fActuatorMessage;
|
const BMessage fActuatorMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +72,7 @@ KeyCommandMap::KeyCommandMap(const char* file)
|
|||||||
BEntry fileEntry(fFileName);
|
BEntry fileEntry(fFileName);
|
||||||
if (fileEntry.InitCheck() == B_NO_ERROR) {
|
if (fileEntry.InitCheck() == B_NO_ERROR) {
|
||||||
node_ref nref;
|
node_ref nref;
|
||||||
|
|
||||||
if (fileEntry.GetNodeRef(&nref) == B_NO_ERROR)
|
if (fileEntry.GetNodeRef(&nref) == B_NO_ERROR)
|
||||||
watch_node(&nref, B_WATCH_STAT, this);
|
watch_node(&nref, B_WATCH_STAT, this);
|
||||||
}
|
}
|
||||||
@@ -82,7 +81,8 @@ KeyCommandMap::KeyCommandMap(const char* file)
|
|||||||
PostMessage(&msg);
|
PostMessage(&msg);
|
||||||
|
|
||||||
fPort = create_port(1, SHORTCUTS_CATCHER_PORT_NAME);
|
fPort = create_port(1, SHORTCUTS_CATCHER_PORT_NAME);
|
||||||
_PutMessageToPort(); // advertise our BMessenger to the world
|
_PutMessageToPort();
|
||||||
|
// advertise our BMessenger to the world
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,66 +90,65 @@ KeyCommandMap::~KeyCommandMap()
|
|||||||
{
|
{
|
||||||
if (fPort >= 0)
|
if (fPort >= 0)
|
||||||
close_port(fPort);
|
close_port(fPort);
|
||||||
|
|
||||||
for (int i = fInjects.CountItems() - 1; i >= 0; i--)
|
for (int i = fInjects.CountItems() - 1; i >= 0; i--)
|
||||||
delete (BMessage*)fInjects.ItemAt(i);
|
delete (BMessage*)fInjects.ItemAt(i);
|
||||||
|
|
||||||
stop_watching(this); // don't know if this is necessary, but it can't hurt
|
stop_watching(this);
|
||||||
|
// don't know if this is necessary, but it can't hurt
|
||||||
_DeleteHKSList(fSpecs);
|
_DeleteHKSList(fSpecs);
|
||||||
delete [] fFileName;
|
delete [] fFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyCommandMap::MouseMoved(const BMessage* mm)
|
KeyCommandMap::MouseMoved(const BMessage* mouseMoved)
|
||||||
{
|
{
|
||||||
// Save the mouse state for later...
|
// Save the mouse state for later...
|
||||||
fLastMouseMessage = *mm;
|
fLastMouseMessage = *mouseMoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
filter_result
|
filter_result
|
||||||
KeyCommandMap::KeyEvent(const BMessage* keyMsg, BList* outlist,
|
KeyCommandMap::KeyEvent(const BMessage* keyMsg, BList* outlist,
|
||||||
const BMessenger& sendTo)
|
const BMessenger& sendTo)
|
||||||
{
|
{
|
||||||
|
filter_result result = B_DISPATCH_MESSAGE;
|
||||||
uint32 modifiers;
|
uint32 modifiers;
|
||||||
filter_result ret = B_DISPATCH_MESSAGE; // default: pass it on
|
int32 key;
|
||||||
|
|
||||||
if (keyMsg->FindInt32("modifiers", (int32*) &modifiers) == B_NO_ERROR) {
|
if (keyMsg->FindInt32("modifiers", (int32*) &modifiers) == B_OK
|
||||||
int32 key;
|
&& keyMsg->FindInt32("key", &key) == B_OK
|
||||||
if (keyMsg->FindInt32("key", &key) == B_NO_ERROR) {
|
&& fSyncSpecs.Lock()) {
|
||||||
if (fSyncSpecs.Lock()) {
|
if (fSpecs != NULL) {
|
||||||
if (fSpecs != NULL) {
|
int count = fSpecs->CountItems();
|
||||||
int num = fSpecs->CountItems();
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
for (int i = 0; i < num; i++) {
|
hks* next = (hks*) fSpecs->ItemAt(i);
|
||||||
hks* next = (hks*) fSpecs->ItemAt(i);
|
|
||||||
|
if (key == next->GetKey()
|
||||||
if ((key == next->GetKey())
|
&& next->DoModifiersMatch(modifiers)) {
|
||||||
&& (next->DoModifiersMatch(modifiers))) {
|
void* asyncData = NULL;
|
||||||
void* asyncData = NULL;
|
result = next->GetActuator()->KeyEvent(keyMsg, outlist,
|
||||||
ret = next->GetActuator()->
|
&asyncData, &fLastMouseMessage);
|
||||||
KeyEvent(keyMsg, outlist, &asyncData, &fLastMouseMessage);
|
|
||||||
|
if (asyncData != NULL) {
|
||||||
if (asyncData) {
|
BMessage newMsg(*keyMsg);
|
||||||
BMessage newMsg(*keyMsg);
|
newMsg.AddMessage("act", &next->GetActuatorMsg());
|
||||||
newMsg.AddMessage("act", &next->GetActuatorMsg());
|
newMsg.AddPointer("adata", asyncData);
|
||||||
newMsg.AddPointer("adata", asyncData);
|
sendTo.SendMessage(&newMsg);
|
||||||
sendTo.SendMessage(&newMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fSyncSpecs.Unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fSyncSpecs.Unlock();
|
||||||
}
|
}
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyCommandMap::DrainInjectedEvents(const BMessage* keyMsg, BList* outlist,
|
KeyCommandMap::DrainInjectedEvents(const BMessage* keyMsg, BList* outlist,
|
||||||
const BMessenger& sendTo)
|
const BMessenger& sendTo)
|
||||||
{
|
{
|
||||||
BList temp;
|
BList temp;
|
||||||
@@ -159,28 +158,28 @@ KeyCommandMap::DrainInjectedEvents(const BMessage* keyMsg, BList* outlist,
|
|||||||
fSyncSpecs.Unlock();
|
fSyncSpecs.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
int is = temp.CountItems();
|
int count = temp.CountItems();
|
||||||
for (int i = 0; i < is; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
BMessage* msg = (BMessage*)temp.ItemAt(i);
|
BMessage* msg = (BMessage*)temp.ItemAt(i);
|
||||||
BArchivable* arc = instantiate_object(msg);
|
|
||||||
|
BArchivable* archive = instantiate_object(msg);
|
||||||
if (arc) {
|
if (archive != NULL) {
|
||||||
CommandActuator* act = dynamic_cast<CommandActuator*>(arc);
|
CommandActuator* actuator = dynamic_cast<CommandActuator*>(archive);
|
||||||
|
if (actuator != NULL) {
|
||||||
if (act) {
|
|
||||||
BMessage newMsg(*keyMsg);
|
BMessage newMsg(*keyMsg);
|
||||||
newMsg.what = B_KEY_DOWN;
|
newMsg.what = B_KEY_DOWN;
|
||||||
|
|
||||||
void* asyncData = NULL;
|
void* asyncData = NULL;
|
||||||
(void) act->KeyEvent(&newMsg, outlist, &asyncData,
|
actuator->KeyEvent(&newMsg, outlist, &asyncData,
|
||||||
&fLastMouseMessage);
|
&fLastMouseMessage);
|
||||||
|
|
||||||
if (asyncData) {
|
if (asyncData != NULL) {
|
||||||
newMsg.AddMessage("act", msg);
|
newMsg.AddMessage("act", msg);
|
||||||
newMsg.AddPointer("adata", asyncData);
|
newMsg.AddPointer("adata", asyncData);
|
||||||
sendTo.SendMessage(&newMsg);
|
sendTo.SendMessage(&newMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete arc;
|
delete archive;
|
||||||
}
|
}
|
||||||
delete msg;
|
delete msg;
|
||||||
}
|
}
|
||||||
@@ -190,81 +189,66 @@ KeyCommandMap::DrainInjectedEvents(const BMessage* keyMsg, BList* outlist,
|
|||||||
void
|
void
|
||||||
KeyCommandMap::MessageReceived(BMessage* msg)
|
KeyCommandMap::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
switch(msg->what) {
|
switch (msg->what) {
|
||||||
case EXECUTE_COMMAND:
|
case EXECUTE_COMMAND:
|
||||||
{
|
{
|
||||||
BMessage subMsg;
|
BMessage subMsg;
|
||||||
|
|
||||||
if (msg->FindMessage("act", &subMsg) == B_NO_ERROR) {
|
if (msg->FindMessage("act", &subMsg) == B_NO_ERROR) {
|
||||||
if (fSyncSpecs.Lock()) {
|
if (fSyncSpecs.Lock()) {
|
||||||
fInjects.AddItem(new BMessage(subMsg));
|
fInjects.AddItem(new BMessage(subMsg));
|
||||||
fSyncSpecs.Unlock();
|
fSyncSpecs.Unlock();
|
||||||
|
|
||||||
// This evil hack forces input_server to call Filter() on
|
// This evil hack forces input_server to call Filter() on
|
||||||
// us so we can process the injected event.
|
// us so we can process the injected event.
|
||||||
BPoint lmp;
|
BPoint lmp;
|
||||||
status_t err = fLastMouseMessage.FindPoint("where", &lmp);
|
status_t err = fLastMouseMessage.FindPoint("where", &lmp);
|
||||||
if (err == B_NO_ERROR)
|
if (err == B_NO_ERROR)
|
||||||
set_mouse_position((int32)lmp.x, (int32)lmp.y);
|
set_mouse_position((int32)lmp.x, (int32)lmp.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case REPLENISH_MESSENGER:
|
case REPLENISH_MESSENGER:
|
||||||
_PutMessageToPort();
|
_PutMessageToPort();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_NODE_MONITOR:
|
case B_NODE_MONITOR:
|
||||||
case FILE_UPDATED:
|
case FILE_UPDATED:
|
||||||
{
|
{
|
||||||
BMessage fileMsg;
|
BMessage fileMsg;
|
||||||
BFile file(fFileName, B_READ_ONLY);
|
BFile file(fFileName, B_READ_ONLY);
|
||||||
if ((file.InitCheck() == B_NO_ERROR)
|
if (file.InitCheck() == B_OK && fileMsg.Unflatten(&file) == B_OK) {
|
||||||
&& (fileMsg.Unflatten(&file) == B_NO_ERROR)) {
|
|
||||||
BList* newList = new BList;
|
BList* newList = new BList;
|
||||||
|
|
||||||
// whatever this is set to will be deleted below.
|
// whatever this is set to will be deleted below.
|
||||||
// defaults to no deletion
|
// defaults to no deletion
|
||||||
BList* oldList = NULL;
|
BList* oldList = NULL;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
BMessage msg;
|
BMessage msg;
|
||||||
while (fileMsg.FindMessage("spec", i++, &msg) == B_NO_ERROR) {
|
while (fileMsg.FindMessage("spec", i++, &msg) == B_OK) {
|
||||||
uint32 key;
|
uint32 key;
|
||||||
BMessage testerMsg;
|
BMessage testerMsg;
|
||||||
BMessage actMsg;
|
BMessage actMsg;
|
||||||
|
|
||||||
if ((msg.FindInt32("key", (int32*) &key) == B_NO_ERROR)
|
if (msg.FindInt32("key", (int32*) &key) == B_OK
|
||||||
&& ((msg.FindMessage("act", &actMsg)) == B_NO_ERROR)
|
&& msg.FindMessage("act", &actMsg) == B_OK
|
||||||
&& ((msg.FindMessage("modtester", &testerMsg))
|
&& msg.FindMessage("modtester", &testerMsg) == B_OK) {
|
||||||
== B_NO_ERROR)) {
|
BArchivable* archive = instantiate_object(&testerMsg);
|
||||||
|
if (BitFieldTester* tester
|
||||||
BArchivable* arcObj = instantiate_object(&testerMsg);
|
= dynamic_cast<BitFieldTester*>(archive)) {
|
||||||
if (arcObj) {
|
archive = instantiate_object(&actMsg);
|
||||||
BitFieldTester* tester =
|
if (CommandActuator* actuator
|
||||||
dynamic_cast<BitFieldTester*>(arcObj);
|
= dynamic_cast<CommandActuator*>(archive)) {
|
||||||
|
newList->AddItem(
|
||||||
if (tester) {
|
new hks(key, tester, actuator, actMsg));
|
||||||
BArchivable* barcObj =
|
} else {
|
||||||
instantiate_object(&actMsg);
|
delete archive;
|
||||||
|
delete tester;
|
||||||
if (barcObj) {
|
}
|
||||||
CommandActuator* act =
|
} else
|
||||||
dynamic_cast<CommandActuator*>(barcObj);
|
delete archive;
|
||||||
|
|
||||||
if (act)
|
|
||||||
newList->AddItem(
|
|
||||||
new hks(key, tester, act, actMsg));
|
|
||||||
else {
|
|
||||||
delete barcObj;
|
|
||||||
delete tester;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
delete tester;
|
|
||||||
} else
|
|
||||||
delete arcObj;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,28 +269,30 @@ KeyCommandMap::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Deletes an HKS-filled BList and its contents.
|
//! Deletes an HKS-filled BList and its contents.
|
||||||
void KeyCommandMap::_DeleteHKSList(BList* l)
|
void
|
||||||
|
KeyCommandMap::_DeleteHKSList(BList* l)
|
||||||
{
|
{
|
||||||
if (l != NULL) {
|
if (l != NULL) {
|
||||||
int num = l->CountItems();
|
int num = l->CountItems();
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
delete ((hks*) l->ItemAt(i));
|
delete ((hks*) l->ItemAt(i));
|
||||||
delete l;
|
delete l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KeyCommandMap::_PutMessageToPort()
|
void
|
||||||
|
KeyCommandMap::_PutMessageToPort()
|
||||||
{
|
{
|
||||||
if (fPort >= 0) {
|
if (fPort >= 0) {
|
||||||
BMessenger toMe(this);
|
BMessage message;
|
||||||
BMessage m;
|
message.AddMessenger("target", this);
|
||||||
m.AddMessenger("target", toMe);
|
|
||||||
|
|
||||||
char buf[2048];
|
char buffer[2048];
|
||||||
ssize_t fs = m.FlattenedSize();
|
ssize_t size = message.FlattenedSize();
|
||||||
if ((fs <= sizeof(buf)) && (m.Flatten(buf, fs) == B_NO_ERROR))
|
if (size <= (ssize_t)sizeof(buffer)
|
||||||
write_port_etc(fPort, 0, buf, fs, B_TIMEOUT, 250000);
|
&& message.Flatten(buffer, size) == B_OK)
|
||||||
|
write_port_etc(fPort, 0, buffer, size, B_TIMEOUT, 250000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user