From 57db20f454b74aaaa90db69169656d23bb831e25 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Sat, 4 Apr 2026 23:19:01 +1300 Subject: Make command bar work and add search stuff --- config.def.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'config.def.h') diff --git a/config.def.h b/config.def.h index 587e85b..3e2b792 100644 --- a/config.def.h +++ b/config.def.h @@ -18,6 +18,8 @@ extern void set_mode(Cinnamon* cinnamon, int new_mode); /* default window width/height, can be resized after. */ #define WINDOW_WIDTH 1024 #define WINDOW_HEIGHT 768 +/* searchengine/homepage */ +#define SEARCH_ENGINE "https://duckduckgo.com/?q=" #define HOMEPAGE "https://start.duckduckgo.com" /* if a keybind is unbound, still don't send when not in insert mode */ #define NO_SEND_UNBOUND_KEYBINDS @@ -100,4 +102,36 @@ static const Keybind keybinds[] = { { "", &_kbd_tabsel, (void*)(intptr_t)-1 }, }; +/* Command definitions */ + +/* as mentioned above, prefixes like _cmd and _kbd are for good practice but in your modified configs you can do what you want. i don't care, i just make the software, do what you want with your config */ +static void _cmd_open(Cinnamon* cinnamon, const char* args) { + GtkWidget *webview = gtk_notebook_get_nth_page(GTK_NOTEBOOK(cinnamon->notebook), gtk_notebook_get_current_page(GTK_NOTEBOOK(cinnamon->notebook))); + + char uri[2048]; + if (strncmp(args, "http://", 7) == 0 || strncmp(args, "https://", 8) == 0) { + snprintf(uri, sizeof(uri), "%s", args); + } else if (strchr(args, '.') && !strchr(args, ' ')) { + /* has a dot and no spaces, probably a domain */ + /* if it's not, oh well, too bad so sad */ + snprintf(uri, sizeof(uri), "https://%s", args); + } else { + /* urlencode magic */ + char encoded[1024]; + int j = 0; + for (int i = 0; args[i] && j < (int)sizeof(encoded)-1; i++) { + if (args[i] == ' ') encoded[j++] = '+'; + else encoded[j++] = args[i]; + } + encoded[j] = '\0'; + snprintf(uri, sizeof(uri), SEARCH_ENGINE "%s", encoded); + } + + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), uri); +} + +static const Command commands[] = { + { "open", &_cmd_open } +}; + #endif -- cgit v1.2.3