Skip to content

Commit

Permalink
Terminal: Audible vs Visible beep option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexispurslane authored and awesomekling committed May 31, 2019
1 parent 9ac95d1 commit f8a02d4
Show file tree
Hide file tree
Showing 7 changed files with 5,995 additions and 9 deletions.
1 change: 1 addition & 0 deletions AK/compile_commands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
16 changes: 9 additions & 7 deletions Applications/Terminal/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ void Terminal::on_char(byte ch)
}
return;
case '\a':
sysbeep();
if (m_should_beep)
sysbeep();
else
m_visual_beep_frames = 2;
return;
case '\t': {
for (unsigned i = m_cursor_column; i < columns(); ++i) {
Expand Down Expand Up @@ -823,7 +826,8 @@ void Terminal::keydown_event(GKeyEvent& event)
}

void Terminal::paint_event(GPaintEvent& event)
{
{
m_visual_beep_frames--;
GFrame::paint_event(event);

GPainter painter(*this);
Expand Down Expand Up @@ -855,9 +859,10 @@ void Terminal::paint_event(GPaintEvent& event)
continue;
line.dirty = false;
bool has_only_one_background_color = line.has_only_one_background_color();
if (has_only_one_background_color) {
if (m_visual_beep_frames > 0)
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));
}
for (word column = 0; column < m_columns; ++column) {
bool should_reverse_fill_for_cursor = m_cursor_blink_state && m_in_active_window && row == m_cursor_row && column == m_cursor_column;
auto& attribute = line.attributes[column];
Expand All @@ -877,9 +882,6 @@ void Terminal::paint_event(GPaintEvent& event)
auto cell_rect = glyph_rect(m_cursor_row, m_cursor_column).inflated(0, m_line_spacing);
painter.draw_rect(cell_rect, lookup_color(line(m_cursor_row).attributes[m_cursor_column].foreground_color));
}

if (m_belling)
painter.draw_rect(frame_inner_rect(), Color::Red);
}

void Terminal::set_window_title(const String& title)
Expand Down
5 changes: 5 additions & 0 deletions Applications/Terminal/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Terminal final : public GFrame {
void apply_size_increments_to_window(GWindow&);

void set_opacity(float);
bool should_beep() { return m_should_beep; };
void set_should_beep(bool sb) { m_should_beep = sb; };

RetainPtr<CConfigFile> config() const { return m_config; }

Expand Down Expand Up @@ -140,6 +142,9 @@ class Terminal final : public GFrame {
byte m_saved_cursor_column { 0 };
bool m_stomp { false };

bool m_should_beep { false };
int m_visual_beep_frames { 0 };

Attribute m_current_attribute;

void execute_escape_sequence(byte final);
Expand Down
33 changes: 33 additions & 0 deletions Applications/Terminal/compile_commands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"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"
}
]
25 changes: 23 additions & 2 deletions Applications/Terminal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ 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);

auto* opacity_adjustment_window = new GWindow;
opacity_adjustment_window->set_title("Adjust opacity");
Expand All @@ -124,15 +125,35 @@ int main(int argc, char** argv)
slider->set_range(0, 100);
slider->set_value(100);

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());
sysbell_radio->on_checked = [&terminal] (const bool res) {
terminal.set_should_beep(res);
};

auto new_opacity = config->read_num_entry("Window", "Opacity", 255);
terminal.set_opacity((float)new_opacity / 255.0);

auto menubar = make<GMenuBar>();

auto app_menu = make<GMenu>("Terminal");
app_menu->add_action(GAction::create("Adjust opacity...", [opacity_adjustment_window] (const GAction&) {
opacity_adjustment_window->show();
}));
opacity_adjustment_window->show();
}));
app_menu->add_action(GAction::create("Change audio output...", [beep_choice_window] (const GAction&) {
beep_choice_window->show();
}));
app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) {
dbgprintf("Terminal: Quit menu activated!\n");
GApplication::the().quit(0);
Expand Down
Loading

0 comments on commit f8a02d4

Please sign in to comment.