This commit is contained in:
Crom (Thibaut CHARLES)
2023-10-14 19:14:46 +02:00
parent a459d8a9b3
commit 6ae354f564
7 changed files with 144 additions and 0 deletions

39
cabi_example/main.c Normal file
View File

@ -0,0 +1,39 @@
#include <gtk/gtk.h>
#include <stdint.h>
typedef struct {
GtkContainer* root;
GtkBox* container;
GtkLabel* label;
GtkButton* button;
} Instance;
//
const size_t wbcabi_version = 1;
void onclicked() { printf("You clicked the button\n"); }
void* wbcabi_init(GtkContainer* root) {
// Allocate the instance object
Instance* inst = malloc(sizeof(Instance));
inst->root = root;
// 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));
// Add a label
inst->label = GTK_LABEL(gtk_label_new("This is a button:"));
gtk_container_add(GTK_CONTAINER(inst->container), GTK_WIDGET(inst->label));
// Add a button
inst->button = GTK_BUTTON(gtk_button_new_with_label("click me !"));
g_signal_connect(inst->button, "clicked", G_CALLBACK(onclicked), NULL);
gtk_container_add(GTK_CONTAINER(inst->container), GTK_WIDGET(inst->button));
// Return instance object
return inst;
}
void wbcabi_deinit(void* instance) { free(instance); }
char* wbcabi_last_error_str(void* instance) { return NULL; }

21
cabi_example/meson.build Normal file
View File

@ -0,0 +1,21 @@
project(
'waybar_cabi_c_example', 'c',
version: '0.1.0',
license: 'MIT',
)
compiler = meson.get_compiler('c')
shared_library('waybar_cabi_c_example',
[
'main.c',
],
dependencies: [
dependency('gtk+-3.0', version : ['>=3.22.0'])
]
# include_directories: include_directories(['../../../include']),
# dependencies: [],
# install: true,
# install_dir: 'plugins',
)