From 5b572393a96e0ad1a916a422c47a257cd6da635b Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 15 Feb 2022 22:46:49 +0200 Subject: [PATCH] LibVT: Use NNOP to store window titles in the Kernel This will allow us to eventually propagate allocation failure. --- Userland/Libraries/LibVT/Attribute.h | 5 ++++- Userland/Libraries/LibVT/Terminal.cpp | 15 ++++++++++++++- Userland/Libraries/LibVT/Terminal.h | 7 ++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibVT/Attribute.h b/Userland/Libraries/LibVT/Attribute.h index 1bc2c8c51e..5bc71531fe 100644 --- a/Userland/Libraries/LibVT/Attribute.h +++ b/Userland/Libraries/LibVT/Attribute.h @@ -7,11 +7,14 @@ #pragma once #include -#include #include #include #include +#ifndef KERNEL +# include +#endif + namespace VT { struct Attribute { diff --git a/Userland/Libraries/LibVT/Terminal.cpp b/Userland/Libraries/LibVT/Terminal.cpp index 7454fdc6fa..d7e216c6ee 100644 --- a/Userland/Libraries/LibVT/Terminal.cpp +++ b/Userland/Libraries/LibVT/Terminal.cpp @@ -383,7 +383,11 @@ void Terminal::XTERM_WM(Parameters params) return; } dbgln_if(TERMINAL_DEBUG, "Title stack push: {}", m_current_window_title); - [[maybe_unused]] auto rc = m_title_stack.try_append(move(m_current_window_title)); +#ifdef KERNEL + (void)m_title_stack.try_append(m_current_window_title.release_nonnull()); // FIXME: Propagate Error +#else + (void)m_title_stack.try_append(move(m_current_window_title)); +#endif break; } case 23: { @@ -395,7 +399,11 @@ void Terminal::XTERM_WM(Parameters params) } m_current_window_title = m_title_stack.take_last(); dbgln_if(TERMINAL_DEBUG, "Title stack pop: {}", m_current_window_title); +#ifdef KERNEL + m_client.set_window_title(m_current_window_title->view()); +#else m_client.set_window_title(m_current_window_title); +#endif break; } default: @@ -1280,8 +1288,13 @@ void Terminal::execute_osc_sequence(OscParameters parameters, u8 last_byte) } else { // FIXME: the split breaks titles containing semicolons. // Should we expose the raw OSC string from the parser? Or join by semicolon? +#ifdef KERNEL + m_current_window_title = Kernel::KString::try_create(stringview_ify(1)).release_value_but_fixme_should_propagate_errors(); + m_client.set_window_title(m_current_window_title->view()); +#else m_current_window_title = stringview_ify(1).to_string(); m_client.set_window_title(m_current_window_title); +#endif } break; case 8: diff --git a/Userland/Libraries/LibVT/Terminal.h b/Userland/Libraries/LibVT/Terminal.h index 7146317bc8..f7b0693c5e 100644 --- a/Userland/Libraries/LibVT/Terminal.h +++ b/Userland/Libraries/LibVT/Terminal.h @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -17,6 +16,7 @@ #include #ifndef KERNEL +# include # include # include #else @@ -435,8 +435,13 @@ protected: Attribute m_current_attribute; Attribute m_saved_attribute; +#ifdef KERNEL + OwnPtr m_current_window_title; + NonnullOwnPtrVector m_title_stack; +#else String m_current_window_title; Vector m_title_stack; +#endif #ifndef KERNEL u32 m_next_href_id { 0 };