Desktop.cpp 2.0 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 <LibCore/ConfigFile.h>
  8. #include <LibGUI/Desktop.h>
  9. #include <LibGUI/WindowServerConnection.h>
  10. #include <string.h>
  11. #include <unistd.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 virtual_desktop_rows, unsigned virtual_desktop_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_virtual_desktop_rows = virtual_desktop_rows;
  35. m_virtual_desktop_columns = virtual_desktop_columns;
  36. }
  37. void Desktop::set_background_color(const StringView& background_color)
  38. {
  39. WindowServerConnection::the().async_set_background_color(background_color);
  40. }
  41. void Desktop::set_wallpaper_mode(const StringView& mode)
  42. {
  43. WindowServerConnection::the().async_set_wallpaper_mode(mode);
  44. }
  45. bool Desktop::set_wallpaper(const 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. RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("WindowManager");
  51. dbgln("Saving wallpaper path '{}' to config file at {}", path, config->filename());
  52. config->write_entry("Background", "Wallpaper", path);
  53. config->sync();
  54. }
  55. return ret_val;
  56. }
  57. String Desktop::wallpaper() const
  58. {
  59. return WindowServerConnection::the().get_wallpaper();
  60. }
  61. }