aboutsummaryrefslogtreecommitdiff
path: root/config.def.h
blob: d7af70e9776f28a7cc6c716c20495b5a95a4b1f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* This file is released into the public domain.
 * No rights reserved. Copy, modify, do whatever you want. */

#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"
/* 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) {
	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\");";
	}

	/* 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", &_kbd_tabclose, NULL },
	// { "o", ":commandline_show \":open\"" },
	{ "i", &_kbd_insmode, NULL },
	{ "j", &_kbd_scroll, "down" },
	{ "k", &_kbd_scroll, "up" },
	{ "h", &_kbd_scroll, "left" },
	{ "l", &_kbd_scroll, "right" },
	{ "<A-1>", &_kbd_tabsel, (void*)(intptr_t)0 },
	{ "<A-2>", &_kbd_tabsel, (void*)(intptr_t)1 },
	{ "<A-3>", &_kbd_tabsel, (void*)(intptr_t)2 },
	{ "<A-4>", &_kbd_tabsel, (void*)(intptr_t)3 },
	{ "<A-5>", &_kbd_tabsel, (void*)(intptr_t)4 },
	{ "<A-6>", &_kbd_tabsel, (void*)(intptr_t)5 },
	{ "<A-7>", &_kbd_tabsel, (void*)(intptr_t)6 },
	{ "<A-8>", &_kbd_tabsel, (void*)(intptr_t)7 },
	{ "<A-9>", &_kbd_tabsel, (void*)(intptr_t)8 },
	{ "<A-0>", &_kbd_tabsel, (void*)(intptr_t)-1 },
};

#endif