瀏覽代碼

LibGfx+WindowServer: Ensure constrain-to-rect ends up inside the rect

Ben Wiederhake 2 年之前
父節點
當前提交
4b7639c3b5
共有 2 個文件被更改,包括 3 次插入3 次删除
  1. 2 2
      Userland/Libraries/LibGfx/Point.cpp
  2. 1 1
      Userland/Services/WindowServer/Screen.cpp

+ 2 - 2
Userland/Libraries/LibGfx/Point.cpp

@@ -15,8 +15,8 @@ namespace Gfx {
 template<typename T>
 void Point<T>::constrain(Rect<T> const& rect)
 {
-    m_x = AK::clamp<T>(x(), rect.left(), rect.left() + rect.width());
-    m_y = AK::clamp<T>(y(), rect.top(), rect.top() + rect.height());
+    m_x = AK::clamp<T>(x(), rect.left(), rect.right());
+    m_y = AK::clamp<T>(y(), rect.top(), rect.bottom());
 }
 
 template<typename T>

+ 1 - 1
Userland/Services/WindowServer/Screen.cpp

@@ -421,7 +421,7 @@ void ScreenInput::on_receive_mouse_data(MousePacket const& packet)
 
     auto* moved_to_screen = Screen::find_by_location(m_cursor_location);
     if (!moved_to_screen) {
-        m_cursor_location = m_cursor_location.constrained(current_screen.rect());
+        m_cursor_location.constrain(current_screen.rect());
         moved_to_screen = &current_screen;
     }