diff options
| author | Arslaan Pathan <[email protected]> | 2026-03-27 15:27:07 +1300 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-03-27 15:27:07 +1300 |
| commit | 3d03dff199e057582b342d8dfd74af971bc2273b (patch) | |
| tree | 630575056ba8937ed87282049e962cd8ec01c9ed /main.c | |
| parent | 7bc8d32de08de78945fd7893a4343875970e0012 (diff) | |
| download | cinnamon-browser-3d03dff199e057582b342d8dfd74af971bc2273b.tar.xz cinnamon-browser-3d03dff199e057582b342d8dfd74af971bc2273b.zip | |
Implement command bar, make Keybinds use functions rather than command strings
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 67 |
1 files changed, 48 insertions, 19 deletions
@@ -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; |
