Desktop.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Function.h>
  9. #include <AK/String.h>
  10. #include <LibGUI/Forward.h>
  11. #include <LibGfx/Rect.h>
  12. #include <Services/Taskbar/TaskbarWindow.h>
  13. #include <Services/WindowServer/ScreenLayout.h>
  14. namespace GUI {
  15. using ScreenLayout = WindowServer::ScreenLayout;
  16. class Desktop {
  17. public:
  18. // Most people will probably have 4 screens or less
  19. static constexpr size_t default_screen_rect_count = 4;
  20. static Desktop& the();
  21. Desktop() = default;
  22. void set_background_color(StringView background_color);
  23. void set_wallpaper_mode(StringView mode);
  24. String wallpaper_path() const;
  25. RefPtr<Gfx::Bitmap> wallpaper_bitmap() const;
  26. bool set_wallpaper(RefPtr<Gfx::Bitmap> wallpaper_bitmap, Optional<String> path);
  27. Gfx::IntRect rect() const { return m_bounding_rect; }
  28. Vector<Gfx::IntRect, 4> const& rects() const { return m_rects; }
  29. size_t main_screen_index() const { return m_main_screen_index; }
  30. unsigned workspace_rows() const { return m_workspace_rows; }
  31. unsigned workspace_columns() const { return m_workspace_columns; }
  32. int taskbar_height() const { return TaskbarWindow::taskbar_height(); }
  33. void did_receive_screen_rects(Badge<ConnectionToWindowServer>, Vector<Gfx::IntRect, 4> const&, size_t, unsigned, unsigned);
  34. template<typename F>
  35. void on_receive_screen_rects(F&& callback)
  36. {
  37. m_receive_rects_callbacks.append(forward<F>(callback));
  38. }
  39. private:
  40. Vector<Gfx::IntRect, default_screen_rect_count> m_rects;
  41. size_t m_main_screen_index { 0 };
  42. Gfx::IntRect m_bounding_rect;
  43. unsigned m_workspace_rows { 1 };
  44. unsigned m_workspace_columns { 1 };
  45. Vector<Function<void(Desktop&)>> m_receive_rects_callbacks;
  46. bool m_is_setting_desktop_wallpaper { false };
  47. };
  48. }