mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 06:32:44 +00:00 
			
		
		
		
	ProcessManager: Use a single timer for refreshing the view.
Also add a menu for changing the update frequency to some nice values.
This commit is contained in:
		
							parent
							
								
									d73ed74d1c
								
							
						
					
					
						commit
						ac19fabaaf
					
				
					 4 changed files with 25 additions and 8 deletions
				
			
		|  | @ -37,7 +37,6 @@ MemoryStatsWidget::MemoryStatsWidget(GWidget* parent) | |||
|     m_kmalloc_label = build_widgets_for_label("Kernel heap:"); | ||||
|     m_kmalloc_count_label = build_widgets_for_label("Calls kmalloc/kfree:"); | ||||
| 
 | ||||
|     start_timer(1000); | ||||
|     refresh(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,15 +8,14 @@ ProcessTableView::ProcessTableView(GWidget* parent) | |||
| { | ||||
|     set_model(GSortingProxyModel::create(ProcessModel::create())); | ||||
|     model()->set_key_column_and_sort_order(ProcessModel::Column::CPU, GSortOrder::Descending); | ||||
|     start_timer(1000); | ||||
|     model()->update(); | ||||
|     refresh(); | ||||
| } | ||||
| 
 | ||||
| ProcessTableView::~ProcessTableView() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void ProcessTableView::timer_event(CTimerEvent&) | ||||
| void ProcessTableView::refresh() | ||||
| { | ||||
|     model()->update(); | ||||
| } | ||||
|  |  | |||
|  | @ -13,10 +13,9 @@ public: | |||
| 
 | ||||
|     pid_t selected_pid() const; | ||||
| 
 | ||||
| protected: | ||||
|     virtual void model_notification(const GModelNotification&) override; | ||||
|     void refresh(); | ||||
| 
 | ||||
| private: | ||||
|     virtual void timer_event(CTimerEvent&) override; | ||||
|     virtual void model_notification(const GModelNotification&) override; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,3 +1,4 @@ | |||
| #include <LibCore/CTimer.h> | ||||
| #include <LibGUI/GWindow.h> | ||||
| #include <LibGUI/GWidget.h> | ||||
| #include <LibGUI/GBoxLayout.h> | ||||
|  | @ -20,8 +21,12 @@ int main(int argc, char** argv) | |||
| 
 | ||||
|     auto* toolbar = new GToolBar(widget); | ||||
|     auto* process_table_view = new ProcessTableView(widget); | ||||
|     auto* memory_stats_widget = new MemoryStatsWidget(widget); | ||||
| 
 | ||||
|     new MemoryStatsWidget(widget); | ||||
|     auto* refresh_timer = new CTimer(1000, [&] { | ||||
|         process_table_view->refresh(); | ||||
|         memory_stats_widget->refresh(); | ||||
|     }); | ||||
| 
 | ||||
|     auto kill_action = GAction::create("Kill process", GraphicsBitmap::load_from_file("/res/icons/kill16.png"), [process_table_view] (const GAction&) { | ||||
|         pid_t pid = process_table_view->selected_pid(); | ||||
|  | @ -59,6 +64,21 @@ int main(int argc, char** argv) | |||
|     process_menu->add_action(continue_action.copy_ref()); | ||||
|     menubar->add_menu(move(process_menu)); | ||||
| 
 | ||||
|     auto frequency_menu = make<GMenu>("Frequency"); | ||||
|     frequency_menu->add_action(GAction::create("0.5 sec", [refresh_timer] (auto&) { | ||||
|         refresh_timer->restart(500); | ||||
|     })); | ||||
|     frequency_menu->add_action(GAction::create("1 sec", [refresh_timer] (auto&) { | ||||
|         refresh_timer->restart(1000); | ||||
|     })); | ||||
|     frequency_menu->add_action(GAction::create("3 sec", [refresh_timer] (auto&) { | ||||
|         refresh_timer->restart(3000); | ||||
|     })); | ||||
|     frequency_menu->add_action(GAction::create("5 sec", [refresh_timer] (auto&) { | ||||
|         refresh_timer->restart(5000); | ||||
|     })); | ||||
|     menubar->add_menu(move(frequency_menu)); | ||||
| 
 | ||||
|     auto help_menu = make<GMenu>("Help"); | ||||
|     help_menu->add_action(GAction::create("About", [] (const GAction&) { | ||||
|         dbgprintf("FIXME: Implement Help/About\n"); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling