aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/main.c b/main.c
index f585465..55432ab 100644
--- a/main.c
+++ b/main.c
@@ -59,6 +59,35 @@ static void on_title_changed(WebKitWebView *webview, GParamSpec *pspec, GtkNoteb
gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(webview), title ? title : "New Tab");
}
+static gboolean on_cmdbar_activate(GtkEntry *entry, gpointer data) {
+ Cinnamon* cinnamon = (Cinnamon*)data;
+ const char *input = gtk_entry_get_text(entry);
+
+ char cmd[64];
+ const char *args = "";
+ const char *space = strchr(input, ' ');
+
+ if (space) {
+ snprintf(cmd, sizeof(cmd), "%.*s", (int)(space - input), input);
+ args = space + 1;
+ } else {
+ snprintf(cmd, sizeof(cmd), "%s", input);
+ }
+
+ /* commands array defined in config.h */
+ for (int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) {
+ if (strcmp(commands[i].name, cmd) == 0) {
+ commands[i].fptr(cinnamon, args);
+ break;
+ }
+ }
+
+ gtk_entry_set_text(entry, "");
+ gtk_widget_hide(cinnamon->cmdbar);
+ cmdbar_focused = false;
+ set_mode(cinnamon, 0);
+}
+
static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) {
Cinnamon* cinnamon = (Cinnamon*)data;
GdkModifierType relevant = GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK;
@@ -83,12 +112,12 @@ static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer dat
return TRUE;
}
+ /* keybinds array defined in config.h */
for (int i = 0; i < sizeof(keybinds) / sizeof(keybinds[0]); i++) {
guint keyval;
GdkModifierType mods;
parse_keybind(keybinds[i].key, &keyval, &mods);
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].arg);
return TRUE;
}
@@ -174,6 +203,9 @@ int main(int argc, char *argv[]) {
/* handle keypresses */
g_signal_connect(cinnamon.window, "key-press-event", G_CALLBACK(on_key_press), &cinnamon);
+ /* handle commands from cmdbar */
+ g_signal_connect(cinnamon.cmdbar, "activate", G_CALLBACK(on_cmdbar_activate), &cinnamon);
+
gtk_widget_show_all(cinnamon.window);
gtk_widget_hide(cinnamon.cmdbar);
#ifdef HIDE_TAB_BAR