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,62 @@
#include "xdg_toplevel_listener.h"
#include "../window.h"
#include "../../application_context.h"
#include <wayland-egl.h>
#include <stdlib.h>
#include <stdio.h>
/******************************/
/********XDG Toplevel**********/
/******************************/
/* listener bound to the toplevel surface
the toplevel may raise a "configure" event, which hints the client about reconfiguring its state
here we propagate the new width and height to the EGL window ( probably for readjusting buffers )
*/
void toplevel_configure(
void *data,
struct xdg_toplevel *xdg_toplevel,
int32_t width,
int32_t height,
struct wl_array *states
) {
(void) states;
gui_component *comp = data;
if( ! comp){
fprintf(stderr, "inconsistency during toplevel configure : no payload\n");
exit(EXIT_FAILURE);
}
window_gui_enrichment *win = (window_gui_enrichment*) comp->specialization;
if( ! win || win->xdg_toplevel != xdg_toplevel){
fprintf(stderr, "inconsistency during toplevel configure\n");
fprintf(stderr, "window->xdg_toplevel %p\nxdg_toplevel %p\n",
(void*) win->xdg_toplevel,
(void*) xdg_toplevel
);
exit(EXIT_FAILURE);
}
if(!width && !height) return;
if( comp->graphics->dimensions->w != width || comp->graphics->dimensions->h != height) {
comp->graphics->dimensions->w = width;
comp->graphics->dimensions->h = height;
wl_egl_window_resize(win->egl_window, width, height, 0, 0);
wl_surface_commit(comp->graphics->surface);
}
}
void toplevel_close( void *data, struct xdg_toplevel *xdg_toplevel) {
(void) xdg_toplevel;
application_context *app = data;
app->running = 0;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "../../../os/WAYLAND/xdg-shell.h"
/******************************/
/********XDG Toplevel**********/
/******************************/
/* listener bound to the toplevel surface
the toplevel may raise a "configure" event, which hints the client about reconfiguring its state
here we propagate the new width and height to the EGL window ( probably for readjusting buffers )
*/
void toplevel_configure(
void *data,
struct xdg_toplevel *xdg_toplevel,
int32_t width,
int32_t height,
struct wl_array *states
);
void toplevel_close( void *data, struct xdg_toplevel *xdg_toplevel);

View File

@@ -0,0 +1,80 @@
#include "window.h"
#include "listeners/xdg_toplevel_listener.h"
#include "../../os/WAYLAND/xdg-shell.h"
#include <wayland-egl.h>
#include <GLES2/gl2.h>
#include <stdlib.h>
#include <stdio.h>
const struct xdg_toplevel_listener toplevel_listener = {
toplevel_configure,
toplevel_close
};
/******************************/
/************APIs**************/
/******************************/
window_gui_enrichment *window_gui_enrichment_new(
struct xdg_surface *xdg_surface,
const char *title,
application_context *ctx
){
window_gui_enrichment *win;
win->egl_window = NULL;
win->egl_surface = NULL;
win->ctx = ctx;
win->xdg_toplevel = xdg_surface_get_toplevel( xdg_surface);
xdg_toplevel_set_title( win->xdg_toplevel, title);
xdg_toplevel_add_listener( win->xdg_toplevel, &toplevel_listener, win);
return win;
}
void swapBuffers( application_context *app){
window_gui_enrichment *win = (window_gui_enrichment*) app->win->specialization;
wl_display_dispatch_pending(app->w_context->display);
eglSwapBuffers( app->e_context->display, win->egl_surface);
}
void draw_callback( gui_component* toDraw, int deltaTime){
glClearColor(1, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* should iterate on all the children */
window_gui_enrichment *win = toDraw->specialization;
swapBuffers( win->ctx);
}
gui_component* window_new(
const char *title,
ui_dimensions *dim,
application_context *app
){
void (*resize_callback) ( gui_component*, resize_event*) = 0;
void (*input_callback) ( gui_component*, resize_event*) = 0;
fprintf(stderr, "WINDOW NEW\n");
gui_component *c = gui_component_new_begin( NULL, ui_position_new(0, 0), dim, draw_callback, resize_callback, input_callback, app->w_context->builders );
fprintf(stderr, "WINDOW DID GUI_COMP_NEW\n");
window_gui_enrichment *spec = window_gui_enrichment_new( c->graphics->xdg_surface, title, app);
c->specialization = (void*) spec;
fprintf(stderr, "WINDOW DID ENRICHMENT NEW\n");
gui_component_new_end( c);
return c;
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include "../gui_component/gui_component.h"
#include "../application_context.h"
#include <EGL/egl.h>
#include "../../os/WAYLAND/wl_context.h"
#include "../../2d_structs.h"
#include "../../os/WAYLAND/xdg-shell.h"
typedef struct {
struct xdg_toplevel *xdg_toplevel;
struct wl_egl_window *egl_window;
EGLSurface *egl_surface;
application_context *ctx;
}
window_gui_enrichment;
window_gui_enrichment *window_gui_enrichment_new(
struct xdg_surface *xdg_surface,
const char *title,
application_context *ctx
);
/* the toplevel listener registration callback offers a void* arg for passing data inside the callback (our app state in this case, waiting for narrowing) */
gui_component* window_new(
const char *title,
ui_dimensions *dim,
application_context *ctx
);