From ebf52e6353c842cc7a9ec6a8f93813d7bd7f339f Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Thu, 26 Mar 2026 20:35:16 +1300 Subject: Some refactoring, Cinnamon struct, defconfig rather than just config --- .gitignore | 1 + Makefile | 5 +++++ README.md | 1 + config.def.h | 40 ++++++++++++++++++++++++++++++++++++++++ config.h | 40 ---------------------------------------- main.c | 20 +++++++++++--------- 6 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 config.def.h delete mode 100644 config.h diff --git a/.gitignore b/.gitignore index 0e9b4c6..043bea3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ cinnamon +config.h diff --git a/Makefile b/Makefile index 76fb5aa..9ddf943 100644 --- a/Makefile +++ b/Makefile @@ -24,4 +24,9 @@ install: $(TARGET) uninstall: rm -f $(PREFIX)/bin/$(TARGET) +config.h: + @cp config.def.h config.h + @echo "config.h created from config.def.h, edit it with your preferred configuration then run make again" + @exit 1 + .PHONY: all clean run diff --git a/README.md b/README.md index 6c14a56..e66bf67 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ To install this software, you must compile it from source. Don't worry, it shoul ```shell $ git clone https://git.arslaancodes.com/cinnamon-browser.git $ cd cinnamon-browser +$ cp config.def.h config.h # make install ``` diff --git a/config.def.h b/config.def.h new file mode 100644 index 0000000..eebd436 --- /dev/null +++ b/config.def.h @@ -0,0 +1,40 @@ +/* This file (and this file ONLY) is released into the public domain. + * No rights reserved. Copy, modify, do whatever you want. */ + +#ifndef CONFIG_H +#define CONFIG_H + +/* default window width/height, can be resized after. */ +#define WINDOW_WIDTH 1024 +#define WINDOW_HEIGHT 768 +#define HOMEPAGE "https://start.duckduckgo.com" +/* this value is required for the browser to launch + if its not there the browser will exit with code 1 + do not ask any questions */ +#define ObamaPrism + +/* Keybind definitions */ +typedef struct { + const char* key; + const char* command; +} Keybind; + +/* TODO: make this use functions and not command strings */ +static const Keybind keybinds[] = { + { "", ":tab_open" }, + { "d", ":tab_close" }, + { "o", ":commandline_show \":open\"" }, + { "i", ":mode insert" }, + { "", ":tab_select 1" }, + { "", ":tab_select 2" }, + { "", ":tab_select 3" }, + { "", ":tab_select 4" }, + { "", ":tab_select 5" }, + { "", ":tab_select 6" }, + { "", ":tab_select 7" }, + { "", ":tab_select 8" }, + { "", ":tab_select 9" }, + { "", ":tab_select 10" }, +}; + +#endif diff --git a/config.h b/config.h deleted file mode 100644 index 3a3a4e6..0000000 --- a/config.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright (c) 2026 Arslaan Pathan -This software is licensed under the ARPL. See LICENSE for details. -*/ -#ifndef CONFIG_H -#define CONFIG_H - -/* default window width/height, can be resized after. */ -#define WINDOW_WIDTH 1024 -#define WINDOW_HEIGHT 768 -#define HOMEPAGE "https://start.duckduckgo.com" -/* this value is required for the browser to launch - if its not there the browser will exit with code 1 - do not ask any questions */ -#define ObamaPrism - -/* Keybind definitions */ -typedef struct { - const char* key; - const char* command; -} Keybind; - -static const Keybind keybinds[] = { - { "", ":tab_open" }, - { "d", ":tab_close" }, - { "o", ":commandline_show \":open\"" }, - { "i", ":mode insert" }, - { "", ":tab_select 1" }, - { "", ":tab_select 2" }, - { "", ":tab_select 3" }, - { "", ":tab_select 4" }, - { "", ":tab_select 5" }, - { "", ":tab_select 6" }, - { "", ":tab_select 7" }, - { "", ":tab_select 8" }, - { "", ":tab_select 9" }, - { "", ":tab_select 10" }, -}; - -#endif diff --git a/main.c b/main.c index a6b012f..d5321a0 100644 --- a/main.c +++ b/main.c @@ -73,29 +73,31 @@ int main(int argc, char *argv[]) { #endif gtk_init(&argc, &argv); + Cinnamon cinnamon = {0}; + /* Create a new window and set default size */ - GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + cinnamon.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* Size constants defined in config.h */ - gtk_window_set_default_size(GTK_WINDOW(window), WINDOW_WIDTH, WINDOW_HEIGHT); - g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); + gtk_window_set_default_size(GTK_WINDOW(cinnamon.window), WINDOW_WIDTH, WINDOW_HEIGHT); + g_signal_connect(cinnamon.window, "destroy", G_CALLBACK(gtk_main_quit), NULL); - GtkWidget *notebook = gtk_notebook_new(); - gtk_container_add(GTK_CONTAINER(window), notebook); + cinnamon.notebook = gtk_notebook_new(); + gtk_container_add(GTK_CONTAINER(cinnamon.window), cinnamon.notebook); /* Create initial tab */ GtkWidget *webview = webkit_web_view_new(); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), webview, gtk_label_new("New Tab")); + gtk_notebook_append_page(GTK_NOTEBOOK(cinnamon.notebook), webview, gtk_label_new("New Tab")); /* HOMEPAGE defined in config.h */ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), HOMEPAGE); /* handle keypresses */ - g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), notebook); + g_signal_connect(cinnamon.window, "key-press-event", G_CALLBACK(on_key_press), &cinnamon); /* handle tab changes */ - g_signal_connect(webview, "notify::title", G_CALLBACK(on_title_changed), notebook); + g_signal_connect(webview, "notify::title", G_CALLBACK(on_title_changed), cinnamon.notebook); - gtk_widget_show_all(window); + gtk_widget_show_all(cinnamon.window); gtk_main(); return 0; -- cgit v1.2.3