Desktop.cpp 2.1 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 <LibCore/ConfigFile.h>
  8. #include <LibGUI/Desktop.h>
  9. #include <LibGUI/WindowServerConnection.h>
  10. #include <string.h>
  11. namespace GUI {
  12. Desktop& Desktop::the()
  13. {
  14. static Desktop* the;
  15. if (!the)
  16. the = new Desktop;
  17. return *the;
  18. }
  19. Desktop::Desktop()
  20. {
  21. }
  22. void Desktop::did_receive_screen_rects(Badge<WindowServerConnection>, const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index, unsigned virtual_desktop_rows, unsigned virtual_desktop_columns)
  23. {
  24. m_main_screen_index = main_screen_index;
  25. m_rects = rects;
  26. if (!m_rects.is_empty()) {
  27. m_bounding_rect = m_rects[0];
  28. for (size_t i = 1; i < m_rects.size(); i++)
  29. m_bounding_rect = m_bounding_rect.united(m_rects[i]);
  30. } else {
  31. m_bounding_rect = {};
  32. }
  33. m_virtual_desktop_rows = virtual_desktop_rows;
  34. m_virtual_desktop_columns = virtual_desktop_columns;
  35. for (auto& callback : m_receive_rects_callbacks)
  36. callback(*this);
  37. }
  38. void Desktop::set_background_color(const StringView& background_color)
  39. {
  40. WindowServerConnection::the().async_set_background_color(background_color);
  41. }
  42. void Desktop::set_wallpaper_mode(const StringView& mode)
  43. {
  44. WindowServerConnection::the().async_set_wallpaper_mode(mode);
  45. }
  46. bool Desktop::set_wallpaper(const StringView& path, bool save_config)
  47. {
  48. WindowServerConnection::the().async_set_wallpaper(path);
  49. auto ret_val = WindowServerConnection::the().wait_for_specific_message<Messages::WindowClient::SetWallpaperFinished>()->success();
  50. if (ret_val && save_config) {
  51. RefPtr<Core::ConfigFile> config = Core::ConfigFile::open_for_app("WindowManager", Core::ConfigFile::AllowWriting::Yes);
  52. dbgln("Saving wallpaper path '{}' to config file at {}", path, config->filename());
  53. config->write_entry("Background", "Wallpaper", path);
  54. config->sync();
  55. }
  56. return ret_val;
  57. }
  58. String Desktop::wallpaper() const
  59. {
  60. return WindowServerConnection::the().get_wallpaper();
  61. }
  62. }