* Now moves with absolute coordinates instead of relative, which makes moving
windows to other workspaces so much easier that even I managed to get it right... * Moving windows on another workspace is now working as well. * Fixed a positioning bug in Desktop::SetWorkspace() - was only visible in case the window was in more than one workspace, but not in all. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16777 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -738,7 +738,12 @@ Desktop::SetWorkspace(int32 index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!window->InWorkspace(previousIndex)) {
|
if (!window->InWorkspace(previousIndex)) {
|
||||||
// this window was not visible before
|
// This window was not visible before, make sure its frame
|
||||||
|
// is up-to-date
|
||||||
|
if (window->Frame().LeftTop() != position) {
|
||||||
|
BPoint offset = position - window->Frame().LeftTop();
|
||||||
|
window->MoveBy(offset.x, offset.y);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -363,12 +363,17 @@ WorkspacesLayer::MouseDown(BMessage* message, BPoint where)
|
|||||||
BRect screenFrame = _ScreenFrame(index);
|
BRect screenFrame = _ScreenFrame(index);
|
||||||
|
|
||||||
WindowLayer* window;
|
WindowLayer* window;
|
||||||
|
BRect windowFrame;
|
||||||
BPoint leftTop;
|
BPoint leftTop;
|
||||||
while (workspace.GetNextWindow(window, leftTop) == B_OK) {
|
while (workspace.GetNextWindow(window, leftTop) == B_OK) {
|
||||||
BRect frame = _WindowFrame(workspaceFrame, screenFrame, window->Frame(),
|
BRect frame = _WindowFrame(workspaceFrame, screenFrame, window->Frame(),
|
||||||
leftTop);
|
leftTop);
|
||||||
if (frame.Contains(where) && window->Feel() != kDesktopWindowFeel)
|
if (frame.Contains(where) && window->Feel() != kDesktopWindowFeel) {
|
||||||
|
// We can't exit the loop here, as we traverse the window
|
||||||
|
// list in the wrong direction...
|
||||||
fSelectedWindow = window;
|
fSelectedWindow = window;
|
||||||
|
windowFrame = frame;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some special functionality (clicked with modifiers)
|
// Some special functionality (clicked with modifiers)
|
||||||
@@ -398,16 +403,20 @@ WorkspacesLayer::MouseDown(BMessage* message, BPoint where)
|
|||||||
if (fSelectedWindow != NULL && (fSelectedWindow->Flags() & B_NOT_MOVABLE) != 0)
|
if (fSelectedWindow != NULL && (fSelectedWindow->Flags() & B_NOT_MOVABLE) != 0)
|
||||||
fSelectedWindow = NULL;
|
fSelectedWindow = NULL;
|
||||||
|
|
||||||
|
fLeftTopOffset = where - windowFrame.LeftTop();
|
||||||
fSelectedWorkspace = index;
|
fSelectedWorkspace = index;
|
||||||
fLastMousePosition = where;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WorkspacesLayer::MouseUp(BMessage* message, BPoint where)
|
WorkspacesLayer::MouseUp(BMessage* message, BPoint where)
|
||||||
{
|
{
|
||||||
if (!fHasMoved && fSelectedWorkspace >= 0)
|
if (!fHasMoved && fSelectedWorkspace >= 0) {
|
||||||
Window()->Desktop()->SetWorkspace(fSelectedWorkspace);
|
int32 index;
|
||||||
|
_WorkspaceAt(where, index);
|
||||||
|
if (index >= 0)
|
||||||
|
Window()->Desktop()->SetWorkspace(index);
|
||||||
|
}
|
||||||
|
|
||||||
fSelectedWindow = NULL;
|
fSelectedWindow = NULL;
|
||||||
}
|
}
|
||||||
@@ -425,21 +434,16 @@ WorkspacesLayer::MouseMoved(BMessage* message, BPoint where)
|
|||||||
|| (buttons & B_PRIMARY_MOUSE_BUTTON) == 0)
|
|| (buttons & B_PRIMARY_MOUSE_BUTTON) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BPoint delta = where - fLastMousePosition;
|
if (!fHasMoved) {
|
||||||
if (delta.x == 0 && delta.y == 0)
|
Window()->Desktop()->SetMouseEventWindow(Window());
|
||||||
return;
|
// don't let us off the mouse
|
||||||
|
}
|
||||||
Window()->Desktop()->SetMouseEventWindow(Window());
|
|
||||||
// don't let us off the mouse
|
|
||||||
|
|
||||||
int32 index;
|
int32 index;
|
||||||
BRect workspaceFrame = _WorkspaceAt(where, index);
|
BRect workspaceFrame = _WorkspaceAt(where, index);
|
||||||
workspaceFrame.InsetBy(1, 1);
|
workspaceFrame.InsetBy(1, 1);
|
||||||
|
|
||||||
if (index != fSelectedWorkspace) {
|
if (index != fSelectedWorkspace) {
|
||||||
return;
|
|
||||||
// TODO: the code below doesn't work yet...
|
|
||||||
#if 0
|
|
||||||
if (!fSelectedWindow->InWorkspace(index) && fSelectedWindow->IsNormal()) {
|
if (!fSelectedWindow->InWorkspace(index) && fSelectedWindow->IsNormal()) {
|
||||||
// move window to this new workspace
|
// move window to this new workspace
|
||||||
uint32 newWorkspaces = fSelectedWindow->Workspaces()
|
uint32 newWorkspaces = fSelectedWindow->Workspaces()
|
||||||
@@ -447,55 +451,29 @@ WorkspacesLayer::MouseMoved(BMessage* message, BPoint where)
|
|||||||
|
|
||||||
Window()->Desktop()->SetWindowWorkspaces(fSelectedWindow,
|
Window()->Desktop()->SetWindowWorkspaces(fSelectedWindow,
|
||||||
newWorkspaces);
|
newWorkspaces);
|
||||||
|
|
||||||
// move window to the correct location on this new workspace
|
|
||||||
// (preserve offset to window relative to the mouse)
|
|
||||||
|
|
||||||
BRect screenFrame = _ScreenFrame(index);
|
|
||||||
BPoint leftTop = fSelectedWindow->Anchor(fSelectedWorkspace).position;
|
|
||||||
BRect windowFrame = _WindowFrame(workspaceFrame, screenFrame,
|
|
||||||
fSelectedWindow->Frame(), leftTop);
|
|
||||||
|
|
||||||
BPoint delta = fLastMousePosition - windowFrame.LeftTop();
|
|
||||||
delta.x = rintf(delta.x * screenFrame.Width() / workspaceFrame.Width());
|
|
||||||
delta.y = rintf(delta.y * screenFrame.Height() / workspaceFrame.Height());
|
|
||||||
printf("delta: %g, %g\n", delta.x, delta.y);
|
|
||||||
|
|
||||||
// normalize position
|
|
||||||
// TODO: take the actual grid position into account!!!
|
|
||||||
|
|
||||||
float left = leftTop.x + delta.x;
|
|
||||||
if (delta.x < 0)
|
|
||||||
left += screenFrame.Width();
|
|
||||||
else if (screenFrame.Width() + delta.x > 0)
|
|
||||||
left -= screenFrame.Width();
|
|
||||||
|
|
||||||
float top = leftTop.y + delta.y;
|
|
||||||
if (delta.y < 0)
|
|
||||||
top += screenFrame.Height();
|
|
||||||
else if (delta.y > 0)
|
|
||||||
top -= screenFrame.Height();
|
|
||||||
|
|
||||||
printf("new absolute position: %g, %g\n", left, top);
|
|
||||||
leftTop = fSelectedWindow->Anchor(index).position;
|
|
||||||
if (leftTop == kInvalidWindowPosition)
|
|
||||||
leftTop = fSelectedWindow->Anchor(fSelectedWorkspace).position;
|
|
||||||
|
|
||||||
Window()->Desktop()->MoveWindowBy(fSelectedWindow, left - leftTop.x,
|
|
||||||
top - leftTop.y, index);
|
|
||||||
}
|
}
|
||||||
fSelectedWorkspace = index;
|
fSelectedWorkspace = index;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BRect screenFrame = _ScreenFrame(index);
|
BRect screenFrame = _ScreenFrame(index);
|
||||||
float deltaX = rintf(delta.x * screenFrame.Width() / workspaceFrame.Width());
|
float left = rintf((where.x - workspaceFrame.left - fLeftTopOffset.x)
|
||||||
float deltaY = rintf(delta.y * screenFrame.Height() / workspaceFrame.Height());
|
* screenFrame.Width() / workspaceFrame.Width());
|
||||||
|
float top = rintf((where.y - workspaceFrame.top - fLeftTopOffset.y)
|
||||||
|
* screenFrame.Height() / workspaceFrame.Height());
|
||||||
|
|
||||||
|
BPoint leftTop;
|
||||||
|
if (fSelectedWorkspace == Window()->Desktop()->CurrentWorkspace())
|
||||||
|
leftTop = fSelectedWindow->Frame().LeftTop();
|
||||||
|
else {
|
||||||
|
if (fSelectedWindow->Anchor(fSelectedWorkspace).position == kInvalidWindowPosition)
|
||||||
|
fSelectedWindow->Anchor(fSelectedWorkspace).position = fSelectedWindow->Frame().LeftTop();
|
||||||
|
leftTop = fSelectedWindow->Anchor(fSelectedWorkspace).position;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window()->Desktop()->MoveWindowBy(fSelectedWindow, left - leftTop.x, top - leftTop.y,
|
||||||
|
fSelectedWorkspace);
|
||||||
|
|
||||||
fHasMoved = true;
|
fHasMoved = true;
|
||||||
Window()->Desktop()->MoveWindowBy(fSelectedWindow, deltaX, deltaY);
|
|
||||||
|
|
||||||
fLastMousePosition += delta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class WorkspacesLayer : public ViewLayer {
|
|||||||
WindowLayer* fSelectedWindow;
|
WindowLayer* fSelectedWindow;
|
||||||
int32 fSelectedWorkspace;
|
int32 fSelectedWorkspace;
|
||||||
bool fHasMoved;
|
bool fHasMoved;
|
||||||
BPoint fLastMousePosition;
|
BPoint fLeftTopOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WORKSPACES_LAYER_H
|
#endif // WORKSPACES_LAYER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user