summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2015-09-01 21:34:05 +0200
committerDavid Härdeman <david@hardeman.nu>2015-09-01 21:34:05 +0200
commit08098b86c58fb3280191258eeb32c025d7c42feb (patch)
tree79be247ffa84f524029047afbab045bec30cf1d0
parent0a9be50b38fc44100d727a60ab487b46f44b605a (diff)
Change button editing from a GtkDialog to a GtkPopover
-rw-r--r--rcm-client-receive.c112
-rw-r--r--rcm-client.ui258
2 files changed, 172 insertions, 198 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
diff --git a/rcm-client.ui b/rcm-client.ui
index 5aaabb0..2880b1a 100644
--- a/rcm-client.ui
+++ b/rcm-client.ui
@@ -779,6 +779,114 @@ Show raw events received from the kernel</property>
<action-widget response="0">advanced_add_cancel</action-widget>
</action-widgets>
</object>
+ <object class="GtkPopover" id="edit_button">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkGrid" id="edit_button_grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">12</property>
+ <property name="margin_right">12</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <property name="row_spacing">12</property>
+ <property name="column_spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="edit_button_keycode_label">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Keycode</property>
+ <property name="xalign">1</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="edit_button_comment_label">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Comment</property>
+ <property name="xalign">1</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="edit_button_keycode_value">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="edit_button_comment_value">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="max_length">100</property>
+ <property name="placeholder_text" translatable="yes">No comment</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButtonBox" id="edit_button_action_area">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">center</property>
+ <child>
+ <object class="GtkButton" id="edit_button_delete">
+ <property name="label" translatable="yes">Delete</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <style>
+ <class name="destructive-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="edit_button_ok">
+ <property name="label" translatable="yes">OK</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
<object class="GtkAdjustment" id="keymap_properties_height_adjustment">
<property name="lower">1</property>
<property name="upper">100</property>
@@ -921,156 +1029,6 @@ Currently connected receivers/transmitters</property>
</object>
</child>
</object>
- <object class="GtkDialog" id="edit_button">
- <property name="can_focus">False</property>
- <property name="title" translatable="yes">Edit Button</property>
- <property name="modal">True</property>
- <property name="destroy_with_parent">True</property>
- <property name="type_hint">dialog</property>
- <property name="transient_for">main_window</property>
- <child internal-child="vbox">
- <object class="GtkBox" id="edit_button_vbox">
- <property name="can_focus">False</property>
- <property name="margin_left">18</property>
- <property name="margin_right">18</property>
- <property name="margin_top">18</property>
- <property name="margin_bottom">18</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
- <child internal-child="action_area">
- <object class="GtkButtonBox" id="edit_button_action_area">
- <property name="can_focus">False</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="edit_button_delete">
- <property name="label" translatable="yes">Delete</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="edit_button_ok">
- <property name="label" translatable="yes">OK</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="edit_button_cancel">
- <property name="label" translatable="yes">Cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkGrid" id="edit_button_grid">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin_bottom">18</property>
- <property name="row_spacing">6</property>
- <property name="column_spacing">12</property>
- <child>
- <object class="GtkImage" id="edit_button_icon">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="yalign">0</property>
- <property name="icon_name">preferences-desktop-keyboard</property>
- <property name="icon_size">6</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="height">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="edit_button_keycode_label">
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Keycode</property>
- <property name="xalign">1</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="edit_button_comment_label">
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Comment</property>
- <property name="xalign">1</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBoxText" id="edit_button_keycode_value">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="edit_button_comment_value">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="max_length">100</property>
- <property name="placeholder_text" translatable="yes">No comment</property>
- </object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="2">edit_button_delete</action-widget>
- <action-widget response="1">edit_button_ok</action-widget>
- <action-widget response="0">edit_button_cancel</action-widget>
- </action-widgets>
- </object>
<object class="GtkDialog" id="hardware_properties">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Hardware Properties</property>