summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-27 00:55:13 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-27 01:16:56 +0100
commit2e846631a80ae1471273129c548b327e408bd5af (patch)
treef47e8cf4569b9ac7a0fa7c594695ee50aea9d484
parent21ccbc2167dc426f825867ac87d79928c2acdd4f (diff)
downloadserenity-2e846631a80ae1471273129c548b327e408bd5af.zip
SystemMonitor: Fetch process icons from their executable
Instead of using the extremely hackish icon_id field in /proc/all, we now retrieve process icons from their executable by using GUI::FileIconProvider.
-rw-r--r--Applications/SystemMonitor/ProcessModel.cpp17
-rw-r--r--Applications/SystemMonitor/ProcessModel.h2
-rw-r--r--Applications/SystemMonitor/main.cpp9
3 files changed, 15 insertions, 13 deletions
diff --git a/Applications/SystemMonitor/ProcessModel.cpp b/Applications/SystemMonitor/ProcessModel.cpp
index ac9717f1bc..d4c6db21bd 100644
--- a/Applications/SystemMonitor/ProcessModel.cpp
+++ b/Applications/SystemMonitor/ProcessModel.cpp
@@ -32,6 +32,7 @@
#include <AK/SharedBuffer.h>
#include <LibCore/File.h>
#include <LibCore/ProcessStatisticsReader.h>
+#include <LibGUI/FileIconProvider.h>
#include <fcntl.h>
#include <stdio.h>
@@ -274,16 +275,12 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
if (role == GUI::ModelRole::Display) {
switch (index.column()) {
- case Column::Icon:
- if (thread.current_state.icon_id != -1) {
- auto icon_buffer = SharedBuffer::create_from_shbuf_id(thread.current_state.icon_id);
- if (icon_buffer) {
- auto icon_bitmap = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *icon_buffer, { 16, 16 });
- if (icon_bitmap)
- return *icon_bitmap;
- }
- }
+ case Column::Icon: {
+ auto icon = GUI::FileIconProvider::icon_for_path(thread.current_state.executable);
+ if (auto* bitmap = icon.bitmap_for_size(16))
+ return *bitmap;
return *m_generic_process_icon;
+ }
case Column::PID:
return thread.current_state.pid;
case Column::TID:
@@ -384,9 +381,9 @@ void ProcessModel::update()
state.amount_clean_inode = it.value.amount_clean_inode;
state.amount_purgeable_volatile = it.value.amount_purgeable_volatile;
state.amount_purgeable_nonvolatile = it.value.amount_purgeable_nonvolatile;
- state.icon_id = it.value.icon_id;
state.name = thread.name;
+ state.executable = it.value.executable;
state.ppid = it.value.ppid;
state.tid = thread.tid;
diff --git a/Applications/SystemMonitor/ProcessModel.h b/Applications/SystemMonitor/ProcessModel.h
index 8739a2df69..9c79d0fcc5 100644
--- a/Applications/SystemMonitor/ProcessModel.h
+++ b/Applications/SystemMonitor/ProcessModel.h
@@ -118,6 +118,7 @@ private:
unsigned times_scheduled;
unsigned ticks_user;
unsigned ticks_kernel;
+ String executable;
String name;
String state;
String user;
@@ -143,7 +144,6 @@ private:
unsigned file_read_bytes;
unsigned file_write_bytes;
float cpu_percent;
- int icon_id;
};
struct Thread {
diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp
index 11e1fd36d7..cbb04bcffd 100644
--- a/Applications/SystemMonitor/main.cpp
+++ b/Applications/SystemMonitor/main.cpp
@@ -137,12 +137,17 @@ int main(int argc, char** argv)
return 1;
}
- if (unveil("/bin/Profiler", "x") < 0) {
+ if (unveil("/bin", "r") < 0) {
perror("unveil");
return 1;
}
- if (unveil("/bin/Inspector", "x") < 0) {
+ if (unveil("/bin/Profiler", "rx") < 0) {
+ perror("unveil");
+ return 1;
+ }
+
+ if (unveil("/bin/Inspector", "rx") < 0) {
perror("unveil");
return 1;
}