Skip to content

Commit

Permalink
DisplaySettings: Show display's manufacturer and size instead of device
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomuta authored and linusg committed Jan 23, 2022
1 parent 869c20b commit 6565ec5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Userland/Applications/DisplaySettings/MonitorSettings.gml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@GUI::Label {
text: "Screen:"
text_alignment: "CenterLeft"
fixed_width: 95
fixed_width: 55
}

@GUI::ComboBox {
Expand Down
49 changes: 38 additions & 11 deletions Userland/Applications/DisplaySettings/MonitorSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions Userland/Applications/DisplaySettings/MonitorSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "MonitorWidget.h"
#include <LibCore/Timer.h>
#include <LibEDID/EDID.h>
#include <LibGUI/ColorInput.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/RadioButton.h>
Expand Down Expand Up @@ -45,6 +46,7 @@ class MonitorSettingsWidget final : public GUI::SettingsWindow::Tab {

WindowServer::ScreenLayout m_screen_layout;
Vector<String> m_screens;
Vector<Optional<EDID::Parser>> m_screen_edids;
Vector<Gfx::IntSize> m_resolutions;

RefPtr<DisplaySettings::MonitorWidget> m_monitor_widget;
Expand Down

0 comments on commit 6565ec5

Please sign in to comment.