diff options
| -rw-r--r-- | config.def.h | 23 | ||||
| -rw-r--r-- | main.c | 18 |
2 files changed, 34 insertions, 7 deletions
diff --git a/config.def.h b/config.def.h index 6bda445..d7af70e 100644 --- a/config.def.h +++ b/config.def.h @@ -4,21 +4,27 @@ #ifndef CONFIG_H #define CONFIG_H +#include <webkit2/webkit2.h> +#include <gtk/gtk.h> + /* forward declarations from main.c */ extern int mode; /* Cinnamon is declared in main.c before including config.h. Yes, I know this code is held together by hopes and dreams, but good enough. */ extern void tabopen(Cinnamon* cinnamon); +extern void tabclose(Cinnamon* cinnamon); + +/* guard to ensure config.h isnt empty or something + * if not defined, main will exit with code 1 */ +#define CINNAMON_ENABLED /* 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 /* if a keybind is unbound, still don't send when not in insert mode */ #define NO_SEND_UNBOUND_KEYBINDS +/* if the last tab is closed, don't quit, just make a fresh one */ +#define NO_QUIT_ON_CLOSE_LAST_TAB /* Keybind definitions */ static void _kbd_insmode(Cinnamon* cinnamon, void* arg) { @@ -45,16 +51,21 @@ static void _kbd_scroll(Cinnamon* cinnamon, void* arg) { js = "alert(\"an unexpected error occurred in the scroll handler\");"; } - webkit_web_view_evaluate_javascript(WEBKIT_WEB_VIEW(webview), js, -1, NULL, NULL, NULL, NULL, NULL); + /* some distros ship older versions of webkit2gtk-4.1, use the deprecated run_javascript api to ensure compatibility */ + webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(webview), js, NULL, NULL, NULL); } static void _kbd_tabsel(Cinnamon* cinnamon, void* arg) { gtk_notebook_set_current_page(GTK_NOTEBOOK(cinnamon->notebook), (int)(intptr_t)arg); } +static void _kbd_tabclose(Cinnamon* cinnamon, void* arg) { + tabclose(cinnamon); +} + static const Keybind keybinds[] = { { "<S-o>", &_kbd_tabopen, NULL }, - // { "d", ":tab_close" }, + { "d", &_kbd_tabclose, NULL }, // { "o", ":commandline_show \":open\"" }, { "i", &_kbd_insmode, NULL }, { "j", &_kbd_scroll, "down" }, @@ -108,8 +108,24 @@ void tabopen(Cinnamon* cinnamon) { gtk_notebook_set_current_page(GTK_NOTEBOOK(cinnamon->notebook), -1); } +void tabclose(Cinnamon* cinnamon) { + int page = gtk_notebook_get_current_page(GTK_NOTEBOOK(cinnamon->notebook)); + + /* dont close last tab */ + if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(cinnamon->notebook)) > 1) { + gtk_notebook_remove_page(GTK_NOTEBOOK(cinnamon->notebook), page); + } else { +#ifdef NO_QUIT_ON_CLOSE_LAST_TAB + tabopen(cinnamon); + gtk_notebook_remove_page(GTK_NOTEBOOK(cinnamon->notebook), page); + return; +#endif + gtk_main_quit(); + } +} + int main(int argc, char *argv[]) { -#ifndef ObamaPrism +#ifndef CINNAMON_ENABLED return 1; #endif gtk_init(&argc, &argv); |
