diff --git a/include/application.h b/include/application.h index 8dcfca1..648d7ab 100644 --- a/include/application.h +++ b/include/application.h @@ -6,3 +6,4 @@ bool application_init(struct swappy_state *state); int application_run(struct swappy_state *state); void application_finish(struct swappy_state *state); +void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state); \ No newline at end of file diff --git a/meson.build b/meson.build index 0ed0245..567030a 100644 --- a/meson.build +++ b/meson.build @@ -53,6 +53,7 @@ executable( wayland_client, wayland_cursor, ], + link_args: '-rdynamic', include_directories: [swappy_inc], install: true, ) diff --git a/res/swappy.ui b/res/swappy.ui index d32828d..fcd96ad 100644 --- a/res/swappy.ui +++ b/res/swappy.ui @@ -162,6 +162,7 @@ True True True + diff --git a/src/application.c b/src/application.c index 433e742..6aee5b4 100644 --- a/src/application.c +++ b/src/application.c @@ -18,6 +18,11 @@ static void swappy_overlay_clear(struct swappy_state *state) { } } +static void switch_mode_to_brush(struct swappy_state *state) { + g_debug("switching mode to brush"); + state->mode = SWAPPY_PAINT_MODE_BRUSH; +} + void application_finish(struct swappy_state *state) { g_debug("application is shutting down"); swappy_overlay_clear(state); @@ -29,6 +34,10 @@ void application_finish(struct swappy_state *state) { g_object_unref(state->app); } +void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state) { + switch_mode_to_brush(state); +} + static gboolean draw_area_handler(GtkWidget *widget, cairo_t *cr, struct swappy_state *state) { cairo_set_source_surface(cr, state->cairo_surface, 0, 0); @@ -119,12 +128,13 @@ static void tools_menu_button_copy_clicked_handler(GtkToggleButton *source, } static void keypress_handler(GtkWidget *widget, GdkEventKey *event, - gpointer data) { - struct swappy_state *state = data; + struct swappy_state *state) { g_debug("keypress_handler key pressed: %d\n", event->keyval); if (event->keyval == GDK_KEY_Escape) { g_debug("keypress_handler: escape key pressed, ciao bye\n"); gtk_window_close(state->window); + } else if (event->keyval == GDK_KEY_B || event->keyval == GDK_KEY_b) { + switch_mode_to_brush(state); } } @@ -232,6 +242,8 @@ static bool load_layout(struct swappy_state *state) { area = GTK_WIDGET(gtk_builder_get_object(builder, "paint_area")); popover = GTK_POPOVER(gtk_builder_get_object(builder, "popover")); + gtk_builder_connect_signals(builder, state); + g_signal_connect(G_OBJECT(state->window), "key_press_event", G_CALLBACK(keypress_handler), state); g_signal_connect(brush, "toggled",