aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h18
-rw-r--r--main.c24
2 files changed, 32 insertions, 10 deletions
diff --git a/config.def.h b/config.def.h
index d7af70e..76df792 100644
--- a/config.def.h
+++ b/config.def.h
@@ -8,13 +8,11 @@
#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);
+extern void set_mode(Cinnamon* cinnamon, int new_mode);
-/* guard to ensure config.h isnt empty or something
- * if not defined, main will exit with code 1 */
+/* guard ensures config exists/enables brower */
#define CINNAMON_ENABLED
/* default window width/height, can be resized after. */
@@ -25,10 +23,13 @@ extern void tabclose(Cinnamon* cinnamon);
#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
+/* hide the tab bar, unless a keybind or command shows it */
+#define HIDE_TAB_BAR
/* Keybind definitions */
+/* we use the _kbd prefix here just because, idk, good practice to keep keybinds isolated? in practice use whatever the hell you want as long as it doesnt interfere with builtin functions */
static void _kbd_insmode(Cinnamon* cinnamon, void* arg) {
- mode = 1;
+ set_mode(cinnamon, 1);
}
static void _kbd_tabopen(Cinnamon* cinnamon, void* arg) {
@@ -52,6 +53,11 @@ static void _kbd_scroll(Cinnamon* cinnamon, void* arg) {
}
/* some distros ship older versions of webkit2gtk-4.1, use the deprecated run_javascript api to ensure compatibility */
+ /* this entire scroll mechanism is scuffed, first of all, i should have abstracted that in main.c, second of all, we're using JS apis of all things just to scroll T_T */
+ /* this code sucks,
+ * you know it,
+ * i know it.
+ * call me an idiot later and just use the browser. */
webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(webview), js, NULL, NULL, NULL);
}
@@ -64,7 +70,7 @@ static void _kbd_tabclose(Cinnamon* cinnamon, void* arg) {
}
static const Keybind keybinds[] = {
- { "<S-o>", &_kbd_tabopen, NULL },
+ { "t", &_kbd_tabopen, NULL },
{ "d", &_kbd_tabclose, NULL },
// { "o", ":commandline_show \":open\"" },
{ "i", &_kbd_insmode, NULL },
diff --git a/main.c b/main.c
index 811bd6a..5f2ef12 100644
--- a/main.c
+++ b/main.c
@@ -10,6 +10,7 @@ typedef struct {
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *cmdbar;
+ GtkWidget *indicator;
} Cinnamon;
typedef struct {
@@ -26,7 +27,7 @@ typedef struct {
#include "config.h"
/* 0 = normal mode, 1 = insert, 2 = passthrough */
-int mode = 0;
+static int mode = 0;
bool cmdbar_focused = false;
static void parse_keybind(const char *key, guint *keyval, GdkModifierType *mods) {
@@ -61,7 +62,7 @@ static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer dat
Cinnamon* cinnamon = (Cinnamon*)data;
if (mode == 1 || mode == 2) {
if (mode == 1 && event->keyval == GDK_KEY_Escape) {
- mode = 0;
+ set_mode(cinnamon, 0);
if (cmdbar_focused) {
gtk_widget_hide(cinnamon->cmdbar);
cmdbar_focused = false;
@@ -73,7 +74,7 @@ static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer dat
gtk_widget_show(cinnamon->cmdbar);
gtk_widget_grab_focus(cinnamon->cmdbar);
cmdbar_focused = true;
- mode = 1;
+ set_mode(cinnamon, 1);
return TRUE;
}
@@ -98,6 +99,15 @@ static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer dat
return FALSE;
}
+void set_mode(Cinnamon* cinnamon, int new_mode) {
+ mode = new_mode;
+ switch (new_mode) {
+ case 0: gtk_label_set_text(GTK_LABEL(cinnamon->indicator), "-- NORMAL --"); break;
+ case 1: gtk_label_set_text(GTK_LABEL(cinnamon->indicator), "-- INSERT --"); break;
+ case 2: gtk_label_set_text(GTK_LABEL(cinnamon->indicator), "-- PASSTHROUGH --"); break;
+ }
+}
+
void tabopen(Cinnamon* cinnamon) {
GtkWidget *webview = webkit_web_view_new();
gtk_notebook_append_page(GTK_NOTEBOOK(cinnamon->notebook), webview, gtk_label_new("New Tab"));
@@ -149,8 +159,11 @@ int main(int argc, char *argv[]) {
/* Create initial tab */
tabopen(&cinnamon);
+ /* Indicator label */
+ cinnamon.indicator = gtk_label_new("-- NORMAL --");
+ gtk_box_pack_end(GTK_BOX(vbox), cinnamon.indicator, FALSE, FALSE, 0);
+
/* 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);
@@ -159,6 +172,9 @@ int main(int argc, char *argv[]) {
gtk_widget_show_all(cinnamon.window);
gtk_widget_hide(cinnamon.cmdbar);
+#ifdef HIDE_TAB_BAR
+ gtk_notebook_set_show_tabs(GTK_NOTEBOOK(cinnamon.notebook), FALSE);
+#endif
gtk_main();
return 0;