2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 14:50:04 -03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-02-16 05:17:49 -03:00
|
|
|
#include <AK/Badge.h>
|
2022-02-13 15:00:57 -03:00
|
|
|
#include <AK/TemporaryChange.h>
|
2022-11-15 13:32:00 -03:00
|
|
|
#include <LibConfig/Client.h>
|
2022-02-25 07:39:33 -03:00
|
|
|
#include <LibGUI/ConnectionToWindowServer.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Desktop.h>
|
2019-03-21 11:54:19 -03:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
Desktop& Desktop::the()
|
2019-03-21 11:54:19 -03:00
|
|
|
{
|
2022-01-28 17:22:13 -03:00
|
|
|
static Desktop s_the;
|
|
|
|
|
return s_the;
|
2019-03-21 11:54:19 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
void Desktop::did_receive_screen_rects(Badge<ConnectionToWindowServer>, Vector<Gfx::IntRect, 4> const& rects, size_t main_screen_index, unsigned workspace_rows, unsigned workspace_columns)
|
2019-04-03 12:22:14 -03:00
|
|
|
{
|
2021-06-13 09:16:06 -03:00
|
|
|
m_main_screen_index = main_screen_index;
|
|
|
|
|
m_rects = rects;
|
|
|
|
|
if (!m_rects.is_empty()) {
|
|
|
|
|
m_bounding_rect = m_rects[0];
|
|
|
|
|
for (size_t i = 1; i < m_rects.size(); i++)
|
|
|
|
|
m_bounding_rect = m_bounding_rect.united(m_rects[i]);
|
|
|
|
|
} else {
|
|
|
|
|
m_bounding_rect = {};
|
|
|
|
|
}
|
2021-06-30 22:12:02 -03:00
|
|
|
|
2021-11-13 08:11:35 -03:00
|
|
|
m_workspace_rows = workspace_rows;
|
|
|
|
|
m_workspace_columns = workspace_columns;
|
2021-07-18 15:41:12 -03:00
|
|
|
|
|
|
|
|
for (auto& callback : m_receive_rects_callbacks)
|
|
|
|
|
callback(*this);
|
2019-04-03 12:22:14 -03:00
|
|
|
}
|
|
|
|
|
|
2021-11-10 20:55:02 -03:00
|
|
|
void Desktop::set_background_color(StringView background_color)
|
2020-03-29 07:32:34 -03:00
|
|
|
{
|
2022-02-25 07:39:33 -03:00
|
|
|
ConnectionToWindowServer::the().async_set_background_color(background_color);
|
2020-03-29 07:32:34 -03:00
|
|
|
}
|
|
|
|
|
|
2021-11-10 20:55:02 -03:00
|
|
|
void Desktop::set_wallpaper_mode(StringView mode)
|
2020-03-29 07:32:34 -03:00
|
|
|
{
|
2022-02-25 07:39:33 -03:00
|
|
|
ConnectionToWindowServer::the().async_set_wallpaper_mode(mode);
|
2020-03-29 07:32:34 -03:00
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
DeprecatedString Desktop::wallpaper_path() const
|
2019-03-21 11:54:19 -03:00
|
|
|
{
|
2022-07-11 14:32:29 -03:00
|
|
|
return Config::read_string("WindowManager"sv, "Background"sv, "Wallpaper"sv);
|
2022-02-13 15:00:57 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefPtr<Gfx::Bitmap> Desktop::wallpaper_bitmap() const
|
|
|
|
|
{
|
2022-02-25 07:39:33 -03:00
|
|
|
return ConnectionToWindowServer::the().get_wallpaper().bitmap();
|
2022-02-13 15:00:57 -03:00
|
|
|
}
|
|
|
|
|
|
2023-03-17 06:38:39 -03:00
|
|
|
bool Desktop::set_wallpaper(RefPtr<Gfx::Bitmap const> wallpaper_bitmap, Optional<StringView> path)
|
2022-02-13 15:00:57 -03:00
|
|
|
{
|
|
|
|
|
if (m_is_setting_desktop_wallpaper)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
TemporaryChange is_setting_desktop_wallpaper_change(m_is_setting_desktop_wallpaper, true);
|
2022-08-01 19:51:37 -03:00
|
|
|
auto result = ConnectionToWindowServer::the().set_wallpaper(wallpaper_bitmap ? wallpaper_bitmap->to_shareable_bitmap() : Gfx::ShareableBitmap {});
|
2020-02-02 08:45:45 -03:00
|
|
|
|
2022-08-01 19:51:37 -03:00
|
|
|
if (result && path.has_value()) {
|
2022-02-13 15:00:57 -03:00
|
|
|
dbgln("Saving wallpaper path '{}' to ConfigServer", *path);
|
2022-07-11 14:32:29 -03:00
|
|
|
Config::write_string("WindowManager"sv, "Background"sv, "Wallpaper"sv, *path);
|
2020-02-02 08:45:45 -03:00
|
|
|
}
|
|
|
|
|
|
2022-08-01 19:51:37 -03:00
|
|
|
return result;
|
2019-03-21 11:54:19 -03:00
|
|
|
}
|
2022-08-01 19:51:37 -03:00
|
|
|
|
2019-03-21 11:54:19 -03:00
|
|
|
}
|