Initial AeroOS source

This commit is contained in:
Joe committed 2026-06-19 10:02:12 -04:00
commit b27732ad89
42 files changed
+3775

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
# aero-lofi — loops the subtle AeroOS lofi track on the PipeWire graph.
# Kept intentionally simple: loop a seamless WAV with pw-play (falls back to
# paplay / aplay). Volume is held low for a "subtle" background feel.
TRACK="${AERO_LOFI_TRACK:-/usr/share/aeros/lofi/aero-lofi.wav}"
VOL="${AERO_LOFI_VOLUME:-0.35}"
[ -r "$TRACK" ] || { echo "aero-lofi: no track at $TRACK" >&2; exit 1; }
player() {
if command -v pw-play >/dev/null 2>&1; then
pw-play --volume "$VOL" "$TRACK"
elif command -v paplay >/dev/null 2>&1; then
paplay "$TRACK"
elif command -v aplay >/dev/null 2>&1; then
aplay -q "$TRACK"
else
echo "aero-lofi: no audio player available" >&2
sleep 3600
fi
}
# Loop forever (the track itself is a seamless loop).
while :; do
player || sleep 2
done
+13
View File
@@ -0,0 +1,13 @@
[Unit]
Description=AeroOS subtle lofi on the home screen
After=pipewire.service wireplumber.service
Wants=pipewire.service
[Service]
Type=simple
ExecStart=/usr/bin/aero-lofi
Restart=on-failure
RestartSec=2
[Install]
WantedBy=default.target
+31
View File
@@ -0,0 +1,31 @@
#!/bin/sh
# aero-session — launches the AeroOS glassmorphism desktop.
# Sets up the runtime/audio environment, then execs the aerowm compositor.
# XDG runtime dir (systemd usually provides this; ensure it exists)
if [ -z "$XDG_RUNTIME_DIR" ]; then
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
mkdir -p "$XDG_RUNTIME_DIR"
chmod 700 "$XDG_RUNTIME_DIR"
fi
export XDG_SESSION_TYPE=wayland
export XDG_CURRENT_DESKTOP=AeroOS
export GTK_THEME=AeroGlass
export GDK_BACKEND=wayland
export QT_QPA_PLATFORM=wayland
export MOZ_ENABLE_WAYLAND=1
export AEROWM_WALLPAPER="/usr/share/backgrounds/aeros/frutiger-aero.png"
# Start the user audio graph (PipeWire) for lofi playback.
if command -v pipewire >/dev/null 2>&1; then
systemctl --user start pipewire pipewire-pulse wireplumber 2>/dev/null || {
pipewire &
sleep 0.3
pipewire-pulse 2>/dev/null &
wireplumber 2>/dev/null &
}
fi
# Hand off to the compositor (it autostarts aero-lofi itself).
exec aerowm
+6
View File
@@ -0,0 +1,6 @@
[Desktop Entry]
Name=AeroOS (aerowm)
Comment=Frutiger Aero glassmorphism desktop
Exec=/usr/bin/aero-session
Type=Application
DesktopNames=AeroOS
+47
View File
@@ -0,0 +1,47 @@
project('aerowm', 'c',
version: '1.0.0',
license: 'MIT',
default_options: ['c_std=c11', 'warning_level=2', 'werror=false'])
add_project_arguments(
['-DWLR_USE_UNSTABLE',
'-Wno-unused-parameter'],
language: 'c')
cc = meson.get_compiler('c')
wlroots = dependency('wlroots-0.18', required: false)
if not wlroots.found()
wlroots = dependency('wlroots', version: '>=0.18.0')
endif
wayland_server = dependency('wayland-server')
xkbcommon = dependency('xkbcommon')
pixman = dependency('pixman-1')
cairo = dependency('cairo')
pango = dependency('pango')
pangocairo = dependency('pangocairo')
glesv2 = dependency('glesv2', required: false)
math = cc.find_library('m', required: false)
# Generate the xdg-shell protocol header from wayland-protocols.
wl_protocol_dir = dependency('wayland-protocols').get_variable('pkgdatadir')
wl_scanner = find_program('wayland-scanner')
xdg_shell_h = custom_target('xdg-shell-protocol.h',
input: wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',
output: 'xdg-shell-protocol.h',
command: [wl_scanner, 'server-header', '@INPUT@', '@OUTPUT@'])
aerowm_deps = [wlroots, wayland_server, xkbcommon, pixman,
cairo, pango, pangocairo, math]
if glesv2.found()
aerowm_deps += glesv2
endif
executable('aerowm',
['src/main.c', 'src/blur.c', 'src/panel.c', 'src/image.c', xdg_shell_h],
dependencies: aerowm_deps,
install: true)
install_data('data/aerowm.desktop',
install_dir: get_option('datadir') / 'wayland-sessions')
+76
View File
@@ -0,0 +1,76 @@
/* aerowm — separable box blur (Gaussian approximation) for ARGB32 buffers. */
#include "blur.h"
#include <stdlib.h>
#include <string.h>
static inline uint8_t clamp8(int v) { return v < 0 ? 0 : (v > 255 ? 255 : v); }
/* One horizontal box blur pass using a sliding window (O(n) per row). */
static void box_blur_h(const uint32_t *src, uint32_t *dst,
int w, int h, int stride, int radius) {
const int diam = radius * 2 + 1;
for (int y = 0; y < h; y++) {
const uint32_t *srow = src + (size_t)y * stride;
uint32_t *drow = dst + (size_t)y * stride;
int a = 0, r = 0, g = 0, b = 0;
/* prime the window with the leftmost pixel repeated for x<0 */
for (int i = -radius; i <= radius; i++) {
int xi = i < 0 ? 0 : (i >= w ? w - 1 : i);
uint32_t p = srow[xi];
a += (p >> 24) & 0xff; r += (p >> 16) & 0xff;
g += (p >> 8) & 0xff; b += p & 0xff;
}
for (int x = 0; x < w; x++) {
drow[x] = ((uint32_t)(a / diam) << 24) |
((uint32_t)(r / diam) << 16) |
((uint32_t)(g / diam) << 8) |
(uint32_t)(b / diam);
int x_out = x - radius;
int x_in = x + radius + 1;
x_out = x_out < 0 ? 0 : (x_out >= w ? w - 1 : x_out);
x_in = x_in < 0 ? 0 : (x_in >= w ? w - 1 : x_in);
uint32_t po = srow[x_out], pi = srow[x_in];
a += ((pi >> 24) & 0xff) - ((po >> 24) & 0xff);
r += ((pi >> 16) & 0xff) - ((po >> 16) & 0xff);
g += ((pi >> 8) & 0xff) - ((po >> 8) & 0xff);
b += ( pi & 0xff) - ( po & 0xff);
}
}
}
/* Transpose so the same horizontal pass blurs columns; keeps cache friendly. */
static void transpose(const uint32_t *src, uint32_t *dst, int w, int h, int stride) {
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
dst[(size_t)x * h + y] = src[(size_t)y * stride + x];
}
void aero_blur_argb32(uint32_t *data, int width, int height, int stride_px,
int radius, int passes) {
if (radius < 1 || width < 2 || height < 2) return;
uint32_t *tmp = malloc((size_t)width * height * sizeof(uint32_t));
uint32_t *tA = malloc((size_t)width * height * sizeof(uint32_t));
uint32_t *tB = malloc((size_t)width * height * sizeof(uint32_t));
if (!tmp || !tA || !tB) { free(tmp); free(tA); free(tB); return; }
for (int p = 0; p < passes; p++) {
/* horizontal */
box_blur_h(data, tmp, width, height, stride_px, radius);
/* vertical via transpose -> horizontal -> transpose back */
transpose(tmp, tA, width, height, stride_px);
box_blur_h(tA, tB, height, width, height, radius);
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
data[(size_t)y * stride_px + x] = tB[(size_t)x * height + y];
}
free(tmp); free(tA); free(tB);
}
uint32_t *aero_blur_copy(const uint32_t *src, int width, int height,
int stride_px, int radius, int passes) {
uint32_t *out = malloc((size_t)stride_px * height * sizeof(uint32_t));
if (!out) return NULL;
memcpy(out, src, (size_t)stride_px * height * sizeof(uint32_t));
aero_blur_argb32(out, width, height, stride_px, radius, passes);
return out;
}
+25
View File
@@ -0,0 +1,25 @@
/* aerowm — glassmorphism helpers: box/Gaussian blur over ARGB32 buffers.
*
* Used to pre-blur the wallpaper once at startup so that frosted-glass panels
* and window backdrops can show a real, performant blurred image through their
* translucent surfaces (the classic "Frutiger Aero" frosted look) without
* paying for a full-scene blur every frame.
*/
#ifndef AEROWM_BLUR_H
#define AEROWM_BLUR_H
#include <stdint.h>
#include <stddef.h>
/* In-place separable box blur approximating a Gaussian.
* data: premultiplied or straight ARGB32 (0xAARRGGBB) row-major.
* Runs `passes` box blurs of the given radius (3 passes ≈ Gaussian).
*/
void aero_blur_argb32(uint32_t *data, int width, int height, int stride_px,
int radius, int passes);
/* Allocate a blurred copy of src (caller frees with free()). */
uint32_t *aero_blur_copy(const uint32_t *src, int width, int height,
int stride_px, int radius, int passes);
#endif
+66
View File
@@ -0,0 +1,66 @@
/* aerowm — image loading + cover-scaling using cairo. */
#include "image.h"
#include <cairo/cairo.h>
#include <stdlib.h>
#include <string.h>
int aero_image_load_png(const char *path, struct aero_image *out) {
cairo_surface_t *s = cairo_image_surface_create_from_png(path);
if (cairo_surface_status(s) != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy(s);
return -1;
}
cairo_surface_flush(s);
int w = cairo_image_surface_get_width(s);
int h = cairo_image_surface_get_height(s);
int stride_bytes = cairo_image_surface_get_stride(s);
int stride_px = stride_bytes / 4;
uint32_t *src = (uint32_t *)cairo_image_surface_get_data(s);
out->width = w; out->height = h; out->stride = stride_px;
out->data = malloc((size_t)stride_px * h * sizeof(uint32_t));
if (!out->data) { cairo_surface_destroy(s); return -1; }
memcpy(out->data, src, (size_t)stride_px * h * sizeof(uint32_t));
cairo_surface_destroy(s);
return 0;
}
int aero_image_cover(const struct aero_image *src, int dw, int dh,
struct aero_image *out) {
cairo_surface_t *dst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dw, dh);
if (cairo_surface_status(dst) != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy(dst); return -1;
}
cairo_surface_t *ss = cairo_image_surface_create_for_data(
(unsigned char *)src->data, CAIRO_FORMAT_ARGB32,
src->width, src->height, src->stride * 4);
double sx = (double)dw / src->width;
double sy = (double)dh / src->height;
double scale = sx > sy ? sx : sy; /* cover */
double ox = (dw - src->width * scale) / 2.0;
double oy = (dh - src->height * scale) / 2.0;
cairo_t *cr = cairo_create(dst);
cairo_translate(cr, ox, oy);
cairo_scale(cr, scale, scale);
cairo_set_source_surface(cr, ss, 0, 0);
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);
cairo_paint(cr);
cairo_destroy(cr);
cairo_surface_flush(dst);
int stride_px = cairo_image_surface_get_stride(dst) / 4;
out->width = dw; out->height = dh; out->stride = stride_px;
out->data = malloc((size_t)stride_px * dh * sizeof(uint32_t));
if (out->data)
memcpy(out->data, cairo_image_surface_get_data(dst),
(size_t)stride_px * dh * sizeof(uint32_t));
cairo_surface_destroy(ss);
cairo_surface_destroy(dst);
return out->data ? 0 : -1;
}
void aero_image_free(struct aero_image *img) {
if (img && img->data) { free(img->data); img->data = NULL; }
}
+21
View File
@@ -0,0 +1,21 @@
/* aerowm — image loading (PNG via cairo) into a pixman/ARGB buffer. */
#ifndef AEROWM_IMAGE_H
#define AEROWM_IMAGE_H
#include <stdint.h>
struct aero_image {
int width, height, stride; /* stride in pixels */
uint32_t *data; /* ARGB32, owned */
};
/* Load a PNG. Returns 0 on success. */
int aero_image_load_png(const char *path, struct aero_image *out);
/* Scale-fill (cover) src into a new image of (dw x dh). Returns 0 on success. */
int aero_image_cover(const struct aero_image *src, int dw, int dh,
struct aero_image *out);
void aero_image_free(struct aero_image *img);
#endif
+584
View File
@@ -0,0 +1,584 @@
/* aerowm — a small wlroots-based Wayland compositor for AeroOS.
*
* Adds, on top of a tinywl-style xdg-shell compositor:
* - a full-screen Frutiger Aero wallpaper (cover-scaled)
* - a pre-blurred copy of the wallpaper used as a frosted backdrop
* - a glassmorphism home UI (top bar + welcome card + dock) drawn with cairo
* - a live clock that re-renders the glass UI each minute
* - autostart of the lofi player + user session
*
* Targets wlroots 0.18. Build with meson (see ../meson.build).
*/
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/interfaces/wlr_buffer.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
#include "image.h"
#include "blur.h"
#include "panel.h"
/* ----------------------------------------------------------------- aero_buffer
* Minimal wlr_buffer backed by a malloc'd ARGB8888 image, so cairo-rendered
* UI and the wallpaper can be placed directly into the wlroots scene graph.
*/
struct aero_buffer {
struct wlr_buffer base;
uint32_t *data; /* ARGB8888, owned */
size_t stride; /* bytes */
};
static void aero_buffer_destroy(struct wlr_buffer *b) {
struct aero_buffer *buf = wl_container_of(b, buf, base);
free(buf->data);
free(buf);
}
static bool aero_buffer_begin_ptr(struct wlr_buffer *b, uint32_t flags,
void **data, uint32_t *format, size_t *stride) {
struct aero_buffer *buf = wl_container_of(b, buf, base);
if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) return false;
*data = buf->data; *stride = buf->stride;
*format = 0x34325241; /* DRM_FORMAT_ARGB8888 */
return true;
}
static void aero_buffer_end_ptr(struct wlr_buffer *b) { (void)b; }
static const struct wlr_buffer_impl aero_buffer_impl = {
.destroy = aero_buffer_destroy,
.begin_data_ptr_access = aero_buffer_begin_ptr,
.end_data_ptr_access = aero_buffer_end_ptr,
};
/* Wrap an aero_image (consumes its data) into a wlr_buffer. */
static struct aero_buffer *aero_buffer_from_image(struct aero_image *img) {
struct aero_buffer *buf = calloc(1, sizeof(*buf));
if (!buf) return NULL;
wlr_buffer_init(&buf->base, &aero_buffer_impl, img->width, img->height);
buf->data = img->data; /* take ownership */
buf->stride = (size_t)img->stride * 4;
img->data = NULL;
return buf;
}
/* ----------------------------------------------------------------- server */
enum cursor_mode { CURSOR_PASSTHROUGH, CURSOR_MOVE, CURSOR_RESIZE };
struct aero_server {
struct wl_display *wl_display;
struct wlr_backend *backend;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_scene *scene;
struct wlr_scene_output_layout *scene_layout;
struct wlr_xdg_shell *xdg_shell;
struct wl_listener new_xdg_toplevel;
struct wl_list toplevels;
struct wlr_cursor *cursor;
struct wlr_xcursor_manager *cursor_mgr;
struct wl_listener cursor_motion, cursor_motion_absolute;
struct wl_listener cursor_button, cursor_axis, cursor_frame;
enum cursor_mode cursor_mode;
struct wlr_seat *seat;
struct wl_listener new_input, request_cursor, request_set_selection;
struct wl_list keyboards;
struct wlr_output_layout *output_layout;
struct wl_list outputs;
struct wl_listener new_output;
/* glassmorphism layers */
struct wlr_scene_tree *layer_bg; /* sharp wallpaper */
struct wlr_scene_tree *layer_apps; /* client windows */
struct wlr_scene_tree *layer_ui; /* glass home UI */
struct aero_image wallpaper; /* loaded source */
struct aero_image blurred_full; /* per-output blurred backdrop */
struct wlr_scene_buffer *ui_node;
int ui_w, ui_h;
struct wl_event_source *clock_timer;
};
struct aero_output {
struct wl_list link;
struct aero_server *server;
struct wlr_output *wlr_output;
struct wl_listener frame, destroy;
};
struct aero_toplevel {
struct wl_list link;
struct aero_server *server;
struct wlr_xdg_toplevel *xdg_toplevel;
struct wlr_scene_tree *scene_tree;
struct wl_listener map, unmap, commit, destroy;
struct wl_listener request_move, request_resize;
};
struct aero_keyboard {
struct wl_list link;
struct aero_server *server;
struct wlr_keyboard *wlr_keyboard;
struct wl_listener modifiers, key, destroy;
};
/* ----------------------------------------------------------------- helpers */
static void spawn(const char *cmd) {
if (fork() == 0) {
setsid();
execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
_exit(127);
}
}
static void focus_toplevel(struct aero_toplevel *toplevel) {
if (!toplevel) return;
struct aero_server *server = toplevel->server;
struct wlr_seat *seat = server->seat;
struct wlr_surface *surface = toplevel->xdg_toplevel->base->surface;
struct wlr_surface *prev = seat->keyboard_state.focused_surface;
if (prev == surface) return;
if (prev) {
struct wlr_xdg_toplevel *pt = wlr_xdg_toplevel_try_from_wlr_surface(prev);
if (pt) wlr_xdg_toplevel_set_activated(pt, false);
}
struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat);
wlr_scene_node_raise_to_top(&toplevel->scene_tree->node);
wl_list_remove(&toplevel->link);
wl_list_insert(&server->toplevels, &toplevel->link);
wlr_xdg_toplevel_set_activated(toplevel->xdg_toplevel, true);
if (kb)
wlr_seat_keyboard_notify_enter(seat, surface, kb->keycodes,
kb->num_keycodes, &kb->modifiers);
}
/* -------------------------------------------------- glass UI build/refresh */
static void refresh_clock(struct aero_server *s);
static void build_ui_for_output(struct aero_server *s, int W, int H) {
/* (Re)build the blurred backdrop + glass UI sized to the output. */
if (s->blurred_full.data) aero_image_free(&s->blurred_full);
struct aero_image cover;
if (aero_image_cover(&s->wallpaper, W, H, &cover) != 0) return;
/* background: sharp wallpaper */
struct aero_buffer *bgbuf = aero_buffer_from_image(&cover); /* consumes cover */
if (bgbuf) {
struct wlr_scene_buffer *bg =
wlr_scene_buffer_create(s->layer_bg, &bgbuf->base);
wlr_scene_node_set_position(&bg->node, 0, 0);
wlr_buffer_drop(&bgbuf->base);
}
/* frosted backdrop: blurred cover (re-make cover since consumed) */
struct aero_image cover2;
if (aero_image_cover(&s->wallpaper, W, H, &cover2) == 0) {
s->blurred_full.width = cover2.width;
s->blurred_full.height = cover2.height;
s->blurred_full.stride = cover2.stride;
s->blurred_full.data = aero_blur_copy(cover2.data, cover2.width,
cover2.height, cover2.stride, 14, 3);
aero_image_free(&cover2);
}
s->ui_w = W; s->ui_h = H;
refresh_clock(s);
}
static int clock_tick(void *data) {
struct aero_server *s = data;
refresh_clock(s);
/* re-arm the same timer (every 30s) instead of leaking a new source */
if (s->clock_timer)
wl_event_source_timer_update(s->clock_timer, 30000);
return 0;
}
static void refresh_clock(struct aero_server *s) {
if (!s->blurred_full.data || s->ui_w == 0) return;
char ct[64], dt[64];
time_t t = time(NULL);
struct tm tmv; localtime_r(&t, &tmv);
strftime(ct, sizeof ct, "<b>%H:%M</b>", &tmv);
strftime(dt, sizeof dt, "%A, %d %B %Y", &tmv);
struct aero_image ui;
if (aero_panel_render(&s->blurred_full, s->ui_w, s->ui_h, ct, dt, &ui) != 0)
return;
struct aero_buffer *uibuf = aero_buffer_from_image(&ui); /* consumes ui */
if (!uibuf) return;
if (s->ui_node) {
wlr_scene_buffer_set_buffer(s->ui_node, &uibuf->base);
} else {
s->ui_node = wlr_scene_buffer_create(s->layer_ui, &uibuf->base);
wlr_scene_node_set_position(&s->ui_node->node, 0, 0);
}
wlr_buffer_drop(&uibuf->base);
}
/* ----------------------------------------------------------------- output */
static void output_frame(struct wl_listener *listener, void *data) {
struct aero_output *output = wl_container_of(listener, output, frame);
struct wlr_scene *scene = output->server->scene;
struct wlr_scene_output *so =
wlr_scene_get_scene_output(scene, output->wlr_output);
wlr_scene_output_commit(so, NULL);
struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now);
wlr_scene_output_send_frame_done(so, &now);
}
static void output_destroy(struct wl_listener *listener, void *data) {
struct aero_output *output = wl_container_of(listener, output, destroy);
wl_list_remove(&output->frame.link);
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->link);
free(output);
}
static void server_new_output(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, new_output);
struct wlr_output *wlr_output = data;
wlr_output_init_render(wlr_output, server->allocator, server->renderer);
struct wlr_output_state state;
wlr_output_state_init(&state);
wlr_output_state_set_enabled(&state, true);
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
if (mode) wlr_output_state_set_mode(&state, mode);
wlr_output_commit_state(wlr_output, &state);
wlr_output_state_finish(&state);
struct aero_output *output = calloc(1, sizeof(*output));
output->wlr_output = wlr_output;
output->server = server;
output->frame.notify = output_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
output->destroy.notify = output_destroy;
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
wl_list_insert(&server->outputs, &output->link);
struct wlr_output_layout_output *lo =
wlr_output_layout_add_auto(server->output_layout, wlr_output);
struct wlr_scene_output *scene_output =
wlr_scene_output_create(server->scene, wlr_output);
wlr_scene_output_layout_add_output(server->scene_layout, lo, scene_output);
/* Build the Aero home UI sized to this output. */
int W = wlr_output->width, H = wlr_output->height;
if (W > 0 && H > 0) build_ui_for_output(server, W, H);
}
/* ----------------------------------------------------------------- xdg shell */
static void xdg_toplevel_map(struct wl_listener *listener, void *data) {
struct aero_toplevel *t = wl_container_of(listener, t, map);
wl_list_insert(&t->server->toplevels, &t->link);
focus_toplevel(t);
}
static void xdg_toplevel_unmap(struct wl_listener *listener, void *data) {
struct aero_toplevel *t = wl_container_of(listener, t, unmap);
wl_list_remove(&t->link);
}
static void xdg_toplevel_commit(struct wl_listener *listener, void *data) {
struct aero_toplevel *t = wl_container_of(listener, t, commit);
if (t->xdg_toplevel->base->initial_commit)
wlr_xdg_toplevel_set_size(t->xdg_toplevel, 0, 0);
}
static void xdg_toplevel_destroy(struct wl_listener *listener, void *data) {
struct aero_toplevel *t = wl_container_of(listener, t, destroy);
wl_list_remove(&t->map.link);
wl_list_remove(&t->unmap.link);
wl_list_remove(&t->commit.link);
wl_list_remove(&t->destroy.link);
free(t);
}
static void server_new_xdg_toplevel(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, new_xdg_toplevel);
struct wlr_xdg_toplevel *xdg_toplevel = data;
struct aero_toplevel *t = calloc(1, sizeof(*t));
t->server = server;
t->xdg_toplevel = xdg_toplevel;
/* client windows live in the apps layer (above wallpaper, below glass UI) */
t->scene_tree = wlr_scene_xdg_surface_create(server->layer_apps,
xdg_toplevel->base);
t->scene_tree->node.data = t;
xdg_toplevel->base->data = t->scene_tree;
t->map.notify = xdg_toplevel_map; wl_signal_add(&xdg_toplevel->base->surface->events.map, &t->map);
t->unmap.notify = xdg_toplevel_unmap; wl_signal_add(&xdg_toplevel->base->surface->events.unmap, &t->unmap);
t->commit.notify = xdg_toplevel_commit; wl_signal_add(&xdg_toplevel->base->surface->events.commit, &t->commit);
t->destroy.notify = xdg_toplevel_destroy; wl_signal_add(&xdg_toplevel->events.destroy, &t->destroy);
}
/* ----------------------------------------------------------------- input */
static void keyboard_handle_modifiers(struct wl_listener *listener, void *data) {
struct aero_keyboard *kb = wl_container_of(listener, kb, modifiers);
wlr_seat_set_keyboard(kb->server->seat, kb->wlr_keyboard);
wlr_seat_keyboard_notify_modifiers(kb->server->seat,
&kb->wlr_keyboard->modifiers);
}
static bool handle_keybinding(struct aero_server *server, xkb_keysym_t sym) {
switch (sym) {
case XKB_KEY_Escape: /* Super+Esc quits compositor */
wl_display_terminate(server->wl_display);
return true;
case XKB_KEY_Return: /* Super+Return: terminal */
spawn("foot || alacritty || xterm");
return true;
case XKB_KEY_d: /* Super+d: launcher */
spawn("wofi --show drun || fuzzel || bemenu-run");
return true;
case XKB_KEY_m: /* Super+m: toggle music */
spawn("systemctl --user is-active aero-lofi && systemctl --user stop aero-lofi || systemctl --user start aero-lofi");
return true;
case XKB_KEY_q: { /* Super+q: close focused window */
struct aero_toplevel *t;
if (!wl_list_empty(&server->toplevels)) {
t = wl_container_of(server->toplevels.next, t, link);
wlr_xdg_toplevel_send_close(t->xdg_toplevel);
}
return true;
}
default: return false;
}
}
static void keyboard_handle_key(struct wl_listener *listener, void *data) {
struct aero_keyboard *kb = wl_container_of(listener, kb, key);
struct aero_server *server = kb->server;
struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms;
int nsyms = xkb_state_key_get_syms(kb->wlr_keyboard->xkb_state, keycode, &syms);
bool handled = false;
uint32_t mods = wlr_keyboard_get_modifiers(kb->wlr_keyboard);
if ((mods & WLR_MODIFIER_LOGO) && event->state == WL_KEYBOARD_KEY_STATE_PRESSED)
for (int i = 0; i < nsyms; i++)
handled |= handle_keybinding(server, syms[i]);
if (!handled) {
wlr_seat_set_keyboard(server->seat, kb->wlr_keyboard);
wlr_seat_keyboard_notify_key(server->seat, event->time_msec,
event->keycode, event->state);
}
}
static void keyboard_handle_destroy(struct wl_listener *listener, void *data) {
struct aero_keyboard *kb = wl_container_of(listener, kb, destroy);
wl_list_remove(&kb->modifiers.link);
wl_list_remove(&kb->key.link);
wl_list_remove(&kb->destroy.link);
wl_list_remove(&kb->link);
free(kb);
}
static void server_new_keyboard(struct aero_server *server,
struct wlr_input_device *device) {
struct wlr_keyboard *wlr_keyboard = wlr_keyboard_from_input_device(device);
struct aero_keyboard *kb = calloc(1, sizeof(*kb));
kb->server = server; kb->wlr_keyboard = wlr_keyboard;
struct xkb_context *ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct xkb_keymap *keymap = xkb_keymap_new_from_names(ctx, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS);
wlr_keyboard_set_keymap(wlr_keyboard, keymap);
xkb_keymap_unref(keymap);
xkb_context_unref(ctx);
wlr_keyboard_set_repeat_info(wlr_keyboard, 25, 600);
kb->modifiers.notify = keyboard_handle_modifiers;
wl_signal_add(&wlr_keyboard->events.modifiers, &kb->modifiers);
kb->key.notify = keyboard_handle_key;
wl_signal_add(&wlr_keyboard->events.key, &kb->key);
kb->destroy.notify = keyboard_handle_destroy;
wl_signal_add(&device->events.destroy, &kb->destroy);
wlr_seat_set_keyboard(server->seat, wlr_keyboard);
wl_list_insert(&server->keyboards, &kb->link);
}
static void server_new_input(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, new_input);
struct wlr_input_device *device = data;
if (device->type == WLR_INPUT_DEVICE_KEYBOARD)
server_new_keyboard(server, device);
else if (device->type == WLR_INPUT_DEVICE_POINTER)
wlr_cursor_attach_input_device(server->cursor, device);
uint32_t caps = WL_SEAT_CAPABILITY_POINTER;
if (!wl_list_empty(&server->keyboards)) caps |= WL_SEAT_CAPABILITY_KEYBOARD;
wlr_seat_set_capabilities(server->seat, caps);
}
static void cursor_motion_abs(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, cursor_motion_absolute);
struct wlr_pointer_motion_absolute_event *e = data;
wlr_cursor_warp_absolute(server->cursor, &e->pointer->base, e->x, e->y);
wlr_seat_pointer_notify_frame(server->seat);
}
static void cursor_motion(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, cursor_motion);
struct wlr_pointer_motion_event *e = data;
wlr_cursor_move(server->cursor, &e->pointer->base, e->delta_x, e->delta_y);
wlr_seat_pointer_notify_frame(server->seat);
}
static void cursor_button(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, cursor_button);
struct wlr_pointer_button_event *e = data;
wlr_seat_pointer_notify_button(server->seat, e->time_msec, e->button, e->state);
}
static void cursor_axis(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, cursor_axis);
struct wlr_pointer_axis_event *e = data;
wlr_seat_pointer_notify_axis(server->seat, e->time_msec, e->orientation,
e->delta, e->delta_discrete, e->source, e->relative_direction);
}
static void cursor_frame(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, cursor_frame);
wlr_seat_pointer_notify_frame(server->seat);
}
static void seat_request_cursor(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, request_cursor);
struct wlr_seat_pointer_request_set_cursor_event *e = data;
if (e->seat_client == server->seat->pointer_state.focused_client)
wlr_cursor_set_surface(server->cursor, e->surface, e->hotspot_x, e->hotspot_y);
}
static void seat_request_selection(struct wl_listener *listener, void *data) {
struct aero_server *server = wl_container_of(listener, server, request_set_selection);
struct wlr_seat_request_set_selection_event *e = data;
wlr_seat_set_selection(server->seat, e->source, e->serial);
}
/* ----------------------------------------------------------------- main */
int main(int argc, char *argv[]) {
wlr_log_init(WLR_INFO, NULL);
const char *startup_cmd = NULL;
int c;
while ((c = getopt(argc, argv, "s:h")) != -1) {
if (c == 's') startup_cmd = optarg;
else { printf("usage: %s [-s startup-command]\n", argv[0]); return 0; }
}
struct aero_server server = {0};
server.wl_display = wl_display_create();
server.backend = wlr_backend_autocreate(
wl_display_get_event_loop(server.wl_display), NULL);
server.renderer = wlr_renderer_autocreate(server.backend);
wlr_renderer_init_wl_display(server.renderer, server.wl_display);
server.allocator = wlr_allocator_autocreate(server.backend, server.renderer);
wlr_compositor_create(server.wl_display, 5, server.renderer);
wlr_subcompositor_create(server.wl_display);
wlr_data_device_manager_create(server.wl_display);
server.output_layout = wlr_output_layout_create(server.wl_display);
wl_list_init(&server.outputs);
server.new_output.notify = server_new_output;
wl_signal_add(&server.backend->events.new_output, &server.new_output);
server.scene = wlr_scene_create();
server.scene_layout = wlr_scene_attach_output_layout(server.scene,
server.output_layout);
/* three stacked layers: wallpaper < apps < glass UI */
server.layer_bg = wlr_scene_tree_create(&server.scene->tree);
server.layer_apps = wlr_scene_tree_create(&server.scene->tree);
server.layer_ui = wlr_scene_tree_create(&server.scene->tree);
/* load the wallpaper */
const char *wp = getenv("AEROWM_WALLPAPER");
if (!wp) wp = "/usr/share/backgrounds/aeros/frutiger-aero.png";
if (aero_image_load_png(wp, &server.wallpaper) != 0)
wlr_log(WLR_ERROR, "could not load wallpaper %s", wp);
wl_list_init(&server.toplevels);
server.xdg_shell = wlr_xdg_shell_create(server.wl_display, 3);
server.new_xdg_toplevel.notify = server_new_xdg_toplevel;
wl_signal_add(&server.xdg_shell->events.new_toplevel, &server.new_xdg_toplevel);
server.cursor = wlr_cursor_create();
wlr_cursor_attach_output_layout(server.cursor, server.output_layout);
server.cursor_mgr = wlr_xcursor_manager_create(NULL, 24);
server.cursor_mode = CURSOR_PASSTHROUGH;
server.cursor_motion.notify = cursor_motion;
wl_signal_add(&server.cursor->events.motion, &server.cursor_motion);
server.cursor_motion_absolute.notify = cursor_motion_abs;
wl_signal_add(&server.cursor->events.motion_absolute, &server.cursor_motion_absolute);
server.cursor_button.notify = cursor_button;
wl_signal_add(&server.cursor->events.button, &server.cursor_button);
server.cursor_axis.notify = cursor_axis;
wl_signal_add(&server.cursor->events.axis, &server.cursor_axis);
server.cursor_frame.notify = cursor_frame;
wl_signal_add(&server.cursor->events.frame, &server.cursor_frame);
wl_list_init(&server.keyboards);
server.new_input.notify = server_new_input;
wl_signal_add(&server.backend->events.new_input, &server.new_input);
server.seat = wlr_seat_create(server.wl_display, "seat0");
server.request_cursor.notify = seat_request_cursor;
wl_signal_add(&server.seat->events.request_set_cursor, &server.request_cursor);
server.request_set_selection.notify = seat_request_selection;
wl_signal_add(&server.seat->events.request_set_selection, &server.request_set_selection);
const char *socket = wl_display_add_socket_auto(server.wl_display);
if (!socket) { wlr_backend_destroy(server.backend); return 1; }
if (!wlr_backend_start(server.backend)) {
wlr_backend_destroy(server.backend);
wl_display_destroy(server.wl_display);
return 1;
}
setenv("WAYLAND_DISPLAY", socket, true);
wlr_log(WLR_INFO, "AeroOS compositor running on WAYLAND_DISPLAY=%s", socket);
/* clock updater */
struct wl_event_source *timer =
wl_event_loop_add_timer(wl_display_get_event_loop(server.wl_display),
clock_tick, &server);
server.clock_timer = timer;
wl_event_source_timer_update(timer, 1000);
/* autostart: lofi + optional session command */
spawn("systemctl --user start aero-lofi.service 2>/dev/null || "
"aero-lofi &");
if (startup_cmd) spawn(startup_cmd);
wl_display_run(server.wl_display);
wl_display_destroy_clients(server.wl_display);
wlr_scene_node_destroy(&server.scene->tree.node);
wlr_allocator_destroy(server.allocator);
wlr_renderer_destroy(server.renderer);
wlr_backend_destroy(server.backend);
wl_display_destroy(server.wl_display);
aero_image_free(&server.wallpaper);
aero_image_free(&server.blurred_full);
return 0;
}
+139
View File
@@ -0,0 +1,139 @@
/* aerowm — glassmorphism home UI (top bar, welcome card, dock) via cairo/pango.
*
* Glassmorphism recipe used here:
* 1. clip to the rounded panel rectangle
* 2. paint the pre-blurred wallpaper inside it (the "frost")
* 3. lay a translucent white gradient over it (the "glass")
* 4. add a 1px top highlight + subtle outer border (the "edge light")
* 5. draw content (text/icons) on top
*/
#include "panel.h"
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static void rounded_rect(cairo_t *cr, double x, double y, double w, double h, double r) {
const double d = 3.14159265358979323846 / 180.0;
cairo_new_sub_path(cr);
cairo_arc(cr, x + w - r, y + r, r, -90 * d, 0 * d);
cairo_arc(cr, x + w - r, y + h - r, r, 0 * d, 90 * d);
cairo_arc(cr, x + r, y + h - r, r, 90 * d, 180 * d);
cairo_arc(cr, x + r, y + r, r, 180 * d, 270 * d);
cairo_close_path(cr);
}
/* Paint one frosted-glass tile at (x,y,w,h) using the blurred backdrop. */
static void glass_tile(cairo_t *cr, cairo_surface_t *blur_surf,
double x, double y, double w, double h, double radius,
double tint_top, double tint_bot) {
cairo_save(cr);
rounded_rect(cr, x, y, w, h, radius);
cairo_clip(cr);
/* 1+2: frosted backdrop (blurred wallpaper, aligned to screen space) */
cairo_set_source_surface(cr, blur_surf, 0, 0);
cairo_paint(cr);
/* 3: translucent white gradient = the glass body */
cairo_pattern_t *g = cairo_pattern_create_linear(x, y, x, y + h);
cairo_pattern_add_color_stop_rgba(g, 0.0, 1, 1, 1, tint_top);
cairo_pattern_add_color_stop_rgba(g, 1.0, 1, 1, 1, tint_bot);
cairo_set_source(cr, g);
cairo_paint(cr);
cairo_pattern_destroy(g);
/* a faint aero cyan sheen down the left to evoke Frutiger glass */
cairo_pattern_t *sheen = cairo_pattern_create_linear(x, y, x + w, y);
cairo_pattern_add_color_stop_rgba(sheen, 0.0, 0.55, 0.85, 1.0, 0.18);
cairo_pattern_add_color_stop_rgba(sheen, 0.4, 0.55, 0.85, 1.0, 0.0);
cairo_set_source(cr, sheen);
cairo_paint(cr);
cairo_pattern_destroy(sheen);
cairo_restore(cr);
/* 4: edge light — bright 1px inner top, soft outer border */
cairo_save(cr);
rounded_rect(cr, x + 0.5, y + 0.5, w - 1, h - 1, radius);
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgba(cr, 1, 1, 1, 0.55);
cairo_stroke(cr);
cairo_restore(cr);
}
static void draw_text(cairo_t *cr, const char *markup, const char *font,
double x, double y, double max_w, PangoAlignment align,
double r, double g, double b, double a) {
PangoLayout *layout = pango_cairo_create_layout(cr);
PangoFontDescription *desc = pango_font_description_from_string(font);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
pango_layout_set_markup(layout, markup, -1);
if (max_w > 0) { pango_layout_set_width(layout, (int)(max_w * PANGO_SCALE));
pango_layout_set_alignment(layout, align); }
cairo_move_to(cr, x, y);
cairo_set_source_rgba(cr, r, g, b, a);
pango_cairo_show_layout(cr, layout);
g_object_unref(layout);
}
int aero_panel_render(const struct aero_image *blurred, int W, int H,
const char *clock_text, const char *date_text,
struct aero_image *out) {
cairo_surface_t *dst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, W, H);
if (cairo_surface_status(dst) != CAIRO_STATUS_SUCCESS) return -1;
cairo_surface_t *blur_surf = cairo_image_surface_create_for_data(
(unsigned char *)blurred->data, CAIRO_FORMAT_ARGB32,
blurred->width, blurred->height, blurred->stride * 4);
cairo_t *cr = cairo_create(dst);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba(cr, 0, 0, 0, 0); /* fully transparent base */
cairo_paint(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
const double M = 16; /* screen margin */
const double barH = 40;
/* ---- top bar -------------------------------------------------------- */
glass_tile(cr, blur_surf, M, M, W - 2 * M, barH, 14, 0.42, 0.20);
draw_text(cr, "<b>✦ AeroOS</b>", "Sans 13", M + 18, M + 9, 0,
PANGO_ALIGN_LEFT, 1, 1, 1, 0.95);
if (clock_text)
draw_text(cr, clock_text, "Sans 13", W - 2 * M - 160, M + 9, 144,
PANGO_ALIGN_RIGHT, 1, 1, 1, 0.95);
/* ---- centered welcome card ----------------------------------------- */
double cw = 460, ch = 200;
double cx = (W - cw) / 2.0, cy = (H - ch) / 2.0 - 30;
glass_tile(cr, blur_surf, cx, cy, cw, ch, 22, 0.34, 0.16);
draw_text(cr, "<span size='28000' weight='bold'>Welcome to AeroOS</span>",
"Sans", cx, cy + 34, cw, PANGO_ALIGN_CENTER, 1, 1, 1, 0.97);
draw_text(cr, "<span size='12000'>Frutiger Aero • glassmorphism • lofi</span>",
"Sans", cx, cy + 84, cw, PANGO_ALIGN_CENTER, 0.92, 0.97, 1.0, 0.9);
if (date_text)
draw_text(cr, date_text, "Sans 11", cx, cy + 130, cw,
PANGO_ALIGN_CENTER, 1, 1, 1, 0.8);
draw_text(cr, "<span size='10000'>♪ lofi is playing — press Super+Return for a terminal</span>",
"Sans", cx, cy + 158, cw, PANGO_ALIGN_CENTER, 0.85, 0.95, 1.0, 0.85);
/* ---- bottom dock hint ---------------------------------------------- */
double dw = 360, dh = 56;
glass_tile(cr, blur_surf, (W - dw) / 2.0, H - dh - M, dw, dh, 18, 0.40, 0.18);
cairo_destroy(cr);
cairo_surface_flush(dst);
int stride_px = cairo_image_surface_get_stride(dst) / 4;
out->width = W; out->height = H; out->stride = stride_px;
out->data = malloc((size_t)stride_px * H * sizeof(uint32_t));
if (out->data)
memcpy(out->data, cairo_image_surface_get_data(dst),
(size_t)stride_px * H * sizeof(uint32_t));
cairo_surface_destroy(blur_surf);
cairo_surface_destroy(dst);
return out->data ? 0 : -1;
}
+23
View File
@@ -0,0 +1,23 @@
/* aerowm — glassmorphism panel/cards rendered with cairo + pango. */
#ifndef AEROWM_PANEL_H
#define AEROWM_PANEL_H
#include "image.h"
/* Render the AeroOS home-screen glass UI onto a transparent ARGB buffer the
* size of the output. `blurred` is a full-screen pre-blurred wallpaper used to
* give panels a real frosted backdrop. The result is composited on top of the
* sharp wallpaper by the compositor.
*
* Draws:
* - a frosted top bar with the AeroOS mark + live clock
* - a centered translucent "welcome" glass card
* - a frosted dock hint at the bottom
*/
int aero_panel_render(const struct aero_image *blurred,
int out_w, int out_h,
const char *clock_text,
const char *date_text,
struct aero_image *out);
#endif