1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 16:37:47 +00:00

Userland: Use Core::Timer::create_foo() factory functions where possible

This commit is contained in:
Sam Atkins 2023-01-11 20:00:46 +00:00 committed by Andreas Kling
parent 6edc0cf5ab
commit e181b1cb82
12 changed files with 37 additions and 51 deletions

View file

@ -31,8 +31,7 @@
#include <unistd.h>
HexEditor::HexEditor()
: m_blink_timer(Core::Timer::construct())
, m_document(make<HexDocumentMemory>(ByteBuffer::create_zeroed(0).release_value_but_fixme_should_propagate_errors()))
: m_document(make<HexDocumentMemory>(ByteBuffer::create_zeroed(0).release_value_but_fixme_should_propagate_errors()))
{
set_should_hide_unnecessary_scrollbars(true);
set_focus_policy(GUI::FocusPolicy::StrongFocus);
@ -42,11 +41,10 @@ HexEditor::HexEditor()
set_foreground_role(ColorRole::BaseText);
vertical_scrollbar().set_step(line_height());
m_blink_timer->set_interval(500);
m_blink_timer->on_timeout = [this]() {
m_blink_timer = Core::Timer::create_repeating(500, [this]() {
m_cursor_blink_active = !m_cursor_blink_active;
update();
};
}).release_value_but_fixme_should_propagate_errors();
m_blink_timer->start();
}

View file

@ -85,7 +85,7 @@ private:
size_t m_position { 0 };
bool m_cursor_at_low_nibble { false };
EditMode m_edit_mode { Hex };
NonnullRefPtr<Core::Timer> m_blink_timer;
RefPtr<Core::Timer> m_blink_timer;
bool m_cursor_blink_active { false };
NonnullOwnPtr<HexDocument> m_document;
GUI::UndoStack m_undo_stack;

View file

@ -47,10 +47,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->resize(840, 600);
window->set_icon(app_icon.bitmap_for_size(16));
auto main_widget_updater = Core::Timer::construct(static_cast<int>((1 / 30.0) * 1000), [&] {
auto main_widget_updater = TRY(Core::Timer::create_repeating(static_cast<int>((1 / 30.0) * 1000), [&] {
if (window->is_active())
Core::EventLoop::current().post_event(main_widget, make<Core::CustomEvent>(0));
});
}));
main_widget_updater->start();
auto& file_menu = window->add_menu("&File");

View file

@ -22,11 +22,9 @@ namespace PixelPaint {
SprayTool::SprayTool()
{
m_timer = Core::Timer::construct();
m_timer->on_timeout = [&]() {
m_timer = Core::Timer::create_repeating(200, [&]() {
paint_it();
};
m_timer->set_interval(200);
}).release_value_but_fixme_should_propagate_errors();
}
static double nrand()

View file

@ -36,11 +36,9 @@ TextTool::TextTool()
m_text_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::NoWrap);
m_selected_font = Gfx::FontDatabase::default_font();
m_text_editor->set_font(m_selected_font);
m_cursor_blink_timer = Core::Timer::construct();
m_cursor_blink_timer->on_timeout = [&]() {
m_cursor_blink_timer = Core::Timer::create_repeating(500, [&]() {
m_cursor_blink_state = !m_cursor_blink_state;
};
m_cursor_blink_timer->set_interval(500);
}).release_value_but_fixme_should_propagate_errors();
}
void TextTool::on_tool_deactivation()

View file

@ -11,11 +11,11 @@ PlaybackManager::PlaybackManager(NonnullRefPtr<Audio::ConnectionToServer> connec
: m_connection(connection)
{
// FIXME: The buffer enqueuing should happen on a wholly independent second thread.
m_timer = Core::Timer::construct(PlaybackManager::update_rate_ms, [&]() {
m_timer = Core::Timer::create_repeating(PlaybackManager::update_rate_ms, [&]() {
if (!m_loader)
return;
next_buffer();
});
}).release_value_but_fixme_should_propagate_errors();
m_device_sample_rate = connection->get_sample_rate();
}