1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:27:45 +00:00

LibCore: Convert CTimer to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-20 15:19:46 +02:00
parent c34fd10b5b
commit 50a6560413
22 changed files with 91 additions and 70 deletions

View file

@ -11,10 +11,11 @@
SprayTool::SprayTool()
{
m_timer.on_timeout = [=]() {
m_timer = CTimer::create();
m_timer->on_timeout = [&]() {
paint_it();
};
m_timer.set_interval(200);
m_timer->set_interval(200);
}
SprayTool::~SprayTool()
@ -54,22 +55,22 @@ void SprayTool::on_mousedown(GMouseEvent& event)
m_color = m_widget->color_for(event);
m_last_pos = event.position();
m_timer.start();
m_timer->start();
paint_it();
}
void SprayTool::on_mousemove(GMouseEvent& event)
{
m_last_pos = event.position();
if (m_timer.is_active()) {
if (m_timer->is_active()) {
paint_it();
m_timer.restart(m_timer.interval());
m_timer->restart(m_timer->interval());
}
}
void SprayTool::on_mouseup(GMouseEvent&)
{
m_timer.stop();
m_timer->stop();
}
void SprayTool::on_contextmenu(GContextMenuEvent& event)

View file

@ -19,7 +19,7 @@ public:
private:
virtual const char* class_name() const override { return "SprayTool"; }
void paint_it();
CTimer m_timer;
ObjectPtr<CTimer> m_timer;
Point m_last_pos;
Color m_color;
OwnPtr<GMenu> m_context_menu;

View file

@ -52,7 +52,7 @@ int main(int argc, char** argv)
auto next_sample_buffer = loader.get_more_samples();
new CTimer(100, [&] {
auto timer = CTimer::create(100, [&] {
if (!next_sample_buffer) {
sample_widget->set_buffer(nullptr);
return;

View file

@ -55,7 +55,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GWidget* parent)
net_tcp_fields.empend("bytes_out", "Bytes Out", TextAlignment::CenterRight);
m_socket_table_view->set_model(GJsonArrayModel::create("/proc/net/tcp", move(net_tcp_fields)));
m_update_timer = new CTimer(
m_update_timer = CTimer::create(
1000, [this] {
update_models();
},

View file

@ -16,5 +16,5 @@ private:
GTableView* m_adapter_table_view { nullptr };
GTableView* m_socket_table_view { nullptr };
CTimer* m_update_timer { nullptr };
ObjectPtr<CTimer> m_update_timer;
};

View file

@ -11,7 +11,7 @@ ProcessStacksWidget::ProcessStacksWidget(GWidget* parent)
m_stacks_editor = new GTextEditor(GTextEditor::Type::MultiLine, this);
m_stacks_editor->set_readonly(true);
m_timer = new CTimer(1000, [this] { refresh(); }, this);
m_timer = CTimer::create(1000, [this] { refresh(); }, this);
}
ProcessStacksWidget::~ProcessStacksWidget()

View file

@ -1,5 +1,6 @@
#pragma once
#include <LibCore/ObjectPtr.h>
#include <LibGUI/GTextEditor.h>
#include <LibGUI/GWidget.h>
@ -17,5 +18,5 @@ public:
private:
pid_t m_pid { -1 };
GTextEditor* m_stacks_editor { nullptr };
CTimer* m_timer { nullptr };
ObjectPtr<CTimer> m_timer;
};

View file

@ -111,7 +111,7 @@ int main(int argc, char** argv)
auto* process_table_view = new ProcessTableView(*cpu_graph, process_table_container);
auto* memory_stats_widget = new MemoryStatsWidget(*memory_graph, graphs_container);
auto* refresh_timer = new CTimer(1000, [&] {
auto refresh_timer = CTimer::create(1000, [&] {
process_table_view->refresh();
memory_stats_widget->refresh();
});
@ -167,19 +167,19 @@ int main(int argc, char** argv)
};
auto frequency_menu = make<GMenu>("Frequency");
frequency_menu->add_action(GAction::create("0.25 sec", [refresh_timer](auto&) {
frequency_menu->add_action(GAction::create("0.25 sec", [&](auto&) {
refresh_timer->restart(250);
}));
frequency_menu->add_action(GAction::create("0.5 sec", [refresh_timer](auto&) {
frequency_menu->add_action(GAction::create("0.5 sec", [&](auto&) {
refresh_timer->restart(500);
}));
frequency_menu->add_action(GAction::create("1 sec", [refresh_timer](auto&) {
frequency_menu->add_action(GAction::create("1 sec", [&](auto&) {
refresh_timer->restart(1000);
}));
frequency_menu->add_action(GAction::create("3 sec", [refresh_timer](auto&) {
frequency_menu->add_action(GAction::create("3 sec", [&](auto&) {
refresh_timer->restart(3000);
}));
frequency_menu->add_action(GAction::create("5 sec", [refresh_timer](auto&) {
frequency_menu->add_action(GAction::create("5 sec", [&](auto&) {
refresh_timer->restart(5000);
}));
menubar->add_menu(move(frequency_menu));

View file

@ -25,6 +25,9 @@ TerminalWidget::TerminalWidget(int ptm_fd, RefPtr<CConfigFile> config)
, m_notifier(ptm_fd, CNotifier::Read)
, m_config(move(config))
{
m_cursor_blink_timer = CTimer::create();
m_visual_beep_timer = CTimer::create();
set_frame_shape(FrameShape::Container);
set_frame_shadow(FrameShadow::Sunken);
set_frame_thickness(2);
@ -36,10 +39,10 @@ TerminalWidget::TerminalWidget(int ptm_fd, RefPtr<CConfigFile> config)
};
dbgprintf("Terminal: Load config file from %s\n", m_config->file_name().characters());
m_cursor_blink_timer.set_interval(m_config->read_num_entry("Text",
m_cursor_blink_timer->set_interval(m_config->read_num_entry("Text",
"CursorBlinkInterval",
500));
m_cursor_blink_timer.on_timeout = [this] {
m_cursor_blink_timer->on_timeout = [this] {
m_cursor_blink_state = !m_cursor_blink_state;
update_cursor();
};
@ -103,10 +106,10 @@ void TerminalWidget::event(CEvent& event)
if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) {
m_in_active_window = event.type() == GEvent::WindowBecameActive;
if (!m_in_active_window) {
m_cursor_blink_timer.stop();
m_cursor_blink_timer->stop();
} else {
m_cursor_blink_state = true;
m_cursor_blink_timer.start();
m_cursor_blink_timer->start();
}
invalidate_cursor();
update();
@ -117,9 +120,9 @@ void TerminalWidget::event(CEvent& event)
void TerminalWidget::keydown_event(GKeyEvent& event)
{
// Reset timer so cursor doesn't blink while typing.
m_cursor_blink_timer.stop();
m_cursor_blink_timer->stop();
m_cursor_blink_state = true;
m_cursor_blink_timer.start();
m_cursor_blink_timer->start();
switch (event.key()) {
case KeyCode::Key_Up:
@ -196,7 +199,7 @@ void TerminalWidget::paint_event(GPaintEvent& event)
painter.add_clip_rect(event.rect());
if (m_visual_beep_timer.is_active())
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(m_opacity));
@ -223,7 +226,7 @@ void TerminalWidget::paint_event(GPaintEvent& event)
continue;
auto& line = line_for_visual_row(row);
bool has_only_one_background_color = line.has_only_one_background_color();
if (m_visual_beep_timer.is_active())
if (m_visual_beep_timer->is_active())
painter.fill_rect(row_rect, Color::Red);
else if (has_only_one_background_color)
painter.fill_rect(row_rect, lookup_color(line.attributes[0].background_color).with_alpha(m_opacity));
@ -563,9 +566,9 @@ void TerminalWidget::beep()
sysbeep();
return;
}
m_visual_beep_timer.restart(200);
m_visual_beep_timer.set_single_shot(true);
m_visual_beep_timer.on_timeout = [this] {
m_visual_beep_timer->restart(200);
m_visual_beep_timer->set_single_shot(true);
m_visual_beep_timer->on_timeout = [this] {
force_repaint();
};
force_repaint();

View file

@ -96,8 +96,8 @@ private:
int m_glyph_width { 0 };
CTimer m_cursor_blink_timer;
CTimer m_visual_beep_timer;
ObjectPtr<CTimer> m_cursor_blink_timer;
ObjectPtr<CTimer> m_visual_beep_timer;
RefPtr<CConfigFile> m_config;
GScrollBar* m_scrollbar { nullptr };