commit e9dffe565c48297d45a6bcf677b5c7c77a2640f2
parent 8946223e127136fe0e1a58ac40e54ea72a7ac88d
Author: lash <dev@holbrook.no>
Date: Tue, 19 Mar 2024 15:08:03 +0000
Add action bar
Diffstat:
8 files changed, 126 insertions(+), 24 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -2,3 +2,4 @@ src/gtk/*.ui
**/*.o
testdata_mdb
*\~
+**/test_*
diff --git a/src/gtk/kee-uicontext.h b/src/gtk/kee-uicontext.h
@@ -9,7 +9,6 @@
#define KEE_W_FRONTLIST "frontlist"
#define KEE_W_CAMERA_VIEWFINDER "camera_view"
#define KEE_W_WINDOW "win"
-#define KEE_W_HEADER "header"
#define KEE_W_PASSPHRASE "passphrase"
#define KEE_ST_UI_HEAD_ADD 0x1
diff --git a/src/gtk/menu.c b/src/gtk/menu.c
@@ -71,53 +71,59 @@ static GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp, KeeUico
return butt;
}
-
-void header_setup(GtkApplication *gapp, KeeUicontext *uctx) {
- GtkWidget *head;
+static void footer_setup(GtkApplication *gapp, KeeUicontext *uctx) {
+ GtkWidget *foot;
GtkWidget *butt;
GtkToggleButton *butt_prev;
- head = gtk_header_bar_new();
-
- butt = menu_button_setup(G_OBJECT(head), gapp, uctx);
- gtk_header_bar_pack_end(GTK_HEADER_BAR(head), butt);
- butt = gtk_button_new_from_icon_name("go-previous");
- gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt);
- gtk_widget_set_visible(butt, false);
-
- butt = gtk_button_new_from_icon_name("insert-object");
- gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt);
- gtk_widget_set_sensitive(butt, false);
- g_object_set_data(G_OBJECT(head), KEE_W_UI_MENU_QUICK_ADD, butt);
+ foot = gtk_action_bar_new();
butt = gtk_toggle_button_new();
gtk_button_set_icon_name(GTK_BUTTON(butt), "insert-image");
- gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt);
+ gtk_action_bar_pack_start(GTK_ACTION_BAR(foot), butt);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(butt), true);
- gtk_widget_set_visible(butt, false);
butt_prev = GTK_TOGGLE_BUTTON(butt);
butt = gtk_toggle_button_new();
gtk_toggle_button_set_group(GTK_TOGGLE_BUTTON(butt), butt_prev);
gtk_button_set_icon_name(GTK_BUTTON(butt), "document-new");
- gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt);
- gtk_widget_set_visible(butt, false);
+ gtk_action_bar_pack_start(GTK_ACTION_BAR(foot), butt);
butt_prev = GTK_TOGGLE_BUTTON(butt);
butt = gtk_toggle_button_new();
gtk_toggle_button_set_group(GTK_TOGGLE_BUTTON(butt), butt_prev);
gtk_button_set_icon_name(GTK_BUTTON(butt), "document-save");
+ gtk_action_bar_pack_start(GTK_ACTION_BAR(foot), butt);
+
+ g_object_set_data(G_OBJECT(uctx), KEE_W_FOOTER, GTK_ACTION_BAR(foot));
+
+ g_signal_connect (uctx, "state", G_CALLBACK(menu_handle_state), foot);
+}
+
+static void header_setup(GtkApplication *gapp, KeeUicontext *uctx) {
+ GtkWidget *head;
+ GtkWidget *butt;
+ head = gtk_header_bar_new();
+
+ butt = menu_button_setup(G_OBJECT(head), gapp, uctx);
+ gtk_header_bar_pack_end(GTK_HEADER_BAR(head), butt);
+
+ butt = gtk_button_new_from_icon_name("go-previous");
gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt);
gtk_widget_set_visible(butt, false);
+ butt = gtk_button_new_from_icon_name("insert-object");
+ gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt);
+ gtk_widget_set_sensitive(butt, false);
+ g_object_set_data(G_OBJECT(head), KEE_W_UI_MENU_QUICK_ADD, butt);
+
g_object_set_data(G_OBJECT(uctx), KEE_W_HEADER, GTK_HEADER_BAR(head));
g_signal_connect (uctx, "state", G_CALLBACK(menu_handle_state), head);
-
-
}
void menu_setup(GtkApplication *gapp, KeeUicontext *uctx) {
header_setup(gapp, uctx);
+ footer_setup(gapp, uctx);
}
diff --git a/src/gtk/menu.h b/src/gtk/menu.h
@@ -3,6 +3,9 @@
#include "kee-uicontext.h"
+#define KEE_W_HEADER "header"
+#define KEE_W_FOOTER "footer"
+
#define KEE_W_UI_MENU_QUICK_ADD "quick_add"
#define KEE_W_UI_MENU_ACT_IMPORT "act_import"
diff --git a/src/gtk/tests/Makefile b/src/gtk/tests/Makefile
@@ -0,0 +1,16 @@
+OBJS := $(patsubst %.c,%.o,$(wildcard *.c))
+LINKOBJS := $(wildcard ../../*.o) $(wildcard ../*.o) ../../aux/varint/varint.o
+INCLUDES := -I../.. -I..
+CFLAGS += `pkg-config --cflags gtk4 gstreamer-1.0` $(INCLUDES) -g3 -Wall
+LIBS := `pkg-config --libs gtk4 zlib lmdb libgcrypt libxdg-basedir gstreamer-1.0` -lb64
+LDFLAGS += $(LIBS)
+
+all: $(OBJS)
+
+%.o: %.c
+ $(CC) $(CFLAGS) $< -o test_$* $(LINKOBJS) $(LDFLAGS)
+
+test_run: $(wildcard test_*)
+ ./$<
+
+test: all test_run
diff --git a/src/gtk/tests/nav.c b/src/gtk/tests/nav.c
@@ -0,0 +1,37 @@
+#include <gtk/gtk.h>
+
+#include "nav.h"
+
+int main(int argc, char **argv) {
+ struct KeeNav nav;
+ GtkWidget *a;
+ GtkWidget *b;
+ GtkWidget *r;
+
+ gtk_init();
+ a = gtk_label_new("foo");
+ b = gtk_label_new("bar");
+
+ kee_nav_push(&nav, a);
+ kee_nav_push(&nav, b);
+ r = kee_nav_pop(&nav);
+ if (r != b) {
+ return 1;
+ }
+ kee_nav_push(&nav, b);
+ r = kee_nav_pop(&nav);
+ if (r != b) {
+ return 1;
+ }
+ r = kee_nav_pop(&nav);
+ if (r != a) {
+ return 1;
+ }
+
+ r = kee_nav_pop(&nav);
+ if (r) {
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -9,6 +9,7 @@
#include "context.h"
#include "state.h"
#include "view.h"
+#include "menu.h"
static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) {
@@ -168,13 +169,14 @@ static GtkWidget* ui_build_view(KeeUicontext *uctx) {
void ui_build(GtkApplication *app, KeeUicontext *uctx) {
GtkWidget *widget;
GtkWidget *win;
+ GtkWidget *box;
GtkWidget *stack;
win = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (win), "kee");
gtk_window_set_default_size (GTK_WINDOW (win), 800, 600);
-
+
stack = gtk_stack_new();
kee_view_init(GTK_STACK(stack));
@@ -190,12 +192,20 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) {
kee_view_next("view");
kee_view_next("unlock");
- gtk_window_set_child(GTK_WINDOW(win), GTK_WIDGET(stack));
widget = g_object_get_data(G_OBJECT(uctx), KEE_W_HEADER);
gtk_window_set_titlebar(GTK_WINDOW(win), widget);
g_object_set_data(G_OBJECT(uctx), KEE_W_WINDOW, GTK_WINDOW(win));
+ box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_vexpand(box, true);
+ gtk_box_append(GTK_BOX(box), stack);
+
+ widget = g_object_get_data(G_OBJECT(uctx), KEE_W_FOOTER);
+ gtk_box_append(GTK_BOX(box), widget);
+
+ gtk_window_set_child(GTK_WINDOW(win), box);
+
gtk_window_present(GTK_WINDOW (win));
}
diff --git a/src/state.c b/src/state.c
@@ -0,0 +1,30 @@
+#include <string.h>
+
+#include "state.h"
+
+
+void kee_state_zero(kee_state_t *state) {
+ memset(state, 0, sizeof(kee_state_t));
+}
+
+char kee_state_add(kee_state_t *target, kee_state_t *delta) {
+ char hint;
+
+ hint = 0;
+ if (delta->ui_menu) {
+ target->ui_menu |= delta->ui_menu;
+ hint |= KEE_ST_HINT_UI_MENU;
+ }
+ if (delta->key) {
+ target->key |= delta->key;
+ hint |= KEE_ST_HINT_KEY;
+ }
+ return hint;
+}
+
+char kee_state_sub(kee_state_t *target, kee_state_t *delta) {
+ char hint;
+
+ hint = 0;
+ return hint;
+}