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

DisplaySettings: Show display's manufacturer and size instead of device

Rather than displaying the path of the framebuffer, try and display
the manufacturer name and the size of the display. If no EDID data is
available, fall back to showing the device path.
This commit is contained in:
Tom 2022-01-17 16:56:48 -07:00 committed by Linus Groh
parent 869c20b05d
commit 6565ec59fa
3 changed files with 41 additions and 12 deletions

View file

@ -7,7 +7,6 @@
#include "MonitorSettingsWidget.h"
#include <Applications/DisplaySettings/MonitorSettingsGML.h>
#include <LibEDID/EDID.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/ComboBox.h>
@ -100,16 +99,45 @@ void MonitorSettingsWidget::create_frame()
m_dpi_label = *find_descendant_of_type_named<GUI::Label>("display_dpi");
}
static String display_name_from_edid(EDID::Parser const& edid)
{
auto manufacturer_name = edid.manufacturer_name();
auto product_name = edid.display_product_name();
auto build_manufacturer_product_name = [&]() {
if (product_name.is_null() || product_name.is_empty())
return manufacturer_name;
return String::formatted("{} {}", manufacturer_name, product_name);
};
if (auto screen_size = edid.screen_size(); screen_size.has_value()) {
auto diagonal_inch = hypot(screen_size.value().horizontal_cm(), screen_size.value().vertical_cm()) / 2.54;
return String::formatted("{} {}\"", build_manufacturer_product_name(), roundf(diagonal_inch));
}
return build_manufacturer_product_name();
}
void MonitorSettingsWidget::load_current_settings()
{
m_screen_layout = GUI::WindowServerConnection::the().get_screen_layout();
m_screens.clear();
m_screen_edids.clear();
for (size_t i = 0; i < m_screen_layout.screens.size(); i++) {
String screen_display_name;
if (auto edid = EDID::Parser::from_framebuffer_device(m_screen_layout.screens[i].device, 0); !edid.is_error()) { // TODO: multihead
screen_display_name = display_name_from_edid(edid.value());
m_screen_edids.append(edid.release_value());
} else {
dbgln("Error getting EDID from device {}: {}", m_screen_layout.screens[i].device, edid.error());
screen_display_name = m_screen_layout.screens[i].device;
m_screen_edids.append({});
}
if (i == m_screen_layout.main_screen_index)
m_screens.append(String::formatted("{}: {} (main screen)", i + 1, m_screen_layout.screens[i].device));
m_screens.append(String::formatted("{}: {} (main screen)", i + 1, screen_display_name));
else
m_screens.append(String::formatted("{}: {}", i + 1, m_screen_layout.screens[i].device));
m_screens.append(String::formatted("{}: {}", i + 1, screen_display_name));
}
m_selected_screen_index = m_screen_layout.main_screen_index;
m_screen_combo->set_selected_index(m_selected_screen_index);
@ -126,19 +154,18 @@ void MonitorSettingsWidget::selected_screen_index_or_resolution_changed()
Optional<unsigned> screen_dpi;
String screen_dpi_tooltip;
if (auto edid = EDID::Parser::from_framebuffer_device(screen.device, 0); !edid.is_error()) { // TODO: multihead
if (m_screen_edids[m_selected_screen_index].has_value()) {
auto& edid = m_screen_edids[m_selected_screen_index];
if (auto screen_size = edid.value().screen_size(); screen_size.has_value()) {
float x_cm = screen_size.value().horizontal_cm();
float y_cm = screen_size.value().vertical_cm();
float diagonal_inch = sqrtf(x_cm * x_cm + y_cm * y_cm) / 2.54f;
float diagonal_pixels = sqrtf(current_resolution.width() * current_resolution.width() + current_resolution.height() * current_resolution.height());
if (diagonal_pixels != 0.0f) {
auto x_cm = screen_size.value().horizontal_cm();
auto y_cm = screen_size.value().vertical_cm();
auto diagonal_inch = hypot(x_cm, y_cm) / 2.54;
auto diagonal_pixels = hypot(current_resolution.width(), current_resolution.height());
if (diagonal_pixels != 0.0) {
screen_dpi = diagonal_pixels / diagonal_inch;
screen_dpi_tooltip = String::formatted("{} inch display ({}cm x {}cm)", roundf(diagonal_inch), x_cm, y_cm);
}
}
} else {
dbgln("Error getting EDID from device {}: {}", screen.device, edid.error());
}
if (screen_dpi.has_value()) {