From 5a2716baeaa5500d8a1d3ed5ec00a8490fa90cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Wed, 23 Mar 2022 01:32:44 +0100 Subject: SystemMonitor: Move entire main UI to GML :^) --- Userland/Applications/SystemMonitor/CMakeLists.txt | 3 + .../Applications/SystemMonitor/SystemMonitor.gml | 120 +++++++++++++++++++++ Userland/Applications/SystemMonitor/main.cpp | 118 +++++--------------- 3 files changed, 152 insertions(+), 89 deletions(-) create mode 100644 Userland/Applications/SystemMonitor/SystemMonitor.gml (limited to 'Userland') diff --git a/Userland/Applications/SystemMonitor/CMakeLists.txt b/Userland/Applications/SystemMonitor/CMakeLists.txt index 058afb4204..30c42dab12 100644 --- a/Userland/Applications/SystemMonitor/CMakeLists.txt +++ b/Userland/Applications/SystemMonitor/CMakeLists.txt @@ -4,6 +4,8 @@ serenity_component( TARGETS SystemMonitor Profiler Inspector ) +compile_gml(SystemMonitor.gml SystemMonitorGML.h system_monitor_gml) + set(SOURCES GraphWidget.cpp main.cpp @@ -15,6 +17,7 @@ set(SOURCES ProcessUnveiledPathsWidget.cpp ProcessStateWidget.cpp ThreadStackWidget.cpp + SystemMonitorGML.h ) serenity_app(SystemMonitor ICON app-system-monitor) diff --git a/Userland/Applications/SystemMonitor/SystemMonitor.gml b/Userland/Applications/SystemMonitor/SystemMonitor.gml new file mode 100644 index 0000000000..8fbf4a09fd --- /dev/null +++ b/Userland/Applications/SystemMonitor/SystemMonitor.gml @@ -0,0 +1,120 @@ +@GUI::Widget { + fill_with_background_color: true + layout: @GUI::VerticalBoxLayout {} + + // Add a tasteful separating line between the menu and the main UI. + @GUI::HorizontalSeparator { + fixed_height: 2 + } + + @GUI::Widget { + layout: @GUI::VerticalBoxLayout { + margins: [0, 4, 4] + } + + @GUI::TabWidget { + name: "main_tabs" + + @GUI::Widget { + title: "Processes" + name: "processes" + layout: @GUI::VerticalBoxLayout { + margins: [4] + spacing: 0 + } + + @GUI::TableView { + name: "process_table" + column_headers_visible: true + } + } + + @GUI::Widget { + title: "Performance" + name: "performance" + background_role: "Button" + fill_with_background_color: true + layout: @GUI::VerticalBoxLayout { + margins: [4] + } + + @GUI::GroupBox { + title: "CPU usage" + name: "cpu_graph" + layout: @GUI::VerticalBoxLayout {} + } + + @GUI::GroupBox { + title: "Memory usage" + fixed_height: 120 + layout: @GUI::VerticalBoxLayout { + margins: [6] + } + + @SystemMonitor::GraphWidget { + stack_values: true + name: "memory_graph" + } + } + + @SystemMonitor::MemoryStatsWidget { + name: "memory_stats" + memory_graph: "memory_graph" + } + } + + @GUI::LazyWidget { + title: "Storage" + name: "storage" + layout: @GUI::VerticalBoxLayout { + margins: [4] + } + + @GUI::TableView { + name: "storage_table" + } + } + + @SystemMonitor::NetworkStatisticsWidget { + title: "Network" + name: "network" + } + + @GUI::LazyWidget { + title: "Hardware" + name: "hardware" + layout: @GUI::VerticalBoxLayout { + margins: [4] + } + + @GUI::GroupBox { + title: "CPUs" + fixed_height: 128 + layout: @GUI::VerticalBoxLayout { + margins: [6] + } + + @GUI::TableView { + name: "cpus_table" + } + } + + @GUI::GroupBox { + title: "PCI devices" + layout: @GUI::VerticalBoxLayout { + margins: [6] + } + + @GUI::TableView { + name: "pci_dev_table" + } + } + } + } + } + + @GUI::Statusbar { + segment_count: 3 + name: "statusbar" + } +} diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index db30e4688d..bab543ee04 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -16,6 +16,7 @@ #include "ProcessUnveiledPathsWidget.h" #include "ThreadStackWidget.h" #include +#include #include #include #include @@ -53,9 +54,9 @@ #include static ErrorOr> build_process_window(pid_t); -static NonnullRefPtr build_storage_widget(); -static NonnullRefPtr build_hardware_tab(); -static NonnullRefPtr build_performance_tab(); +static void build_storage_widget(GUI::LazyWidget&); +static void build_hardware_tab(GUI::LazyWidget&); +static void build_performance_tab(GUI::Widget&); static RefPtr statusbar; @@ -145,19 +146,11 @@ ErrorOr serenity_main(Main::Arguments arguments) window->resize(560, 430); auto main_widget = TRY(window->try_set_main_widget()); - main_widget->set_layout(); - main_widget->set_fill_with_background_color(true); - - // Add a tasteful separating line between the menu and the main UI. - auto& top_line = main_widget->add(Gfx::Orientation::Horizontal); - top_line.set_fixed_height(2); + main_widget->load_from_gml(system_monitor_gml); + auto& tabwidget = *main_widget->find_descendant_of_type_named("main_tabs"); + statusbar = main_widget->find_descendant_of_type_named("statusbar"); - auto& tabwidget_container = main_widget->add(); - tabwidget_container.set_layout(); - tabwidget_container.layout()->set_margins({ 0, 4, 4 }); - auto& tabwidget = tabwidget_container.add(); - - statusbar = main_widget->add(3); + auto& process_table_container = *tabwidget.find_descendant_of_type_named("processes"); auto process_model = ProcessModel::create(); process_model->on_state_update = [&](int process_count, int thread_count) { @@ -165,30 +158,16 @@ ErrorOr serenity_main(Main::Arguments arguments) statusbar->set_text(1, String::formatted("Threads: {}", thread_count)); }; - auto& process_table_container = tabwidget.add_tab("Processes"); - - auto performance_widget = build_performance_tab(); - performance_widget->set_title("Performance"); - tabwidget.add_widget(performance_widget); + auto& performance_widget = *tabwidget.find_descendant_of_type_named("performance"); + build_performance_tab(performance_widget); - auto storage_widget = build_storage_widget(); - storage_widget->set_title("Storage"); - tabwidget.add_widget(storage_widget); + auto& storage_widget = *tabwidget.find_descendant_of_type_named("storage"); + build_storage_widget(storage_widget); - auto network_stats_widget = SystemMonitor::NetworkStatisticsWidget::construct(); - network_stats_widget->set_title("Network"); - tabwidget.add_widget(network_stats_widget); + auto& hardware_widget = *tabwidget.find_descendant_of_type_named("hardware"); + build_hardware_tab(hardware_widget); - auto hardware_widget = build_hardware_tab(); - hardware_widget->set_title("Hardware"); - tabwidget.add_widget(hardware_widget); - - process_table_container.set_layout(); - process_table_container.layout()->set_margins(4); - process_table_container.layout()->set_spacing(0); - - auto& process_table_view = process_table_container.add(); - process_table_view.set_column_headers_visible(true); + auto& process_table_view = *process_table_container.find_child_of_type_named("process_table"); process_table_view.set_model(TRY(GUI::SortingProxyModel::create(process_model))); for (auto column = 0; column < ProcessModel::Column::__Count; ++column) process_table_view.set_column_visible(column, false); @@ -379,13 +358,13 @@ ErrorOr serenity_main(Main::Arguments arguments) if (args_tab_view == "processes") tabwidget.set_active_widget(&process_table_container); else if (args_tab_view == "graphs") - tabwidget.set_active_widget(performance_widget); + tabwidget.set_active_widget(&performance_widget); else if (args_tab_view == "fs") - tabwidget.set_active_widget(storage_widget); + tabwidget.set_active_widget(&storage_widget); else if (args_tab_view == "hardware") - tabwidget.set_active_widget(hardware_widget); + tabwidget.set_active_widget(&hardware_widget); else if (args_tab_view == "network") - tabwidget.set_active_widget(network_stats_widget); + tabwidget.set_active_widget(tabwidget.find_descendant_of_type_named("network")); return app->exec(); } @@ -477,14 +456,10 @@ ErrorOr> build_process_window(pid_t pid) return window; } -NonnullRefPtr build_storage_widget() +void build_storage_widget(GUI::LazyWidget& widget) { - auto widget = GUI::LazyWidget::construct(); - - widget->on_first_show = [](GUI::LazyWidget& self) { - self.set_layout(); - self.layout()->set_margins(4); - auto& fs_table_view = self.add(); + widget.on_first_show = [](GUI::LazyWidget& self) { + auto& fs_table_view = *self.find_child_of_type_named("storage_table"); Vector df_fields; df_fields.empend("mount_point", "Mount point", Gfx::TextAlignment::CenterLeft); @@ -571,22 +546,12 @@ NonnullRefPtr build_storage_widget() fs_table_view.model()->invalidate(); }; - return widget; } -NonnullRefPtr build_hardware_tab() +void build_hardware_tab(GUI::LazyWidget& widget) { - auto widget = GUI::LazyWidget::construct(); - - widget->on_first_show = [](GUI::LazyWidget& self) { - self.set_layout(); - self.layout()->set_margins(4); - + widget.on_first_show = [](GUI::LazyWidget& self) { { - auto& cpu_group_box = self.add("CPUs"); - cpu_group_box.set_layout(); - cpu_group_box.layout()->set_margins(6); - Vector processors_field; processors_field.empend("processor", "Processor", Gfx::TextAlignment::CenterRight); processors_field.empend("cpuid", "CPUID", Gfx::TextAlignment::CenterLeft); @@ -605,21 +570,13 @@ NonnullRefPtr build_hardware_tab() processors_field.empend("stepping", "Stepping", Gfx::TextAlignment::CenterRight); processors_field.empend("type", "Type", Gfx::TextAlignment::CenterRight); - auto& processors_table_view = cpu_group_box.add(); + auto& processors_table_view = *self.find_descendant_of_type_named("cpus_table"); auto json_model = GUI::JsonArrayModel::create("/proc/cpuinfo", move(processors_field)); processors_table_view.set_model(json_model); json_model->invalidate(); - - cpu_group_box.set_fixed_height(128); } { - auto& pci_group_box = self.add("PCI devices"); - pci_group_box.set_layout(); - pci_group_box.layout()->set_margins(6); - - auto& pci_table_view = pci_group_box.add(); - auto db = PCIDB::Database::open(); if (!db) warnln("Couldn't open PCI ID database!"); @@ -663,25 +620,16 @@ NonnullRefPtr build_hardware_tab() return String::formatted("{:02x}", revision_id); }); + auto& pci_table_view = *self.find_descendant_of_type_named("pci_dev_table"); pci_table_view.set_model(MUST(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/pci", move(pci_fields))))); pci_table_view.model()->invalidate(); } }; - - return widget; } -NonnullRefPtr build_performance_tab() +void build_performance_tab(GUI::Widget& graphs_container) { - auto graphs_container = GUI::Widget::construct(); - - graphs_container->set_fill_with_background_color(true); - graphs_container->set_background_role(ColorRole::Button); - graphs_container->set_layout(); - graphs_container->layout()->set_margins(4); - - auto& cpu_graph_group_box = graphs_container->add("CPU usage"); - cpu_graph_group_box.set_layout(); + auto& cpu_graph_group_box = *graphs_container.find_descendant_of_type_named("cpu_graph"); size_t cpu_graphs_per_row = min(4, ProcessModel::the().cpus().size()); auto cpu_graph_rows = ceil_div(ProcessModel::the().cpus().size(), cpu_graphs_per_row); @@ -721,12 +669,7 @@ NonnullRefPtr build_performance_tab() statusbar->set_text(2, String::formatted("CPU usage: {}%", (int)roundf(cpu_usage))); }; - auto& memory_graph_group_box = graphs_container->add("Memory usage"); - memory_graph_group_box.set_layout(); - memory_graph_group_box.layout()->set_margins(6); - memory_graph_group_box.set_fixed_height(120); - auto& memory_graph = memory_graph_group_box.add(); - memory_graph.set_stack_values(true); + auto& memory_graph = *graphs_container.find_descendant_of_type_named("memory_graph"); memory_graph.set_value_format(0, { .graph_color_role = ColorRole::SyntaxComment, .text_formatter = [](int bytes) { @@ -745,7 +688,4 @@ NonnullRefPtr build_performance_tab() return String::formatted("Kernel heap: {}", human_readable_size(bytes)); }, }); - - graphs_container->add(&memory_graph); - return graphs_container; } -- cgit v1.2.3