Desktop.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_rect(Badge<WindowServerConnection>, const Gfx::IntRect& rect)
  24. {
  25. if (m_rect == rect)
  26. return;
  27. m_rect = rect;
  28. }
  29. void Desktop::set_background_color(const StringView& background_color)
  30. {
  31. WindowServerConnection::the().async_set_background_color(background_color);
  32. }
  33. void Desktop::set_wallpaper_mode(const StringView& mode)
  34. {
  35. WindowServerConnection::the().async_set_wallpaper_mode(mode);
  36. }
  37. bool Desktop::set_wallpaper(const StringView& path, bool save_config)
  38. {
  39. WindowServerConnection::the().async_set_wallpaper(path);
  40. auto ret_val = WindowServerConnection::the().wait_for_specific_message<Messages::WindowClient::SetWallpaperFinished>()->success();
  41. if (ret_val && save_config) {
  42. RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("WindowManager");
  43. dbgln("Saving wallpaper path '{}' to config file at {}", path, config->filename());
  44. config->write_entry("Background", "Wallpaper", path);
  45. config->sync();
  46. }
  47. return ret_val;
  48. }
  49. String Desktop::wallpaper() const
  50. {
  51. return WindowServerConnection::the().get_wallpaper();
  52. }
  53. }