mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-13 14:42:29 +02:00
Send update dispatcher though FFI
This commit is contained in:
@ -7,6 +7,9 @@ Most language can implement the required functions and constants (C, C++, Rust,
|
||||
Go, Python, ...), meaning you can develop custom modules using your language of
|
||||
choice, as long as there's GTK bindings.
|
||||
|
||||
Symbols to implement are documented in the
|
||||
[waybar_cffi_module.h](waybar_cffi_module.h) file.
|
||||
|
||||
# Usage
|
||||
|
||||
## Building this module
|
||||
|
@ -19,7 +19,8 @@ void onclicked(GtkButton* button) {
|
||||
// You must
|
||||
const size_t wbcffi_version = 1;
|
||||
|
||||
void* wbcffi_init(GtkContainer* root, const struct wbcffi_config_entry* config_entries,
|
||||
void* wbcffi_init(GtkContainer* root_widget, void (*trigger_update)(void*),
|
||||
void* trigger_update_arg, const struct 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,7 +29,7 @@ void* wbcffi_init(GtkContainer* root, const struct wbcffi_config_entry* config_e
|
||||
|
||||
// Allocate the instance object
|
||||
Instance* inst = malloc(sizeof(Instance));
|
||||
inst->root = root;
|
||||
inst->root = root_widget;
|
||||
|
||||
// Add a container for displaying the next widgets
|
||||
inst->container = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5));
|
||||
@ -51,13 +52,18 @@ void* wbcffi_init(GtkContainer* root, const struct wbcffi_config_entry* config_e
|
||||
printf("cffi_example inst=%p: init success ! (%d total instances)\n", inst, ++instance_count);
|
||||
return inst;
|
||||
}
|
||||
|
||||
void wbcffi_deinit(void* instance) {
|
||||
printf("cffi_example inst=%p: free memory\n", instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void wbcffi_update(void* instance) { printf("cffi_example inst=%p: Update request\n", instance); }
|
||||
|
||||
void wbcffi_refresh(void* instance, int signal) {
|
||||
printf("cffi_example inst=%p: Received refresh signal %d\n", instance, signal);
|
||||
}
|
||||
|
||||
void wbcffi_doaction(void* instance, const char* name) {
|
||||
printf("cffi_example inst=%p: doAction(%s)\n", instance, name);
|
||||
}
|
@ -23,12 +23,16 @@ struct wbcffi_config_entry {
|
||||
/// 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 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 struct wbcffi_config_entry* config_entries,
|
||||
void* wbcffi_init(GtkContainer* root_widget, const void (*trigger_update)(void*),
|
||||
void* trigger_update_arg, const struct 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
|
||||
@ -38,8 +42,15 @@ void* wbcffi_init(GtkContainer* root_widget, const struct wbcffi_config_entry* c
|
||||
/// @param instance Module instance data (as returned by `wbcffi_init`)
|
||||
void wbcffi_deinit(void* instance);
|
||||
|
||||
/// When Waybar receives a POSIX signal, it forwards the signal to each module, calling this
|
||||
/// function
|
||||
/// Called from the GTK main event loop, to update the UI
|
||||
///
|
||||
/// Optional CFFI function
|
||||
///
|
||||
/// @param instance Module instance data (as returned by `wbcffi_init`)
|
||||
/// @param action_name Action name
|
||||
void wbcffi_update(void* instance);
|
||||
|
||||
/// Called when Waybar receives a POSIX signal and forwards it to each module
|
||||
///
|
||||
/// Optional CFFI function
|
||||
///
|
||||
@ -47,12 +58,14 @@ void wbcffi_deinit(void* instance);
|
||||
/// @param signal Signal ID
|
||||
void wbcffi_refresh(void* instance, int signal);
|
||||
|
||||
/// Called on module action (see
|
||||
/// https://github.com/Alexays/Waybar/wiki/Configuration#module-actions-config)
|
||||
///
|
||||
/// Optional CFFI function
|
||||
///
|
||||
/// @param instance Module instance data (as returned by `wbcffi_init`)
|
||||
/// @param name Action name
|
||||
void wbcffi_doaction(void* instance, const char* name);
|
||||
/// @param action_name Action name
|
||||
void wbcffi_doaction(void* instance, const char* action_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Reference in New Issue
Block a user