| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 15:04:03 +01:00
										 |  |  | #include <LibCore/ConfigFile.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | #include <LibGUI/GDesktop.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-08 11:39:45 +01:00
										 |  |  | #include <LibGUI/GWindowServerConnection.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2019-04-03 17:22:14 +02:00
										 |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | namespace GUI { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Desktop& Desktop::the() | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     static Desktop* the; | 
					
						
							| 
									
										
										
										
											2019-04-05 05:10:18 +02:00
										 |  |  |     if (!the) | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         the = new Desktop; | 
					
						
							| 
									
										
										
										
											2019-04-05 05:10:18 +02:00
										 |  |  |     return *the; | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | Desktop::Desktop() | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 11:56:38 +01:00
										 |  |  | void Desktop::did_receive_screen_rect(Badge<WindowServerConnection>, const Gfx::Rect& rect) | 
					
						
							| 
									
										
										
										
											2019-04-03 17:22:14 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-03 19:38:44 +02:00
										 |  |  |     if (m_rect == rect) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-04-03 17:22:14 +02:00
										 |  |  |     m_rect = rect; | 
					
						
							| 
									
										
										
										
											2019-04-03 19:38:44 +02:00
										 |  |  |     if (on_rect_change) | 
					
						
							|  |  |  |         on_rect_change(rect); | 
					
						
							| 
									
										
										
										
											2019-04-03 17:22:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | bool Desktop::set_wallpaper(const StringView& path) | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     WindowServerConnection::the().post_message(WindowServer::AsyncSetWallpaper(path)); | 
					
						
							|  |  |  |     auto ret_val = WindowServerConnection::the().wait_for_specific_message<WindowClient::AsyncSetWallpaperFinished>()->success(); | 
					
						
							| 
									
										
										
										
											2020-02-02 14:45:45 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (ret_val) { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |         RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("WindowManager"); | 
					
						
							| 
									
										
										
										
											2020-02-02 14:45:45 +03:00
										 |  |  |         dbg() << "Saving wallpaper path '" << path << "' to config file at " << config->file_name(); | 
					
						
							|  |  |  |         config->write_entry("Background", "Wallpaper", path); | 
					
						
							|  |  |  |         config->sync(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ret_val; | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  | String Desktop::wallpaper() const | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-02 15:07:41 +01:00
										 |  |  |     return WindowServerConnection::the().send_sync<WindowServer::GetWallpaper>()->path(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-21 15:54:19 +01:00
										 |  |  | } |