Changed some printf to PRINT macro

Now uses BScreen to constrain mouse cursor
Now handles gracefully screen resolution changes
Yeah it works!


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9213 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2004-10-05 20:42:08 +00:00
parent e5572c09e6
commit 1a813abdc9
4 changed files with 70 additions and 52 deletions
+21 -19
View File
@@ -59,13 +59,15 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (status < B_OK) if (status < B_OK)
return status; return status;
printf("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path()); PRINT(("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path()));
image_id addon_image = load_add_on(path.Path()); image_id addon_image = load_add_on(path.Path());
if (addon_image < B_OK) if (addon_image < B_OK) {
PRINT(("load addon %s failed\n", path.Path()));
return addon_image; return addon_image;
}
BEntry parent; BEntry parent;
entry.GetParent(&parent); entry.GetParent(&parent);
BPath parentPath(&parent); BPath parentPath(&parent);
@@ -76,21 +78,21 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (get_image_symbol(addon_image, "instantiate_input_device", if (get_image_symbol(addon_image, "instantiate_input_device",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n", PRINT(("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n",
path.Path()); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerDevice *isd = (*instantiate_func)(); BInputServerDevice *isd = (*instantiate_func)();
if (isd == NULL) { if (isd == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n", PRINT(("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n",
path.Path()); path.Path()));
goto exit_error; goto exit_error;
} }
status_t status = isd->InitCheck(); status_t status = isd->InitCheck();
if (status != B_OK) { if (status != B_OK) {
printf("AddOnManager::RegisterAddOn(): BInputServerDevice.InitCheck in \"%s\" returned %s\n", PRINT(("AddOnManager::RegisterAddOn(): BInputServerDevice.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status)); path.Path(), strerror(status)));
delete isd; delete isd;
goto exit_error; goto exit_error;
} }
@@ -103,21 +105,21 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (get_image_symbol(addon_image, "instantiate_input_filter", if (get_image_symbol(addon_image, "instantiate_input_filter",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n", PRINT(("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n",
path.Path()); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerFilter *isf = (*instantiate_func)(); BInputServerFilter *isf = (*instantiate_func)();
if (isf == NULL) { if (isf == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n", PRINT(("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n",
path.Path()); path.Path()));
goto exit_error; goto exit_error;
} }
status_t status = isf->InitCheck(); status_t status = isf->InitCheck();
if (status != B_OK) { if (status != B_OK) {
printf("AddOnManager::RegisterAddOn(): BInputServerFilter.InitCheck in \"%s\" returned %s\n", PRINT(("AddOnManager::RegisterAddOn(): BInputServerFilter.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status)); path.Path(), strerror(status)));
delete isf; delete isf;
goto exit_error; goto exit_error;
} }
@@ -129,15 +131,15 @@ AddOnManager::RegisterAddOn(BEntry &entry)
if (get_image_symbol(addon_image, "instantiate_input_method", if (get_image_symbol(addon_image, "instantiate_input_method",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
printf("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n", PRINT(("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n",
path.Path()); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerMethod *ism = (*instantiate_func)(); BInputServerMethod *ism = (*instantiate_func)();
if (ism == NULL) { if (ism == NULL) {
printf("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n", PRINT(("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n",
path.Path()); path.Path()));
goto exit_error; goto exit_error;
} }
status_t status = ism->InitCheck(); status_t status = ism->InitCheck();
+39 -29
View File
@@ -48,6 +48,8 @@
#include <PortLink.h> #include <PortLink.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
#define FAST_MOUSE_MOVED '_FMM' // received from app_server when screen res changed, but could be sent to too.
extern "C" void RegisterDevices(input_device_ref** devices) extern "C" void RegisterDevices(input_device_ref** devices)
{ {
@@ -93,7 +95,8 @@ int main()
* Descr: * Descr:
*/ */
InputServer::InputServer(void) : BApplication(INPUTSERVER_SIGNATURE), InputServer::InputServer(void) : BApplication(INPUTSERVER_SIGNATURE),
sSafeMode(false) sSafeMode(false),
fScreen(B_MAIN_SCREEN_ID)
{ {
#if DEBUG == 2 #if DEBUG == 2
if (sLogFile == NULL) if (sLogFile == NULL)
@@ -101,9 +104,8 @@ InputServer::InputServer(void) : BApplication(INPUTSERVER_SIGNATURE),
#endif #endif
CALLED(); CALLED();
void *pointer=NULL;
EventLoop(pointer); EventLoop();
uint8 p1; uint8 p1;
uint32 p2 = 1; uint32 p2 = 1;
@@ -137,7 +139,7 @@ InputServer::InputServer(void) : BApplication(INPUTSERVER_SIGNATURE),
PRINT(("is_as port :%ld\n", fAsPort)); PRINT(("is_as port :%ld\n", fAsPort));
//buffer[1] = 0; buffer[1] = fEventLooperPort;
buffer[0] = fAsPort; buffer[0] = fAsPort;
status_t err; status_t err;
@@ -209,9 +211,9 @@ InputServer::InitKeyboardMouseStates(void)
// This is where we determine the screen resolution from the app_server and find the center of the screen // This is where we determine the screen resolution from the app_server and find the center of the screen
// sMousePos is then set to the center of the screen. // sMousePos is then set to the center of the screen.
fMousePos.x = 200; fFrame = fScreen.Frame();
fMousePos.y = 200; fMousePos = BPoint(fFrame.right/2, fFrame.bottom/2);
if (LoadKeymap()!=B_OK) if (LoadKeymap()!=B_OK)
LoadSystemKeymap(); LoadSystemKeymap();
@@ -328,9 +330,9 @@ InputServer::QuitRequested(void)
fAddOnManager->SaveState(); fAddOnManager->SaveState();
gDeviceManager.SaveState(); gDeviceManager.SaveState();
kill_thread(ISPortThread); kill_thread(fISPortThread);
delete_port(EventLooperPort); delete_port(fEventLooperPort);
EventLooperPort = -1; fEventLooperPort = -1;
return true; return true;
} }
@@ -690,15 +692,13 @@ InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound)
case B_MOUSE_MOVED: case B_MOUSE_MOVED:
case B_MOUSE_DOWN: case B_MOUSE_DOWN:
case B_MOUSE_UP: case B_MOUSE_UP:
case FAST_MOUSE_MOVED:
// get point and button from msg // get point and button from msg
if((outbound->FindInt32("x", &xValue) == B_OK) if((outbound->FindInt32("x", &xValue) == B_OK)
&& (outbound->FindInt32("y", &yValue) == B_OK)) { && (outbound->FindInt32("y", &yValue) == B_OK)) {
fMousePos.x += xValue; fMousePos.x += xValue;
fMousePos.y -= yValue; fMousePos.y -= yValue;
if (fMousePos.x<0) fMousePos.ConstrainTo(fFrame);
fMousePos.x = 0;
if (fMousePos.y<0)
fMousePos.y = 0;
outbound->RemoveName("x"); outbound->RemoveName("x");
outbound->RemoveName("y"); outbound->RemoveName("y");
outbound->AddPoint("where", fMousePos); outbound->AddPoint("where", fMousePos);
@@ -810,7 +810,8 @@ InputServer::HandleGetSetKeyRepeatRate(BMessage* message,
status_t status_t
InputServer::HandleGetSetKeyMap(BMessage *message, InputServer::HandleGetSetKeyMap(BMessage *message,
BMessage *reply) BMessage *reply)
{ {
CALLED();
status_t status; status_t status;
if (message->what == IS_GET_KEY_MAP) { if (message->what == IS_GET_KEY_MAP) {
status = reply->AddData("keymap", B_ANY_TYPE, &fKeys, sizeof(fKeys)); status = reply->AddData("keymap", B_ANY_TYPE, &fKeys, sizeof(fKeys));
@@ -1024,7 +1025,7 @@ InputServer::EnqueueDeviceMessage(BMessage *message)
char buffer[length]; char buffer[length];
if ((err = message->Flatten(buffer,length)) < B_OK) if ((err = message->Flatten(buffer,length)) < B_OK)
return err; return err;
return write_port(EventLooperPort, 0, buffer, length); return write_port(fEventLooperPort, 0, buffer, length);
} }
@@ -1043,7 +1044,7 @@ InputServer::EnqueueMethodMessage(BMessage *message)
char buffer[length]; char buffer[length];
if ((err = message->Flatten(buffer,length)) < B_OK) if ((err = message->Flatten(buffer,length)) < B_OK)
return err; return err;
return write_port(EventLooperPort, 0, buffer, length); return write_port(fEventLooperPort, 0, buffer, length);
} }
@@ -1108,15 +1109,15 @@ InputServer::MethodReplicant(void)
* Descr: * Descr:
*/ */
status_t status_t
InputServer::EventLoop(void *) InputServer::EventLoop()
{ {
CALLED(); CALLED();
EventLooperPort = create_port(100, "obos_is_event_port"); fEventLooperPort = create_port(100, "obos_is_event_port");
if(EventLooperPort < 0) { if(fEventLooperPort < 0) {
_sPrintf("OBOS InputServer: create_port error: (0x%x) %s\n",EventLooperPort,strerror(EventLooperPort)); _sPrintf("OBOS InputServer: create_port error: (0x%x) %s\n", fEventLooperPort, strerror(fEventLooperPort));
} }
ISPortThread = spawn_thread(ISPortWatcher, "_input_server_event_loop_", B_REAL_TIME_DISPLAY_PRIORITY+3, this); fISPortThread = spawn_thread(ISPortWatcher, "_input_server_event_loop_", B_REAL_TIME_DISPLAY_PRIORITY+3, this);
resume_thread(ISPortThread); resume_thread(fISPortThread);
return 0; return 0;
} }
@@ -1656,18 +1657,18 @@ InputServer::WatchPort()
while (true) { while (true) {
// Block until we find the size of the next message // Block until we find the size of the next message
ssize_t length = port_buffer_size(EventLooperPort); ssize_t length = port_buffer_size(fEventLooperPort);
PRINT(("[Event Looper] BMessage Size = %lu\n", length)); PRINT(("[Event Looper] BMessage Size = %lu\n", length));
int32 code; int32 code;
char buffer[length]; char buffer[length];
status_t err = read_port(EventLooperPort, &code, buffer, length); status_t err = read_port(fEventLooperPort, &code, buffer, length);
if(err != length) { if(err != length) {
if(err >= 0) { if(err >= 0) {
printf("InputServer: failed to read full packet (read %lu of %lu)\n", err, length); PRINT(("InputServer: failed to read full packet (read %lu of %lu)\n", err, length));
} else { } else {
printf("InputServer: read_port error: (0x%lx) %s\n", err, strerror(err)); PRINT(("InputServer: read_port error: (0x%lx) %s\n", err, strerror(err)));
} }
continue; continue;
} }
@@ -1675,12 +1676,21 @@ InputServer::WatchPort()
BMessage *event = new BMessage; BMessage *event = new BMessage;
if ((err = event->Unflatten(buffer)) < 0) { if ((err = event->Unflatten(buffer)) < 0) {
printf("[InputServer] Unflatten() error: (0x%lx) %s\n", err, strerror(err)); PRINT(("[InputServer] Unflatten() error: (0x%lx) %s\n", err, strerror(err)));
delete event; delete event;
} else { } else {
// This is where the message should be processed. // This is where the message should be processed.
//PRINT_OBJECT(*event);
// here we test for a message coming from app_server, screen resolution change could have happened
if (event->what == FAST_MOUSE_MOVED) {
BRect frame = fScreen.Frame();
if (frame != fFrame) {
fMousePos.x = fMousePos.x * frame.Width() / fFrame.Width();
fMousePos.y = fMousePos.y * frame.Height() / fFrame.Height();
fFrame = frame;
}
}
HandleSetMousePosition(event, event); HandleSetMousePosition(event, event);
BList list; BList list;
+8 -4
View File
@@ -49,6 +49,7 @@
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <Message.h> #include <Message.h>
#include <OS.h> #include <OS.h>
#include <Screen.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#define INPUTSERVER_SIGNATURE "application/x-vnd.OBOS-input_server" #define INPUTSERVER_SIGNATURE "application/x-vnd.OBOS-input_server"
@@ -140,7 +141,7 @@ public:
//SetActiveMethod(_BMethodAddOn_*); //SetActiveMethod(_BMethodAddOn_*);
const BMessenger* MethodReplicant(void); const BMessenger* MethodReplicant(void);
status_t EventLoop(void*); status_t EventLoop();
static bool EventLoopRunning(void); static bool EventLoopRunning(void);
bool DispatchEvents(BList*); bool DispatchEvents(BList*);
@@ -191,9 +192,9 @@ private:
char *fChars; // current keymap chars char *fChars; // current keymap chars
uint32 fCharsSize; // current keymap char count uint32 fCharsSize; // current keymap char count
port_id ISPort; port_id fEventLooperPort;
port_id EventLooperPort; thread_id fISPortThread;
thread_id ISPortThread;
static int32 ISPortWatcher(void *arg); static int32 ISPortWatcher(void *arg);
void WatchPort(); void WatchPort();
@@ -202,6 +203,9 @@ private:
AddOnManager *fAddOnManager; AddOnManager *fAddOnManager;
BList fEventsCache; BList fEventsCache;
BScreen fScreen;
BRect fFrame;
#ifndef COMPILE_FOR_R5 #ifndef COMPILE_FOR_R5
// added this to communicate via portlink // added this to communicate via portlink
+2
View File
@@ -35,6 +35,8 @@ UsePrivateHeaders app ;
UsePrivateHeaders input ; UsePrivateHeaders input ;
UsePrivateHeaders storage ; UsePrivateHeaders storage ;
SubDirC++Flags -DADD_ON_STABLE_SECONDS=1 ; # for AddOnMonitorHandler.cpp
Server input_server : Server input_server :
InputServer.cpp InputServer.cpp
InputServerDevice.cpp InputServerDevice.cpp