From f8cb6e03dfe1ca945a31a967ace880741f7d652e Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 2 Aug 2023 15:16:10 +0200 Subject: [PATCH] kernel: Allow turning off the TTY by setting it to graphical mode --- kernel/src/fs/devices/ConsoleDevice.cpp | 7 +++++++ kernel/src/fs/devices/ConsoleDevice.h | 1 + libc/include/bits/ioctl-defs.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/kernel/src/fs/devices/ConsoleDevice.cpp b/kernel/src/fs/devices/ConsoleDevice.cpp index 5b21e486..52cafa66 100644 --- a/kernel/src/fs/devices/ConsoleDevice.cpp +++ b/kernel/src/fs/devices/ConsoleDevice.cpp @@ -11,6 +11,7 @@ #include Vector> ConsoleDevice::m_console_devices; +bool ConsoleDevice::s_is_in_graphical_mode { false }; Result ConsoleDevice::create() { @@ -60,6 +61,8 @@ Result ConsoleDevice::write(const u8* buf, usize, usize length) { if (m_settings.c_lflag & TOSTOP) TRY(handle_background_process_group(true, SIGTTOU)); + if (s_is_in_graphical_mode) return length; + TextConsole::write((const char*)buf, length); return length; } @@ -229,6 +232,10 @@ Result ConsoleDevice::ioctl(int request, void* arg) if (!MemoryManager::copy_to_user_typed((struct winsize*)arg, &window)) return err(EFAULT); return 0; } + case TTYSETGFX: { + s_is_in_graphical_mode = (bool)arg; + return 0; + } default: return err(EINVAL); } } diff --git a/kernel/src/fs/devices/ConsoleDevice.h b/kernel/src/fs/devices/ConsoleDevice.h index d6b7d186..db457400 100644 --- a/kernel/src/fs/devices/ConsoleDevice.h +++ b/kernel/src/fs/devices/ConsoleDevice.h @@ -40,6 +40,7 @@ class ConsoleDevice : public Device mutable Keyboard::KeyboardState m_kb_state; static Vector> m_console_devices; + static bool s_is_in_graphical_mode; void process_key_event(u8 scancode); diff --git a/libc/include/bits/ioctl-defs.h b/libc/include/bits/ioctl-defs.h index 29c20bde..4d2e7298 100644 --- a/libc/include/bits/ioctl-defs.h +++ b/libc/include/bits/ioctl-defs.h @@ -8,4 +8,7 @@ #define FB_GET_HEIGHT 1 #define FB_GET_SCANLINE 2 +/* TTY requests. */ +#define TTYSETGFX 162 + #endif