From 87d9f9a48463814acc752df72fdcd423f1937327 Mon Sep 17 00:00:00 2001 From: uint Date: Sat, 29 Nov 2025 16:25:19 +0000 Subject: rename to quartz because suckless took quark >:( . --- Makefile | 14 ++--- README.md | 2 +- include/engine.h | 4 +- include/quark.h | 46 --------------- include/quartz.h | 46 +++++++++++++++ quartz | Bin 0 -> 31672 bytes src/engine.c | 8 +-- src/quark.c | 168 ------------------------------------------------------- src/quartz.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/render.c | 2 +- src/sdl.c | 2 +- 11 files changed, 230 insertions(+), 230 deletions(-) delete mode 100644 include/quark.h create mode 100644 include/quartz.h create mode 100755 quartz delete mode 100644 src/quark.c create mode 100644 src/quartz.c diff --git a/Makefile b/Makefile index a6e197f..7151105 100644 --- a/Makefile +++ b/Makefile @@ -5,23 +5,23 @@ INCLUDE = -Iinclude CFLAGS = -std=c99 -O2 -Wall -Wextra $(INCLUDE) LDFLAGS = $(DEPS) -SRC = src/quark.c src/sdl.c src/render.c src/engine.c -OBJ = build/quark.o build/sdl.o build/render.o build/engine.o +SRC = src/quartz.c src/sdl.c src/render.c src/engine.c +OBJ = build/quartz.o build/sdl.o build/render.o build/engine.o -all: quark +all: quartz -quark: $(OBJ) - $(CC) -o quark $(OBJ) $(LDFLAGS) +quartz: $(OBJ) + $(CC) -o quartz $(OBJ) $(LDFLAGS) build/%.o: src/%.c mkdir -p build $(CC) $(CFLAGS) -c $< -o $@ clean: - rm -f quark $(OBJ) + rm -f quartz $(OBJ) run: - ./quark + ./quartz compile_flags: rm -f compile_flags.txt diff --git a/README.md b/README.md index c131a74..5c678b4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# quark +# quartz more suckless web-browser diff --git a/include/engine.h b/include/engine.h index 6228465..45ebac8 100644 --- a/include/engine.h +++ b/include/engine.h @@ -8,7 +8,7 @@ typedef struct { char* url; char* title; bool loading; -} quark_tab_t; +} quartz_tab_t; int engine_get_current_index(void); int engine_get_tab_count(void); @@ -16,7 +16,7 @@ bool engine_init(void); void engine_load_url(int id, const char* url); void engine_shutdown(void); void engine_tab_close(int id); -quark_tab_t* engine_tab_current(void); +quartz_tab_t* engine_tab_current(void); int engine_tab_new(const char* url); void engine_tab_switch(int id); void engine_update(void); diff --git a/include/quark.h b/include/quark.h deleted file mode 100644 index 233314e..0000000 --- a/include/quark.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include -#include - -#include - -/* types */ -typedef struct { - SDL_Window* win; - SDL_GLContext gl; - int win_w; - int win_h; - bool running; -} quark_t; - -/* logging */ -#define ANSI_RESET "\x1b[0m" -#define ANSI_FG_WHITE "\x1b[37m" -#define ANSI_BG_CYAN "\x1b[46m" -#define ANSI_BG_MAGENTA "\x1b[45m" -#define ANSI_BG_RED "\x1b[41m" -#define ANSI_BG_GREEN "\x1b[42m" -#define ANSI_BG_YELLOW "\x1b[43m" - -#define LOG(fmt, ...) \ - fprintf(stdout, fmt "\n", ##__VA_ARGS__) - -#define LOG_INFO(fmt, ...) \ - fprintf(stdout, ANSI_FG_WHITE ANSI_BG_CYAN " INFO " ANSI_RESET " " fmt "\n", ##__VA_ARGS__) - -#define LOG_PASS(fmt, ...) \ - fprintf(stdout, ANSI_FG_WHITE ANSI_BG_GREEN " PASS " ANSI_RESET " " fmt " (%s:%d)\n", ##__VA_ARGS__, __FILE__, __LINE__) - -#define LOG_WARN(fmt, ...) \ - fprintf(stderr, ANSI_FG_WHITE ANSI_BG_YELLOW " WARN " ANSI_RESET " " fmt "\n", ##__VA_ARGS__) - -#define LOG_ERROR(fmt, ...) \ - fprintf(stderr, ANSI_FG_WHITE ANSI_BG_RED " ERROR " ANSI_RESET " " fmt " (%s:%d)\n", ##__VA_ARGS__, __FILE__, __LINE__) - -#ifdef DEBUG -#define LOG_DEBUG(fmt, ...) \ - fprintf(stdout, ANSI_FG_WHITE ANSI_BG_MAGENTA " DEBUG " ANSI_RESET " " fmt "\n", ##__VA_ARGS__) -#else -#define LOG_DEBUG(fmt, ...) ((void)0) -#endif diff --git a/include/quartz.h b/include/quartz.h new file mode 100644 index 0000000..7c1c92d --- /dev/null +++ b/include/quartz.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include + +#include + +/* types */ +typedef struct { + SDL_Window* win; + SDL_GLContext gl; + int win_w; + int win_h; + bool running; +} quartz_t; + +/* logging */ +#define ANSI_RESET "\x1b[0m" +#define ANSI_FG_WHITE "\x1b[37m" +#define ANSI_BG_CYAN "\x1b[46m" +#define ANSI_BG_MAGENTA "\x1b[45m" +#define ANSI_BG_RED "\x1b[41m" +#define ANSI_BG_GREEN "\x1b[42m" +#define ANSI_BG_YELLOW "\x1b[43m" + +#define LOG(fmt, ...) \ + fprintf(stdout, fmt "\n", ##__VA_ARGS__) + +#define LOG_INFO(fmt, ...) \ + fprintf(stdout, ANSI_FG_WHITE ANSI_BG_CYAN " INFO " ANSI_RESET " " fmt "\n", ##__VA_ARGS__) + +#define LOG_PASS(fmt, ...) \ + fprintf(stdout, ANSI_FG_WHITE ANSI_BG_GREEN " PASS " ANSI_RESET " " fmt " (%s:%d)\n", ##__VA_ARGS__, __FILE__, __LINE__) + +#define LOG_WARN(fmt, ...) \ + fprintf(stderr, ANSI_FG_WHITE ANSI_BG_YELLOW " WARN " ANSI_RESET " " fmt "\n", ##__VA_ARGS__) + +#define LOG_ERROR(fmt, ...) \ + fprintf(stderr, ANSI_FG_WHITE ANSI_BG_RED " ERROR " ANSI_RESET " " fmt " (%s:%d)\n", ##__VA_ARGS__, __FILE__, __LINE__) + +#ifdef DEBUG +#define LOG_DEBUG(fmt, ...) \ + fprintf(stdout, ANSI_FG_WHITE ANSI_BG_MAGENTA " DEBUG " ANSI_RESET " " fmt "\n", ##__VA_ARGS__) +#else +#define LOG_DEBUG(fmt, ...) ((void)0) +#endif diff --git a/quartz b/quartz new file mode 100755 index 0000000..79cf700 Binary files /dev/null and b/quartz differ diff --git a/src/engine.c b/src/engine.c index bf6ed35..5d4afe2 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2,9 +2,9 @@ #include #include "engine.h" -#include "quark.h" +#include "quartz.h" -static quark_tab_t tabs[MAX_TABS]; +static quartz_tab_t tabs[MAX_TABS]; static int tab_count = 0; static int current_tab = -1; @@ -68,7 +68,7 @@ void engine_tab_close(int id) current_tab = tab_count - 1; } -quark_tab_t* engine_tab_current(void) +quartz_tab_t* engine_tab_current(void) { for (int i = 0; i < tab_count; i++) if (i == current_tab) @@ -84,7 +84,7 @@ int engine_tab_new(const char* url) return -1; } - quark_tab_t* t = &tabs[tab_count]; + quartz_tab_t* t = &tabs[tab_count]; t->url = SDL_strdup(url ? url : "about_blank"); t->title = SDL_strdup("new tab"); /* TODO: customise */ t->loading = true; diff --git a/src/quark.c b/src/quark.c deleted file mode 100644 index f850bd5..0000000 --- a/src/quark.c +++ /dev/null @@ -1,168 +0,0 @@ -#include - -#include -#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 quit(void) -{ - engine_shutdown(); - render_shutdown(); - sdl_quit(); - LOG_INFO("quark: quitting"); -} - -void render_tmp(void) -{ - render_begin(quark.win_w, quark.win_h); - - /* top bar */ - render_rect(0, 0, quark.win_w, 32, 0.15f, 0.15f, 0.22f, 1.0f); - - /* number of tabs changes color */ - int n = engine_get_tab_count(); - int cur = engine_get_current_index(); - - 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("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) { - 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 init(void) -{ - sdl_init(); - quark.win = sdl_create_window("quark", 800, 600); - if (!quark.win) { - LOG_ERROR("sdl: failed to create quark window"); - exit(EXIT_FAILURE); - } - else { - LOG_PASS("sdl: created SDL window"); - } - quark.win_w = 800; - quark.win_h = 600; - - /* init systems */ - quark.gl = SDL_GL_CreateContext(quark.win); - if (!quark.gl) { - 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("engine: created initial tab"); - } -} - -int main(int argc, char** argv) -{ - (void) argc; - (void) argv; - - init(); - run(); - quit(); - - return EXIT_SUCCESS; -} diff --git a/src/quartz.c b/src/quartz.c new file mode 100644 index 0000000..8c7d92e --- /dev/null +++ b/src/quartz.c @@ -0,0 +1,168 @@ +#include + +#include +#include +#include + +#include "engine.h" +#include "quartz.h" +#include "render.h" +#include "sdl.h" + +quartz_t quartz; + +void init(void); +void quit(void); +void render_tmp(void); +void run(void); + +void quit(void) +{ + engine_shutdown(); + render_shutdown(); + sdl_quit(); + LOG_INFO("quartz: quitting"); +} + +void render_tmp(void) +{ + render_begin(quartz.win_w, quartz.win_h); + + /* top bar */ + render_rect(0, 0, quartz.win_w, 32, 0.15f, 0.15f, 0.22f, 1.0f); + + /* number of tabs changes color */ + int n = engine_get_tab_count(); + int cur = engine_get_current_index(); + + 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(quartz.win); +} + +void run(void) +{ + quartz.running = true; + LOG_INFO("quartz: starting"); + + SDL_Event ev; + + while (quartz.running) { + /* TODO: add event handler + this is just test until WebKit implemented */ + while (SDL_PollEvent(&ev)) { + if (ev.type == SDL_QUIT) + quartz.running = false; + + if (ev.type == SDL_WINDOWEVENT) { + if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + quartz.win_w = ev.window.data1; + quartz.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("quartz: new tab %d", id); + engine_tab_switch(id); + } + } + + /* C-w: close current tab */ + if ((mods & KMOD_CTRL) && key == SDLK_w) { + quartz_tab_t* cur = engine_tab_current(); + if (cur) { + LOG_INFO("quartz: 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 init(void) +{ + sdl_init(); + quartz.win = sdl_create_window("quartz", 800, 600); + if (!quartz.win) { + LOG_ERROR("sdl: failed to create quartz window"); + exit(EXIT_FAILURE); + } + else { + LOG_PASS("sdl: created SDL window"); + } + quartz.win_w = 800; + quartz.win_h = 600; + + /* init systems */ + quartz.gl = SDL_GL_CreateContext(quartz.win); + if (!quartz.gl) { + 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("engine: created initial tab"); + } +} + +int main(int argc, char** argv) +{ + (void) argc; + (void) argv; + + init(); + run(); + quit(); + + return EXIT_SUCCESS; +} diff --git a/src/render.c b/src/render.c index 8220edb..2bc4430 100644 --- a/src/render.c +++ b/src/render.c @@ -4,7 +4,7 @@ #include #include -#include "quark.h" +#include "quartz.h" #include "render.h" /* shader handles */ diff --git a/src/sdl.c b/src/sdl.c index 03821a0..55feaea 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -2,7 +2,7 @@ #include -#include "quark.h" +#include "quartz.h" #include "sdl.h" SDL_Window* sdl_create_window(const char* title, int w, int h) -- cgit v1.2.3