aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h40
-rw-r--r--main.c67
2 files changed, 72 insertions, 35 deletions
diff --git a/config.def.h b/config.def.h
index 8ea25ec..485c3b5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -4,6 +4,11 @@
#ifndef CONFIG_H
#define CONFIG_H
+/* forward declarations */
+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);
+
/* default window width/height, can be resized after. */
#define WINDOW_WIDTH 1024
#define WINDOW_HEIGHT 768
@@ -16,25 +21,28 @@
/* Keybind definitions */
typedef struct {
const char* key;
- const char* command;
+ void (*fptr)(Cinnamon*);
} Keybind;
-/* TODO: make this use functions and not command strings */
+static void _insmode(Cinnamon* cinnamon) {
+ mode = 1;
+}
+
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" },
+ { "<S-o>", &tabopen },
+ // { "d", ":tab_close" },
+ // { "o", ":commandline_show \":open\"" },
+ { "i", &_insmode },
+ // { "<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
diff --git a/main.c b/main.c
index d5321a0..3f61958 100644
--- a/main.c
+++ b/main.c
@@ -4,17 +4,22 @@ This software is licensed under the ARPL. See LICENSE for details.
*/
#include <webkit2/webkit2.h>
#include <gtk/gtk.h>
-#include "config.h"
-
-/* struct so we can easily pass objects around. will actually use this in code later */
+/* declare BEFORE including config.h so that config.h can reference it */
typedef struct {
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *cmdbar;
} Cinnamon;
+#include "config.h"
+
/* 0 = normal mode, 1 = insert, 2 = passthrough */
-static int mode = 0;
+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];
@@ -45,22 +50,36 @@ static void on_title_changed(WebKitWebView *webview, GParamSpec *pspec, GtkNoteb
}
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;
+ Cinnamon* cinnamon = (Cinnamon*)data;
+ if (mode == 1 || mode == 2) {
+ if (mode == 1 && event->keyval == GDK_KEY_Escape) {
+ mode = 0;
+ if (cmdbar_focused) {
+ gtk_widget_hide(cinnamon->cmdbar);
+ cmdbar_focused = false;
+ }
+ }
}
-
- 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);
+ else {
+ if (event->keyval == GDK_KEY_colon) {
+ gtk_widget_show(cinnamon->cmdbar);
+ gtk_widget_grab_focus(cinnamon->cmdbar);
+ cmdbar_focused = true;
+ mode = 1;
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 */
+ keybinds[i].fptr(cinnamon);
+ return TRUE;
+ }
+ }
}
/* event not consumed pass to webview */
@@ -81,9 +100,13 @@ int main(int argc, char *argv[]) {
gtk_window_set_default_size(GTK_WINDOW(cinnamon.window), WINDOW_WIDTH, WINDOW_HEIGHT);
g_signal_connect(cinnamon.window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
- cinnamon.notebook = gtk_notebook_new();
- gtk_container_add(GTK_CONTAINER(cinnamon.window), cinnamon.notebook);
+ /* Create a vertical GtkBox for layout stuff */
+ GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ gtk_container_add(GTK_CONTAINER(cinnamon.window), vbox);
+ cinnamon.notebook = gtk_notebook_new();
+ // gtk_container_add(GTK_CONTAINER(cinnamon.window), cinnamon.notebook);
+ gtk_box_pack_start(GTK_BOX(vbox), cinnamon.notebook, TRUE, TRUE, 0);
/* Create initial tab */
GtkWidget *webview = webkit_web_view_new();
@@ -91,6 +114,11 @@ int main(int argc, char *argv[]) {
/* HOMEPAGE defined in config.h */
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), HOMEPAGE);
+ /* Create cmdbar */
+ /* im sleepy so just add a placeholder commented-out pack for future reference */
+ cinnamon.cmdbar = gtk_entry_new();
+ gtk_box_pack_end(GTK_BOX(vbox), cinnamon.cmdbar, FALSE, FALSE, 0);
+
/* handle keypresses */
g_signal_connect(cinnamon.window, "key-press-event", G_CALLBACK(on_key_press), &cinnamon);
@@ -98,6 +126,7 @@ int main(int argc, char *argv[]) {
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();
return 0;