Desktop.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 s_the;
  16. return s_the;
  17. }
  18. Desktop::Desktop()
  19. {
  20. }
  21. 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)
  22. {
  23. m_main_screen_index = main_screen_index;
  24. m_rects = rects;
  25. if (!m_rects.is_empty()) {
  26. m_bounding_rect = m_rects[0];
  27. for (size_t i = 1; i < m_rects.size(); i++)
  28. m_bounding_rect = m_bounding_rect.united(m_rects[i]);
  29. } else {
  30. m_bounding_rect = {};
  31. }
  32. m_workspace_rows = workspace_rows;
  33. m_workspace_columns = workspace_columns;
  34. for (auto& callback : m_receive_rects_callbacks)
  35. callback(*this);
  36. }
  37. void Desktop::set_background_color(StringView background_color)
  38. {
  39. WindowServerConnection::the().async_set_background_color(background_color);
  40. }
  41. void Desktop::set_wallpaper_mode(StringView mode)
  42. {
  43. WindowServerConnection::the().async_set_wallpaper_mode(mode);
  44. }
  45. bool Desktop::set_wallpaper(StringView path, bool save_config)
  46. {
  47. WindowServerConnection::the().async_set_wallpaper(path);
  48. auto ret_val = WindowServerConnection::the().wait_for_specific_message<Messages::WindowClient::SetWallpaperFinished>()->success();
  49. if (ret_val && save_config) {
  50. dbgln("Saving wallpaper path '{}' to ConfigServer", path);
  51. Config::write_string("WindowManager", "Background", "Wallpaper", path);
  52. }
  53. return ret_val;
  54. }
  55. String Desktop::wallpaper() const
  56. {
  57. return WindowServerConnection::the().get_wallpaper();
  58. }
  59. }