Skip to content

Commit 04a6a92

Browse files
committed
fixed event type definitions and added a splash screen to the display manager
1 parent 4fec6f9 commit 04a6a92

9 files changed

Lines changed: 299 additions & 41 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef STLXDM_SPLASH_H
2+
#define STLXDM_SPLASH_H
3+
4+
#include "stlxdm_compositor.h"
5+
6+
/**
7+
* Display a splash screen with animated elements
8+
* @param compositor - initialized compositor with framebuffer info
9+
* @return 0 on success, negative on error
10+
*/
11+
int stlxdm_show_splash_screen(stlxdm_compositor_t* compositor);
12+
13+
#endif // STLXDM_SPLASH_H

userland/apps/stlxdm/src/stlxdm.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sys/un.h>
1212
#include <time.h>
1313
#include "stlxdm.h"
14+
#include "stlxdm_splash.h"
1415
#include <stlxgfx/stlxgfx.h>
1516
#include <stlxgfx/internal/stlxgfx_dm.h>
1617
#include <stlxgfx/internal/stlxgfx_comm.h>
@@ -29,7 +30,7 @@ int main() {
2930
return 1;
3031
}
3132

32-
// Initialize compositor (heap allocated)
33+
// Initialize compositor
3334
stlxdm_compositor_t* compositor = malloc(sizeof(stlxdm_compositor_t));
3435
if (!compositor) {
3536
printf("ERROR: Failed to allocate compositor\n");
@@ -44,6 +45,15 @@ int main() {
4445
return 1;
4546
}
4647

48+
// === SHOW SPLASH SCREEN ===
49+
if (stlxdm_show_splash_screen(compositor) != 0) {
50+
printf("ERROR: Failed to show splash screen\n");
51+
stlxdm_compositor_cleanup(compositor);
52+
free(compositor);
53+
stlxgfx_cleanup(gfx_ctx);
54+
return 1;
55+
}
56+
4757
// Initialize display manager server (heap allocated)
4858
stlxdm_server_t* server = malloc(sizeof(stlxdm_server_t));
4959
if (!server) {
@@ -63,7 +73,7 @@ int main() {
6373
return 1;
6474
}
6575

66-
// Initialize input manager (heap allocated, after compositor and server)
76+
// Initialize input manager
6777
stlxdm_input_manager_t* input_manager = malloc(sizeof(stlxdm_input_manager_t));
6878
if (!input_manager) {
6979
printf("ERROR: Failed to allocate input manager\n");

userland/apps/stlxdm/src/stlxdm_input_manager.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#define STLXDM_GRAB_BOTH (STLXDM_GRAB_KEYBOARD | STLXDM_GRAB_MOUSE)
1313

1414
// Forward declarations for internal functions
15-
static int _handle_keyboard_event(stlxdm_input_manager_t* input_mgr, const struct input_event_t* event);
16-
static int _handle_mouse_event(stlxdm_input_manager_t* input_mgr, const struct input_event_t* event);
15+
static int _handle_keyboard_event(stlxdm_input_manager_t* input_mgr, const stlxgfx_event_t* event);
16+
static int _handle_mouse_event(stlxdm_input_manager_t* input_mgr, const stlxgfx_event_t* event);
1717
static void _update_modifier_state(stlxdm_input_manager_t* input_mgr, uint32_t modifiers);
1818
static stlxdm_global_shortcut_t _check_global_shortcuts(stlxdm_input_manager_t* input_mgr, uint32_t keycode);
19-
static int _route_event_to_focused_window(stlxdm_input_manager_t* input_mgr, const struct input_event_t* event);
19+
static int _route_event_to_focused_window(stlxdm_input_manager_t* input_mgr, const stlxgfx_event_t* event);
2020
static uint32_t _get_current_time_ms(void);
2121
static int _initiate_window_drag(stlxdm_input_manager_t* input_mgr, stlxdm_client_info_t* client, int32_t click_x, int32_t click_y);
2222
static int _terminate_window_drag(stlxdm_input_manager_t* input_mgr);
@@ -112,7 +112,7 @@ int stlxdm_input_manager_process_events(stlxdm_input_manager_t* input_mgr) {
112112
return -1;
113113
}
114114

115-
struct input_event_t events[STLXDM_INPUT_MAX_EVENTS_PER_FRAME];
115+
stlxgfx_event_t events[STLXDM_INPUT_MAX_EVENTS_PER_FRAME];
116116
long events_read = stlx_read_input_events(INPUT_QUEUE_ID_SYSTEM, 0, events, STLXDM_INPUT_MAX_EVENTS_PER_FRAME);
117117

118118
if (events_read < 0) {
@@ -131,7 +131,7 @@ int stlxdm_input_manager_process_events(stlxdm_input_manager_t* input_mgr) {
131131

132132
// Process each event
133133
for (int i = 0; i < events_read; i++) {
134-
const struct input_event_t* event = &events[i];
134+
const stlxgfx_event_t* event = &events[i];
135135

136136
switch (event->type) {
137137
case KBD_EVT_KEY_PRESSED:
@@ -157,7 +157,7 @@ int stlxdm_input_manager_process_events(stlxdm_input_manager_t* input_mgr) {
157157
return events_read;
158158
}
159159

160-
static int _handle_keyboard_event(stlxdm_input_manager_t* input_mgr, const struct input_event_t* event) {
160+
static int _handle_keyboard_event(stlxdm_input_manager_t* input_mgr, const stlxgfx_event_t* event) {
161161
uint32_t keycode = event->udata1;
162162
uint32_t modifiers = event->udata2;
163163
bool is_pressed = (event->type == KBD_EVT_KEY_PRESSED);
@@ -202,7 +202,7 @@ static int _handle_keyboard_event(stlxdm_input_manager_t* input_mgr, const struc
202202
return 0;
203203
}
204204

205-
static int _handle_mouse_event(stlxdm_input_manager_t* input_mgr, const struct input_event_t* event) {
205+
static int _handle_mouse_event(stlxdm_input_manager_t* input_mgr, const stlxgfx_event_t* event) {
206206
switch (event->type) {
207207
case POINTER_EVT_MOUSE_MOVED: {
208208
// Update cursor position
@@ -469,7 +469,7 @@ static stlxdm_global_shortcut_t _check_global_shortcuts(stlxdm_input_manager_t*
469469
return STLXDM_SHORTCUT_NONE;
470470
}
471471

472-
static int _route_event_to_focused_window(stlxdm_input_manager_t* input_mgr, const struct input_event_t* event) {
472+
static int _route_event_to_focused_window(stlxdm_input_manager_t* input_mgr, const stlxgfx_event_t* event) {
473473
if (!input_mgr->focused_client || !input_mgr->focused_client->window) {
474474
// No focused window - route to system console
475475
if (event->type == KBD_EVT_KEY_PRESSED) {
@@ -489,7 +489,7 @@ static int _route_event_to_focused_window(stlxdm_input_manager_t* input_mgr, con
489489
// Convert kernel event to userland event format (they're compatible)
490490
stlxgfx_event_t userland_event;
491491
userland_event.id = event->id;
492-
userland_event.type = (stlxgfx_input_event_type_t)event->type; // Cast is safe since types match
492+
userland_event.type = (stlxgfx_input_event_type_t)event->type;
493493
userland_event.udata1 = event->udata1;
494494
userland_event.udata2 = event->udata2;
495495
userland_event.sdata1 = event->sdata1;

userland/apps/stlxdm/src/stlxdm_server.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
119119
const uint8_t* payload);
120120

121121
static int stlxdm_server_handle_destroy_window_request(stlxdm_server_t* server,
122-
stlxdm_client_info_t* client,
123-
const stlxgfx_message_header_t* header,
124-
const uint8_t* payload);
122+
stlxdm_client_info_t* client,
123+
const stlxgfx_message_header_t* header,
124+
const uint8_t* payload);
125125

126126
static int stlxdm_server_dispatch_message(stlxdm_server_t* server,
127127
stlxdm_client_info_t* client,
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
#define _POSIX_C_SOURCE 199309L
2+
#include "stlxdm_splash.h"
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
#include <unistd.h>
7+
#include <math.h>
8+
#include <time.h>
9+
#include <stlxgfx/internal/stlxgfx_dm.h>
10+
#include <stlxgfx/surface.h>
11+
#include <stlibc/stlibc.h>
12+
13+
// Splash screen configuration
14+
#define SPLASH_FRAME_RATE 60 // Target 60 FPS
15+
#define SPLASH_FRAME_DELAY_MS (1000 / SPLASH_FRAME_RATE)
16+
17+
// Color definitions
18+
#define SPLASH_BG_DARK 0xFF0A0A0A
19+
#define SPLASH_CYAN_BORDER 0xFF00FFFF
20+
#define SPLASH_WHITE_BRIGHT 0xFFFFFFFF
21+
#define SPLASH_WHITE_MIN 0xFF808080
22+
23+
// Logo dimensions
24+
#define LOGO_WIDTH 600
25+
#define LOGO_HEIGHT 80
26+
#define LOGO_BORDER_WIDTH 10
27+
#define LOGO_BORDER_RADIUS 15
28+
29+
static void create_dark_background(stlxgfx_surface_t* surface) {
30+
if (!surface) return;
31+
stlxgfx_clear_surface(surface, SPLASH_BG_DARK);
32+
}
33+
34+
static void draw_animated_gradient_logo(stlxgfx_surface_t* surface, uint32_t frame) {
35+
if (!surface) return;
36+
37+
uint32_t center_x = surface->width / 2;
38+
uint32_t logo_y = surface->height / 3;
39+
uint32_t logo_x = center_x - LOGO_WIDTH / 2;
40+
41+
// Create flowing gradient animation
42+
for (uint32_t y = logo_y; y < logo_y + LOGO_HEIGHT; y++) {
43+
for (uint32_t x = logo_x; x < logo_x + LOGO_WIDTH; x++) {
44+
float progress_x = (float)(x - logo_x) / LOGO_WIDTH;
45+
float progress_y = (float)(y - logo_y) / LOGO_HEIGHT;
46+
47+
// Add flowing animation to the gradient
48+
float flow_offset = sinf((float)frame * 0.02f + progress_x * 3.14159f) * 0.1f;
49+
progress_x += flow_offset;
50+
51+
if (progress_x < 0.0f) progress_x = 0.0f;
52+
if (progress_x > 1.0f) progress_x = 1.0f;
53+
54+
// Deep purple to magenta gradient with vertical variation
55+
uint32_t red = (uint32_t)(40 + progress_x * 140 + progress_y * 15);
56+
uint32_t green = (uint32_t)(0 + progress_y * 20);
57+
uint32_t blue = (uint32_t)(80 + progress_x * 120 + progress_y * 10);
58+
59+
if (red > 255) red = 255;
60+
if (green > 255) green = 255;
61+
if (blue > 255) blue = 255;
62+
63+
uint32_t color = 0xFF000000 | (red << 16) | (green << 8) | blue;
64+
stlxgfx_draw_pixel(surface, x, y, color);
65+
}
66+
}
67+
}
68+
69+
static void draw_cyan_border(stlxgfx_surface_t* surface) {
70+
if (!surface) return;
71+
72+
uint32_t center_x = surface->width / 2;
73+
uint32_t logo_y = surface->height / 3;
74+
uint32_t logo_x = center_x - LOGO_WIDTH / 2;
75+
76+
stlxgfx_draw_rounded_rect(surface,
77+
logo_x - LOGO_BORDER_WIDTH,
78+
logo_y - LOGO_BORDER_WIDTH,
79+
LOGO_WIDTH + (2 * LOGO_BORDER_WIDTH),
80+
LOGO_HEIGHT + (2 * LOGO_BORDER_WIDTH),
81+
LOGO_BORDER_RADIUS,
82+
SPLASH_CYAN_BORDER);
83+
}
84+
85+
static void draw_static_title(stlxgfx_surface_t* surface, stlxgfx_context_t* gfx_ctx) {
86+
if (!surface || !gfx_ctx) return;
87+
88+
const char* title = "Display Manager v0.1.0";
89+
uint32_t center_x = surface->width / 2;
90+
uint32_t logo_y = surface->height / 3;
91+
uint32_t title_y = logo_y + LOGO_HEIGHT + 30;
92+
93+
uint32_t text_width = strlen(title) * 28 * 0.6f;
94+
uint32_t title_x = center_x - text_width / 2;
95+
96+
stlxgfx_render_text(gfx_ctx, surface, title, title_x, title_y, 28, SPLASH_WHITE_BRIGHT);
97+
}
98+
99+
static void draw_breathing_text(stlxgfx_surface_t* surface, stlxgfx_context_t* gfx_ctx,
100+
uint32_t frame) {
101+
if (!surface || !gfx_ctx) return;
102+
103+
const char* text = "Press Enter to continue...";
104+
uint32_t center_x = surface->width / 2;
105+
uint32_t logo_y = surface->height / 3;
106+
uint32_t text_y = logo_y + LOGO_HEIGHT + 130;
107+
108+
// Slower breathing effect
109+
float breath = 0.5f + 0.5f * sinf((float)frame * 0.15f);
110+
111+
// Interpolate between minimum brightness and full brightness
112+
uint8_t min_intensity = 0x80;
113+
uint8_t max_intensity = 0xFF;
114+
uint8_t intensity = (uint8_t)(min_intensity + (max_intensity - min_intensity) * breath);
115+
116+
uint32_t text_color = 0xFF000000 | (intensity << 16) | (intensity << 8) | intensity;
117+
118+
uint32_t text_width = strlen(text) * 16 * 0.6f;
119+
uint32_t text_x = center_x - text_width / 2;
120+
121+
stlxgfx_render_text(gfx_ctx, surface, text, text_x, text_y, 16, text_color);
122+
}
123+
124+
static void add_modern_decorative_elements(stlxgfx_surface_t* surface, uint32_t frame) {
125+
if (!surface) return;
126+
127+
uint32_t center_x = surface->width / 2;
128+
uint32_t logo_y = surface->height / 3;
129+
uint32_t logo_x = center_x - LOGO_WIDTH / 2;
130+
131+
// Add breathing corner accents
132+
float breath = 0.5f + 0.5f * sinf((float)frame * 0.15f);
133+
uint8_t min_intensity = 0x40;
134+
uint8_t max_intensity = 0xFF;
135+
uint8_t corner_intensity = (uint8_t)(min_intensity + (max_intensity - min_intensity) * breath);
136+
uint32_t corner_color = 0xFF000000 | (corner_intensity << 16) | (corner_intensity << 8) | corner_intensity;
137+
138+
uint32_t corner_size = 8;
139+
140+
// Top-left corner
141+
stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size,
142+
logo_y - LOGO_BORDER_WIDTH - corner_size, corner_size, 2, corner_color);
143+
stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size,
144+
logo_y - LOGO_BORDER_WIDTH - corner_size, 2, corner_size, corner_color);
145+
146+
// Top-right corner
147+
stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH,
148+
logo_y - LOGO_BORDER_WIDTH - corner_size, corner_size, 2, corner_color);
149+
stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH + corner_size - 2,
150+
logo_y - LOGO_BORDER_WIDTH - corner_size, 2, corner_size, corner_color);
151+
152+
// Bottom-left corner (rotated 90 degrees clockwise from top-left)
153+
stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size,
154+
logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH, 2, corner_size, corner_color);
155+
stlxgfx_fill_rect(surface, logo_x - LOGO_BORDER_WIDTH - corner_size,
156+
logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH + corner_size - 2, corner_size, 2, corner_color);
157+
158+
// Bottom-right corner (rotated 90 degrees clockwise from top-right)
159+
stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH + corner_size - 2,
160+
logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH, 2, corner_size, corner_color);
161+
stlxgfx_fill_rect(surface, logo_x + LOGO_WIDTH + LOGO_BORDER_WIDTH,
162+
logo_y + LOGO_HEIGHT + LOGO_BORDER_WIDTH + corner_size - 2, corner_size, 2, corner_color);
163+
}
164+
165+
static int check_for_enter_key() {
166+
input_event_t events[16];
167+
int n = stlx_read_input_events(STLXGFX_INPUT_QUEUE_ID_SYSTEM, 0, events, 16);
168+
169+
if (n > 0) {
170+
for (int i = 0; i < n; i++) {
171+
if (events[i].type == STLXGFX_KBD_EVT_KEY_PRESSED) {
172+
if (events[i].udata1 == 40) {
173+
return 1; // Enter pressed
174+
}
175+
}
176+
}
177+
}
178+
179+
return 0; // No Enter key
180+
}
181+
182+
int stlxdm_show_splash_screen(stlxdm_compositor_t* compositor) {
183+
if (!compositor || !compositor->initialized) {
184+
printf("[STLXDM_SPLASH] ERROR: Invalid compositor for splash screen\n");
185+
return -1;
186+
}
187+
188+
printf("[STLXDM_SPLASH] Starting splash screen...\n");
189+
190+
const struct gfx_framebuffer_info* fb_info = stlxdm_compositor_get_fb_info(compositor);
191+
if (!fb_info) {
192+
printf("[STLXDM_SPLASH] ERROR: No framebuffer info available\n");
193+
return -1;
194+
}
195+
196+
stlxgfx_surface_t* splash_surface = stlxgfx_dm_create_surface(
197+
compositor->gfx_ctx,
198+
fb_info->width,
199+
fb_info->height,
200+
compositor->gop_format
201+
);
202+
203+
if (!splash_surface) {
204+
printf("[STLXDM_SPLASH] ERROR: Failed to create splash surface\n");
205+
return -1;
206+
}
207+
208+
uint32_t frame = 0;
209+
printf("[STLXDM_SPLASH] Displaying splash screen (press Enter to continue)\n");
210+
211+
while (1) {
212+
create_dark_background(splash_surface);
213+
draw_animated_gradient_logo(splash_surface, frame);
214+
draw_cyan_border(splash_surface);
215+
draw_static_title(splash_surface, compositor->gfx_ctx);
216+
draw_breathing_text(splash_surface, compositor->gfx_ctx, frame);
217+
add_modern_decorative_elements(splash_surface, frame);
218+
219+
stlxdm_begin_frame();
220+
int present_result = stlxgfx_blit_surface_to_buffer(
221+
splash_surface,
222+
compositor->framebuffer,
223+
fb_info->pitch
224+
);
225+
stlxdm_end_frame();
226+
227+
if (present_result != 0) {
228+
printf("[STLXDM_SPLASH] Warning: Failed to present splash frame\n");
229+
}
230+
231+
if (check_for_enter_key()) {
232+
printf("[STLXDM_SPLASH] Enter key pressed, continuing to display manager\n");
233+
break;
234+
}
235+
236+
struct timespec delay = {
237+
.tv_sec = 0,
238+
.tv_nsec = SPLASH_FRAME_DELAY_MS * 1000000
239+
};
240+
nanosleep(&delay, NULL);
241+
242+
frame++;
243+
}
244+
245+
stlxgfx_dm_destroy_surface(compositor->gfx_ctx, splash_surface);
246+
printf("[STLXDM_SPLASH] Splash screen completed\n");
247+
return 0;
248+
}

0 commit comments

Comments
 (0)