DisplaySettings: Allow setting wallpapers from outside /res/wallpapers
Ideally, we would copy the file to `/res/wallpapers`, add an entry to `ComboBox` model and set the index to this entry. I didn't want to touch anything outside of `DisplaySettings`, so this is more of a workaround :^)
This commit is contained in:
parent
3a4e121904
commit
9f58624802
Notes:
sideshowbarker
2024-07-19 05:20:54 +09:00
Author: https://github.com/devsh0 Commit: https://github.com/SerenityOS/serenity/commit/9f58624802b Pull-request: https://github.com/SerenityOS/serenity/pull/2642 Reviewed-by: https://github.com/awesomekling
3 changed files with 14 additions and 5 deletions
|
@ -125,6 +125,11 @@ void DisplaySettingsWidget::create_frame()
|
|||
m_wallpaper_combo->set_model(*ItemListModel<AK::String>::create(m_wallpapers));
|
||||
m_wallpaper_combo->on_change = [this](auto& text, const GUI::ModelIndex& index) {
|
||||
String path = text;
|
||||
if (m_monitor_widget->set_wallpaper(path)) {
|
||||
m_monitor_widget->update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (index.row() == 0) {
|
||||
path = "";
|
||||
} else {
|
||||
|
@ -136,8 +141,8 @@ void DisplaySettingsWidget::create_frame()
|
|||
}
|
||||
}
|
||||
|
||||
this->m_monitor_widget->set_wallpaper(path);
|
||||
this->m_monitor_widget->update();
|
||||
m_monitor_widget->set_wallpaper(path);
|
||||
m_monitor_widget->update();
|
||||
};
|
||||
|
||||
auto& button = wallpaper_selection_container.add<GUI::Button>();
|
||||
|
|
|
@ -33,10 +33,14 @@ MonitorWidget::MonitorWidget()
|
|||
m_monitor_rect = { 8, 9, 320, 180 };
|
||||
}
|
||||
|
||||
void MonitorWidget::set_wallpaper(String path)
|
||||
bool MonitorWidget::set_wallpaper(String path)
|
||||
{
|
||||
m_desktop_wallpaper_path = path;
|
||||
m_desktop_wallpaper_bitmap = Gfx::Bitmap::load_from_file(path);
|
||||
auto bitmap_ptr = Gfx::Bitmap::load_from_file(path);
|
||||
if (!bitmap_ptr)
|
||||
return false;
|
||||
m_desktop_wallpaper_bitmap = bitmap_ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
String MonitorWidget::wallpaper()
|
||||
|
|
|
@ -35,7 +35,7 @@ class MonitorWidget final : public GUI::Widget {
|
|||
public:
|
||||
MonitorWidget();
|
||||
|
||||
void set_wallpaper(String path);
|
||||
bool set_wallpaper(String path);
|
||||
String wallpaper();
|
||||
|
||||
void set_wallpaper_mode(String mode);
|
||||
|
|
Loading…
Add table
Reference in a new issue