2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2021-11-23 01:20:52 +03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
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>
|
2021-06-26 22:20:41 +03:00
|
|
|
#include <LibCore/DirIterator.h>
|
|
|
|
#include <LibCore/File.h>
|
2021-11-23 12:59:50 +03:00
|
|
|
#include <LibCore/System.h>
|
2020-02-06 14:04:00 +03:00
|
|
|
#include <LibGfx/Palette.h>
|
|
|
|
#include <LibGfx/SystemTheme.h>
|
2021-11-23 01:20:52 +03:00
|
|
|
#include <LibMain/Main.h>
|
2019-03-01 18:16:23 +03:00
|
|
|
#include <signal.h>
|
2020-03-08 14:05:14 +03:00
|
|
|
#include <string.h>
|
2019-01-16 18:03:50 +03:00
|
|
|
|
2021-11-23 01:20:52 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2019-01-16 18:03:50 +03:00
|
|
|
{
|
2021-11-28 01:26:34 +03:00
|
|
|
TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction"));
|
2021-11-23 12:59:50 +03:00
|
|
|
TRY(Core::System::unveil("/res", "r"));
|
|
|
|
TRY(Core::System::unveil("/tmp", "cw"));
|
|
|
|
TRY(Core::System::unveil("/etc/WindowServer.ini", "rwc"));
|
|
|
|
TRY(Core::System::unveil("/dev", "rw"));
|
2020-01-21 00:23:18 +03:00
|
|
|
|
2021-11-23 01:20:52 +03:00
|
|
|
struct sigaction act = {};
|
2019-03-01 18:16:23 +03:00
|
|
|
act.sa_flags = SA_NOCLDWAIT;
|
|
|
|
act.sa_handler = SIG_IGN;
|
2021-11-23 12:59:50 +03:00
|
|
|
TRY(Core::System::sigaction(SIGCHLD, &act, nullptr));
|
2021-12-12 21:44:48 +03:00
|
|
|
TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc"));
|
2019-03-01 18:16:23 +03:00
|
|
|
|
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
|
|
|
|
2022-02-01 04:18:15 +03:00
|
|
|
auto default_font_query = wm_config->read_entry("Fonts", "Default", "Katica 10 400 0");
|
|
|
|
auto fixed_width_font_query = wm_config->read_entry("Fonts", "FixedWidth", "Csilla 10 400 0");
|
2021-05-21 19:59:07 +03:00
|
|
|
|
|
|
|
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-11-28 01:26:34 +03:00
|
|
|
TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc"));
|
2020-01-11 23:25:03 +03:00
|
|
|
|
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;
|
2021-06-14 06:09:47 +03:00
|
|
|
|
2021-07-18 19:24:41 +03:00
|
|
|
auto add_unconfigured_devices = [&]() {
|
|
|
|
// Enumerate the /dev/fbX devices and try to set up any ones we find that we haven't already used
|
|
|
|
Core::DirIterator di("/dev", Core::DirIterator::SkipParentAndBaseDir);
|
|
|
|
while (di.has_next()) {
|
|
|
|
auto path = di.next_path();
|
|
|
|
if (!path.starts_with("fb"))
|
|
|
|
continue;
|
|
|
|
auto full_path = String::formatted("/dev/{}", path);
|
|
|
|
if (!Core::File::is_device(full_path))
|
|
|
|
continue;
|
|
|
|
if (fb_devices_configured.find(full_path) != fb_devices_configured.end())
|
|
|
|
continue;
|
|
|
|
if (!screen_layout.try_auto_add_framebuffer(full_path))
|
|
|
|
dbgln("Could not auto-add framebuffer device {} to screen layout", full_path);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto apply_and_generate_generic_screen_layout = [&]() {
|
|
|
|
screen_layout = {};
|
|
|
|
fb_devices_configured = {};
|
|
|
|
add_unconfigured_devices();
|
|
|
|
if (!WindowServer::Screen::apply_layout(move(screen_layout), error_msg)) {
|
|
|
|
dbgln("Failed to apply generated fallback screen layout: {}", error_msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbgln("Applied generated fallback screen layout!");
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (screen_layout.load_config(*wm_config, &error_msg)) {
|
|
|
|
for (auto& screen_info : screen_layout.screens)
|
|
|
|
fb_devices_configured.set(screen_info.device);
|
|
|
|
|
|
|
|
add_unconfigured_devices();
|
|
|
|
|
|
|
|
if (!WindowServer::Screen::apply_layout(move(screen_layout), error_msg)) {
|
|
|
|
dbgln("Error applying screen layout: {}", error_msg);
|
|
|
|
if (!apply_and_generate_generic_screen_layout())
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dbgln("Error loading screen configuration: {}", error_msg);
|
|
|
|
if (!apply_and_generate_generic_screen_layout())
|
|
|
|
return 1;
|
2021-06-14 06:09:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-11-23 12:59:50 +03:00
|
|
|
TRY(Core::System::unveil("/tmp", ""));
|
2020-01-21 00:23:18 +03:00
|
|
|
|
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
|
|
|
|
2021-11-23 12:59:50 +03:00
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-01-21 00:23:18 +03:00
|
|
|
|
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
|
|
|
}
|