2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-01-15 03:30:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-06 13:34:26 +00:00
|
|
|
#include <AK/String.h>
|
2020-02-06 14:04:03 +00:00
|
|
|
#include <LibCore/ConfigFile.h>
|
2020-02-14 23:24:14 +00:00
|
|
|
#include <LibCore/ElapsedTimer.h>
|
2020-02-06 14:04:03 +00:00
|
|
|
#include <LibCore/Notifier.h>
|
|
|
|
#include <LibCore/Timer.h>
|
2020-02-14 23:24:14 +00:00
|
|
|
#include <LibGUI/Frame.h>
|
2020-02-06 11:07:05 +00:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-06 11:04:00 +00:00
|
|
|
#include <LibGfx/Rect.h>
|
2019-08-12 15:32:16 +00:00
|
|
|
#include <LibVT/Terminal.h>
|
2019-01-15 03:30:55 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
class TerminalWidget final : public GUI::Frame
|
2019-08-12 15:32:16 +00:00
|
|
|
, public VT::TerminalClient {
|
2019-08-13 11:21:58 +00:00
|
|
|
C_OBJECT(TerminalWidget)
|
2019-01-15 03:30:55 +00:00
|
|
|
public:
|
2020-02-02 11:34:39 +00:00
|
|
|
TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Core::ConfigFile> config);
|
2019-08-13 11:21:58 +00:00
|
|
|
virtual ~TerminalWidget() override;
|
2019-01-15 03:30:55 +00:00
|
|
|
|
2019-10-22 19:57:53 +00:00
|
|
|
void set_pty_master_fd(int fd);
|
2019-10-22 20:14:36 +00:00
|
|
|
void inject_string(const StringView& string)
|
|
|
|
{
|
|
|
|
m_terminal.inject_string(string);
|
|
|
|
flush_dirty_lines();
|
|
|
|
}
|
2019-10-22 19:57:53 +00:00
|
|
|
|
2019-01-15 03:30:55 +00:00
|
|
|
void create_window();
|
|
|
|
|
2019-02-10 13:28:39 +00:00
|
|
|
void flush_dirty_lines();
|
2019-02-12 09:08:35 +00:00
|
|
|
void force_repaint();
|
2019-01-17 16:38:04 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
void apply_size_increments_to_window(GUI::Window&);
|
2019-02-20 23:21:23 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
const Gfx::Font& bold_font() const { return *m_bold_font; }
|
2020-01-15 21:22:17 +00:00
|
|
|
|
2019-07-03 19:17:35 +00:00
|
|
|
void set_opacity(u8);
|
2019-05-31 20:28:47 +00:00
|
|
|
float opacity() { return m_opacity; };
|
|
|
|
bool should_beep() { return m_should_beep; }
|
2019-05-31 19:43:58 +00:00
|
|
|
void set_should_beep(bool sb) { m_should_beep = sb; };
|
2019-04-29 17:24:18 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
RefPtr<Core::ConfigFile> config() const { return m_config; }
|
2019-05-25 23:43:15 +00:00
|
|
|
|
2019-06-23 07:18:17 +00:00
|
|
|
bool has_selection() const;
|
2019-08-13 10:48:54 +00:00
|
|
|
bool selection_contains(const VT::Position&) const;
|
2019-06-23 07:18:17 +00:00
|
|
|
String selected_text() const;
|
2020-02-06 10:56:38 +00:00
|
|
|
VT::Position buffer_position_at(const Gfx::Point&) const;
|
2019-08-13 10:48:54 +00:00
|
|
|
VT::Position normalized_selection_start() const;
|
|
|
|
VT::Position normalized_selection_end() const;
|
2019-06-23 07:18:17 +00:00
|
|
|
|
2019-08-20 18:11:56 +00:00
|
|
|
bool is_scrollable() const;
|
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
GUI::Action& copy_action() { return *m_copy_action; }
|
|
|
|
GUI::Action& paste_action() { return *m_paste_action; }
|
2019-11-20 20:33:23 +00:00
|
|
|
|
|
|
|
void copy();
|
|
|
|
void paste();
|
|
|
|
|
2019-10-21 18:14:51 +00:00
|
|
|
virtual bool accepts_focus() const override { return true; }
|
|
|
|
|
2019-10-21 20:07:59 +00:00
|
|
|
Function<void(const StringView&)> on_title_change;
|
2019-10-22 19:57:53 +00:00
|
|
|
Function<void()> on_command_exit;
|
2019-10-21 20:07:59 +00:00
|
|
|
|
2019-01-15 03:30:55 +00:00
|
|
|
private:
|
2020-02-02 14:07:41 +00:00
|
|
|
// ^GUI::Widget
|
2020-02-02 11:34:39 +00:00
|
|
|
virtual void event(Core::Event&) override;
|
2020-02-02 14:07:41 +00:00
|
|
|
virtual void paint_event(GUI::PaintEvent&) override;
|
|
|
|
virtual void resize_event(GUI::ResizeEvent&) override;
|
|
|
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
2020-03-06 04:34:31 +00:00
|
|
|
virtual void keyup_event(GUI::KeyEvent&) override;
|
2020-02-02 14:07:41 +00:00
|
|
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
|
|
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
|
|
|
virtual void mousewheel_event(GUI::MouseEvent&) override;
|
|
|
|
virtual void doubleclick_event(GUI::MouseEvent&) override;
|
2020-02-02 11:34:39 +00:00
|
|
|
virtual void focusin_event(Core::Event&) override;
|
|
|
|
virtual void focusout_event(Core::Event&) override;
|
2020-02-02 14:07:41 +00:00
|
|
|
virtual void context_menu_event(GUI::ContextMenuEvent&) override;
|
|
|
|
virtual void drop_event(GUI::DropEvent&) override;
|
2020-05-09 15:04:12 +00:00
|
|
|
virtual void leave_event(Core::Event&) override;
|
2020-01-08 20:09:43 +00:00
|
|
|
virtual void did_change_font() override;
|
2019-02-10 13:28:39 +00:00
|
|
|
|
2019-08-12 15:32:16 +00:00
|
|
|
// ^TerminalClient
|
|
|
|
virtual void beep() override;
|
|
|
|
virtual void set_window_title(const StringView&) override;
|
|
|
|
virtual void terminal_did_resize(u16 columns, u16 rows) override;
|
2019-08-19 17:12:34 +00:00
|
|
|
virtual void terminal_history_changed() override;
|
2020-05-09 08:38:57 +00:00
|
|
|
virtual void emit(const u8*, size_t) override;
|
2019-01-15 03:30:55 +00:00
|
|
|
|
2019-10-21 18:14:51 +00:00
|
|
|
void set_logical_focus(bool);
|
|
|
|
|
2020-02-06 12:02:38 +00:00
|
|
|
Gfx::Rect glyph_rect(u16 row, u16 column);
|
|
|
|
Gfx::Rect row_rect(u16 row);
|
2019-05-29 19:10:08 +00:00
|
|
|
|
2019-08-12 15:32:16 +00:00
|
|
|
void update_cursor();
|
|
|
|
void invalidate_cursor();
|
2019-01-15 03:30:55 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
void relayout(const Gfx::Size&);
|
2020-01-08 20:09:43 +00:00
|
|
|
|
2020-02-06 12:32:14 +00:00
|
|
|
Gfx::Size compute_base_size() const;
|
2019-08-25 16:20:32 +00:00
|
|
|
int first_selection_column_on_row(int row) const;
|
|
|
|
int last_selection_column_on_row(int row) const;
|
2019-08-19 17:12:34 +00:00
|
|
|
|
2019-08-12 15:32:16 +00:00
|
|
|
VT::Terminal m_terminal;
|
2019-01-15 03:30:55 +00:00
|
|
|
|
2019-08-13 10:48:54 +00:00
|
|
|
VT::Position m_selection_start;
|
|
|
|
VT::Position m_selection_end;
|
2019-01-15 06:30:24 +00:00
|
|
|
|
2020-05-09 14:16:16 +00:00
|
|
|
String m_hovered_href;
|
|
|
|
String m_hovered_href_id;
|
|
|
|
|
2019-05-31 19:43:58 +00:00
|
|
|
bool m_should_beep { false };
|
2019-01-15 03:30:55 +00:00
|
|
|
bool m_belling { false };
|
2020-03-06 04:34:31 +00:00
|
|
|
bool m_alt_key_held { false };
|
|
|
|
bool m_rectangle_selection { false };
|
2019-01-15 03:30:55 +00:00
|
|
|
|
|
|
|
int m_pixel_width { 0 };
|
|
|
|
int m_pixel_height { 0 };
|
2019-01-15 06:39:51 +00:00
|
|
|
|
|
|
|
int m_inset { 2 };
|
|
|
|
int m_line_spacing { 4 };
|
2019-01-17 15:19:49 +00:00
|
|
|
int m_line_height { 0 };
|
|
|
|
|
2019-02-10 13:28:39 +00:00
|
|
|
int m_ptm_fd { -1 };
|
|
|
|
|
2019-10-21 18:14:51 +00:00
|
|
|
bool m_has_logical_focus { false };
|
2019-01-17 16:38:04 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
RefPtr<Core::Notifier> m_notifier;
|
2019-02-19 00:42:53 +00:00
|
|
|
|
2019-07-03 19:17:35 +00:00
|
|
|
u8 m_opacity { 255 };
|
2019-02-19 00:42:53 +00:00
|
|
|
bool m_needs_background_fill { true };
|
2019-03-30 20:40:27 +00:00
|
|
|
bool m_cursor_blink_state { true };
|
2019-10-21 18:28:30 +00:00
|
|
|
bool m_automatic_size_policy { false };
|
2019-03-06 10:03:10 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
RefPtr<Gfx::Font> m_bold_font;
|
2020-01-15 21:22:17 +00:00
|
|
|
|
2019-03-06 10:03:10 +00:00
|
|
|
int m_glyph_width { 0 };
|
2019-03-30 20:40:27 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
RefPtr<Core::Timer> m_cursor_blink_timer;
|
|
|
|
RefPtr<Core::Timer> m_visual_beep_timer;
|
|
|
|
RefPtr<Core::ConfigFile> m_config;
|
2019-08-19 17:12:34 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
RefPtr<GUI::ScrollBar> m_scrollbar;
|
2019-11-15 22:48:58 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
RefPtr<GUI::Action> m_copy_action;
|
|
|
|
RefPtr<GUI::Action> m_paste_action;
|
2019-11-20 20:33:23 +00:00
|
|
|
|
2020-02-02 14:07:41 +00:00
|
|
|
RefPtr<GUI::Menu> m_context_menu;
|
2020-05-09 14:42:42 +00:00
|
|
|
RefPtr<GUI::Menu> m_context_menu_for_hyperlink;
|
2019-11-20 20:39:26 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
Core::ElapsedTimer m_triple_click_timer;
|
2019-01-15 03:30:55 +00:00
|
|
|
};
|