From 444a4e4d391f7c74a8ecda04fd072fdad6e49582 Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 16 Sep 2019 15:50:47 +1000 Subject: [PATCH] DisplayProperties: Auto-resolution and graphical fix (#566) The program will now automatically select the user's currently chosen resolution when it is loaded up, however it is not "visually selected" in the `GListView` Moved the `resolution_list` list to be on the top to keep it consistent with the wallpaper tab. --- .../DisplayProperties/DisplayProperties.cpp | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Applications/DisplayProperties/DisplayProperties.cpp b/Applications/DisplayProperties/DisplayProperties.cpp index 788d8ee604..12046f5113 100644 --- a/Applications/DisplayProperties/DisplayProperties.cpp +++ b/Applications/DisplayProperties/DisplayProperties.cpp @@ -39,12 +39,37 @@ void DisplayPropertiesWidget::create_resolution_list() m_resolutions.append({ 800, 600 }); m_resolutions.append({ 1024, 768 }); m_resolutions.append({ 1280, 1024 }); - m_resolutions.append({ 1366, 768 }); m_resolutions.append({ 1440, 900 }); m_resolutions.append({ 1600, 900 }); m_resolutions.append({ 1920, 1080 }); m_resolutions.append({ 2560, 1080 }); + Size find_size; + + bool okay = false; + // Let's attempt to find the current resolution and select it! + find_size.set_width(m_wm_config->read_entry("Screen", "Width", "1024").to_int(okay)); + if (!okay) { + fprintf(stderr, "DisplayProperties: failed to convert width to int!"); + return; + } + + find_size.set_height(m_wm_config->read_entry("Screen", "Height", "768").to_int(okay)); + if (!okay) { + fprintf(stderr, "DisplayProperties: failed to convert height to int!"); + return; + } + + int index = 0; + for (auto& resolution : m_resolutions) { + if (resolution == find_size) { + m_selected_resolution = m_resolutions.at(index); + return; // We don't need to do anything else + } + + index++; + } + m_selected_resolution = m_resolutions.at(0); } @@ -97,7 +122,6 @@ void DisplayPropertiesWidget::create_frame() auto* settings_content = new GWidget(settings_splitter); settings_content->set_layout(make(Orientation::Vertical)); - settings_content->layout()->add_spacer(); settings_content->layout()->set_margins({ 4, 4, 4, 4 }); auto* resolution_list = new GListView(settings_content); @@ -108,6 +132,8 @@ void DisplayPropertiesWidget::create_frame() m_selected_resolution = m_resolutions.at(index.row()); }; + settings_content->layout()->add_spacer(); + // Add the apply and cancel buttons auto* bottom_widget = new GWidget(m_root_widget); bottom_widget->set_layout(make(Orientation::Horizontal));