Ver Fonte

WindowServer: Allow overriding position when getting bitmap

FrHun há 2 anos atrás
pai
commit
6d4e37138e

+ 7 - 4
Userland/Services/WindowServer/ConnectionFromClient.cpp

@@ -1193,10 +1193,14 @@ Messages::WindowServer::GetScreenBitmapResponse ConnectionFromClient::get_screen
 }
 }
 
 
 Messages::WindowServer::GetScreenBitmapAroundCursorResponse ConnectionFromClient::get_screen_bitmap_around_cursor(Gfx::IntSize size)
 Messages::WindowServer::GetScreenBitmapAroundCursorResponse ConnectionFromClient::get_screen_bitmap_around_cursor(Gfx::IntSize size)
+{
+    return get_screen_bitmap_around_location(size, ScreenInput::the().cursor_location()).bitmap();
+}
+
+Messages::WindowServer::GetScreenBitmapAroundLocationResponse ConnectionFromClient::get_screen_bitmap_around_location(Gfx::IntSize size, Gfx::IntPoint location)
 {
 {
     // TODO: Mixed scale setups at what scale? Lowest? Highest? Configurable?
     // TODO: Mixed scale setups at what scale? Lowest? Highest? Configurable?
-    auto cursor_location = ScreenInput::the().cursor_location();
-    Gfx::Rect rect { cursor_location.x() - (size.width() / 2), cursor_location.y() - (size.height() / 2), size.width(), size.height() };
+    Gfx::Rect rect { location.x() - (size.width() / 2), location.y() - (size.height() / 2), size.width(), size.height() };
 
 
     // Recompose the screen to make sure the cursor is painted in the location we think it is.
     // Recompose the screen to make sure the cursor is painted in the location we think it is.
     // FIXME: This is rather wasteful. We can probably think of a way to avoid this.
     // FIXME: This is rather wasteful. We can probably think of a way to avoid this.
@@ -1210,10 +1214,9 @@ Messages::WindowServer::GetScreenBitmapAroundCursorResponse ConnectionFromClient
         return IterationDecision::Continue;
         return IterationDecision::Continue;
     });
     });
 
 
-    auto screen_scale_factor = ScreenInput::the().cursor_location_screen().scale_factor();
     if (intersecting_with_screens == 1) {
     if (intersecting_with_screens == 1) {
         auto& screen = Screen::closest_to_rect(rect);
         auto& screen = Screen::closest_to_rect(rect);
-        auto crop_rect = rect.translated(-screen.rect().location()) * screen_scale_factor;
+        auto crop_rect = rect.translated(-screen.rect().location()) * screen.scale_factor();
         auto bitmap_or_error = Compositor::the().front_bitmap_for_screenshot({}, screen).cropped(crop_rect);
         auto bitmap_or_error = Compositor::the().front_bitmap_for_screenshot({}, screen).cropped(crop_rect);
         if (bitmap_or_error.is_error()) {
         if (bitmap_or_error.is_error()) {
             dbgln("get_screen_bitmap_around_cursor: Failed to crop screenshot: {}", bitmap_or_error.error());
             dbgln("get_screen_bitmap_around_cursor: Failed to crop screenshot: {}", bitmap_or_error.error());

+ 1 - 0
Userland/Services/WindowServer/ConnectionFromClient.h

@@ -174,6 +174,7 @@ private:
     virtual Messages::WindowServer::GetScrollStepSizeResponse get_scroll_step_size() override;
     virtual Messages::WindowServer::GetScrollStepSizeResponse get_scroll_step_size() override;
     virtual Messages::WindowServer::GetScreenBitmapResponse get_screen_bitmap(Optional<Gfx::IntRect> const&, Optional<u32> const&) override;
     virtual Messages::WindowServer::GetScreenBitmapResponse get_screen_bitmap(Optional<Gfx::IntRect> const&, Optional<u32> const&) override;
     virtual Messages::WindowServer::GetScreenBitmapAroundCursorResponse get_screen_bitmap_around_cursor(Gfx::IntSize) override;
     virtual Messages::WindowServer::GetScreenBitmapAroundCursorResponse get_screen_bitmap_around_cursor(Gfx::IntSize) override;
+    virtual Messages::WindowServer::GetScreenBitmapAroundLocationResponse get_screen_bitmap_around_location(Gfx::IntSize, Gfx::IntPoint) override;
     virtual void set_double_click_speed(i32) override;
     virtual void set_double_click_speed(i32) override;
     virtual Messages::WindowServer::GetDoubleClickSpeedResponse get_double_click_speed() override;
     virtual Messages::WindowServer::GetDoubleClickSpeedResponse get_double_click_speed() override;
     virtual void set_mouse_buttons_switched(bool) override;
     virtual void set_mouse_buttons_switched(bool) override;

+ 1 - 0
Userland/Services/WindowServer/WindowServer.ipc

@@ -168,6 +168,7 @@ endpoint WindowServer
 
 
     get_screen_bitmap(Optional<Gfx::IntRect> rect, Optional<u32> screen_index) => (Gfx::ShareableBitmap bitmap)
     get_screen_bitmap(Optional<Gfx::IntRect> rect, Optional<u32> screen_index) => (Gfx::ShareableBitmap bitmap)
     get_screen_bitmap_around_cursor(Gfx::IntSize size) => (Gfx::ShareableBitmap bitmap)
     get_screen_bitmap_around_cursor(Gfx::IntSize size) => (Gfx::ShareableBitmap bitmap)
+    get_screen_bitmap_around_location(Gfx::IntSize size, Gfx::IntPoint location) => (Gfx::ShareableBitmap bitmap)
     get_color_under_cursor() => (Optional<Gfx::Color> color)
     get_color_under_cursor() => (Optional<Gfx::Color> color)
 
 
     pong() =|
     pong() =|