mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-13 22:52:30 +02:00
Moved all waybar info into a single struct
This commit is contained in:
@ -2,10 +2,10 @@
|
||||
#include "waybar_cffi_module.h"
|
||||
|
||||
typedef struct {
|
||||
GtkContainer* root;
|
||||
wbcffi_module* waybar_module;
|
||||
GtkBox* container;
|
||||
GtkButton* button;
|
||||
} Instance;
|
||||
} ExampleMod;
|
||||
|
||||
// This static variable is shared between all instances of this module
|
||||
static int instance_count = 0;
|
||||
@ -19,8 +19,7 @@ void onclicked(GtkButton* button) {
|
||||
// You must
|
||||
const size_t wbcffi_version = 1;
|
||||
|
||||
void* wbcffi_init(GtkContainer* root_widget, void (*trigger_update)(void*),
|
||||
void* trigger_update_arg, const struct wbcffi_config_entry* config_entries,
|
||||
void* wbcffi_init(const wbcffi_init_info* init_info, const wbcffi_config_entry* config_entries,
|
||||
size_t config_entries_len) {
|
||||
printf("cffi_example: init config:\n");
|
||||
for (size_t i = 0; i < config_entries_len; i++) {
|
||||
@ -28,12 +27,14 @@ void* wbcffi_init(GtkContainer* root_widget, void (*trigger_update)(void*),
|
||||
}
|
||||
|
||||
// Allocate the instance object
|
||||
Instance* inst = malloc(sizeof(Instance));
|
||||
inst->root = root_widget;
|
||||
ExampleMod* inst = malloc(sizeof(ExampleMod));
|
||||
inst->waybar_module = init_info->obj;
|
||||
|
||||
GtkContainer* root = init_info->get_root_widget(init_info->obj);
|
||||
|
||||
// Add a container for displaying the next widgets
|
||||
inst->container = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5));
|
||||
gtk_container_add(GTK_CONTAINER(inst->root), GTK_WIDGET(inst->container));
|
||||
gtk_container_add(GTK_CONTAINER(root), GTK_WIDGET(inst->container));
|
||||
|
||||
// Add a label
|
||||
GtkLabel* label = GTK_LABEL(gtk_label_new("[Example C FFI Module:"));
|
||||
|
@ -10,29 +10,46 @@ extern "C" {
|
||||
/// Waybar ABI version. 1 is the latest version
|
||||
extern const size_t wbcffi_version;
|
||||
|
||||
/// Private Waybar CFFI module
|
||||
typedef struct wbcffi_module wbcffi_module;
|
||||
|
||||
/// Waybar module information
|
||||
typedef struct {
|
||||
/// Waybar CFFI object pointer
|
||||
wbcffi_module* obj;
|
||||
|
||||
/// Waybar version string
|
||||
const char* waybar_version;
|
||||
|
||||
/// Returns the waybar widget allocated for this module
|
||||
/// @param obj Waybar CFFI object pointer
|
||||
GtkContainer* (*get_root_widget)(wbcffi_module* obj);
|
||||
|
||||
/// Queues a request for calling wbcffi_update() on the next GTK main event
|
||||
/// loop iteration
|
||||
/// @param obj Waybar CFFI object pointer
|
||||
void (*queue_update)(wbcffi_module*);
|
||||
} wbcffi_init_info;
|
||||
|
||||
/// Config key-value pair
|
||||
struct wbcffi_config_entry {
|
||||
typedef struct {
|
||||
/// Entry key
|
||||
const char* key;
|
||||
/// Entry value as string. JSON object and arrays are serialized.
|
||||
const char* value;
|
||||
};
|
||||
} wbcffi_config_entry;
|
||||
|
||||
/// Module init/new function, called on module instantiation
|
||||
///
|
||||
/// MANDATORY CFFI function
|
||||
///
|
||||
/// @param root_widget Root GTK widget instantiated by Waybar
|
||||
/// @param trigger_update Call this function with trigger_update_arg as argument to trigger
|
||||
/// wbcffi_update() on the next GTK main event loop iteration
|
||||
/// @param trigger_update_arg Argument for trigger_update call
|
||||
/// @param init_info Waybar module information
|
||||
/// @param config_entries Flat representation of the module JSON config. The data only available
|
||||
/// during wbcffi_init call.
|
||||
/// @param config_entries_len Number of entries in `config_entries`
|
||||
///
|
||||
/// @return A untyped pointer to module data, NULL if the module failed to load.
|
||||
void* wbcffi_init(GtkContainer* root_widget, const void (*trigger_update)(void*),
|
||||
void* trigger_update_arg, const struct wbcffi_config_entry* config_entries,
|
||||
void* wbcffi_init(const wbcffi_init_info* init_info, const wbcffi_config_entry* config_entries,
|
||||
size_t config_entries_len);
|
||||
|
||||
/// Module deinit/delete function, called when Waybar is closed or when the module is removed
|
||||
|
Reference in New Issue
Block a user