From 12c7b954e14c0533ddb7da2dae095ad06b984d32 Mon Sep 17 00:00:00 2001 From: Peter Elliott Date: Thu, 28 Apr 2022 01:19:32 -0600 Subject: [PATCH] Kernel+WindowServer: Move setting tty graphical mode to Userspace This will allow using the console tty and WindowServer regardless of your kernel command line. Also this fixes a bug where, when booting in text mode, the console was in graphical mode, and would not accept input. --- Base/etc/SystemServer.ini | 2 ++ Kernel/init.cpp | 3 --- Userland/Services/WindowServer/main.cpp | 12 ++++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Base/etc/SystemServer.ini b/Base/etc/SystemServer.ini index 35daa8abb5..19c613403c 100644 --- a/Base/etc/SystemServer.ini +++ b/Base/etc/SystemServer.ini @@ -86,6 +86,8 @@ SocketPermissions=660 Priority=high KeepAlive=true User=window +# Ensure windowserver has a controlling TTY. +StdIO=/dev/tty0 [InspectorServer] Socket=/tmp/portal/inspector,/tmp/portal/inspectables diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 19cf69139a..d564b3bd7d 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -377,9 +377,6 @@ void init_stage2(void*) // NOTE: Everything marked UNMAP_AFTER_INIT becomes inaccessible after this point. MM.unmap_text_after_init(); - // FIXME: It would be nicer to set the mode from userspace. - // FIXME: It would be smarter to not hardcode that the first tty is the only graphical one - ConsoleManagement::the().first_tty()->set_graphical(GraphicsManagement::the().framebuffer_devices_exist()); RefPtr thread; auto userspace_init = kernel_command_line().userspace_init(); auto init_args = kernel_command_line().userspace_init_args(); diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp index 6f3511c17a..3e12ae7c7e 100644 --- a/Userland/Services/WindowServer/main.cpp +++ b/Userland/Services/WindowServer/main.cpp @@ -21,7 +21,7 @@ ErrorOr serenity_main(Main::Arguments) { - TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction exec")); + TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc sigaction exec tty")); TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/tmp", "cw")); TRY(Core::System::unveil("/etc/WindowServer.ini", "rwc")); @@ -34,7 +34,7 @@ ErrorOr serenity_main(Main::Arguments) act.sa_flags = SA_NOCLDWAIT; act.sa_handler = SIG_IGN; TRY(Core::System::sigaction(SIGCHLD, &act, nullptr)); - TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc exec")); + TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc exec tty")); auto wm_config = TRY(Core::ConfigFile::open("/etc/WindowServer.ini")); auto theme_name = wm_config->read_entry("Theme", "Name", "Default"); @@ -50,6 +50,14 @@ ErrorOr serenity_main(Main::Arguments) Gfx::FontDatabase::set_default_font_query(default_font_query); Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query); + { + // FIXME: Map switched tty from screens. + // FIXME: Gracefully cleanup the TTY graphics mode. + int tty_fd = TRY(Core::System::open("/dev/tty", O_RDWR)); + TRY(Core::System::ioctl(tty_fd, KDSETMODE, KD_GRAPHICS)); + TRY(Core::System::close(tty_fd)); + } + WindowServer::EventLoop loop; TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath proc exec"));