Desktop.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <AK/TemporaryChange.h>
  8. #include <LibGUI/ConnectionToWindowServer.h>
  9. #include <LibGUI/Desktop.h>
  10. #include <string.h>
  11. // Including this after to avoid LibIPC errors
  12. #include <LibConfig/Client.h>
  13. namespace GUI {
  14. Desktop& Desktop::the()
  15. {
  16. static Desktop s_the;
  17. return s_the;
  18. }
  19. Desktop::Desktop()
  20. {
  21. }
  22. void Desktop::did_receive_screen_rects(Badge<ConnectionToWindowServer>, const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index, unsigned workspace_rows, unsigned workspace_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_workspace_rows = workspace_rows;
  34. m_workspace_columns = workspace_columns;
  35. for (auto& callback : m_receive_rects_callbacks)
  36. callback(*this);
  37. }
  38. void Desktop::set_background_color(StringView background_color)
  39. {
  40. ConnectionToWindowServer::the().async_set_background_color(background_color);
  41. }
  42. void Desktop::set_wallpaper_mode(StringView mode)
  43. {
  44. ConnectionToWindowServer::the().async_set_wallpaper_mode(mode);
  45. }
  46. String Desktop::wallpaper_path() const
  47. {
  48. return Config::read_string("WindowManager", "Background", "Wallpaper");
  49. }
  50. RefPtr<Gfx::Bitmap> Desktop::wallpaper_bitmap() const
  51. {
  52. return ConnectionToWindowServer::the().get_wallpaper().bitmap();
  53. }
  54. bool Desktop::set_wallpaper(RefPtr<Gfx::Bitmap> wallpaper_bitmap, Optional<String> path)
  55. {
  56. if (m_is_setting_desktop_wallpaper)
  57. return false;
  58. TemporaryChange is_setting_desktop_wallpaper_change(m_is_setting_desktop_wallpaper, true);
  59. ConnectionToWindowServer::the().async_set_wallpaper(wallpaper_bitmap ? wallpaper_bitmap->to_shareable_bitmap() : Gfx::ShareableBitmap {});
  60. auto ret_val = ConnectionToWindowServer::the().wait_for_specific_message<Messages::WindowClient::SetWallpaperFinished>()->success();
  61. if (ret_val && path.has_value()) {
  62. dbgln("Saving wallpaper path '{}' to ConfigServer", *path);
  63. Config::write_string("WindowManager", "Background", "Wallpaper", *path);
  64. }
  65. return ret_val;
  66. }
  67. }