GDesktop.cpp 1.2 KB

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