blob: 906a7d6f5c4b33aecb75c3dc02c0af71db8b76a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <fstream>
#include <sstream>
#include <unistd.h>
#include "xorg-conf.h"
#include "helpers.h"
#include "xit-server.h"
XOrgConfig::XOrgConfig(const std::string& path) {
if (path.empty())
SetPath(XITServer::GetDefaultConfigFile());
std::stringstream section;
section << ""
"Section \"ServerFlags\"\n"
" Option \"Log\" \"flush\"\n"
"EndSection\n";
sections.push_back(section.str());
auto_add_devices = false;
}
void XOrgConfig::WriteConfig(const std::string &path) {
if (!path.empty()) {
config_file = path;
SetPath(path);
}
std::ofstream conffile(config_file.c_str());
conffile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
conffile << ""
"Section \"ServerLayout\"\n"
" Identifier \"Dummy layout\"\n";
if (!auto_add_devices)
conffile << " Option \"AutoAddDevices\" \"off\"\n";
if (!default_device.empty())
conffile << " Screen 0 \"" << default_device << " screen\" 0 0\n";
std::vector<std::string>::const_iterator it;
for (it = input_devices.begin(); it != input_devices.end(); it++)
conffile << " InputDevice \"" << *it << "\"\n";
conffile << "EndSection\n";
for (it = sections.begin(); it != sections.end(); it++)
conffile << "\n" << *it;
}
void XOrgConfig::RemoveConfig() {
unlink(GetPath().c_str());
}
void XOrgConfig::AddDefaultScreenWithDriver(const std::string &driver,
const std::string &identifier,
const std::string &options) {
default_device = identifier;
std::stringstream section;
section << "Section \"Device\"\n"
" Identifier \"" << identifier << "\"\n"
" Driver \"" << driver << "\"\n"
<< options << "\n" <<
"EndSection\n";
sections.push_back(section.str());
section.str(std::string());
section << "Section \"Screen\"\n"
" Identifier \"" << identifier << " screen\"\n"
" Device \"" << identifier << "\"\n"
"EndSection\n";
sections.push_back(section.str());
}
void XOrgConfig::AddInputSection(const std::string &driver,
const std::string &identifier,
const std::string &options,
bool reference_from_layout) {
if (reference_from_layout)
input_devices.push_back(identifier);
std::stringstream section;
section << "Section \"InputDevice\"\n"
" Identifier \"" << identifier << "\"\n"
" Driver \"" << driver << "\"\n"
<< options << "\n" <<
"EndSection\n";
sections.push_back(section.str());
}
void XOrgConfig::SetAutoAddDevices(bool enabled) {
auto_add_devices = enabled;
}
const std::string& XOrgConfig::GetPath() {
return config_file;
}
void XOrgConfig::SetPath(const std::string& path) {
config_file = path;
}
|