From 4a76a46ce85ce92fb633205a01fcd1c3d34d5296 Mon Sep 17 00:00:00 2001 From: Toni500git Date: Sun, 27 Oct 2024 22:00:38 +0100 Subject: [PATCH] gui: fix resizing of window when bg-image or logo is image --- include/gui.hpp | 9 +++++---- src/display.cpp | 6 ++++-- src/gui.cpp | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/gui.hpp b/include/gui.hpp index 681b34d7..992493ad 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -4,6 +4,7 @@ #ifdef GUI_MODE #include "config.hpp" +#include "gdkmm/pixbuf.h" #include "gtkmm/alignment.h" #include "gtkmm/box.h" #include "gtkmm/container.h" @@ -29,11 +30,11 @@ class Window : public Gtk::Window Gtk::Image *m_img, m_bg_image; Glib::RefPtr m_original_pixbuf; - void update_background_image(int width, int height) + void update_background_image(const int width, const int height) { if (m_original_pixbuf) { - Glib::RefPtr scaled_pixbuf = + const Glib::RefPtr scaled_pixbuf = m_original_pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR); m_bg_image.set(scaled_pixbuf); @@ -43,8 +44,8 @@ class Window : public Gtk::Window // Signal handler for window resize void on_window_resized(Gtk::Allocation& allocation) { - int new_width = allocation.get_width(); - int new_height = allocation.get_height(); + const int new_width = allocation.get_width(); + const int new_height = allocation.get_height(); // Update the background image with the new dimensions update_background_image(new_width, new_height); diff --git a/src/display.cpp b/src/display.cpp index f2358a01..cf6a93c0 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -70,7 +70,8 @@ static std::vector render_with_image(systemInfo_t& systemInfo, std: for (std::string& line : layout) { line = parse(line, parse_args); - line.insert(0, NOCOLOR); + if (!config.m_disable_colors) + line.insert(0, NOCOLOR); } // erase each element for each instance of MAGIC_LINE @@ -296,7 +297,8 @@ std::vector Display::render(const Config& config, const colors_t& c for (std::string& line : layout) { line = parse(line, _, parse_args); - line.insert(0, NOCOLOR); + if (!config.gui && !config.m_disable_colors) + line.insert(0, NOCOLOR); } // erase each element for each instance of MAGIC_LINE diff --git a/src/gui.cpp b/src/gui.cpp index bae702d1..4e199d17 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -137,8 +137,8 @@ Window::Window(const Config& config, const colors_t& colors, const std::string_v die("Background image path '{}' doesn't exist", config.gui_bg_image); m_original_pixbuf = Gdk::Pixbuf::create_from_file(config.gui_bg_image); - update_background_image(get_allocation().get_width(), get_allocation().get_height()); - m_overlay.add(m_bg_image); + m_bg_image.set(m_original_pixbuf); + m_overlay.add_overlay(m_bg_image); } m_box.pack_start(m_label, Gtk::PACK_SHRINK);