more code for input events. refractored some code in RootLayer class

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14119 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2005-09-05 18:55:32 +00:00
parent e96ac99568
commit ffd509fd9b
4 changed files with 96 additions and 67 deletions
+6
View File
@@ -190,6 +190,12 @@ class Layer {
uint32 EventOptions() const uint32 EventOptions() const
{ return fEventOptions; } { return fEventOptions; }
inline void QuietlySetEventMask(uint32 em)
{ fEventMask = em; }
inline void QuietlySetEventOptions(uint32 eo)
{ fEventOptions = eo; }
void PruneTree(); void PruneTree();
// debugging // debugging
+79 -60
View File
@@ -79,8 +79,9 @@ RootLayer::RootLayer(const char *name, int32 workspaceCount,
fLastMouseMoved(this), fLastMouseMoved(this),
fMouseTargetWinBorder(NULL), fMouseTargetWinBorder(NULL),
fViewAction(B_ENTERED_VIEW), fViewAction(B_ENTERED_VIEW),
fEventMaskLayer(NULL), fNotifyLayer(NULL),
fSavedEventMask(0),
fSavedEventOptions(0),
fAllRegionsLock("root layer region lock"), fAllRegionsLock("root layer region lock"),
fThreadID(B_ERROR), fThreadID(B_ERROR),
@@ -682,7 +683,7 @@ bool RootLayer::SetActiveWorkspace(int32 index)
return false; return false;
// you cannot switch workspaces on R5 if there is an event mask layer // you cannot switch workspaces on R5 if there is an event mask layer
if (fEventMaskLayer) if (fNotifyLayer)
return false; return false;
// if fWorkspace[index] object does not exist, create and add allowed WinBorders // if fWorkspace[index] object does not exist, create and add allowed WinBorders
@@ -733,13 +734,13 @@ bool RootLayer::SetActiveWorkspace(int32 index)
fActiveWksIndex = index; fActiveWksIndex = index;
if (fMouseTargetWinBorder) { if (fMouseTargetWinBorder) {
// if (fMovingWindow && fEventMaskLayer) { // if (fMovingWindow && fNotifyLayer) {
// WinBorder *movingWinBorder = (WinBorder*)fEventMaskLayer; // WinBorder *movingWinBorder = (WinBorder*)fNotifyLayer;
// movingWinBorder->MouseUp(DEC_NONE); // movingWinBorder->MouseUp(DEC_NONE);
// NOTE: DO NOT reset these 2 members! We still want to move our window in the new workspace // NOTE: DO NOT reset these 2 members! We still want to move our window in the new workspace
//fEventMaskLayer = NULL; //fNotifyLayer = NULL;
//fMovingWindow = false; //fMovingWindow = false;
// fResizingWindow = false; // fResizingWindow = false;
@@ -772,15 +773,15 @@ bool RootLayer::SetActiveWorkspace(int32 index)
fMouseTargetWinBorder->QuietlySetWorkspaces(wks); fMouseTargetWinBorder->QuietlySetWorkspaces(wks);
fMouseTargetWinBorder->Window()->SendMessageToClient(&changedMsg, B_NULL_TOKEN, false); fMouseTargetWinBorder->Window()->SendMessageToClient(&changedMsg, B_NULL_TOKEN, false);
} }
}/* else if (fEventMaskLayer) { }/* else if (fNotifyLayer) {
// is this a WinBorder object? // is this a WinBorder object?
if (!fEventMaskLayer->fOwner) if (!fNotifyLayer->fOwner)
{ {
// this WinBorder captured the mouse for a reason. allow it to finish its task. // this WinBorder captured the mouse for a reason. allow it to finish its task.
((WinBorder*)fEventMaskLayer)->MouseUp(DEC_NONE); ((WinBorder*)fNotifyLayer)->MouseUp(DEC_NONE);
} }
fEventMaskLayer = NULL; fNotifyLayer = NULL;
fMovingWindow = false; fMovingWindow = false;
fResizingWindow = false; fResizingWindow = false;
}*/ }*/
@@ -853,18 +854,18 @@ RootLayer::SetWinBorderWorskpaces(WinBorder *winBorder, uint32 oldWksIndex, uint
} }
// TODO: look into this... // TODO: look into this...
if (fEventMaskLayer) { if (fNotifyLayer) {
WinBorder* wb = fEventMaskLayer->fOwner ? WinBorder* wb = fNotifyLayer->fOwner ?
fEventMaskLayer->fOwner : (WinBorder*)fEventMaskLayer; fNotifyLayer->fOwner : (WinBorder*)fNotifyLayer;
if (!fWorkspace[fActiveWksIndex]->HasWinBorder(wb)) { if (!fWorkspace[fActiveWksIndex]->HasWinBorder(wb)) {
/* if (wb == fEventMaskLayer) /* if (wb == fNotifyLayer)
{ {
fMovingWindow = false; fMovingWindow = false;
fResizingWindow = false; fResizingWindow = false;
wb->MouseUp(DEC_NONE); wb->MouseUp(DEC_NONE);
}*/ }*/
fEventMaskLayer = NULL; fNotifyLayer = NULL;
} }
} }
@@ -1132,7 +1133,7 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg)
} }
if (fLastMouseMoved->EventMask() & B_POINTER_EVENTS) if (fLastMouseMoved->EventMask() & B_POINTER_EVENTS)
fEventMaskLayer = fLastMouseMoved; fNotifyLayer = fLastMouseMoved;
break; break;
} }
@@ -1163,6 +1164,10 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg)
evt.where.ConstrainTo(fFrame); evt.where.ConstrainTo(fFrame);
#if 0
ClearNotifyLayer();
#endif
if (fLastMouseMoved == NULL) { if (fLastMouseMoved == NULL) {
CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_UP) fLastMouseMoved is null!\n"); CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_UP) fLastMouseMoved is null!\n");
break; break;
@@ -1178,23 +1183,23 @@ fprintf(stderr, "mouse position changed in B_MOUSE_UP (%.1f, %.1f) from last B_M
fLastMousePosition = evt.where; fLastMousePosition = evt.where;
} }
// TODO: what if 'fEventMaskLayer' is deleted in the mean time. // TODO: what if 'fNotifyLayer' is deleted in the mean time.
if (fEventMaskLayer) { if (fNotifyLayer) {
// if this is a regular Layer, sent message to counterpart BView. // if this is a regular Layer, sent message to counterpart BView.
if (fEventMaskLayer->fOwner) { if (fNotifyLayer->fOwner) {
BMessage upmsg(B_MOUSE_UP); BMessage upmsg(B_MOUSE_UP);
upmsg.AddInt64("when",evt.when); upmsg.AddInt64("when",evt.when);
upmsg.AddPoint("where",evt.where); upmsg.AddPoint("where",evt.where);
upmsg.AddInt32("modifiers",evt.modifiers); upmsg.AddInt32("modifiers",evt.modifiers);
fEventMaskLayer->Window()->SendMessageToClient(&upmsg, fEventMaskLayer->fViewToken, false); fNotifyLayer->Window()->SendMessageToClient(&upmsg, fNotifyLayer->fViewToken, false);
} else { } else {
// this surely is a WinBorder // this surely is a WinBorder
// TODO: This code is too confusing. There should be a clear separation. // TODO: This code is too confusing. There should be a clear separation.
// ((WinBorder*)fEventMaskLayer)->MouseUp(((WinBorder*)fEventMaskLayer)->TellWhat(evt)); // ((WinBorder*)fNotifyLayer)->MouseUp(((WinBorder*)fNotifyLayer)->TellWhat(evt));
} }
fEventMaskLayer = NULL; fNotifyLayer = NULL;
} else { } else {
// NOTE: focus may be NULL // NOTE: focus may be NULL
if (fLastMouseMoved->Window() && fLastMouseMoved->fOwner == FocusWinBorder()) { if (fLastMouseMoved->Window() && fLastMouseMoved->fOwner == FocusWinBorder()) {
@@ -1272,20 +1277,20 @@ fprintf(stderr, "mouse position changed in B_MOUSE_UP (%.1f, %.1f) from last B_M
// This will need to be cleaned up as following the code flow // This will need to be cleaned up as following the code flow
// is very hard. // is very hard.
// fEventMaskLayer is always != this // fNotifyLayer is always != this
if (fEventMaskLayer) { if (fNotifyLayer) {
if (fEventMaskLayer == target) { if (fNotifyLayer == target) {
if (target == fLastMouseMoved) if (target == fLastMouseMoved)
fViewAction = B_INSIDE_VIEW; fViewAction = B_INSIDE_VIEW;
else else
fViewAction = B_ENTERED_VIEW; fViewAction = B_ENTERED_VIEW;
} else if (fEventMaskLayer == fLastMouseMoved) { } else if (fNotifyLayer == fLastMouseMoved) {
fViewAction = B_EXITED_VIEW; fViewAction = B_EXITED_VIEW;
} else { } else {
fViewAction = B_OUTSIDE_VIEW; fViewAction = B_OUTSIDE_VIEW;
} }
if (fEventMaskLayer->fOwner) { if (fNotifyLayer->fOwner) {
// top layer does not have B_POINTER_EVENTS in its event mask // top layer does not have B_POINTER_EVENTS in its event mask
BMessage movemsg(B_MOUSE_MOVED); BMessage movemsg(B_MOUSE_MOVED);
movemsg.AddInt64("when", evt.when); movemsg.AddInt64("when", evt.when);
@@ -1293,9 +1298,9 @@ fprintf(stderr, "mouse position changed in B_MOUSE_UP (%.1f, %.1f) from last B_M
movemsg.AddInt32("buttons", evt.buttons); movemsg.AddInt32("buttons", evt.buttons);
movemsg.AddInt32("transit", fViewAction); movemsg.AddInt32("transit", fViewAction);
fEventMaskLayer->Window()->SendMessageToClient(&movemsg, fEventMaskLayer->fViewToken, false); fNotifyLayer->Window()->SendMessageToClient(&movemsg, fNotifyLayer->fViewToken, false);
} else { } else {
winBorderUnder = (WinBorder*)fEventMaskLayer; winBorderUnder = (WinBorder*)fNotifyLayer;
} }
} else { } else {
if (fLastMouseMoved && fLastMouseMoved != target) { if (fLastMouseMoved && fLastMouseMoved != target) {
@@ -1748,7 +1753,7 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg)
} }
bool bool
RootLayer::SetEventMaskLayer(Layer *lay, uint32 mask, uint32 options) RootLayer::AddToInputNotificationLists(Layer *lay, uint32 mask, uint32 options)
{ {
if (!lay) if (!lay)
return false; return false;
@@ -1758,21 +1763,21 @@ RootLayer::SetEventMaskLayer(Layer *lay, uint32 mask, uint32 options)
Lock(); Lock();
if (mask & B_POINTER_EVENTS) { if (mask & B_POINTER_EVENTS) {
if (fMouseEventsLayerList.HasItem(lay)) if (!fMouseNotificationList.HasItem(lay))
fMouseEventsLayerList.AddItem(lay); fMouseNotificationList.AddItem(lay);
} }
else { else {
if (options == 0) if (options == 0)
fMouseEventsLayerList.RemoveItem(lay); fMouseNotificationList.RemoveItem(lay);
} }
if (mask & B_KEYBOARD_EVENTS) { if (mask & B_KEYBOARD_EVENTS) {
if (fKeyboardEventsLayerList.HasItem(lay)) if (!fKeyboardNotificationList.HasItem(lay))
fKeyboardEventsLayerList.AddItem(lay); fKeyboardNotificationList.AddItem(lay);
} }
else { else {
if (options == 0) if (options == 0)
fKeyboardEventsLayerList.RemoveItem(lay); fKeyboardNotificationList.RemoveItem(lay);
} }
// TODO: set options!!! // TODO: set options!!!
@@ -1784,7 +1789,7 @@ RootLayer::SetEventMaskLayer(Layer *lay, uint32 mask, uint32 options)
} }
bool bool
RootLayer::SetMouseEventMaskLayer(Layer *lay, uint32 mask, uint32 options) RootLayer::SetNotifyLayer(Layer *lay, uint32 mask, uint32 options)
{ {
if (!lay) if (!lay)
return false; return false;
@@ -1794,28 +1799,21 @@ RootLayer::SetMouseEventMaskLayer(Layer *lay, uint32 mask, uint32 options)
Lock(); Lock();
#if 0 // to be removed when the new "event" stuff is ready #if 0 // to be removed when the new "event" stuff is ready
// TODO: fEventMaskLayer to be changed in fMouseEventLayer fNotifyLayer = lay;
fEventMaskLayer = lay; fSavedEventMask = lay->EventMask();
if (mask & B_POINTER_EVENTS) { fSavedOptions = lay->EventOptions();
if (fMouseEventsLayerList.HasItem(lay))
fMouseEventsLayerList.AddItem(lay);
}
if (mask & B_KEYBOARD_EVENTS) { AddToInputNotificationLists(lay, mask, options);
if (fKeyboardEventsLayerList.HasItem(lay))
fKeyboardEventsLayerList.AddItem(lay);
}
// TODO: set options!!! // TODO: set other options!!!
// B_NO_POINTER_HISTORY How? By telling to the input_server?
// B_SUSPEND_VIEW_FOCUS // B_SUSPEND_VIEW_FOCUS
// B_LOCK_WINDOW_FOCUS // B_LOCK_WINDOW_FOCUS
#else #else
if (fEventMaskLayer && fEventMaskLayer != lay) { if (fNotifyLayer && fNotifyLayer != lay) {
fprintf(stderr, "WARNING: fEventMaskLayer already set and different than the required one!\n"); fprintf(stderr, "WARNING: fNotifyLayer already set and different than the required one!\n");
returnValue = false; returnValue = false;
} else { } else {
fEventMaskLayer = lay; fNotifyLayer = lay;
// TODO: use this mask and options! // TODO: use this mask and options!
} }
#endif #endif
@@ -1824,12 +1822,33 @@ RootLayer::SetMouseEventMaskLayer(Layer *lay, uint32 mask, uint32 options)
return returnValue; return returnValue;
} }
void
RootLayer::ClearNotifyLayer()
{
if (fNotifyLayer) {
Lock();
AddToInputNotificationLists(fNotifyLayer, 0UL, 0UL);
fNotifyLayer->QuietlySetEventMask(fSavedEventMask);
fNotifyLayer->QuietlySetEventOptions(fSavedEventOptions);
AddToInputNotificationLists(fNotifyLayer, fSavedEventMask, fSavedEventOptions);
fNotifyLayer = NULL;
fSavedEventMask = 0UL;
fSavedEventOptions = 0UL;
Unlock();
}
}
// LayerRemoved // LayerRemoved
void void
RootLayer::LayerRemoved(Layer* layer) RootLayer::LayerRemoved(Layer* layer)
{ {
if (layer == fEventMaskLayer) if (layer == fNotifyLayer)
fEventMaskLayer = NULL; fNotifyLayer = NULL;
if (layer == fLastMouseMoved) if (layer == fLastMouseMoved)
fLastMouseMoved = NULL; fLastMouseMoved = NULL;
@@ -1965,19 +1984,19 @@ RootLayer::change_winBorder_feel(WinBorder *winBorder, int32 newFeel)
if (isVisible) if (isVisible)
{ {
if (fEventMaskLayer) if (fNotifyLayer)
{ {
// TODO: What was this supposed to do?!? // TODO: What was this supposed to do?!?
/* WinBorder *wb = fEventMaskLayer->fOwner? /* WinBorder *wb = fNotifyLayer->fOwner?
fEventMaskLayer->fOwner: fNotifyLayer->fOwner:
(WinBorder*)fEventMaskLayer; (WinBorder*)fNotifyLayer;
if (wb == fEventMaskLayer) if (wb == fNotifyLayer)
{ {
fMovingWindow = false; fMovingWindow = false;
fResizingWindow = false; fResizingWindow = false;
wb->MouseUp(DEC_NONE); wb->MouseUp(DEC_NONE);
}*/ }*/
fEventMaskLayer = NULL; fNotifyLayer = NULL;
} }
winBorder->Show(false); winBorder->Show(false);
+9 -5
View File
@@ -114,8 +114,9 @@ public:
void SetDragMessage(BMessage *msg); void SetDragMessage(BMessage *msg);
BMessage* DragMessage(void) const; BMessage* DragMessage(void) const;
bool SetEventMaskLayer(Layer *lay, uint32 mask, uint32 options); bool AddToInputNotificationLists(Layer *lay, uint32 mask, uint32 options);
bool SetMouseEventMaskLayer(Layer *lay, uint32 mask, uint32 options); bool SetNotifyLayer(Layer *lay, uint32 mask, uint32 options);
void ClearNotifyLayer();
void LayerRemoved(Layer* layer); void LayerRemoved(Layer* layer);
@@ -176,9 +177,12 @@ friend class Desktop;
Layer* fLastMouseMoved; Layer* fLastMouseMoved;
WinBorder* fMouseTargetWinBorder; WinBorder* fMouseTargetWinBorder;
int32 fViewAction; int32 fViewAction;
Layer* fEventMaskLayer;
BList fMouseEventsLayerList; Layer* fNotifyLayer;
BList fKeyboardEventsLayerList; uint32 fSavedEventMask;
uint32 fSavedEventOptions;
BList fMouseNotificationList;
BList fKeyboardNotificationList;
BLocker fAllRegionsLock; BLocker fAllRegionsLock;
+2 -2
View File
@@ -679,7 +679,7 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint32>(&options); link.Read<uint32>(&options);
if (myRootLayer) if (myRootLayer)
myRootLayer->SetEventMaskLayer(fCurrentLayer, mask, options); myRootLayer->AddToInputNotificationLists(fCurrentLayer, mask, options);
} }
case AS_LAYER_SET_MOUSE_EVENT_MASK: case AS_LAYER_SET_MOUSE_EVENT_MASK:
{ {
@@ -692,7 +692,7 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint32>(&options); link.Read<uint32>(&options);
if (myRootLayer) if (myRootLayer)
myRootLayer->SetMouseEventMaskLayer(fCurrentLayer, mask, options); myRootLayer->SetNotifyLayer(fCurrentLayer, mask, options);
break; break;
} }
case AS_LAYER_MOVE_TO: case AS_LAYER_MOVE_TO: