Skip to content

Commit

Permalink
gui: fix resizing of window when bg-image or logo is image
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Oct 27, 2024
1 parent d171c33 commit 4a76a46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,11 +30,11 @@ class Window : public Gtk::Window
Gtk::Image *m_img, m_bg_image;
Glib::RefPtr<Gdk::Pixbuf> 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<Gdk::Pixbuf> scaled_pixbuf =
const Glib::RefPtr<Gdk::Pixbuf> scaled_pixbuf =
m_original_pixbuf->scale_simple(width, height, Gdk::INTERP_BILINEAR);

m_bg_image.set(scaled_pixbuf);
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ static std::vector<std::string> 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
Expand Down Expand Up @@ -296,7 +297,8 @@ std::vector<std::string> 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
Expand Down
4 changes: 2 additions & 2 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4a76a46

Please sign in to comment.