Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New UI device (aquabsd.black.ui) #31

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
aquabsd.alps/ui
src/aquabsd.alps/ui
*.sw[op]
devset
keysyms.xml
keysymdef.h
bin
aquabsd.black/wgpu/wgpu.h
aquabsd.black/wgpu/wgpu_types.h
*.core
compile_commands.json
.cache
26 changes: 13 additions & 13 deletions src/aquabsd.alps/font/public.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ typedef struct {
int x_res, y_res;
} aquabsd_alps_font_text_t;

aquabsd_alps_font_t* (*aquabsd_alps_font_load_font) (const char* path);
int (*aquabsd_alps_font_free_font) (aquabsd_alps_font_t* font);
static aquabsd_alps_font_t* (*aquabsd_alps_font_load_font) (const char* path);
static int (*aquabsd_alps_font_free_font) (aquabsd_alps_font_t* font);

aquabsd_alps_font_text_t* (*aquabsd_alps_font_create_text) (aquabsd_alps_font_t* font, const char* str);
int (*aquabsd_alps_font_free_text) (aquabsd_alps_font_text_t* text);
static aquabsd_alps_font_text_t* (*aquabsd_alps_font_create_text) (aquabsd_alps_font_t* font, const char* str);
static int (*aquabsd_alps_font_free_text) (aquabsd_alps_font_text_t* text);

int (*aquabsd_alps_font_text_colour) (aquabsd_alps_font_text_t* text, float r, float g, float b, float a);
int (*aquabsd_alps_font_text_size) (aquabsd_alps_font_text_t* text, uint64_t size);
int (*aquabsd_alps_font_text_wrap) (aquabsd_alps_font_text_t* text, uint64_t wrap_width, uint64_t wrap_height);
int (*aquabsd_alps_font_text_align) (aquabsd_alps_font_text_t* text, aquabsd_alps_font_align_t align);
int (*aquabsd_alps_font_text_markup) (aquabsd_alps_font_text_t* text, bool markup);
static int (*aquabsd_alps_font_text_colour) (aquabsd_alps_font_text_t* text, float r, float g, float b, float a);
static int (*aquabsd_alps_font_text_size) (aquabsd_alps_font_text_t* text, uint64_t size);
static int (*aquabsd_alps_font_text_wrap) (aquabsd_alps_font_text_t* text, uint64_t wrap_width, uint64_t wrap_height);
static int (*aquabsd_alps_font_text_align) (aquabsd_alps_font_text_t* text, aquabsd_alps_font_align_t align);
static int (*aquabsd_alps_font_text_markup) (aquabsd_alps_font_text_t* text, bool markup);

int (*aquabsd_alps_font_text_get_res) (aquabsd_alps_font_text_t* text, uint64_t* x_res_ref, uint64_t* y_res_ref);
int (*aquabsd_alps_font_text_pos_to_i) (aquabsd_alps_font_text_t* text, uint64_t x, uint64_t y);
int (*aquabsd_alps_font_text_i_to_pos) (aquabsd_alps_font_text_t* text, uint64_t i, uint64_t* x_ref, uint64_t* y_ref, uint64_t* width_ref, uint64_t* height_ref);
static int (*aquabsd_alps_font_text_get_res) (aquabsd_alps_font_text_t* text, uint64_t* x_res_ref, uint64_t* y_res_ref);
static int (*aquabsd_alps_font_text_pos_to_i) (aquabsd_alps_font_text_t* text, uint64_t x, uint64_t y);
static int (*aquabsd_alps_font_text_i_to_pos) (aquabsd_alps_font_text_t* text, uint64_t i, uint64_t* x_ref, uint64_t* y_ref, uint64_t* width_ref, uint64_t* height_ref);

int (*aquabsd_alps_font_draw_text) (aquabsd_alps_font_text_t* text, uint8_t** bmp_ref);
static int (*aquabsd_alps_font_draw_text) (aquabsd_alps_font_text_t* text, uint8_t** bmp_ref);

#endif
25 changes: 13 additions & 12 deletions src/aquabsd.alps/kbd/public.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !defined(__AQUABSD_ALPS_KBD)
#define __AQUABSD_ALPS_KBD
#pragma once

#include <stdbool.h>
#include <stddef.h>
Expand Down Expand Up @@ -32,18 +31,20 @@ struct aquabsd_alps_kbd_t {
#define AQUABSD_ALPS_KBD_AQUABSD_CONSOLE_KBD
#endif

unsigned (*aquabsd_alps_kbd_get_default_kbd_id) (void);
int (*aquabsd_alps_kbd_update_kbd) (unsigned kbd_id);
#define FP static __attribute__((unused))

unsigned (*aquabsd_alps_kbd_poll_button) (unsigned kbd_id, unsigned button);
FP unsigned (*aquabsd_alps_kbd_get_default_kbd_id) (void);
FP int (*aquabsd_alps_kbd_update_kbd) (unsigned kbd_id);

unsigned (*aquabsd_alps_kbd_get_buf_len) (unsigned kbd_id);
char* (*aquabsd_alps_kbd_get_buf) (unsigned kbd_id);
FP unsigned (*aquabsd_alps_kbd_poll_button) (unsigned kbd_id, unsigned button);

unsigned (*aquabsd_alps_kbd_get_keys_len) (unsigned kbd_id);
const char** (*aquabsd_alps_kbd_get_keys) (unsigned kbd_id);
FP unsigned (*aquabsd_alps_kbd_get_buf_len) (unsigned kbd_id);
FP char* (*aquabsd_alps_kbd_get_buf) (unsigned kbd_id);

aquabsd_alps_kbd_t* (*aquabsd_alps_kbd_register_kbd) (const char* name, aquabsd_alps_kbd_update_callback_t update_callback, void* update_cb_param, unsigned set_default);
const char* (*aquabsd_alps_kbd_x11_map) (int key);
FP unsigned (*aquabsd_alps_kbd_get_keys_len) (unsigned kbd_id);
FP char const** (*aquabsd_alps_kbd_get_keys) (unsigned kbd_id);

#endif
FP aquabsd_alps_kbd_t* (*aquabsd_alps_kbd_register_kbd) (char const* name, aquabsd_alps_kbd_update_callback_t update_callback, void* update_cb_param, unsigned set_default);
FP char const* (*aquabsd_alps_kbd_x11_map) (int key);

#undef FP
17 changes: 9 additions & 8 deletions src/aquabsd.alps/mouse/public.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !defined(__AQUABSD_ALPS_MOUSE)
#define __AQUABSD_ALPS_MOUSE
#pragma once

// definitions accessible to AQUA programs (through 'aqua-lib') and other devices

Expand Down Expand Up @@ -44,12 +43,14 @@ struct aquabsd_alps_mouse_t {
#define AQUABSD_ALPS_MOUSE_AQUABSD_CONSOLE_MOUSE
#endif

unsigned (*aquabsd_alps_mouse_get_default_mouse_id) (void);
int (*aquabsd_alps_mouse_update_mouse) (unsigned mouse_id);
#define FP static __attribute__((unused))

unsigned (*aquabsd_alps_mouse_poll_button) (unsigned mouse_id, aquabsd_alps_mouse_button_t button);
float (*aquabsd_alps_mouse_poll_axis) (unsigned mouse_id, aquabsd_alps_mouse_axis_t axis);
FP unsigned (*aquabsd_alps_mouse_get_default_mouse_id) (void);
FP int (*aquabsd_alps_mouse_update_mouse) (unsigned mouse_id);

aquabsd_alps_mouse_t* (*aquabsd_alps_mouse_register_mouse) (const char* name, aquabsd_alps_mouse_update_callback_t update_callback, void* update_cb_param, unsigned set_default);
FP unsigned (*aquabsd_alps_mouse_poll_button) (unsigned mouse_id, aquabsd_alps_mouse_button_t button);
FP float (*aquabsd_alps_mouse_poll_axis) (unsigned mouse_id, aquabsd_alps_mouse_axis_t axis);

#endif
FP aquabsd_alps_mouse_t* (*aquabsd_alps_mouse_register_mouse) (const char* name, aquabsd_alps_mouse_update_callback_t update_callback, void* update_cb_param, unsigned set_default);

#undef FP
81 changes: 5 additions & 76 deletions src/aquabsd.alps/win/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,99 +884,28 @@ dynamic win_t* create(unsigned x_res, unsigned y_res) {
return NULL;
}

// find a depth/visual we like
// if we can't find a 32-bit depth one, just use the root depth/visual
// thanks to http://metan.ucw.cz/blog/things-i-wanted-to-know-about-libxcb.html
// (although there is some irony in the whole "saner API for X programming" thing 😛)
// also thanks to i3bar source

LOG_VERBOSE("Look for a depth/visual we like")

xcb_visualtype_t* visual = NULL;
int depth = 0;

for (
xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(win->screen);
depth_iter.rem;
xcb_depth_next(&depth_iter)
) {
if (depth_iter.data->depth != 32) {
continue;
}

depth = depth_iter.data->depth;

for (
xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
visual_iter.rem;
xcb_visualtype_next(&visual_iter)
) {
visual = visual_iter.data;

if (
visual->_class != XCB_VISUAL_CLASS_TRUE_COLOR &&
visual->_class != XCB_VISUAL_CLASS_DIRECT_COLOR
) {
continue;
}

if (visual->bits_per_rgb_value != 8) {
continue;
}

goto found;
}
}

visual->visual_id = win->screen->root_visual;
depth = win->screen->root_depth;

found: {}

xcb_colormap_t const colourmap = xcb_generate_id(win->connection);
xcb_void_cookie_t cookie = xcb_create_colormap_checked(win->connection, XCB_COLORMAP_ALLOC_NONE, colourmap, win->root, visual->visual_id);

if (xcb_request_check(win->connection, cookie)) {
LOG_ERROR("Failed to create colourmap")
return NULL;
}

// create window

LOG_VERBOSE("Actually create X window")

win->x_res = x_res;
win->y_res = y_res;

uint32_t const mask =
XCB_CW_BACK_PIXEL |
XCB_CW_BORDER_PIXEL |
XCB_CW_EVENT_MASK |
XCB_CW_COLORMAP;

const uint32_t win_attribs[] = {
win->screen->black_pixel,
win->screen->black_pixel,
XCB_EVENT_MASK_EXPOSURE | // probably not all that important anymore
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION |
XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE,
colourmap,
};

win->win = xcb_generate_id(win->connection);

cookie = xcb_create_window_checked(
win->connection, depth, win->win, win->root,
30, 30, win->x_res, win->y_res, 0, // window geometry
XCB_WINDOW_CLASS_INPUT_OUTPUT, visual->visual_id,
mask, win_attribs);

if (xcb_request_check(win->connection, cookie)) {
LOG_ERROR("Failed to create window")
return NULL;
}
xcb_create_window(
win->connection, XCB_COPY_FROM_PARENT, win->win, win->root,
0, 0, win->x_res, win->y_res, 0, // window geometry
XCB_WINDOW_CLASS_INPUT_OUTPUT, win->screen->root_visual,
XCB_CW_EVENT_MASK, win_attribs);

// set sensible minimum and maximum sizes for the window

Expand Down
50 changes: 25 additions & 25 deletions src/aquabsd.alps/win/public.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !defined(__AQUABSD_ALPS_WIN)
#define __AQUABSD_ALPS_WIN
#pragma once

#include <aquabsd.alps/mouse/public.h>
#include <aquabsd.alps/kbd/public.h>
Expand Down Expand Up @@ -133,41 +132,42 @@ struct aquabsd_alps_win_t {

// functions exposed to devices & apps

aquabsd_alps_win_t* (*aquabsd_alps_win_create) (unsigned x_res, unsigned y_res);
int (*aquabsd_alps_win_delete) (aquabsd_alps_win_t* win);
#define FP static __attribute__((unused))

int (*aquabsd_alps_win_set_caption) (aquabsd_alps_win_t* win, char const* caption);
char* (*aquabsd_alps_win_get_caption) (aquabsd_alps_win_t* win);
FP aquabsd_alps_win_t* (*aquabsd_alps_win_create) (unsigned x_res, unsigned y_res);
FP int (*aquabsd_alps_win_delete) (aquabsd_alps_win_t* win);

aquabsd_alps_win_state_t (*aquabsd_alps_win_get_state) (aquabsd_alps_win_t* win);
FP int (*aquabsd_alps_win_set_caption) (aquabsd_alps_win_t* win, char const* caption);
FP char* (*aquabsd_alps_win_get_caption) (aquabsd_alps_win_t* win);

int (*aquabsd_alps_win_register_cb) (aquabsd_alps_win_t* win, aquabsd_alps_win_cb_t type, uint64_t cb, uint64_t param);
int (*aquabsd_alps_win_loop) (aquabsd_alps_win_t* win);
FP aquabsd_alps_win_state_t (*aquabsd_alps_win_get_state) (aquabsd_alps_win_t* win);

int (*aquabsd_alps_win_close_win) (aquabsd_alps_win_t* win);
int (*aquabsd_alps_win_grab_focus) (aquabsd_alps_win_t* win);
FP int (*aquabsd_alps_win_register_cb) (aquabsd_alps_win_t* win, aquabsd_alps_win_cb_t type, uint64_t cb, uint64_t param);
FP int (*aquabsd_alps_win_loop) (aquabsd_alps_win_t* win);

int (*aquabsd_alps_win_modify) (aquabsd_alps_win_t* win, float x, float y, unsigned x_res, unsigned y_res);
FP int (*aquabsd_alps_win_close_win) (aquabsd_alps_win_t* win);
FP int (*aquabsd_alps_win_grab_focus) (aquabsd_alps_win_t* win);

float (*aquabsd_alps_win_get_x_pos) (aquabsd_alps_win_t* win);
float (*aquabsd_alps_win_get_y_pos) (aquabsd_alps_win_t* win);
FP int (*aquabsd_alps_win_modify) (aquabsd_alps_win_t* win, float x, float y, unsigned x_res, unsigned y_res);

unsigned (*aquabsd_alps_win_get_x_res) (aquabsd_alps_win_t* win);
unsigned (*aquabsd_alps_win_get_y_res) (aquabsd_alps_win_t* win);
FP float (*aquabsd_alps_win_get_x_pos) (aquabsd_alps_win_t* win);
FP float (*aquabsd_alps_win_get_y_pos) (aquabsd_alps_win_t* win);

unsigned (*aquabsd_alps_win_get_wm_x_res) (aquabsd_alps_win_t* win);
unsigned (*aquabsd_alps_win_get_wm_y_res) (aquabsd_alps_win_t* win);
FP unsigned (*aquabsd_alps_win_get_x_res) (aquabsd_alps_win_t* win);
FP unsigned (*aquabsd_alps_win_get_y_res) (aquabsd_alps_win_t* win);

// AQUA DWD protocol stuff
FP unsigned (*aquabsd_alps_win_get_wm_x_res) (aquabsd_alps_win_t* win);
FP unsigned (*aquabsd_alps_win_get_wm_y_res) (aquabsd_alps_win_t* win);

unsigned (*aquabsd_alps_win_supports_dwd) (aquabsd_alps_win_t* win);
// AQUA DWD protocol stuff

int (*aquabsd_alps_win_set_dwd_close_pos) (aquabsd_alps_win_t* win, float x, float y);
FP unsigned (*aquabsd_alps_win_supports_dwd) (aquabsd_alps_win_t* win);
FP int (*aquabsd_alps_win_set_dwd_close_pos) (aquabsd_alps_win_t* win, float x, float y);

// functions exposed exclusively to devices

aquabsd_alps_win_t* (*aquabsd_alps_win_create_setup) (void);
int (*aquabsd_alps_win_register_dev_cb) (aquabsd_alps_win_t* win, aquabsd_alps_win_cb_t type, int (*cb) (aquabsd_alps_win_t* win, void* param, uint64_t cb, uint64_t cb_param), void* param);
xcb_window_t (*aquabsd_alps_win_get_draw_win) (aquabsd_alps_win_t* win);
FP aquabsd_alps_win_t* (*aquabsd_alps_win_create_setup) (void);
FP int (*aquabsd_alps_win_register_dev_cb) (aquabsd_alps_win_t* win, aquabsd_alps_win_cb_t type, int (*cb) (aquabsd_alps_win_t* win, void* param, uint64_t cb, uint64_t cb_param), void* param);
FP xcb_window_t (*aquabsd_alps_win_get_draw_win) (aquabsd_alps_win_t* win);

#endif
#undef FP
13 changes: 13 additions & 0 deletions src/aquabsd.black/ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# .ui

This device provides commands for AQUA apps to create user interfaces through a variety of different backends.
This implementation specifically provides the `wgpu` and `fb` backends.

## WebGPU backend (`wgpu`)

WebGPU context on an `aquabsd.alps.win` window.
Relies on the `wgpu-native` library (see `aquabsd.black.wgpu`'s README for more info), but doesn't rely on `.wgpu` (at runtime, at least).

## Framebuffer backend (`fb`)

To be done! 🚧
16 changes: 16 additions & 0 deletions src/aquabsd.black/ui/backends/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Form is subject to the terms of the AQUA Software License, v. 1.0.
// Copyright (c) 2023 Aymeric Wibo

void backend_dummy_destroy(void* internal) {
(void) internal;
}

int backend_dummy_prerender(void* internal) {
(void) internal;
return 0;
}

int backend_dummy_postrender(void* internal) {
(void) internal;
return 0;
}
8 changes: 8 additions & 0 deletions src/aquabsd.black/ui/backends/dummy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This Source Form is subject to the terms of the AQUA Software License, v. 1.0.
// Copyright (c) 2023 Aymeric Wibo

#pragma once

void backend_dummy_destroy(void* internal);
int backend_dummy_prerender(void* internal);
int backend_dummy_postrender(void* internal);
Loading