aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/main.c b/main.c
index 3f61958..bd27028 100644
--- a/main.c
+++ b/main.c
@@ -4,23 +4,31 @@ This software is licensed under the ARPL. See LICENSE for details.
*/
#include <webkit2/webkit2.h>
#include <gtk/gtk.h>
-/* declare BEFORE including config.h so that config.h can reference it */
+
+/* forward declare BEFORE including config.h so that config.h can reference them */
typedef struct {
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *cmdbar;
} Cinnamon;
-#include "config.h"
+typedef struct {
+ const char* key;
+ void (*fptr)(Cinnamon*, void* arg);
+ void* arg;
+} Keybind;
+
+typedef struct {
+ const char* name;
+ void (*fptr)(Cinnamon*, const char *args);
+} Command;
+
+#include "config.h"
/* 0 = normal mode, 1 = insert, 2 = passthrough */
int mode = 0;
bool cmdbar_focused = false;
-void tabopen(Cinnamon* cinnamon) {
- printf("this should open a tab, will implement later\n");
-}
-
static void parse_keybind(const char *key, guint *keyval, GdkModifierType *mods) {
char name[32];
const char *start;
@@ -76,16 +84,30 @@ static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer dat
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 */
- keybinds[i].fptr(cinnamon);
+ keybinds[i].fptr(cinnamon, keybinds[i].arg);
return TRUE;
}
}
+#ifdef NO_SEND_UNBOUND_KEYBINDS
+ /* make sure that outside of insert/passthrough, we still don't send unbound keybinds to the webview */
+ return TRUE;
+#endif
}
/* event not consumed pass to webview */
return FALSE;
}
+void tabopen(Cinnamon* cinnamon) {
+ GtkWidget *webview = webkit_web_view_new();
+ gtk_notebook_append_page(GTK_NOTEBOOK(cinnamon->notebook), webview, gtk_label_new("New Tab"));
+ g_signal_connect(webview, "notify::title", G_CALLBACK(on_title_changed), cinnamon->notebook);
+ /* HOMEPAGE defined in config.h */
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), HOMEPAGE);
+ gtk_widget_show_all(cinnamon->notebook);
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(cinnamon->notebook), -1);
+}
+
int main(int argc, char *argv[]) {
#ifndef ObamaPrism
return 1;
@@ -109,10 +131,7 @@ int main(int argc, char *argv[]) {
gtk_box_pack_start(GTK_BOX(vbox), cinnamon.notebook, TRUE, TRUE, 0);
/* Create initial tab */
- GtkWidget *webview = webkit_web_view_new();
- gtk_notebook_append_page(GTK_NOTEBOOK(cinnamon.notebook), webview, gtk_label_new("New Tab"));
- /* HOMEPAGE defined in config.h */
- webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), HOMEPAGE);
+ tabopen(&cinnamon);
/* Create cmdbar */
/* im sleepy so just add a placeholder commented-out pack for future reference */
@@ -122,9 +141,6 @@ int main(int argc, char *argv[]) {
/* handle keypresses */
g_signal_connect(cinnamon.window, "key-press-event", G_CALLBACK(on_key_press), &cinnamon);
- /* handle tab changes */
- g_signal_connect(webview, "notify::title", G_CALLBACK(on_title_changed), cinnamon.notebook);
-
gtk_widget_show_all(cinnamon.window);
gtk_widget_hide(cinnamon.cmdbar);
gtk_main();