2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2020-02-09 20:37:42 +03:00
|
|
|
#include "AppletManager.h"
|
2020-02-06 22:03:37 +03:00
|
|
|
#include "Compositor.h"
|
|
|
|
#include "EventLoop.h"
|
|
|
|
#include "Screen.h"
|
|
|
|
#include "WindowManager.h"
|
2020-02-06 17:04:03 +03:00
|
|
|
#include <LibCore/ConfigFile.h>
|
2020-02-06 14:04:00 +03:00
|
|
|
#include <LibGfx/Palette.h>
|
|
|
|
#include <LibGfx/SystemTheme.h>
|
2019-03-01 18:16:23 +03:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2020-03-08 14:05:14 +03:00
|
|
|
#include <string.h>
|
2021-03-12 19:29:37 +03:00
|
|
|
#include <unistd.h>
|
2019-01-16 18:03:50 +03:00
|
|
|
|
2019-02-17 02:13:47 +03:00
|
|
|
int main(int, char**)
|
2019-01-16 18:03:50 +03:00
|
|
|
{
|
2021-05-14 00:20:26 +03:00
|
|
|
if (pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction", nullptr) < 0) {
|
2020-01-11 23:25:03 +03:00
|
|
|
perror("pledge");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-01-21 00:23:18 +03:00
|
|
|
if (unveil("/res", "r") < 0) {
|
2020-06-05 01:50:58 +03:00
|
|
|
perror("unveil /res");
|
2020-01-21 00:23:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unveil("/tmp", "cw") < 0) {
|
2020-06-05 01:50:58 +03:00
|
|
|
perror("unveil /tmp cw");
|
2020-01-21 00:23:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-04-29 22:40:59 +03:00
|
|
|
if (unveil("/etc/WindowServer.ini", "rwc") < 0) {
|
|
|
|
perror("unveil /etc/WindowServer.ini");
|
2020-01-21 00:23:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unveil("/dev", "rw") < 0) {
|
2020-06-05 01:50:58 +03:00
|
|
|
perror("unveil /dev rw");
|
2020-01-21 00:23:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-03-01 18:16:23 +03:00
|
|
|
struct sigaction act;
|
|
|
|
memset(&act, 0, sizeof(act));
|
|
|
|
act.sa_flags = SA_NOCLDWAIT;
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
int rc = sigaction(SIGCHLD, &act, nullptr);
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("sigaction");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-04-29 22:40:59 +03:00
|
|
|
auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini");
|
2019-12-23 22:24:26 +03:00
|
|
|
auto theme_name = wm_config->read_entry("Theme", "Name", "Default");
|
|
|
|
|
2021-01-16 14:00:33 +03:00
|
|
|
auto theme = Gfx::load_system_theme(String::formatted("/res/themes/{}.ini", theme_name));
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(theme.is_valid());
|
2021-01-16 19:20:53 +03:00
|
|
|
Gfx::set_system_theme(theme);
|
|
|
|
auto palette = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
|
2019-12-23 22:24:26 +03:00
|
|
|
|
2021-05-21 19:59:07 +03:00
|
|
|
auto default_font_query = wm_config->read_entry("Fonts", "Default", "Katica 10 400");
|
|
|
|
auto fixed_width_font_query = wm_config->read_entry("Fonts", "FixedWidth", "Csilla 10 400");
|
|
|
|
|
|
|
|
Gfx::FontDatabase::set_default_font_query(default_font_query);
|
|
|
|
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
|
2021-05-21 19:10:23 +03:00
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowServer::EventLoop loop;
|
2019-05-25 19:26:23 +03:00
|
|
|
|
2021-01-16 19:20:53 +03:00
|
|
|
if (pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc", nullptr) < 0) {
|
2020-01-11 23:25:03 +03:00
|
|
|
perror("pledge");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-06-13 15:16:06 +03:00
|
|
|
// First check which screens are explicitly configured
|
2021-06-15 06:19:56 +03:00
|
|
|
{
|
|
|
|
AK::HashTable<String> fb_devices_configured;
|
|
|
|
WindowServer::ScreenLayout screen_layout;
|
|
|
|
String error_msg;
|
|
|
|
if (!screen_layout.load_config(*wm_config, &error_msg)) {
|
|
|
|
dbgln("Error loading screen configuration: {}", error_msg);
|
|
|
|
return 1;
|
2021-06-14 06:09:47 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 06:19:56 +03:00
|
|
|
for (auto& screen_info : screen_layout.screens)
|
|
|
|
fb_devices_configured.set(screen_info.device);
|
2021-06-13 15:16:06 +03:00
|
|
|
|
2021-06-15 06:19:56 +03:00
|
|
|
// TODO: Enumerate the /dev/fbX devices and set up any ones we find that we haven't already used
|
2021-06-13 15:16:06 +03:00
|
|
|
|
2021-06-15 06:19:56 +03:00
|
|
|
if (!WindowServer::Screen::apply_layout(move(screen_layout), error_msg)) {
|
|
|
|
dbgln("Error applying screen layout: {}", error_msg);
|
2021-06-14 06:09:47 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-13 15:16:06 +03:00
|
|
|
auto& screen_input = WindowServer::ScreenInput::the();
|
|
|
|
screen_input.set_cursor_location(WindowServer::Screen::main().rect().center());
|
|
|
|
screen_input.set_acceleration_factor(atof(wm_config->read_entry("Mouse", "AccelerationFactor", "1.0").characters()));
|
|
|
|
screen_input.set_scroll_step_size(wm_config->read_num_entry("Mouse", "ScrollStepSize", 4));
|
|
|
|
|
2020-02-06 22:03:37 +03:00
|
|
|
WindowServer::Compositor::the();
|
|
|
|
auto wm = WindowServer::WindowManager::construct(*palette);
|
2020-02-09 20:37:42 +03:00
|
|
|
auto am = WindowServer::AppletManager::construct();
|
2020-02-06 22:03:37 +03:00
|
|
|
auto mm = WindowServer::MenuManager::construct();
|
2019-01-16 18:03:50 +03:00
|
|
|
|
2020-01-21 00:23:18 +03:00
|
|
|
if (unveil("/tmp", "") < 0) {
|
2020-06-05 01:50:58 +03:00
|
|
|
perror("unveil /tmp");
|
2020-01-21 00:23:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-06-15 06:19:56 +03:00
|
|
|
// NOTE: Because we dynamically need to be able to open new /dev/fb*
|
|
|
|
// devices we can't really unveil all of /dev unless we have some
|
|
|
|
// other mechanism that can hand us file descriptors for these.
|
2020-01-21 00:23:18 +03:00
|
|
|
|
|
|
|
if (unveil(nullptr, nullptr) < 0) {
|
|
|
|
perror("unveil");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-01-09 20:51:44 +03:00
|
|
|
dbgln("Entering WindowServer main loop");
|
2019-07-17 12:09:09 +03:00
|
|
|
loop.exec();
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-01-16 18:03:50 +03:00
|
|
|
}
|