Skip to content

Commit

Permalink
Add welcome screen at the boot of Kot
Browse files Browse the repository at this point in the history
  • Loading branch information
konect-V committed Aug 16, 2024
1 parent 1b5d28c commit cbec21a
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 39 deletions.
5 changes: 2 additions & 3 deletions sources/core/apps/datetime/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ VERSION = 0-0-1
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc \
-lz
-lc

# Recursive Wild Card
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
Expand All @@ -37,7 +36,7 @@ $(LIB)/%_c.o: $(SOURCE)/%.c

link:
@ mkdir -m 777 -p $(BIN)
@ $(CC) $(LDFLAGS) -o $(BIN)/datetime $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a
@ $(CC) $(LDFLAGS) -o $(BIN)/datetime $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a $(LIBRARIES)/libz.a

tar:
@ mkdir -m 777 -p $(TAR)
Expand Down
16 changes: 15 additions & 1 deletion sources/core/apps/init/source/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <sys/types.h>


int main(int argc, char* argv[]){
Expand All @@ -27,7 +29,19 @@ int main(int argc, char* argv[]){

setenv("PS1", "\\[\e[0;92m$USER@$HOSTNAME\e[0;37m: \e[0;94m\\w\e[0;37m\\$\e[0m\\] ", 1); // '#' is used to indicate root user session

char *exe_argv[2] = {"/usr/bin/bash", NULL};
pid_t p = fork();
if(p < 0){
perror("init: fork fail");
return EXIT_FAILURE;
}else if (p == 0){
char* exe_argv[2] = {"/usr/bin/welcome", NULL};
execvp("/usr/bin/welcome", exe_argv);
}

int status = 0;
wait(&status);

char* exe_argv[2] = {"/usr/bin/bash", NULL};
execvp("/usr/bin/bash", exe_argv);

perror("init: /usr/bin/bash");
Expand Down
5 changes: 2 additions & 3 deletions sources/core/apps/ip/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ VERSION = 0-0-1
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc \
-lz
-lc

# Recursive Wild Card
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
Expand All @@ -37,7 +36,7 @@ $(LIB)/%_c.o: $(SOURCE)/%.c

link:
@ mkdir -m 777 -p $(BIN)
@ $(CC) $(LDFLAGS) -o $(BIN)/ip $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a
@ $(CC) $(LDFLAGS) -o $(BIN)/ip $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a $(LIBRARIES)/libz.a

tar:
@ mkdir -m 777 -p $(TAR)
Expand Down
5 changes: 2 additions & 3 deletions sources/core/apps/llm/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ VERSION = 0-0-1
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc \
-lz
-lc

# Recursive Wild Card
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
Expand All @@ -37,7 +36,7 @@ $(LIB)/%_c.o: $(SOURCE)/%.c

link:
@ mkdir -m 777 -p $(BIN)
@ $(CC) $(LDFLAGS) -o $(BIN)/llm $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a
@ $(CC) $(LDFLAGS) -o $(BIN)/llm $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a $(LIBRARIES)/libz.a

tar:
@ mkdir -m 777 -p $(TAR)
Expand Down
5 changes: 2 additions & 3 deletions sources/core/apps/store/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ LIB = lib
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc \
-lz
-lc

# Recursive Wild Card
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
Expand All @@ -35,6 +34,6 @@ $(LIB)/%_c.o: $(SOURCE)/%.c

link:
@ mkdir -m 777 -p $(BIN)
@ $(CC) $(LDFLAGS) -o $(BIN)/store $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a $(LIBRARIES)/libcjson.a
@ $(CC) $(LDFLAGS) -o $(BIN)/store $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a $(LIBRARIES)/libcjson.a $(LIBRARIES)/libz.a

build: $(OBJS) link
5 changes: 2 additions & 3 deletions sources/core/apps/weather/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ VERSION = 0-0-1
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc \
-lz
-lc

# Recursive Wild Card
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
Expand All @@ -37,7 +36,7 @@ $(LIB)/%_c.o: $(SOURCE)/%.c

link:
@ mkdir -m 777 -p $(BIN)
@ $(CC) $(LDFLAGS) -o $(BIN)/weather $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a
@ $(CC) $(LDFLAGS) -o $(BIN)/weather $(OBJS) $(LIBRARIES)/libcurl.a $(LIBRARIES)/libtls.a $(LIBRARIES)/libssl.a $(LIBRARIES)/libz.a

tar:
@ mkdir -m 777 -p $(TAR)
Expand Down
75 changes: 56 additions & 19 deletions sources/core/apps/welcome/source/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
#include <kot-graphics/utils.h>
#include <kot-graphics/image.h>

#define TEXT_WIDTH 500
#define TEXT_MARGIN 100
#define TITLE_SIZE 36
#define TEXT_SIZE 27
#define SIGNATURE_SIZE 24
#define TEXT_START TEXT_MARGIN / 2
#define TEXT_COLOR 0xffffff
#define LINK_COLOR 0x33ddff
#define TEXT_BACKGROUND 0x222222
#define TEXT_BOX_WIDTH TEXT_WIDTH + TEXT_MARGIN
#define SLIDE_TIME 5000
#define PROGRESSBAR_HEIGHT 50
#define PROGRESSBAR_COLOR 0xffffff
#define TEXT_WIDTH (500)
#define TEXT_MARGIN (100)
#define TITLE_SIZE (36)
#define TEXT_SIZE (27)
#define SIGNATURE_SIZE (24)
#define TEXT_START (TEXT_MARGIN / 2)
#define TEXT_COLOR (0xffffff)
#define LINK_COLOR (0x33ddff)
#define TEXT_BACKGROUND (0x222222)
#define TEXT_BOX_WIDTH (TEXT_WIDTH + TEXT_MARGIN)
#define SLIDE_TIME (5000)
#define PROGRESSBAR_HEIGHT (5)
#define PROGRESSBAR_COLOR (0xffffff)
#define INFO_SIZE (16)

kfont_t font;

Expand Down Expand Up @@ -59,6 +60,7 @@ int get_key(int* pressed, uint64_t* key){
*pressed = false;
}
*key = buffer & ~((uint64_t)1 << 63);
return 1;
}
return 0;
}
Expand All @@ -69,18 +71,53 @@ int wait_for_the_next_slide(){
uint64_t current_tick = start_tick;
uint64_t tick_to_stop = start_tick + SLIDE_TIME;

while(current_tick < tick_to_stop){
current_tick = get_ticks_ms();
uint64_t progress_size = ((current_tick - start_tick) * TEXT_BOX_WIDTH) / SLIDE_TIME;
draw_rectangle(&fb, 0, fb.height - PROGRESSBAR_HEIGHT, progress_size, PROGRESSBAR_HEIGHT, PROGRESSBAR_COLOR);
draw_frame();
set_pen_size(font, INFO_SIZE);
write_paragraph(font, -1, fb.height - INFO_SIZE - (PROGRESSBAR_HEIGHT * 4) - 10, fmin(TEXT_WIDTH, fb.width), PARAGRAPH_CENTER, "Quit : <esc> | Next : <enter> | Pause : <p>\n");

bool is_paused = false;
uint64_t progress_size = 0;

while(current_tick < tick_to_stop || is_paused){
if(!is_paused){
current_tick = get_ticks_ms();
progress_size = ((current_tick - start_tick) * TEXT_BOX_WIDTH) / SLIDE_TIME;
draw_rectangle(&fb, 0, fb.height - PROGRESSBAR_HEIGHT, progress_size, PROGRESSBAR_HEIGHT, PROGRESSBAR_COLOR);
draw_frame();
}

int pressed;
uint64_t key;
if(get_key(&pressed, &key)){
if(pressed && key == 28){
break;
}
if(pressed && key == 1){
ret = 1;
break;
}
if(pressed && key == 25){
is_paused = true;
draw_rectangle(&fb, 0, fb.height - PROGRESSBAR_HEIGHT, progress_size, PROGRESSBAR_HEIGHT, TEXT_BACKGROUND);
draw_frame();
}
if(!pressed && key == 25){
if(is_paused){
start_tick = get_ticks_ms();
current_tick = start_tick;
tick_to_stop = start_tick + SLIDE_TIME;
is_paused = false;
}
}
}
}

return ret;
}

int main(int argc, char* argv[]){
fb_fd = open("/dev/fb0", O_RDWR);
fb_fd = open("/dev/fb0", O_RDWR);

printf("Loading welcome app...\n");

assert(fb_fd >= 0);

Expand Down
5 changes: 2 additions & 3 deletions sources/core/apps/welcome/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ LIB = lib
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc \
-lz
-lc

# Recursive Wild Card
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
Expand All @@ -35,7 +34,7 @@ $(LIB)/%_c.o: $(SOURCE)/%.c

link:
@ mkdir -m 777 -p $(BIN)
@ $(CC) $(LDFLAGS) -o $(BIN)/welcome $(OBJS) $(LIBRARIES)/libkot-graphics.a $(LIBRARIES)/libfreetype.a $(LIBRARIES)/libturbojpeg.a
$(CC) $(LDFLAGS) -o $(BIN)/welcome $(OBJS) $(LIBRARIES)/libkot-graphics.a $(LIBRARIES)/libfreetype.a $(LIBRARIES)/libz.a $(LIBRARIES)/libturbojpeg.a

copy_res:
@ mkdir -m 777 -p $(BIN)/res/welcome
Expand Down
2 changes: 1 addition & 1 deletion sources/core/libs/kot-graphics/source/utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ uint32_t blend_alpha(uint32_t color, uint8_t factor){
void draw_rectangle(kframebuffer_t* fb, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t color){
for (uint32_t i = 0; i < width; i++) {
for (uint32_t j = 0; j < height; j++) {
*(uint32_t*)((uint64_t)fb->buffer + i * fb->btpp + j * fb->pitch) = color;
*(uint32_t*)((uint64_t)fb->buffer + (i + x) * fb->btpp + (j + y) * fb->pitch) = color;
}
}
}

0 comments on commit cbec21a

Please sign in to comment.