mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-13 18:00:40 +00:00
Terminal: Single settings window & consistant visual bell timing
This commit is contained in:
parent
6a4cb25557
commit
b0d8dba16d
Notes:
sideshowbarker
2024-07-19 13:49:02 +09:00
Author: https://github.com/alexispurslane Commit: https://github.com/SerenityOS/serenity/commit/b0d8dba16da Pull-request: https://github.com/SerenityOS/serenity/pull/153 Reviewed-by: https://github.com/awesomekling
5 changed files with 60 additions and 87 deletions
1
Applications/Terminal/.gitignore
vendored
1
Applications/Terminal/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
*.o
|
||||
*.d
|
||||
Terminal
|
||||
compile_commands.json
|
||||
|
|
|
@ -630,8 +630,16 @@ void Terminal::on_char(byte ch)
|
|||
case '\a':
|
||||
if (m_should_beep)
|
||||
sysbeep();
|
||||
else
|
||||
m_visual_beep_frames = 2;
|
||||
else {
|
||||
m_visual_beep_timer.restart(500);
|
||||
m_visual_beep_timer.set_single_shot(true);
|
||||
m_visual_beep_timer.on_timeout = [this] {
|
||||
m_needs_background_fill = true;
|
||||
update();
|
||||
};
|
||||
m_needs_background_fill = true;
|
||||
update();
|
||||
}
|
||||
return;
|
||||
case '\t': {
|
||||
for (unsigned i = m_cursor_column; i < columns(); ++i) {
|
||||
|
@ -827,14 +835,16 @@ void Terminal::keydown_event(GKeyEvent& event)
|
|||
|
||||
void Terminal::paint_event(GPaintEvent& event)
|
||||
{
|
||||
m_visual_beep_frames--;
|
||||
GFrame::paint_event(event);
|
||||
|
||||
GPainter painter(*this);
|
||||
|
||||
if (m_needs_background_fill) {
|
||||
m_needs_background_fill = false;
|
||||
painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(255 * m_opacity));
|
||||
if (m_visual_beep_timer.is_active())
|
||||
painter.fill_rect(frame_inner_rect(), Color::Red);
|
||||
else
|
||||
painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(255 * m_opacity));
|
||||
}
|
||||
|
||||
if (m_rows_to_scroll_backing_store && m_rows_to_scroll_backing_store < m_rows) {
|
||||
|
@ -859,7 +869,7 @@ void Terminal::paint_event(GPaintEvent& event)
|
|||
continue;
|
||||
line.dirty = false;
|
||||
bool has_only_one_background_color = line.has_only_one_background_color();
|
||||
if (m_visual_beep_frames > 0)
|
||||
if (m_visual_beep_timer.is_active())
|
||||
painter.fill_rect(row_rect(row), Color::Red);
|
||||
else if (has_only_one_background_color)
|
||||
painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color).with_alpha(255 * m_opacity));
|
||||
|
|
|
@ -144,7 +144,6 @@ private:
|
|||
bool m_stomp { false };
|
||||
|
||||
bool m_should_beep { false };
|
||||
int m_visual_beep_frames { 0 };
|
||||
|
||||
Attribute m_current_attribute;
|
||||
|
||||
|
@ -196,5 +195,6 @@ private:
|
|||
int m_glyph_width { 0 };
|
||||
|
||||
CTimer m_cursor_blink_timer;
|
||||
CTimer m_visual_beep_timer;
|
||||
RetainPtr<CConfigFile> m_config;
|
||||
};
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
[
|
||||
{
|
||||
"arguments": [
|
||||
"i686-pc-serenity-g++",
|
||||
"-c",
|
||||
"-Wextra",
|
||||
"-Wall",
|
||||
"-Wundef",
|
||||
"-Wcast-qual",
|
||||
"-Wwrite-strings",
|
||||
"-Wimplicit-fallthrough",
|
||||
"-Os",
|
||||
"-fno-exceptions",
|
||||
"-fno-rtti",
|
||||
"-std=c++17",
|
||||
"-Wno-sized-deallocation",
|
||||
"-fno-sized-deallocation",
|
||||
"-I/home/christopherdumas/serenity",
|
||||
"-I.",
|
||||
"-I/home/christopherdumas/serenity/LibC",
|
||||
"-I/home/christopherdumas/serenity/Servers",
|
||||
"-I/home/christopherdumas/serenity/LibM",
|
||||
"-DSANITIZE_PTRS",
|
||||
"-DDEBUG",
|
||||
"-DUSERLAND",
|
||||
"-o",
|
||||
"Terminal.o",
|
||||
"Terminal.cpp"
|
||||
],
|
||||
"directory": "/home/christopherdumas/serenity/Applications/Terminal",
|
||||
"file": "Terminal.cpp"
|
||||
}
|
||||
]
|
|
@ -15,6 +15,7 @@
|
|||
#include <LibGUI/GRadioButton.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <LibGUI/GGroupBox.h>
|
||||
#include <LibGUI/GMenuBar.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GFontDatabase.h>
|
||||
|
@ -80,14 +81,41 @@ static void make_shell(int ptm_fd)
|
|||
}
|
||||
}
|
||||
|
||||
GWindow* create_opacity_settings_window(Terminal& terminal, RetainPtr<CConfigFile> config)
|
||||
GWindow* create_settings_window(Terminal& terminal, RetainPtr<CConfigFile> config)
|
||||
{
|
||||
auto* opacity_adjustment_window = new GWindow;
|
||||
opacity_adjustment_window->set_title("Adjust opacity");
|
||||
opacity_adjustment_window->set_rect(50, 50, 200, 100);
|
||||
auto* window = new GWindow;
|
||||
window->set_title("Terminal Settings");
|
||||
window->set_rect(50, 50, 200, 140);
|
||||
|
||||
auto* slider = new GSlider(nullptr);
|
||||
opacity_adjustment_window->set_main_widget(slider);
|
||||
|
||||
auto* settings = new GWidget;
|
||||
window->set_main_widget(settings);
|
||||
settings->set_fill_with_background_color(true);
|
||||
settings->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
settings->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto* radio_container = new GGroupBox("Bell Mode", settings);
|
||||
radio_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
radio_container->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
radio_container->set_fill_with_background_color(true);
|
||||
radio_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
radio_container->set_preferred_size({ 100, 70 });
|
||||
|
||||
auto* sysbell_radio = new GRadioButton("Use (Audible) System Bell", radio_container);
|
||||
auto* visbell_radio = new GRadioButton("Use (Visual) Terminal Bell", radio_container);
|
||||
sysbell_radio->set_checked(terminal.should_beep());
|
||||
visbell_radio->set_checked(!terminal.should_beep());
|
||||
sysbell_radio->on_checked = [&terminal] (const bool checked) {
|
||||
terminal.set_should_beep(checked);
|
||||
};
|
||||
|
||||
auto* slider_container = new GGroupBox("Background Opacity", settings);
|
||||
slider_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
slider_container->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
slider_container->set_fill_with_background_color(true);
|
||||
slider_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
slider_container->set_preferred_size({ 100, 50 });
|
||||
auto* slider = new GSlider(slider_container);
|
||||
slider->set_fill_with_background_color(true);
|
||||
slider->set_background_color(Color::LightGray);
|
||||
|
||||
|
@ -99,29 +127,7 @@ GWindow* create_opacity_settings_window(Terminal& terminal, RetainPtr<CConfigFil
|
|||
slider->set_range(0, 100);
|
||||
slider->set_value(terminal.opacity() * 100.0);
|
||||
|
||||
return opacity_adjustment_window;
|
||||
}
|
||||
|
||||
GWindow* create_beep_choice_window(Terminal& terminal, RetainPtr<CConfigFile> config)
|
||||
{
|
||||
auto* beep_choice_window = new GWindow;
|
||||
beep_choice_window->set_title("Terminal beep settings");
|
||||
beep_choice_window->set_rect(50, 50, 200, 100);
|
||||
|
||||
auto* radio_buttons = new GWidget;
|
||||
beep_choice_window->set_main_widget(radio_buttons);
|
||||
radio_buttons->set_fill_with_background_color(true);
|
||||
radio_buttons->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
radio_buttons->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto* sysbell_radio = new GRadioButton("Use (Audible) System Bell", radio_buttons);
|
||||
auto* visbell_radio = new GRadioButton("Use (Visual) Terminal Bell", radio_buttons);
|
||||
sysbell_radio->set_checked(terminal.should_beep());
|
||||
visbell_radio->set_checked(!terminal.should_beep());
|
||||
sysbell_radio->on_checked = [&terminal] (const bool res) {
|
||||
terminal.set_should_beep(res);
|
||||
};
|
||||
return beep_choice_window;
|
||||
return window;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
@ -152,13 +158,9 @@ int main(int argc, char** argv)
|
|||
terminal.apply_size_increments_to_window(*window);
|
||||
window->show();
|
||||
window->set_icon_path("/res/icons/16x16/app-terminal.png");
|
||||
terminal.set_should_beep(config->read_num_entry("Window", "AudibleBeep", 1) == 1);
|
||||
terminal.set_should_beep(config->read_bool_entry("Window", "AudibleBeep", true));
|
||||
|
||||
WeakPtr<GWindow> opacity_adjustment_window =
|
||||
create_opacity_settings_window(terminal, config)->make_weak_ptr();
|
||||
|
||||
WeakPtr<GWindow> beep_choice_window =
|
||||
create_beep_choice_window(terminal, config)->make_weak_ptr();
|
||||
WeakPtr<GWindow> settings_window;
|
||||
|
||||
auto new_opacity = config->read_num_entry("Window", "Opacity", 255);
|
||||
terminal.set_opacity((float)new_opacity / 255.0);
|
||||
|
@ -166,19 +168,12 @@ int main(int argc, char** argv)
|
|||
auto menubar = make<GMenuBar>();
|
||||
|
||||
auto app_menu = make<GMenu>("Terminal");
|
||||
app_menu->add_action(GAction::create("Adjust opacity...",
|
||||
[&opacity_adjustment_window, &terminal, &config] (const GAction&) {
|
||||
if (!opacity_adjustment_window)
|
||||
opacity_adjustment_window =
|
||||
create_opacity_settings_window(terminal, config)->make_weak_ptr();
|
||||
opacity_adjustment_window->show();
|
||||
}));
|
||||
app_menu->add_action(GAction::create("Change audio output...",
|
||||
[&beep_choice_window, &terminal, &config] (const GAction&) {
|
||||
if (!beep_choice_window)
|
||||
beep_choice_window =
|
||||
create_beep_choice_window(terminal, config)->make_weak_ptr();
|
||||
beep_choice_window->show();
|
||||
app_menu->add_action(GAction::create("Settings...",
|
||||
[&settings_window, &terminal, &config] (const GAction&) {
|
||||
if (!settings_window)
|
||||
settings_window =
|
||||
create_settings_window(terminal, config)->make_weak_ptr();
|
||||
settings_window->show();
|
||||
}));
|
||||
app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) {
|
||||
dbgprintf("Terminal: Quit menu activated!\n");
|
||||
|
|
Loading…
Reference in a new issue