From 0f7443f0109c4e914eb31437fa689f45b525de19 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 4 Apr 2021 20:46:46 +0200 Subject: [PATCH] SystemMonitor: Add a status bar to the main window To get us started, this shows the number of processes and threads in the last captured state. --- .../Applications/SystemMonitor/ProcessModel.cpp | 3 +++ Userland/Applications/SystemMonitor/ProcessModel.h | 1 + Userland/Applications/SystemMonitor/main.cpp | 14 +++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/SystemMonitor/ProcessModel.cpp b/Userland/Applications/SystemMonitor/ProcessModel.cpp index 51894ac2693..da7251d1c4e 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.cpp +++ b/Userland/Applications/SystemMonitor/ProcessModel.cpp @@ -429,6 +429,9 @@ void ProcessModel::update() if (on_cpu_info_change) on_cpu_info_change(m_cpus); + if (on_state_update) + on_state_update(all_processes->size(), m_threads.size()); + // FIXME: This is a rather hackish way of invalidating indexes. // It would be good if GUI::Model had a way to orchestrate removal/insertion while preserving indexes. did_update(previous_tid_count == m_tids.size() ? GUI::Model::UpdateFlag::DontInvalidateIndexes : GUI::Model::UpdateFlag::InvalidateAllIndexes); diff --git a/Userland/Applications/SystemMonitor/ProcessModel.h b/Userland/Applications/SystemMonitor/ProcessModel.h index 803b9bdfcd2..1c664c4dece 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.h +++ b/Userland/Applications/SystemMonitor/ProcessModel.h @@ -94,6 +94,7 @@ public: }; Function&)> on_cpu_info_change; + Function on_state_update; const NonnullOwnPtrVector& cpus() const { return m_cpus; } diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index b684ecea84c..f9b4c36068b 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -174,10 +175,17 @@ int main(int argc, char** argv) auto& keeper = window->set_main_widget(); keeper.set_layout(); keeper.set_fill_with_background_color(true); - keeper.layout()->set_margins({ 2, 2, 2, 2 }); + keeper.layout()->set_margins({ 2, 2, 2, 0 }); auto& tabwidget = keeper.add(); + auto& statusbar = keeper.add(2); + auto process_model = ProcessModel::create(); + process_model->on_state_update = [&](int process_count, int thread_count) { + statusbar.set_text(0, String::formatted("Processes: {}", process_count)); + statusbar.set_text(1, String::formatted("Threads: {}", thread_count)); + }; + auto process_container_splitter = GUI::VerticalSplitter::construct(); tabwidget.add_widget("Processes", process_container_splitter); process_container_splitter->layout()->set_margins({ 4, 4, 4, 4 }); @@ -210,7 +218,7 @@ int main(int argc, char** argv) auto& process_table_view = process_table_container.add(); process_table_view.set_column_headers_visible(true); - process_table_view.set_model(GUI::SortingProxyModel::create(ProcessModel::create())); + process_table_view.set_model(GUI::SortingProxyModel::create(process_model)); process_table_view.set_key_column_and_sort_order(ProcessModel::Column::CPU, GUI::SortOrder::Descending); process_table_view.model()->update();