From a1a34c7fb00aba61666b1cec9adac901f82673df Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Fri, 27 Mar 2026 22:13:02 +1300 Subject: Many improvements, arguments in keybind handlers, more default functions --- config.def.h | 70 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 21 deletions(-) (limited to 'config.def.h') diff --git a/config.def.h b/config.def.h index 485c3b5..6bda445 100644 --- a/config.def.h +++ b/config.def.h @@ -4,10 +4,10 @@ #ifndef CONFIG_H #define CONFIG_H -/* forward declarations */ -int mode; +/* 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. */ -void tabopen(Cinnamon* cinnamon); +extern void tabopen(Cinnamon* cinnamon); /* default window width/height, can be resized after. */ #define WINDOW_WIDTH 1024 @@ -17,32 +17,60 @@ void tabopen(Cinnamon* cinnamon); 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 /* Keybind definitions */ -typedef struct { - const char* key; - void (*fptr)(Cinnamon*); -} Keybind; - -static void _insmode(Cinnamon* cinnamon) { +static void _kbd_insmode(Cinnamon* cinnamon, void* arg) { mode = 1; } +static void _kbd_tabopen(Cinnamon* cinnamon, void* arg) { + /* wrapper to satisfy the arg + keep keybinds isolated */ + tabopen(cinnamon); +} + +static void _kbd_scroll(Cinnamon* cinnamon, void* arg) { + GtkWidget *webview = gtk_notebook_get_nth_page(GTK_NOTEBOOK(cinnamon->notebook), gtk_notebook_get_current_page(GTK_NOTEBOOK(cinnamon->notebook))); + const char* js; + if (strcmp((const char*)arg, "left") == 0) { + js = "window.scrollBy(-100, 0);"; + } else if (strcmp((const char*)arg, "right") == 0) { + js = "window.scrollBy(100, 0);"; + } else if (strcmp((const char*)arg, "up") == 0) { + js = "window.scrollBy(0, -100);"; + } else if (strcmp((const char*)arg, "down") == 0) { + js = "window.scrollBy(0, 100);"; + } else { + 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); +} + +static void _kbd_tabsel(Cinnamon* cinnamon, void* arg) { + gtk_notebook_set_current_page(GTK_NOTEBOOK(cinnamon->notebook), (int)(intptr_t)arg); +} + static const Keybind keybinds[] = { - { "", &tabopen }, + { "", &_kbd_tabopen, NULL }, // { "d", ":tab_close" }, // { "o", ":commandline_show \":open\"" }, - { "i", &_insmode }, - // { "", ":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" }, + { "i", &_kbd_insmode, NULL }, + { "j", &_kbd_scroll, "down" }, + { "k", &_kbd_scroll, "up" }, + { "h", &_kbd_scroll, "left" }, + { "l", &_kbd_scroll, "right" }, + { "", &_kbd_tabsel, (void*)(intptr_t)0 }, + { "", &_kbd_tabsel, (void*)(intptr_t)1 }, + { "", &_kbd_tabsel, (void*)(intptr_t)2 }, + { "", &_kbd_tabsel, (void*)(intptr_t)3 }, + { "", &_kbd_tabsel, (void*)(intptr_t)4 }, + { "", &_kbd_tabsel, (void*)(intptr_t)5 }, + { "", &_kbd_tabsel, (void*)(intptr_t)6 }, + { "", &_kbd_tabsel, (void*)(intptr_t)7 }, + { "", &_kbd_tabsel, (void*)(intptr_t)8 }, + { "", &_kbd_tabsel, (void*)(intptr_t)-1 }, }; #endif -- cgit v1.2.3