Hermes
0.7.0
Linux game streaming host
Toggle main menu visibility
Loading...
Searching...
No Matches
monitor_restore.h
Go to the documentation of this file.
1
5
#pragma once
6
7
#include <algorithm>
8
#include <map>
9
#include <optional>
10
#include <string>
11
#include <vector>
12
13
namespace
VDISPLAY {
15
struct
kscreen_output_t
{
16
std::string
name
;
17
bool
connected
{
false
};
18
bool
enabled
{
false
};
19
int
priority
{0};
20
int
x
{0};
21
int
y
{0};
22
int
width
{0};
23
int
height
{0};
24
};
25
26
namespace
monitor_restore {
27
using
targets_t = std::map<std::string, int>;
28
using
snapshot_t = std::optional<std::vector<kscreen_output_t>>;
29
37
template
<
class
Query,
class
Apply>
38
bool
restore
(
const
targets_t &saved, Query query, Apply apply) {
39
if
(saved.empty()) {
40
return
true
;
41
}
42
const
auto
before = query();
43
if
(!before) {
44
return
false
;
45
}
46
targets_t connected;
47
bool
already_restored =
true
;
48
for
(
const
auto
&output : *before) {
49
const
auto
target = saved.find(output.name);
50
if
(target != saved.end() && output.connected) {
51
connected.emplace(*target);
52
already_restored &= output.enabled &&
53
(target->second <= 0 || output.priority == target->second);
54
}
55
}
56
if
(connected.empty() || already_restored) {
57
return
true
;
58
}
59
60
// Always verify, even if the command failed after partially applying.
61
apply(connected);
62
const
auto
after = query();
63
if
(!after) {
64
return
false
;
65
}
66
for
(
const
auto
&[name, priority] : connected) {
67
const
auto
output = std::find_if(after->begin(), after->end(), [&name](
const
auto
&entry) {
68
return entry.name == name;
69
});
70
if
(output != after->end() && output->connected && !output->enabled) {
71
return
false
;
72
}
73
}
74
return
true
;
75
}
76
}
// namespace monitor_restore
77
}
// namespace VDISPLAY
VDISPLAY::monitor_restore::restore
bool restore(const targets_t &saved, Query query, Apply apply)
Definition
monitor_restore.h:38
VDISPLAY::kscreen_output_t
One output as kscreen-doctor -j reports it.
Definition
monitor_restore.h:15
VDISPLAY::kscreen_output_t::name
std::string name
Connector name, e.g. "HDMI-A-1".
Definition
monitor_restore.h:16
VDISPLAY::kscreen_output_t::connected
bool connected
The connector exists in this session.
Definition
monitor_restore.h:17
VDISPLAY::kscreen_output_t::enabled
bool enabled
KWin is composing on it.
Definition
monitor_restore.h:18
VDISPLAY::kscreen_output_t::width
int width
Logical width.
Definition
monitor_restore.h:22
VDISPLAY::kscreen_output_t::x
int x
Logical x.
Definition
monitor_restore.h:20
VDISPLAY::kscreen_output_t::y
int y
Logical y.
Definition
monitor_restore.h:21
VDISPLAY::kscreen_output_t::height
int height
Logical height.
Definition
monitor_restore.h:23
VDISPLAY::kscreen_output_t::priority
int priority
KScreen priority; 1 marks the primary output.
Definition
monitor_restore.h:19
src
platform
linux
monitor_restore.h
Generated by
1.18.0