Skip to content

Commit

Permalink
GTK4: Migration. Image
Browse files Browse the repository at this point in the history
Signed-off-by: Viktar Lukashonak <[email protected]>
  • Loading branch information
LukashonakV committed Apr 7, 2024
1 parent edfd1d3 commit 53948bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
12 changes: 4 additions & 8 deletions include/modules/image.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
#pragma once

#include <fmt/format.h>
#include <gtkmm/image.h>

#include <csignal>
#include <string>

#include "ALabel.hpp"
#include "AModule.hpp"
#include "gtkmm/box.h"
#include "util/command.hpp"
#include "util/json.hpp"
#include "util/sleeper_thread.hpp"


namespace waybar::modules {

class Image : public AModule {
class Image final : public AModule {
public:
Image(const std::string&, const Json::Value&);
virtual ~Image() = default;
Expand All @@ -29,7 +25,7 @@ class Image : public AModule {
Gtk::Box box_;
Gtk::Image image_;
std::string path_;
std::string tooltip_;
Glib::ustring tooltip_;
int size_;
int interval_;
util::command::res output_;
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ src_files = files(
'src/modules/disk.cpp',
'src/modules/temperature.cpp',
'src/modules/idle_inhibitor.cpp',
'src/modules/image.cpp',
'src/util/rewrite_string.cpp'
)

Expand Down
12 changes: 6 additions & 6 deletions src/modules/image.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "modules/image.hpp"

waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
: AModule(config, "image", id), box_(Gtk::ORIENTATION_HORIZONTAL, 0) {
box_.pack_start(image_);
: AModule(config, "image", id), box_(Gtk::Orientation::HORIZONTAL, 0) {
box_.append(image_);
box_.set_name("image");
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);
AModule::bindEvents(box_);

dp.emit();

Expand All @@ -30,7 +30,7 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
void waybar::modules::Image::delayWorker() {
thread_ = [this] {
dp.emit();
auto interval = std::chrono::seconds(interval_);
auto interval{std::chrono::seconds(interval_)};
thread_.sleep_for(interval);
};
}
Expand All @@ -51,7 +51,7 @@ auto waybar::modules::Image::update() -> void {
} else {
path_ = "";
}
if (Glib::file_test(path_, Glib::FILE_TEST_EXISTS))
if (Glib::file_test(path_, Glib::FileTest::EXISTS))
pixbuf = Gdk::Pixbuf::create_from_file(path_, size_, size_);
else
pixbuf = {};
Expand All @@ -75,7 +75,7 @@ auto waybar::modules::Image::update() -> void {
void waybar::modules::Image::parseOutputRaw() {
std::istringstream output(output_.out);
std::string line;
int i = 0;
int i{0};
while (getline(output, line)) {
if (i == 0) {
path_ = line;
Expand Down

0 comments on commit 53948bd

Please sign in to comment.