Desktop.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Badge.h>
  7. #include <LibGUI/Desktop.h>
  8. #include <LibGUI/WindowServerConnection.h>
  9. #include <string.h>
  10. // Including this after to avoid LibIPC errors
  11. #include <LibConfig/Client.h>
  12. namespace GUI {
  13. Desktop& Desktop::the()
  14. {
  15. static Desktop* the;
  16. if (!the)
  17. the = new Desktop;
  18. return *the;
  19. }
  20. Desktop::Desktop()
  21. {
  22. }
  23. void Desktop::did_receive_screen_rects(Badge<WindowServerConnection>, const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index, unsigned workspace_rows, unsigned workspace_columns)
  24. {
  25. m_main_screen_index = main_screen_index;
  26. m_rects = rects;
  27. if (!m_rects.is_empty()) {
  28. m_bounding_rect = m_rects[0];
  29. for (size_t i = 1; i < m_rects.size(); i++)
  30. m_bounding_rect = m_bounding_rect.united(m_rects[i]);
  31. } else {
  32. m_bounding_rect = {};
  33. }
  34. m_workspace_rows = workspace_rows;
  35. m_workspace_columns = workspace_columns;
  36. for (auto& callback : m_receive_rects_callbacks)
  37. callback(*this);
  38. }
  39. void Desktop::set_background_color(StringView background_color)
  40. {
  41. WindowServerConnection::the().async_set_background_color(background_color);
  42. }
  43. void Desktop::set_wallpaper_mode(StringView mode)
  44. {
  45. WindowServerConnection::the().async_set_wallpaper_mode(mode);
  46. }
  47. bool Desktop::set_wallpaper(StringView path, bool save_config)
  48. {
  49. WindowServerConnection::the().async_set_wallpaper(path);
  50. auto ret_val = WindowServerConnection::the().wait_for_specific_message<Messages::WindowClient::SetWallpaperFinished>()->success();
  51. if (ret_val && save_config) {
  52. dbgln("Saving wallpaper path '{}' to ConfigServer", path);
  53. Config::write_string("WindowManager", "Background", "Wallpaper", path);
  54. }
  55. return ret_val;
  56. }
  57. String Desktop::wallpaper() const
  58. {
  59. return WindowServerConnection::the().get_wallpaper();
  60. }
  61. }