project for a (works on my devices) demo

This commit is contained in:
beno
2026-03-13 02:28:59 +01:00
parent a00ae79ab5
commit dc39a56e91
36 changed files with 3892 additions and 61 deletions

View File

@@ -0,0 +1,87 @@
#include "gui_component.h"
#include "listeners/xdg_surface_listener.h"
#include <stdlib.h>
/*
listener to be bound on XDG surfaces
the only event declared by the xdg_surface is the "configure" one
indicates the hint for the client to update the arrangement of surfaces ( i.e. change of resolution )
*/
const struct xdg_surface_listener surface_listener = {
surface_configure
};
gui_component_graphics* gui_component_graphics_new(
ui_position *pos,
ui_dimensions *dim,
surface_builders *builders
){
gui_component_graphics *g = malloc( sizeof( gui_component_graphics));
g->dimensions = dim;
g->position = pos;
g->surface = wl_compositor_create_surface( builders->compositor);
g->xdg_surface = xdg_wm_base_get_xdg_surface( builders->xdg_wm_base, g->surface);
xdg_surface_add_listener( g->xdg_surface, &surface_listener, NULL);
return g;
}
gui_component* gui_component_new_begin(
gui_component *parent,
ui_position *pos,
ui_dimensions *dim,
void (*draw_callback) ( gui_component*, int),
void (*resize_callback) ( gui_component*, resize_event*),
void (*input_callback) ( gui_component*, resize_event*),
surface_builders *builders
){
gui_component* c = malloc( sizeof( gui_component));
c->specialization = NULL;
c->graphics = gui_component_graphics_new( pos, dim, builders);
c->draw_callback = draw_callback;
if( parent){
gui_component_add_child( parent, c);
}
c->children = gui_components_list_new();
return c;
}
void gui_component_new_end( gui_component* toComplete){
/*
must be called at the end of the configuration
*/
wl_surface_commit( toComplete->graphics->surface);
}
void gui_component_add_child( gui_component *parent, gui_component *child){
/* missing args */
if( ! parent || ! child){
}
/* components cannot be moved around at the moment, plug once and bye */
if( child->parent){
}
child->parent = parent;
gui_components_list_add( parent->children, child);
}
void child_draw( gui_component* child, void *extra){
int *casted = (int*) extra;
int deltaTime = *casted;
gui_component_draw( child, deltaTime);
}
void gui_component_draw( gui_component *c, int deltaTime){
c->draw_callback( c, deltaTime);
gui_components_list_foreach( c->children, child_draw, (void*) &deltaTime);
}

View File

@@ -0,0 +1,72 @@
#pragma once
#include "../../os/WAYLAND/wl_context.h"
#include "../../2d_structs.h"
#include "gui_components_list.h"
typedef struct {
int type;
} input_event;
typedef struct {
int w;
int h;
} resize_event;
typedef struct {
ui_dimensions *dimensions;
ui_position *position;
struct wl_surface *surface;
struct xdg_surface *xdg_surface;
}
gui_component_graphics;
typedef struct gui_component_raw {
void ( *draw_callback) ( struct gui_component_raw*, int);
void ( *resize_callback) ( struct gui_component_raw*, resize_event*);
void ( *input_callback) ( struct gui_component_raw*, resize_event*);
struct gui_component_raw *parent;
struct gui_components_list_raw *children;
gui_component_graphics *graphics;
void *specialization;
}
gui_component;
gui_component_graphics* gui_component_graphics_new(
ui_position *pos,
ui_dimensions *dim,
surface_builders *builders
);
/* called for initializing common configs */
gui_component* gui_component_new_begin(
gui_component *parent,
ui_position *pos,
ui_dimensions *dim,
void (*draw_callback) ( gui_component*, int),
void (*resize_callback) ( gui_component*, resize_event*),
void (*input_callback) ( gui_component*, resize_event*),
surface_builders *builders
);
/* must be called after specialized init for completing the configuration */
void gui_component_new_end( gui_component* toComplete);
void gui_component_add_child( gui_component *parent, gui_component *child);
void gui_component_draw( gui_component *c, int deltaTime);
void gui_component_input_event( gui_component *c, input_event *e);
void gui_component_resize_event( gui_component *c, resize_event *e);
/*
draw callback
input callback
resize callback
*/

View File

@@ -0,0 +1,28 @@
#include "gui_components_list.h"
#include <stdlib.h>
gui_components_list* gui_components_list_new(){
gui_components_list *l = malloc( sizeof( gui_components_list));
l->count = 0;
TAILQ_INIT(&( l->queue));
return l;
}
void gui_components_list_add( gui_components_list* list, gui_component *toAdd){
gui_components_list_entry *entry = malloc( sizeof( gui_components_list_entry));
entry->data = toAdd;
TAILQ_INSERT_TAIL( &(list->queue), entry, gui_components_list_entries);
list->count++;
}
void gui_components_list_foreach( gui_components_list* list, void ( *toRun) ( gui_component*, void*), void* extra){
gui_components_list_head *headp = &( list->queue);
gui_components_list_entry *current;
TAILQ_FOREACH( current, headp, gui_components_list_entries){
toRun( current->data, extra);
}
}

View File

@@ -0,0 +1,41 @@
#pragma once
#include "gui_component.h"
#include <sys/queue.h>
/*
typedef struct AAA_RAW {
void *data;
TAILQ_ENTRY(AAA_RAW) AAAs; // Singly linked List
} AAA;
typedef TAILQ_HEAD(BBB_RAW, AAA_RAW) BBB;
typedef struct {
BBB queue;
int count;
} CCC;
*/
typedef struct gui_components_list_entry_raw {
struct gui_component_raw *data;
TAILQ_ENTRY(gui_components_list_entry_raw) gui_components_list_entries; /* Singly linked List. */
} gui_components_list_entry;
typedef TAILQ_HEAD(gui_components_list_head_raw, gui_components_list_entry_raw) gui_components_list_head;
typedef struct gui_components_list_raw {
gui_components_list_head queue;
int count;
}
gui_components_list;
gui_components_list* gui_components_list_new();
void gui_components_list_add( gui_components_list *list, struct gui_component_raw *toAdd);
void gui_components_list_foreach( gui_components_list *list, void (*toRun) ( struct gui_component_raw*, void*), void *extra);

View File

@@ -0,0 +1,16 @@
#include "xdg_surface_listener.h"
/******************************/
/********XDG surface **********/
/******************************/
/* listener bound to the various xdg_surfaces for listening to "configure" events
the client should rearrange its surfaces to accomodate the new state
the client should answer to (ACK) the event
*/
void surface_configure(void *data, struct xdg_surface *xdg_surface,
uint32_t serial) {
(void) data;
xdg_surface_ack_configure(xdg_surface, serial);
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../../../os/WAYLAND/xdg-shell.h"
void surface_configure(
void *data,
struct xdg_surface *xdg_surface,
uint32_t serial
);