Files
Waybar/include/modules/custom.hpp
T
Austin Horstman 5f4b96ad1d refactor(custom): move continuous exec onto GLib command stream
Replace the custom module's continuous getline() worker with the new GLib-backed command stream helper.

This moves line delivery, child exit handling, and restart scheduling onto the main loop so continuous commands no longer depend on a blocking FILE* read inside SleeperThread.

The behavior is kept aligned with the old module semantics: stdout lines still emit updates, non-zero exits still surface as errors, and restart-interval still respawns the command.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2026-07-04 08:41:35 -05:00

59 lines
1.5 KiB
C++

#pragma once
#include <fmt/format.h>
#include <csignal>
#include <memory>
#include <string>
#include "AIconLabel.hpp"
#include "util/command.hpp"
#include "util/command_line_stream.hpp"
#include "util/json.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules {
class Custom : public AIconLabel {
public:
Custom(const std::string&, const std::string&, const Json::Value&, const std::string&);
virtual ~Custom();
auto update() -> void override;
void refresh(int /*signal*/) override;
private:
void delayWorker();
void continuousWorker();
void startContinuousProcess(bool throw_on_failure);
void handleContinuousProcessExit(int exit_code);
void scheduleContinuousRestart();
void waitingWorker();
void parseOutputRaw();
void parseOutputJson();
void handleEvent();
bool handleScroll(GdkEventScroll* e) override;
bool handleToggle(GdkEventButton* const& e) override;
const std::string name_;
const std::string output_name_;
std::string text_;
std::string id_;
std::string alt_;
std::string tooltip_;
std::string last_tooltip_markup_;
std::string image_path_;
std::string image_name_;
unsigned app_icon_size_{24};
const bool tooltip_format_enabled_;
std::vector<std::string> class_;
int percentage_;
util::command::res output_;
util::JsonParser parser_;
std::unique_ptr<util::command::LineStream> continuous_stream_;
sigc::connection restart_connection_;
util::SleeperThread thread_;
};
} // namespace waybar::modules