diff options
| -rw-r--r-- | Makefile | 18 | ||||
| -rwxr-xr-x | cinnamon | bin | 0 -> 72440 bytes | |||
| -rw-r--r-- | compile_flags.txt | 1 | ||||
| -rw-r--r-- | config.h | 35 | ||||
| -rw-r--r-- | main.c | 92 |
5 files changed, 146 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..08599a1 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CC = clang +CFLAGS = -std=gnu17 `pkg-config --cflags webkit2gtk-4.1 gtk+-3.0` +LIBS = `pkg-config --libs webkit2gtk-4.1 gtk+-3.0` +TARGET = cinnamon +SRC = main.c + +all: $(TARGET) + +$(TARGET): $(SRC) + $(CC) -o $(TARGET) $(SRC) $(CFLAGS) $(LIBS) + +clean: + rm -f $(TARGET) + +run: $(TARGET) + ./$(TARGET) + +.PHONY: all clean run diff --git a/cinnamon b/cinnamon Binary files differnew file mode 100755 index 0000000..51fdc65 --- /dev/null +++ b/cinnamon diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..7da7515 --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1 @@ +-I/usr/include/webkitgtk-4.1 -I/usr/include/libsoup-3.0 -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/cloudproviders -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glycin-2 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/atk-1.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/fribidi -I/usr/include/pixman-1 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gio-unix-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -pthread -lwebkit2gtk-4.1 -lsoup-3.0 -ljavascriptcoregtk-4.1 -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lcairo-gobject -lgdk_pixbuf-2.0 -latk-1.0 -lpango-1.0 -lcairo -lharfbuzz -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -pthread -lglib-2.0 diff --git a/config.h b/config.h new file mode 100644 index 0000000..08f692d --- /dev/null +++ b/config.h @@ -0,0 +1,35 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#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[] = { + { "<S-o>", ":tab_open" }, + { "d", ":tab_close" }, + { "o", ":commandline_show \":open\"" }, + { "i", ":mode insert" }, + { "<A-1>", ":tab_select 1" }, + { "<A-2>", ":tab_select 2" }, + { "<A-3>", ":tab_select 3" }, + { "<A-4>", ":tab_select 4" }, + { "<A-5>", ":tab_select 5" }, + { "<A-6>", ":tab_select 6" }, + { "<A-7>", ":tab_select 7" }, + { "<A-8>", ":tab_select 8" }, + { "<A-9>", ":tab_select 9" }, + { "<A-0>", ":tab_select 10" }, +}; + +#endif @@ -0,0 +1,92 @@ +#include <webkit2/webkit2.h> +#include <gtk/gtk.h> +#include "config.h" + +/* 0 = normal mode, 1 = insert, 2 = passthrough */ +static int mode = 0; + +static void parse_keybind(const char *key, guint *keyval, GdkModifierType *mods) { + char name[32]; + const char *start; + const char *end; + + *mods = 0; + if (key[0] != '<') { + *keyval = gdk_keyval_from_name(key); + return; + } + + if (strstr(key, "S-")) *mods |= GDK_SHIFT_MASK; + if (strstr(key, "C-")) *mods |= GDK_CONTROL_MASK; + if (strstr(key, "A-")) *mods |= GDK_MOD1_MASK; + + /* everything after the last '-' and before '>' */ + start = strrchr(key, '-') + 1; + end = strchr(key, '>'); + snprintf(name, sizeof(name), "%.*s", (int)(end - start), start); + *keyval = gdk_keyval_from_name(name); +} + +static void on_title_changed(WebKitWebView *webview, GParamSpec *pspec, GtkNotebook *notebook) { + const char *title = webkit_web_view_get_title(webview); + int page = gtk_notebook_page_num(notebook, GTK_WIDGET(webview)); + gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(webview), title ? title : "New Tab"); +} + +static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) { + if (event->keyval == GDK_KEY_colon) { + /* we dont have command bar yet so pretend we did something and printf */ + printf("this should show the command bar\n"); + return TRUE; + } + + for (int i = 0; i < sizeof(keybinds) / sizeof(keybinds[0]); i++) { + guint keyval; + GdkModifierType mods; + parse_keybind(keybinds[i].key, &keyval, &mods); + GdkModifierType relevant = GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK; + if (gdk_keyval_to_lower(event->keyval) == keyval && (event->state & relevant) == mods) { + /* we dont know what to do yet, printf */ + printf("%s\n", keybinds[i].command); + return TRUE; + } + } + + /* event not consumed pass to webview */ + return FALSE; +} + +int main(int argc, char *argv[]) { +#ifndef ObamaPrism + return 1; +#endif + gtk_init(&argc, &argv); + + /* Create a new window and set default size */ + GtkWidget *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); + + GtkWidget *notebook = gtk_notebook_new(); + gtk_container_add(GTK_CONTAINER(window), notebook); + + + /* Create initial tab */ + GtkWidget *webview = webkit_web_view_new(); + gtk_notebook_append_page(GTK_NOTEBOOK(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); + + /* handle tab changes */ + g_signal_connect(webview, "notify::title", G_CALLBACK(on_title_changed), notebook); + + gtk_widget_show_all(window); + gtk_main(); + + return 0; +} + |
