summaryrefslogtreecommitdiff
path: root/rcm-client-receive.c
diff options
context:
space:
mode:
Diffstat (limited to 'rcm-client-receive.c')
-rw-r--r--rcm-client-receive.c112
1 files changed, 64 insertions, 48 deletions
diff --git a/rcm-client-receive.c b/rcm-client-receive.c
index 828d07e..7c54645 100644
--- a/rcm-client-receive.c
+++ b/rcm-client-receive.c
@@ -55,6 +55,7 @@ struct state {
bool editing;
GtkWidget *stack;
GtkWidget *title;
+ GtkWidget *popover;
};
static struct state state;
@@ -215,18 +216,72 @@ static GtkWidget *
new_blank_widget(struct rcbutton *rcb);
static void
+edit_button_ok(GtkButton *button, gpointer user_data)
+{
+ struct rcbutton *rcb = user_data;
+ GtkComboBoxText *keycode_cbox;
+ gchar *keycode;
+
+ keycode_cbox = GTK_COMBO_BOX_TEXT(get_object("edit_button_keycode_value"));
+ keycode = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(keycode_cbox));
+ if (!keycode)
+ goto out;
+
+ printf("New keycode is %s\n", keycode);
+
+ if (rcb->name)
+ g_free(rcb->name);
+
+ if (rcb->button)
+ gtk_widget_destroy(rcb->button);
+
+ rcb->name = keycode;
+ rcb->type = RCBUTTON_TYPE_NORMAL;
+ rcb->button = new_button_widget(rcb, "dummy", 0xf001f001, keycode);
+ gtk_widget_set_sensitive(rcb->button, true);
+ gtk_widget_show_all(rcb->button);
+
+out:
+ gtk_widget_hide(state.popover);
+}
+
+static void
+edit_button_delete(GtkButton *button, gpointer user_data)
+{
+ struct rcbutton *rcb = user_data;
+
+ if (rcb->type == RCBUTTON_TYPE_BLANK)
+ goto out;
+
+ g_free(rcb->name);
+ rcb->name = NULL;
+ rcb->type = RCBUTTON_TYPE_BLANK;
+ gtk_widget_destroy(rcb->button);
+ rcb->button = new_blank_widget(rcb);
+ gtk_revealer_set_reveal_child(GTK_REVEALER(rcb->button), true);
+ gtk_widget_show_all(rcb->button);
+
+out:
+ gtk_widget_hide(state.popover);
+}
+
+static void
edit_button_dialog(GtkButton *button, struct rcbutton *rcb)
{
- GtkWidget *dialog;
GtkComboBoxText *keycode_cbox;
GtkEntry *comment_entry;
- gint r;
GList *ke;
unsigned i;
- dialog = GTK_WIDGET(gtk_builder_get_object(global->builder, "edit_button"));
+ if (!state.popover) {
+ GtkWidget *popover;
- keycode_cbox = GTK_COMBO_BOX_TEXT(gtk_builder_get_object(global->builder, "edit_button_keycode_value"));
+ popover = GTK_WIDGET(get_object("edit_button"));
+ gtk_popover_set_position(GTK_POPOVER(popover), GTK_POS_BOTTOM);
+ state.popover = popover;
+ }
+
+ keycode_cbox = GTK_COMBO_BOX_TEXT(get_object("edit_button_keycode_value"));
gtk_combo_box_text_remove_all(keycode_cbox);
for (ke = rcb->remote->keymap, i = 0; ke; ke = ke->next, i++) {
struct keymap_entry *entry = ke->data;
@@ -236,53 +291,14 @@ edit_button_dialog(GtkButton *button, struct rcbutton *rcb)
gtk_combo_box_set_active(GTK_COMBO_BOX(keycode_cbox), i);
}
- comment_entry = GTK_ENTRY(gtk_builder_get_object(global->builder, "edit_button_comment_value"));
+ comment_entry = GTK_ENTRY(get_object("edit_button_comment_value"));
gtk_entry_set_text(comment_entry, "");
- gtk_widget_show_all(dialog);
-
- r = gtk_dialog_run(GTK_DIALOG(dialog));
- switch (r) {
- case 1: {
- gchar *keycode;
- keycode = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(keycode_cbox));
- if (!keycode)
- goto out;
-
- printf("New keycode is %s\n", keycode);
+ g_signal_replace_id("edit_button_ok", "clicked", G_CALLBACK(edit_button_ok), rcb);
+ g_signal_replace_id("edit_button_delete", "clicked", G_CALLBACK(edit_button_delete), rcb);
- if (rcb->name)
- g_free(rcb->name);
-
- if (rcb->button)
- gtk_widget_destroy(rcb->button);
-
- rcb->name = keycode;
- rcb->type = RCBUTTON_TYPE_NORMAL;
- rcb->button = new_button_widget(rcb, "dummy", 0xf001f001, keycode);
- gtk_widget_show_all(rcb->button);
- break;
- }
-
- case 2:
- if (rcb->type == RCBUTTON_TYPE_BLANK)
- goto out;
-
- g_free(rcb->name);
- rcb->name = NULL;
- rcb->type = RCBUTTON_TYPE_BLANK;
- gtk_widget_destroy(rcb->button);
- rcb->button = new_blank_widget(rcb);
- gtk_revealer_set_reveal_child(GTK_REVEALER(rcb->button), true);
- gtk_widget_show_all(rcb->button);
- break;
-
- default:
- break;
- }
-
-out:
- gtk_widget_hide(dialog);
+ gtk_popover_set_relative_to(GTK_POPOVER(state.popover), GTK_WIDGET(button));
+ gtk_widget_show_all(state.popover);
}
static void