Desktop.h 1.8 KB

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