Added message filter to the CardView; it now intercepts all messages, so that "Command-Q"

will no longer quit the haiku_app_server, but the application running in the server.
"Print Key" now also works as expected.
Only switching workspaces continues to use "Control-Fx" in the test environment. Under
Haiku, it now uses "Command-Fx" as on BeOS.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14834 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-10 18:37:55 +00:00
parent c12196d47b
commit 0964291534
2 changed files with 116 additions and 123 deletions
+12 -47
View File
@@ -1179,13 +1179,8 @@ RootLayer::KeyboardEventHandler(BMessage *msg)
// F1-F12 // F1-F12
if (scancode > 0x01 && scancode < 0x0e) { if (scancode > 0x01 && scancode < 0x0e) {
// Check for workspace change or safe video mode // Check for workspace change or safe video mode
#if !TEST_MODE
if (scancode == 0x0d && (modifiers & (B_LEFT_COMMAND_KEY if (scancode == 0x0d && (modifiers & (B_LEFT_COMMAND_KEY
| B_LEFT_CONTROL_KEY | B_LEFT_SHIFT_KEY)) != 0) | B_LEFT_CONTROL_KEY | B_LEFT_SHIFT_KEY)) != 0)
#else
if (scancode == 0x0d && (modifiers & (B_LEFT_CONTROL_KEY
| B_LEFT_SHIFT_KEY | B_LEFT_OPTION_KEY)) != 0)
#endif
{ {
// TODO: Set to Safe Mode in KeyboardEventHandler:B_KEY_DOWN. (DrawingEngine API change) // TODO: Set to Safe Mode in KeyboardEventHandler:B_KEY_DOWN. (DrawingEngine API change)
STRACE(("Safe Video Mode invoked - code unimplemented\n")); STRACE(("Safe Video Mode invoked - code unimplemented\n"));
@@ -1193,9 +1188,9 @@ RootLayer::KeyboardEventHandler(BMessage *msg)
} }
#if !TEST_MODE #if !TEST_MODE
if (modifiers & B_CONTROL_KEY) if (modifiers & B_COMMAND_KEY)
#else #else
if (modifiers & (B_LEFT_SHIFT_KEY | B_LEFT_CONTROL_KEY)) if (modifiers & B_CONTROL_KEY)
#endif #endif
{ {
STRACE(("Set Workspace %ld\n",scancode-1)); STRACE(("Set Workspace %ld\n",scancode-1));
@@ -1212,12 +1207,7 @@ RootLayer::KeyboardEventHandler(BMessage *msg)
} }
// Tab key // Tab key
#if !TEST_MODE if (scancode == 0x26 && (modifiers & B_CONTROL_KEY)) {
if (scancode == 0x26 && (modifiers & B_CONTROL_KEY))
#else
if (scancode == 0x26 && (modifiers & B_SHIFT_KEY))
#endif
{
STRACE(("Twitcher\n")); STRACE(("Twitcher\n"));
//ServerApp *deskbar = app_server->FindApp("application/x-vnd.Be-TSKB"); //ServerApp *deskbar = app_server->FindApp("application/x-vnd.Be-TSKB");
//if(deskbar) //if(deskbar)
@@ -1228,14 +1218,8 @@ RootLayer::KeyboardEventHandler(BMessage *msg)
//} //}
} }
#if !TEST_MODE
// PrintScreen // PrintScreen
if (scancode == 0xe) if (scancode == 0xe) {
#else
// Pause/Break
if (scancode == 0x7f)
#endif
{
if (GetDrawingEngine()) { if (GetDrawingEngine()) {
char filename[128]; char filename[128];
BEntry entry; BEntry entry;
@@ -1269,10 +1253,8 @@ RootLayer::KeyboardEventHandler(BMessage *msg)
msg->FindInt32("key", &scancode); msg->FindInt32("key", &scancode);
msg->FindInt32("modifiers", &modifiers); msg->FindInt32("modifiers", &modifiers);
#if !TEST_MODE
// Tab key // Tab key
if(scancode==0x26 && (modifiers & B_CONTROL_KEY)) if (scancode == 0x26 && (modifiers & B_CONTROL_KEY)) {
{
//ServerApp *deskbar=app_server->FindApp("application/x-vnd.Be-TSKB"); //ServerApp *deskbar=app_server->FindApp("application/x-vnd.Be-TSKB");
//if(deskbar) //if(deskbar)
//{ //{
@@ -1280,53 +1262,36 @@ RootLayer::KeyboardEventHandler(BMessage *msg)
break; break;
//} //}
} }
#else // TEST_MODE
if(scancode==0x26 && (modifiers & B_LEFT_SHIFT_KEY))
{
//ServerApp *deskbar=app_server->FindApp("application/x-vnd.Be-TSKB");
//if(deskbar)
//{
printf("Send Twitcher message key to Deskbar - unimplmemented\n");
break;
//}
}
#endif
// We got this far, so apparently it's safe to pass to the active // We got this far, so apparently it's safe to pass to the active
// window. // window.
if (Focus()) if (Focus())
Focus()->KeyUp(msg); Focus()->KeyUp(msg);
break; break;
} }
case B_UNMAPPED_KEY_DOWN: case B_UNMAPPED_KEY_DOWN:
{ if (Focus())
if(Focus())
Focus()->UnmappedKeyDown(msg); Focus()->UnmappedKeyDown(msg);
break; break;
}
case B_UNMAPPED_KEY_UP: case B_UNMAPPED_KEY_UP:
{ if (Focus())
if(Focus())
Focus()->UnmappedKeyUp(msg); Focus()->UnmappedKeyUp(msg);
break; break;
}
case B_MODIFIERS_CHANGED: case B_MODIFIERS_CHANGED:
{ if (Focus())
if(Focus())
Focus()->ModifiersChanged(msg); Focus()->ModifiersChanged(msg);
break; break;
}
default: default:
break; break;
} }
} }
bool bool
RootLayer::AddToInputNotificationLists(Layer *lay, uint32 mask, uint32 options) RootLayer::AddToInputNotificationLists(Layer *lay, uint32 mask, uint32 options)
{ {
+100 -72
View File
@@ -1,15 +1,13 @@
//------------------------------------------------------------------------------ /*
// * Copyright 2001-2005, Haiku.
// Copyright 2002-2005, Haiku, Inc. * Distributed under the terms of the MIT License.
// Distributed under the terms of the MIT License. *
// * Authors:
// * DarkWyrm <[email protected]>
// File Name: ViewHWInterface.cpp * Stephan Aßmus <[email protected]>
// Authors: DarkWyrm <[email protected]> */
// Stephan Aßmus <[email protected]>
// Description: BView/BWindow combination HWInterface implementation /** BView/BWindow combination HWInterface implementation */
//
//------------------------------------------------------------------------------
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
@@ -19,6 +17,7 @@
#include <Cursor.h> #include <Cursor.h>
#include <Locker.h> #include <Locker.h>
#include <Message.h> #include <Message.h>
#include <MessageFilter.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Region.h> #include <Region.h>
#include <Screen.h> #include <Screen.h>
@@ -112,19 +111,15 @@ class CardView : public BView {
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage);
virtual void MouseUp(BPoint where);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
// CardView // CardView
void SetBitmap(const BBitmap* bimtap); void SetBitmap(const BBitmap* bimtap);
void ForwardMessage(); void ForwardMessage(BMessage* message = NULL);
private: private:
port_id fInputPort; port_id fInputPort;
const BBitmap* fBitmap; const BBitmap* fBitmap;
}; };
@@ -147,8 +142,18 @@ class CardWindow : public BWindow {
BLocker fUpdateLock; BLocker fUpdateLock;
}; };
class CardMessageFilter : public BMessageFilter {
public:
CardMessageFilter(CardView* view);
virtual filter_result Filter(BMessage *message, BHandler **_target);
private:
CardView* fView;
};
// #pragma mark -
//extern RGBColor workspace_default_color;
CardView::CardView(BRect bounds) CardView::CardView(BRect bounds)
: BView(bounds, "graphics card view", B_FOLLOW_ALL, B_WILL_DRAW), : BView(bounds, "graphics card view", B_FOLLOW_ALL, B_WILL_DRAW),
@@ -162,12 +167,17 @@ CardView::CardView(BRect bounds)
fInputPort = create_port(100, "ViewInputDevice"); fInputPort = create_port(100, "ViewInputDevice");
#endif #endif
#ifdef ENABLE_INPUT_SERVER_EMULATION
AddFilter(new CardMessageFilter(this));
#endif
} }
CardView::~CardView() CardView::~CardView()
{ {
} }
// AttachedToWindow // AttachedToWindow
void void
CardView::AttachedToWindow() CardView::AttachedToWindow()
@@ -188,64 +198,32 @@ CardView::Draw(BRect updateRect)
// to do anything else. // to do anything else.
void void
CardView::ForwardMessage() CardView::ForwardMessage(BMessage* message)
{ {
BMessage *message = Window()->CurrentMessage(); if (message == NULL)
message = Window()->CurrentMessage();
if (message == NULL)
return;
size_t length = message->FlattenedSize(); size_t length = message->FlattenedSize();
char stream[length]; char stream[length];
if ( message->Flatten(stream, length) == B_OK) { if (message->Flatten(stream, length) == B_OK)
write_port(fInputPort, 0, stream, length); write_port(fInputPort, 0, stream, length);
}
} }
// MouseDown
void
CardView::MouseDown(BPoint pt)
{
#ifdef ENABLE_INPUT_SERVER_EMULATION
ForwardMessage();
#endif
}
// MouseMoved
void
CardView::MouseMoved(BPoint pt, uint32 transit, const BMessage* dragMessage)
{
if (!Bounds().Contains(pt))
return;
// A bug in R5 prevents this call from having an effect if
// called elsewhere, and calling it here works, if we're lucky :-)
BCursor cursor(kEmptyCursor);
SetViewCursor(&cursor, true);
#ifdef ENABLE_INPUT_SERVER_EMULATION
ForwardMessage();
#endif
}
// MouseUp
void
CardView::MouseUp(BPoint pt)
{
#ifdef ENABLE_INPUT_SERVER_EMULATION
ForwardMessage();
#endif
}
// MessageReceived
void void
CardView::MessageReceived(BMessage* message) CardView::MessageReceived(BMessage* message)
{ {
switch(message->what) { switch (message->what) {
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
break; break;
} }
} }
// SetBitmap // SetBitmap
void void
CardView::SetBitmap(const BBitmap* bitmap) CardView::SetBitmap(const BBitmap* bitmap)
@@ -258,7 +236,53 @@ CardView::SetBitmap(const BBitmap* bitmap)
} }
} }
// constructor
// #pragma mark -
CardMessageFilter::CardMessageFilter(CardView* view)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
fView(view)
{
}
filter_result
CardMessageFilter::Filter(BMessage *message, BHandler **target)
{
switch (message->what) {
case B_KEY_DOWN:
case B_UNMAPPED_KEY_DOWN:
case B_KEY_UP:
case B_UNMAPPED_KEY_UP:
case B_MOUSE_DOWN:
case B_MOUSE_UP:
case B_MOUSE_WHEEL_CHANGED:
fView->ForwardMessage(message);
return B_SKIP_MESSAGE;
case B_MOUSE_MOVED:
{
int32 transit;
if (message->FindInt32("be:transit", &transit) == B_OK
&& transit == B_ENTERED_VIEW) {
// A bug in R5 prevents this call from having an effect if
// called elsewhere, and calling it here works, if we're lucky :-)
BCursor cursor(kEmptyCursor);
fView->SetViewCursor(&cursor, true);
}
fView->ForwardMessage(message);
return B_SKIP_MESSAGE;
}
}
return B_DISPATCH_MESSAGE;
}
// #pragma mark -
CardWindow::CardWindow(BRect frame) CardWindow::CardWindow(BRect frame)
: BWindow(frame, "Haiku App Server", B_TITLED_WINDOW, : BWindow(frame, "Haiku App Server", B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE), B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
@@ -268,20 +292,24 @@ CardWindow::CardWindow(BRect frame)
{ {
fView = new CardView(Bounds()); fView = new CardView(Bounds());
AddChild(fView); AddChild(fView);
fView->MakeFocus();
// make it receive key events
} }
// destructor
CardWindow::~CardWindow() CardWindow::~CardWindow()
{ {
delete fUpdateRunner; delete fUpdateRunner;
} }
void CardWindow::MessageReceived(BMessage *msg)
void
CardWindow::MessageReceived(BMessage *msg)
{ {
STRACE("CardWindow::MessageReceived()\n"); STRACE("CardWindow::MessageReceived()\n");
switch (msg->what) { switch (msg->what) {
case MSG_UPDATE: case MSG_UPDATE:
STRACE("MSG_UPDATE\n"); STRACE("MSG_UPDATE\n");
// invalidate all areas in the view that need redrawing // invalidate all areas in the view that need redrawing
if (fUpdateLock.LockWithTimeout(2000LL) >= B_OK) { if (fUpdateLock.LockWithTimeout(2000LL) >= B_OK) {
/* int32 count = fUpdateRegion.CountRects(); /* int32 count = fUpdateRegion.CountRects();
@@ -300,15 +328,13 @@ STRACE("MSG_UPDATE\n");
} }
break; break;
default: default:
#ifdef ENABLE_INPUT_SERVER_EMULATION BWindow::MessageReceived(msg);
fView->ForwardMessage();
#endif
BWindow::MessageReceived(msg);
break; break;
} }
STRACE("CardWindow::MessageReceived() - exit\n"); STRACE("CardWindow::MessageReceived() - exit\n");
} }
// QuitRequested // QuitRequested
bool bool
CardWindow::QuitRequested() CardWindow::QuitRequested()
@@ -348,7 +374,9 @@ CardWindow::Invalidate(const BRect& frame)
} }
// constructor // #pragma mark -
ViewHWInterface::ViewHWInterface() ViewHWInterface::ViewHWInterface()
: HWInterface(), : HWInterface(),
fBackBuffer(NULL), fBackBuffer(NULL),
@@ -360,7 +388,7 @@ ViewHWInterface::ViewHWInterface()
fDisplayMode.space = B_RGBA32; fDisplayMode.space = B_RGBA32;
} }
// destructor
ViewHWInterface::~ViewHWInterface() ViewHWInterface::~ViewHWInterface()
{ {
if (fWindow) { if (fWindow) {