bool Manager::Impl::HandleFrameEvent(XEvent* event) { if (WindowManager::Default().IsScaleActive()) return false; auto const& win = GetWindowByFrame(event->xany.window); // ButtonRelease events might happen also outside the frame window, in this // case we must unset the mouse owner, wherever the event happens. if (!win && event->type != ButtonRelease) return false; auto const& input_mixer = win ? win->impl_->input_mixer_ : last_mouse_owner_.lock(); if (!input_mixer) return false; switch (event->type) { case MotionNotify: { input_mixer->MotionEvent(CompPoint(event->xmotion.x_root, event->xmotion.y_root), event->xmotion.time); break; } case EnterNotify: { input_mixer->EnterEvent(CompPoint(event->xcrossing.x_root, event->xcrossing.y_root)); break; } case LeaveNotify: { input_mixer->LeaveEvent(CompPoint(event->xcrossing.x_root, event->xcrossing.y_root)); break; } case ButtonPress: { input_mixer->ButtonDownEvent(CompPoint(event->xbutton.x_root, event->xbutton.y_root), event->xbutton.button, event->xbutton.time); if (input_mixer->GetMouseOwner()) last_mouse_owner_ = input_mixer; break; } case ButtonRelease: { input_mixer->ButtonUpEvent(CompPoint(event->xbutton.x_root, event->xbutton.y_root), event->xbutton.button, event->xbutton.time); last_mouse_owner_.reset(); break; } } // This causes the Alt+Move not to work, we should probably return this value based on the actual handled state // return true; return false; }
TEST(WallOffsetMovementTest, TestOffsetBottom) { CompRect sbr (0, 750, 500, 500); CompRegion sr (0, 0, 1000, 1000); CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr); EXPECT_EQ (offset, CompPoint (0, -250)); }
TEST(WallOffsetMovementTest, TestOffsetTopMMSlice) { CompRect sbr (0, -250, 500, 500); CompRegion sr (0, 0, 1000, 1000); sr -= CompRegion (400, 0, 200, 0); CompPoint offset = compiz::wall::movementWindowOnScreen (sbr, sr); EXPECT_EQ (offset, CompPoint (0, 250)); }
void GrabEdge::ButtonDownEvent(CompPoint const& p, unsigned button, Time timestamp) { if (button != 1) { if (button == 2 || button == 3) PerformWMAction(p, button, timestamp); return; } if (!IsMaximizable() && !always_wait_grab_timeout_) { Edge::ButtonDownEvent(p, button, timestamp); return; } auto const& style = Style::Get(); unsigned max_time_delta = std::max(0, style->DoubleClickMaxTimeDelta()); bool double_clicked = false; if (timestamp - last_click_time_ < max_time_delta) { int max_distance = style->DoubleClickMaxDistance(); if (std::abs(p.x() - last_click_pos_.x()) < max_distance && std::abs(p.y() - last_click_pos_.y()) < max_distance) { PerformWMAction(p, button, timestamp); double_clicked = true; button_down_timer_.reset(); } } if (!double_clicked) { button_down_timer_.reset(new glib::Timeout(style->grab_wait())); button_down_timer_->Run([this] { Edge::ButtonDownEvent(CompPoint(pointerX, pointerY), button_down_, last_click_time_); button_down_timer_.reset(); return false; }); } button_down_ = button; last_click_pos_ = p; last_click_time_ = timestamp; }
CompPoint compiz::wall::movementWindowOnScreen (const CompRect &serverBorderRect, const CompRegion &screenRegion) { CompRegion sbrRegion (serverBorderRect); /* If the window would be partially offscreen * after it was moved then we should move it back * so that it is completely onscreen, since we moved * from mostly offscreen on B to mostly onscreen on A, * the user should be able to see their selected window */ CompRegion inter = sbrRegion.intersected (screenRegion); CompRegion rem = sbrRegion - screenRegion; int dx = 0; int dy = 0; const CompRect::vector &rects (rem.rects ()); for (std::vector <CompRect>::const_iterator it = rects.begin (); it != rects.end (); ++it) { const CompRect &r = *it; if (r.x1 () >= inter.boundingRect ().x2 ()) dx -= r.width (); else if (r.x2 () <= inter.boundingRect ().x1 ()) dx += r.width (); if (r.y1 () >= inter.boundingRect ().y2 ()) dy -= r.height (); else if (r.y2 () <= inter.boundingRect ().y1 ()) dy += r.height (); } return CompPoint (dx, dy); }
CompPoint compiz::window::extents::shift (const CompWindowExtents &extents, unsigned int gravity) { CompPoint rv = CompPoint (); switch (gravity) { case NorthGravity: case NorthWestGravity: case NorthEastGravity: rv.setY (extents.top); break; case SouthGravity: case SouthWestGravity: case SouthEastGravity: rv.setY (-extents.bottom); break; default: break; } switch (gravity) { case WestGravity: case NorthWestGravity: case SouthWestGravity: rv.setX (extents.left); break; case EastGravity: case NorthEastGravity: case SouthEastGravity: rv.setX (-extents.right); break; } return rv; }
CompPoint CompWindow::serverPos () const { return CompPoint (serverGeometry ().x (), serverGeometry ().y ()); }
CompPoint CompWindow::pos () const { return CompPoint (geometry ().x (), geometry ().y ()); }
TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange) { CompSize current, old; compiz::window::Geometry g (200, 250, 300, 400, 0); MockScreenSizeChangeObject ms (g); current = CompSize (1280, 800); /* Reserve top, bottom and left parts of the screen for * fake "24px" panels */ CompRect workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); /* First test that changing the screen size * to something smaller here doesn't cause our * (small) window to be moved */ old = current; current = CompSize (1024, 768); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0)); /* Making the screen size bigger with no * saved geometry should cause the window not to move */ old = current; current = CompSize (2048, 768); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0)); /* Move the window to the other "monitor" */ ms.setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0)); old = current; /* Unplug a "monitor" */ current = CompSize (1024, 768); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (724, 250, 300, 400, 0)); old = current; /* Re-plug the monitor - window should go back * to the same position */ current = CompSize (2048, 768); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0)); old = current; /* Plug 2 monitors downwards, no change */ current = CompSize (2048, 1536); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0)); /* Move the window to the bottom "monitor" */ ms.setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0)); old = current; /* Unplug bottom "monitor" */ current = CompSize (2048, 768); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (1025, 344, 300, 400, 0)); old = current; /* Re-plug bottom "monitor" */ current = CompSize (2048, 1356); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (1025, 791, 300, 400, 0)); /* Move the entire window right a viewport */ g.setPos (g.pos () + CompPoint (current.width (), 0)); ms.setGeometry (g); /* Now change the screen resolution again - the window should * move to be within the constrained size of its current * viewport */ /* Unplug a "monitor" */ old = current; current = CompSize (1024, 1356); workArea = CompRect (0, 0, current.width (), current.height ()); reserveStruts (workArea); ms.setWorkArea (workArea); g = ms.adjustForSize (old, current); EXPECT_EQ (g, compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0)); }
CompPoint CompPoint::operator- (const CompPoint &rhs) const { return CompPoint (mX - rhs.mX, mY - rhs.mY); }
CompPoint CompPoint::operator+ (const CompPoint &rhs) const { return CompPoint (mX + rhs.mX, mY + rhs.mY); }