Browse Source

WindowServer: Always return properly cropped bitmap

Previously, when `screen_index` was not provided when calling
`ClientConnection::get_screen_bitmap`, the bitmap that was created
was always the size of the bounding rect of the screen. The actual
screen bitmap was being cropped, but the bitmap being returned was
of the original size with just black pixels everywhere else.
Mustafa Quraish 3 năm trước cách đây
mục cha
commit
5f23958abd

+ 2 - 1
Userland/Services/WindowServer/ClientConnection.cpp

@@ -973,7 +973,8 @@ Messages::WindowServer::GetScreenBitmapResponse ClientConnection::get_screen_bit
         return bitmap.to_shareable_bitmap();
         return bitmap.to_shareable_bitmap();
     }
     }
     // TODO: Mixed scale setups at what scale? Lowest? Highest? Configurable?
     // TODO: Mixed scale setups at what scale? Lowest? Highest? Configurable?
-    if (auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, Screen::bounding_rect().size(), 1)) {
+    auto bitmap_size = rect.value_or(Screen::bounding_rect()).size();
+    if (auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, bitmap_size, 1)) {
         Gfx::Painter painter(*bitmap);
         Gfx::Painter painter(*bitmap);
         Screen::for_each([&](auto& screen) {
         Screen::for_each([&](auto& screen) {
             auto screen_rect = screen.rect();
             auto screen_rect = screen.rect();