2023-10-16 20:13:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "AModule.hpp"
|
|
|
|
#include "util/command.hpp"
|
|
|
|
#include "util/json.hpp"
|
|
|
|
#include "util/sleeper_thread.hpp"
|
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
2023-10-19 20:10:32 +00:00
|
|
|
namespace ffi {
|
2023-10-16 20:13:51 +00:00
|
|
|
extern "C" {
|
2023-10-19 20:10:32 +00:00
|
|
|
typedef struct wbcffi_module wbcffi_module;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
wbcffi_module* obj;
|
|
|
|
const char* waybar_version;
|
|
|
|
GtkContainer* (*get_root_widget)(wbcffi_module*);
|
|
|
|
void (*queue_update)(wbcffi_module*);
|
|
|
|
} wbcffi_init_info;
|
|
|
|
|
2023-10-16 20:13:51 +00:00
|
|
|
struct wbcffi_config_entry {
|
|
|
|
const char* key;
|
|
|
|
const char* value;
|
|
|
|
};
|
|
|
|
}
|
2023-10-19 20:10:32 +00:00
|
|
|
} // namespace ffi
|
2023-10-16 20:13:51 +00:00
|
|
|
|
|
|
|
class CFFI : public AModule {
|
|
|
|
public:
|
|
|
|
CFFI(const std::string&, const std::string&, const Json::Value&);
|
|
|
|
virtual ~CFFI();
|
|
|
|
|
|
|
|
virtual auto refresh(int signal) -> void override;
|
|
|
|
virtual auto doAction(const std::string& name) -> void override;
|
2023-10-17 16:11:48 +00:00
|
|
|
virtual auto update() -> void override;
|
2023-10-16 20:13:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
void* cffi_instance_ = nullptr;
|
|
|
|
|
2023-10-19 20:10:32 +00:00
|
|
|
typedef void*(InitFn)(const ffi::wbcffi_init_info* init_info,
|
|
|
|
const ffi::wbcffi_config_entry* config_entries, size_t config_entries_len);
|
2023-10-16 20:13:51 +00:00
|
|
|
typedef void(DenitFn)(void* instance);
|
|
|
|
typedef void(RefreshFn)(void* instance, int signal);
|
|
|
|
typedef void(DoActionFn)(void* instance, const char* name);
|
2023-10-17 16:11:48 +00:00
|
|
|
typedef void(UpdateFn)(void* instance);
|
2023-10-16 20:13:51 +00:00
|
|
|
|
|
|
|
// FFI hooks
|
|
|
|
struct {
|
|
|
|
std::function<InitFn> init = nullptr;
|
|
|
|
std::function<DenitFn> deinit = nullptr;
|
|
|
|
std::function<RefreshFn> refresh = [](void*, int) {};
|
|
|
|
std::function<DoActionFn> doAction = [](void*, const char*) {};
|
2023-10-17 16:11:48 +00:00
|
|
|
std::function<UpdateFn> update = [](void*) {};
|
2023-10-16 20:13:51 +00:00
|
|
|
} hooks_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules
|