2020-01-18 08:38:21 +00: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-16 08:17:49 +00:00
|
|
|
#include <AK/Badge.h>
|
2020-02-06 14:04:03 +00:00
|
|
|
#include <LibCore/ConfigFile.h>
|
2020-02-06 19:33:02 +00:00
|
|
|
#include <LibGUI/Desktop.h>
|
|
|
|
#include <LibGUI/WindowServerConnection.h>
|
2019-03-21 14:54:19 +00:00
|
|
|
#include <string.h>
|
2019-04-03 15:22:14 +00:00
|
|
|
#include <unistd.h>
|
2019-03-21 14:54:19 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
Desktop& Desktop::the()
|
2019-03-21 14:54:19 +00:00
|
|
|
{
|
2020-02-02 14:07:41 +00:00
|
|
|
static Desktop* the;
|
2019-04-05 03:10:18 +00:00
|
|
|
if (!the)
|
2020-02-02 14:07:41 +00:00
|
|
|
the = new Desktop;
|
2019-04-05 03:10:18 +00:00
|
|
|
return *the;
|
2019-03-21 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
Desktop::Desktop()
|
2019-03-21 14:54:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
void Desktop::did_receive_screen_rect(Badge<WindowServerConnection>, const Gfx::Rect& rect)
|
2019-04-03 15:22:14 +00:00
|
|
|
{
|
2019-04-03 17:38:44 +00:00
|
|
|
if (m_rect == rect)
|
|
|
|
return;
|
2019-04-03 15:22:14 +00:00
|
|
|
m_rect = rect;
|
2019-04-03 17:38:44 +00:00
|
|
|
if (on_rect_change)
|
|
|
|
on_rect_change(rect);
|
2019-04-03 15:22:14 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
bool Desktop::set_wallpaper(const StringView& path)
|
2019-03-21 14:54:19 +00:00
|
|
|
{
|
2020-02-06 19:20:44 +00:00
|
|
|
WindowServerConnection::the().post_message(Messages::WindowServer::AsyncSetWallpaper(path));
|
|
|
|
auto ret_val = WindowServerConnection::the().wait_for_specific_message<Messages::WindowClient::AsyncSetWallpaperFinished>()->success();
|
2020-02-02 11:45:45 +00:00
|
|
|
|
|
|
|
if (ret_val) {
|
2020-02-02 14:07:41 +00:00
|
|
|
RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("WindowManager");
|
2020-02-02 11:45:45 +00: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 14:54:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
String Desktop::wallpaper() const
|
2019-03-21 14:54:19 +00:00
|
|
|
{
|
2020-02-06 19:20:44 +00:00
|
|
|
return WindowServerConnection::the().send_sync<Messages::WindowServer::GetWallpaper>()->path();
|
2020-02-02 14:07:41 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 14:54:19 +00:00
|
|
|
}
|