From eff35c23402d9c5f435a1ee0111e87bab88b9481 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Thu, 9 Jul 2015 23:42:41 +0200 Subject: Add a skeleton dialog when a button is clicked in edit mode --- rcm-client-receive.c | 54 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/rcm-client-receive.c b/rcm-client-receive.c index 36c34eb..8b2fc6f 100644 --- a/rcm-client-receive.c +++ b/rcm-client-receive.c @@ -18,6 +18,7 @@ struct remote { guint width; guint height; struct rcbutton *hover; + bool editing; }; struct rcbutton { @@ -89,6 +90,7 @@ draw_curve_rectangle(cairo_t * cr, struct rcbutton *rcb) gdk_cairo_set_source_rgba(cr, rcb->color); else gdk_cairo_set_source_rgba(cr, rcb->clicked ? cre : cd); + cairo_fill_preserve(cr); gdk_cairo_set_source_rgba(cr, cb); @@ -263,6 +265,23 @@ button_redraw(struct rcbutton *rcb, GtkWidget *widget) rcb->width + 2, rcb->height + 2); } +static void +quick_message(GtkWindow *parent, gchar *message) +{ + GtkWidget *dialog, *label, *content_area; + GtkDialogFlags flags; + + flags = GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL; + + dialog = gtk_dialog_new_with_buttons("Message", parent, flags, "OK", + GTK_RESPONSE_NONE, NULL); + content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + label = gtk_label_new(message); + g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); + gtk_container_add(GTK_CONTAINER(content_area), label); + gtk_widget_show_all(dialog); +} + static gboolean button_press_event_cb(GtkWidget *widget, GdkEventButton *event, @@ -270,7 +289,6 @@ button_press_event_cb(GtkWidget *widget, { struct rcbutton *rcb; GList *l; - char buf[1024]; if (event->button != GDK_BUTTON_PRIMARY) return true; @@ -284,10 +302,15 @@ button_press_event_cb(GtkWidget *widget, if (event->y < rcb->y || event->y > (rcb->y + rcb->height)) continue; - rcb->clicked = true; - button_redraw(rcb, widget); - sprintf(buf, "Button at %ux%u clicked\n", rcb->x, rcb->y); - poke_objects(); + if (remote->editing) { + printf("Button at %ux%u clicked in edit mode\n", rcb->x, rcb->y); + quick_message(GTK_WINDOW(gtk_widget_get_toplevel(widget)), "Edit button pressed"); + } else { + rcb->clicked = true; + button_redraw(rcb, widget); + printf("Button at %ux%u clicked\n", rcb->x, rcb->y); + poke_objects(); + } } return true; @@ -319,9 +342,9 @@ button_release_event_cb(GtkWidget *widget, } static gboolean -motion_notify_event_cb (GtkWidget *widget, - GdkEventMotion *event, - gpointer data) +motion_notify_event_cb(GtkWidget *widget, + GdkEventMotion *event, + gpointer data) { struct rcbutton *rcb; static GdkCursor *cursor = NULL; @@ -416,7 +439,7 @@ static void edit_keymap(GtkButton *button, gpointer user_data) { guint i; - gboolean *do_edit = user_data; + //struct remote *remote = user_data; struct rcbutton *rcb; g_print("Button clicked\n"); @@ -424,7 +447,7 @@ edit_keymap(GtkButton *button, gpointer user_data) if (remote->width < 1 || remote->height < 1) return; - if (!*do_edit) { + if (!remote->editing) { move_buttons(2, 2); new_button_add("+", &cgreen, 2, 1, remote->width, 1); new_button_add("+", &cgreen, 2, 2 + remote->height, remote->width, 1); @@ -451,7 +474,6 @@ edit_keymap(GtkButton *button, gpointer user_data) */ gtk_widget_queue_draw(da); - *do_edit = true; } else { GList *l = remote->buttons; @@ -468,22 +490,19 @@ edit_keymap(GtkButton *button, gpointer user_data) } move_buttons(-2, -2); gtk_widget_queue_draw(da); - *do_edit = false; - } + remote->editing = !remote->editing; } static void on_notebook_page_change(GtkNotebook *notebook, GtkWidget *page, guint new_page_num, gpointer user_data) { - static gboolean do_edit = false; - if (new_page_num != own_page_num) { if (header_button) { gtk_widget_destroy(header_button); header_button = NULL; - do_edit = false; + remote->editing = false; } return; } @@ -491,7 +510,7 @@ on_notebook_page_change(GtkNotebook *notebook, GtkWidget *page, guint new_page_n GtkWidget *test = gtk_button_new_from_icon_name("gtk-add", GTK_ICON_SIZE_BUTTON); gtk_button_set_label(GTK_BUTTON(test), "Edit Keymap"); gtk_button_set_always_show_image(GTK_BUTTON(test), TRUE); - g_signal_connect(test, "clicked", G_CALLBACK(edit_keymap), &do_edit); + g_signal_connect(test, "clicked", G_CALLBACK(edit_keymap), &remote); gtk_widget_show_all(test); gtk_header_bar_pack_end(GTK_HEADER_BAR(global->header), test); header_button = test; @@ -533,6 +552,7 @@ void rcng_client_receive_init_ui(GDBusObject *new_hw) remote = g_malloc0(sizeof(*remote)); remote->width = km_width; remote->height = km_height; + remote->editing = false; g_print("type of keymaps is %s\n", g_variant_get_type_string(km_entries)); GVariantIter iter; -- cgit v1.2.3