Serenity Operating System
at master 88 lines 2.2 kB view raw
1/* 2 * Copyright (c) 2020, the SerenityOS developers. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/DeprecatedString.h> 10#include <AK/Vector.h> 11#include <LibCore/ConfigFile.h> 12#include <LibGfx/Rect.h> 13#include <LibGfx/Size.h> 14#include <LibIPC/Forward.h> 15 16namespace WindowServer { 17 18class ScreenLayout { 19public: 20 struct Screen { 21 enum class Mode { 22 Invalid, 23 Device, 24 Virtual, 25 } mode; 26 Optional<DeprecatedString> device; 27 Gfx::IntPoint location; 28 Gfx::IntSize resolution; 29 int scale_factor; 30 31 Gfx::IntRect virtual_rect() const 32 { 33 return { location, { resolution.width() / scale_factor, resolution.height() / scale_factor } }; 34 } 35 36 static StringView mode_to_string(Mode mode) 37 { 38#define __ENUMERATE_MODE_ENUM(val) \ 39 case Mode::val: \ 40 return #val##sv; 41 42 switch (mode) { 43 __ENUMERATE_MODE_ENUM(Invalid) 44 __ENUMERATE_MODE_ENUM(Device) 45 __ENUMERATE_MODE_ENUM(Virtual) 46 } 47 VERIFY_NOT_REACHED(); 48 49#undef __ENUMERATE_MODE_ENUM 50 } 51 52 bool operator==(Screen const&) const = default; 53 }; 54 55 Vector<Screen> screens; 56 unsigned main_screen_index { 0 }; 57 58 bool is_valid(DeprecatedString* error_msg = nullptr) const; 59 bool normalize(); 60 bool load_config(Core::ConfigFile const& config_file, DeprecatedString* error_msg = nullptr); 61 bool save_config(Core::ConfigFile& config_file, bool sync = true) const; 62 bool try_auto_add_display_connector(DeprecatedString const&); 63 64 // TODO: spaceship operator 65 bool operator!=(ScreenLayout const& other) const; 66 bool operator==(ScreenLayout const& other) const 67 { 68 return !(*this != other); 69 } 70}; 71 72} 73 74namespace IPC { 75 76template<> 77ErrorOr<void> encode(Encoder&, WindowServer::ScreenLayout::Screen const&); 78 79template<> 80ErrorOr<WindowServer::ScreenLayout::Screen> decode(Decoder&); 81 82template<> 83ErrorOr<void> encode(Encoder&, WindowServer::ScreenLayout const&); 84 85template<> 86ErrorOr<WindowServer::ScreenLayout> decode(Decoder&); 87 88}