mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00

Currently, the generated IPC decoders will default-construct the type to be decoded, then pass that value by reference to the concrete decoder. This, of course, requires that the type is default-constructible. This was an issue for decoding Variants, which had to require the first type in the Variant list is Empty, to ensure it is default constructible. Further, this made it possible for values to become uninitialized in user-defined decoders. This patch makes the decoder interface such that the concrete decoders themselves contruct the decoded type upon return from the decoder. To do so, the default decoders in IPC::Decoder had to be moved to the IPC namespace scope, as these decoders are now specializations instead of overloaded methods (C++ requires specializations to be in a namespace scope).
88 lines
2.1 KiB
C++
88 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/DeprecatedString.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibCore/ConfigFile.h>
|
|
#include <LibGfx/Rect.h>
|
|
#include <LibGfx/Size.h>
|
|
#include <LibIPC/Forward.h>
|
|
|
|
namespace WindowServer {
|
|
|
|
class ScreenLayout {
|
|
public:
|
|
struct Screen {
|
|
enum class Mode {
|
|
Invalid,
|
|
Device,
|
|
Virtual,
|
|
} mode;
|
|
Optional<DeprecatedString> device;
|
|
Gfx::IntPoint location;
|
|
Gfx::IntSize resolution;
|
|
int scale_factor;
|
|
|
|
Gfx::IntRect virtual_rect() const
|
|
{
|
|
return { location, { resolution.width() / scale_factor, resolution.height() / scale_factor } };
|
|
}
|
|
|
|
static StringView mode_to_string(Mode mode)
|
|
{
|
|
#define __ENUMERATE_MODE_ENUM(val) \
|
|
case Mode::val: \
|
|
return #val##sv;
|
|
|
|
switch (mode) {
|
|
__ENUMERATE_MODE_ENUM(Invalid)
|
|
__ENUMERATE_MODE_ENUM(Device)
|
|
__ENUMERATE_MODE_ENUM(Virtual)
|
|
}
|
|
VERIFY_NOT_REACHED();
|
|
|
|
#undef __ENUMERATE_MODE_ENUM
|
|
}
|
|
|
|
bool operator==(Screen const&) const = default;
|
|
};
|
|
|
|
Vector<Screen> screens;
|
|
unsigned main_screen_index { 0 };
|
|
|
|
bool is_valid(DeprecatedString* error_msg = nullptr) const;
|
|
bool normalize();
|
|
bool load_config(Core::ConfigFile const& config_file, DeprecatedString* error_msg = nullptr);
|
|
bool save_config(Core::ConfigFile& config_file, bool sync = true) const;
|
|
bool try_auto_add_display_connector(DeprecatedString const&);
|
|
|
|
// TODO: spaceship operator
|
|
bool operator!=(ScreenLayout const& other) const;
|
|
bool operator==(ScreenLayout const& other) const
|
|
{
|
|
return !(*this != other);
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
namespace IPC {
|
|
|
|
template<>
|
|
bool encode(Encoder&, WindowServer::ScreenLayout::Screen const&);
|
|
|
|
template<>
|
|
ErrorOr<WindowServer::ScreenLayout::Screen> decode(Decoder&);
|
|
|
|
template<>
|
|
bool encode(Encoder&, WindowServer::ScreenLayout const&);
|
|
|
|
template<>
|
|
ErrorOr<WindowServer::ScreenLayout> decode(Decoder&);
|
|
|
|
}
|