GDesktop.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <LibGUI/GDesktop.h>
  2. #include <LibGUI/GEventLoop.h>
  3. #include <AK/Eternal.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. GDesktop& GDesktop::the()
  7. {
  8. static Eternal<GDesktop> the;
  9. return the;
  10. }
  11. GDesktop::GDesktop()
  12. {
  13. }
  14. void GDesktop::did_receive_screen_rect(Badge<GEventLoop>, const Rect& rect)
  15. {
  16. if (m_rect == rect)
  17. return;
  18. m_rect = rect;
  19. if (on_rect_change)
  20. on_rect_change(rect);
  21. }
  22. bool GDesktop::set_wallpaper(const String& path)
  23. {
  24. WSAPI_ClientMessage message;
  25. message.type = WSAPI_ClientMessage::Type::SetWallpaper;
  26. ASSERT(path.length() < (int)sizeof(message.text));
  27. strncpy(message.text, path.characters(), path.length());
  28. message.text_length = path.length();
  29. auto response = GEventLoop::current().sync_request(message, WSAPI_ServerMessage::Type::DidSetWallpaper);
  30. return response.value;
  31. }
  32. String GDesktop::wallpaper() const
  33. {
  34. WSAPI_ClientMessage message;
  35. message.type = WSAPI_ClientMessage::Type::GetWallpaper;
  36. auto response = GEventLoop::current().sync_request(message, WSAPI_ServerMessage::Type::DidGetWallpaper);
  37. return String(response.text, response.text_length);
  38. }