Desktop.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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(const StringView& background_color);
  22. void set_wallpaper_mode(const StringView& mode);
  23. String wallpaper() const;
  24. bool set_wallpaper(const StringView& path, bool save_config = true);
  25. Gfx::IntRect rect() const { return m_bounding_rect; }
  26. const Vector<Gfx::IntRect, 4>& rects() const { return m_rects; }
  27. size_t main_screen_index() const { return m_main_screen_index; }
  28. unsigned virtual_desktop_rows() const { return m_virtual_desktop_rows; }
  29. unsigned virtual_desktop_columns() const { return m_virtual_desktop_columns; }
  30. int taskbar_height() const { return TaskbarWindow::taskbar_height(); }
  31. void did_receive_screen_rects(Badge<WindowServerConnection>, const Vector<Gfx::IntRect, 4>&, size_t, unsigned, unsigned);
  32. template<typename F>
  33. void on_receive_screen_rects(F&& callback)
  34. {
  35. m_receive_rects_callbacks.append(forward<F>(callback));
  36. }
  37. private:
  38. Vector<Gfx::IntRect, default_screen_rect_count> m_rects;
  39. size_t m_main_screen_index { 0 };
  40. Gfx::IntRect m_bounding_rect;
  41. unsigned m_virtual_desktop_rows { 1 };
  42. unsigned m_virtual_desktop_columns { 1 };
  43. Vector<Function<void(Desktop&)>> m_receive_rects_callbacks;
  44. };
  45. }