1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

Magnifier: Add desktop display scale awareness

Continues to magnify correctly at the most current
desktop scale.
This commit is contained in:
Eugene Barnett 2021-06-05 21:36:30 -04:00 committed by Andreas Kling
parent 4ef85de9dc
commit cab2ee5ea2
2 changed files with 3 additions and 1 deletions

View file

@ -38,6 +38,7 @@ void MagnifierWidget::set_scale_factor(int scale_factor)
void MagnifierWidget::timer_event(Core::TimerEvent&)
{
m_mouse_position = GUI::WindowServerConnection::the().get_global_cursor_position();
m_desktop_display_scale = GUI::WindowServerConnection::the().get_desktop_display_scale();
update();
}
@ -47,7 +48,7 @@ void MagnifierWidget::paint_event(GUI::PaintEvent&)
// Grab and paint our screenshot.
Gfx::IntSize region_size { size().width() / m_scale_factor, size().height() / m_scale_factor };
Gfx::Rect region { m_mouse_position.x() - (region_size.width() / 2), m_mouse_position.y() - (region_size.height() / 2), region_size.width(), region_size.height() };
Gfx::Rect region { (m_mouse_position.x() * m_desktop_display_scale) - (region_size.width() / 2), (m_mouse_position.y() * m_desktop_display_scale) - (region_size.height() / 2), region_size.width(), region_size.height() };
auto map = GUI::WindowServerConnection::the().get_screen_bitmap(region);
painter.draw_scaled_bitmap(rect(), *map.bitmap(), map.bitmap()->rect());
}

View file

@ -24,4 +24,5 @@ private:
Gfx::IntPoint m_mouse_position;
int m_scale_factor { 2 };
int m_desktop_display_scale { 1 };
};