From 5d5f1c0ad39481cd11960c0f25c1d7c5318fef6d Mon Sep 17 00:00:00 2001 From: Abhinav Prasai Date: Sun, 23 Nov 2025 02:16:17 +0000 Subject: add engine (no webkit yet, only tab support) --- src/quark.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 93 insertions(+), 23 deletions(-) (limited to 'src/quark.c') diff --git a/src/quark.c b/src/quark.c index ed98a83..f850bd5 100644 --- a/src/quark.c +++ b/src/quark.c @@ -4,84 +4,154 @@ #include #include +#include "engine.h" #include "quark.h" +#include "render.h" #include "sdl.h" quark_t quark; +void init(void); void quit(void); void render_tmp(void); void run(void); -void setup(void); void quit(void) { - LOG_INFO("quitting quark..."); + engine_shutdown(); + render_shutdown(); sdl_quit(); + LOG_INFO("quark: quitting"); } void render_tmp(void) { - glViewport(0, 0, quark.win_w, quark.win_h); + render_begin(quark.win_w, quark.win_h); - glClearColor(0.0, 0.0, 0.0, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); + /* top bar */ + render_rect(0, 0, quark.win_w, 32, 0.15f, 0.15f, 0.22f, 1.0f); - glEnable(GL_SCISSOR_TEST); - int bar_h = 32; - glScissor(0, quark.win_h - bar_h, quark.win_w, bar_h); - glClearColor(0.25, 0.25, 0.30, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - glDisable(GL_SCISSOR_TEST); + /* number of tabs changes color */ + int n = engine_get_tab_count(); + int cur = engine_get_current_index(); - SDL_GL_SwapWindow(quark.win); + float intensity = 0.2f + 0.05f * (float)n; + if (intensity > 1.0f) + intensity = 1.0f; + + /* tab indicator */ + render_rect(10, 8, 100, 16, intensity, (cur >= 0 ? 0.5f : 0.2f), 0.2f, 1.0f); + + render_end(quark.win); } void run(void) { quark.running = true; - LOG_INFO("starting quark..."); + LOG_INFO("quark: starting"); SDL_Event ev; while (quark.running) { + /* TODO: add event handler + this is just test until WebKit implemented */ while (SDL_PollEvent(&ev)) { if (ev.type == SDL_QUIT) quark.running = false; - if (ev.type == SDL_WINDOWEVENT_RESIZED) { - quark.win_w = ev.window.data1; - quark.win_h = ev.window.data2; + if (ev.type == SDL_WINDOWEVENT) { + if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + quark.win_w = ev.window.data1; + quark.win_h = ev.window.data2; + } + } + + if (ev.type == SDL_KEYDOWN) { + SDL_Keycode key = ev.key.keysym.sym; + SDL_Keymod mods = ev.key.keysym.mod; + + /* C-t: new tab */ + if ((mods & KMOD_CTRL) && key == SDLK_t) { + int id = engine_tab_new("about:blank"); + if (id >= 0) { + LOG_INFO("quark: new tab %d", id); + engine_tab_switch(id); + } + } + + /* C-w: close current tab */ + if ((mods & KMOD_CTRL) && key == SDLK_w) { + quark_tab_t* cur = engine_tab_current(); + if (cur) { + LOG_INFO("quark: closing current tab"); + engine_tab_close(engine_get_current_index()); + } + } + + /* C-t: switch tab */ + if ((mods & KMOD_CTRL) && key == SDLK_TAB) { + int n = engine_get_tab_count(); + int cur = engine_get_current_index(); + if (n > 0 && cur >= 0) { + int next = (cur + 1) % n; + engine_tab_switch(next); + } + } } } + engine_update(); render_tmp(); SDL_Delay(10); } } -void setup(void) +void init(void) { sdl_init(); quark.win = sdl_create_window("quark", 800, 600); if (!quark.win) { - LOG_ERROR("failed to create quark window"); + LOG_ERROR("sdl: failed to create quark window"); exit(EXIT_FAILURE); } else { - LOG_PASS("created SDL window"); + LOG_PASS("sdl: created SDL window"); } quark.win_w = 800; quark.win_h = 600; - /* create OpenGL context */ + /* init systems */ quark.gl = SDL_GL_CreateContext(quark.win); if (!quark.gl) { - LOG_ERROR("failed to create GL context"); + LOG_ERROR("opengl: failed to create GL context"); + exit(EXIT_FAILURE); + } + else { + LOG_PASS("opengl: created OpenGL ES context"); + } + + if (!render_init()) { + LOG_ERROR("renderer: failed to initialise renderer"); + exit(EXIT_FAILURE); + } + else { + LOG_PASS("renderer: initialised renderer "); + } + + if (!engine_init()) { + LOG_ERROR("engine: failed to init engine"); + exit(EXIT_FAILURE); + } + else { + LOG_ERROR("engine: initialised engine"); + } + + /* starting tab */ + if (engine_tab_new("about:blank") < 0) { + LOG_ERROR("engine: failed to create initial tab"); exit(EXIT_FAILURE); } else { - LOG_PASS("created OpenGL ES context"); + LOG_PASS("engine: created initial tab"); } } @@ -90,7 +160,7 @@ int main(int argc, char** argv) (void) argc; (void) argv; - setup(); + init(); run(); quit(); -- cgit v1.2.3