summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2015-07-10 09:33:54 +0200
committerDavid Härdeman <david@hardeman.nu>2015-07-10 09:33:54 +0200
commit28163dd2de67012f4d407127383aa8beafad7cd0 (patch)
tree16357e28484f08fcf89941989e3c476244d7c3a8
parenteff35c23402d9c5f435a1ee0111e87bab88b9481 (diff)
Simplify header button creation
-rw-r--r--rcm-client-receive.c64
1 files changed, 41 insertions, 23 deletions
diff --git a/rcm-client-receive.c b/rcm-client-receive.c
index 8b2fc6f..aaeca42 100644
--- a/rcm-client-receive.c
+++ b/rcm-client-receive.c
@@ -15,6 +15,7 @@
struct remote {
GList *buttons;
+ GList *header_buttons;
guint width;
guint height;
struct rcbutton *hover;
@@ -398,7 +399,6 @@ void rcng_client_receive_destroy_ui()
}
static gint own_page_num = -1;
-static GtkWidget *header_button = NULL;
static GtkWidget *da;
#if 0
@@ -435,6 +435,34 @@ on_hover_delete(struct rcbutton *rcb, GtkWidget *widget, bool hover)
}
+/* FIXME: These two functions should probably move to the core */
+static void
+create_header_button(const gchar *label, const gchar *icon_name,
+ GCallback callback, gpointer user_data)
+{
+ GtkWidget *button;
+
+ button = gtk_button_new_from_icon_name(icon_name, GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_label(GTK_BUTTON(button), label);
+ gtk_button_set_always_show_image(GTK_BUTTON(button), TRUE);
+ g_signal_connect(button, "clicked", callback, user_data);
+ gtk_widget_show_all(button);
+ gtk_header_bar_pack_end(GTK_HEADER_BAR(global->header), button);
+ remote->header_buttons = g_list_prepend(remote->header_buttons, button);
+}
+
+static void
+remove_header_buttons(void)
+{
+ GList *l;
+
+ for (l = remote->header_buttons; l; l = l->next)
+ gtk_widget_destroy(l->data);
+
+ g_list_free(remote->header_buttons);
+ remote->header_buttons = NULL;
+}
+
static void
edit_keymap(GtkButton *button, gpointer user_data)
{
@@ -448,6 +476,8 @@ edit_keymap(GtkButton *button, gpointer user_data)
return;
if (!remote->editing) {
+ remove_header_buttons();
+ create_header_button("Done Editing Keymap", "gtk-apply", G_CALLBACK(edit_keymap), &remote);
move_buttons(2, 2);
new_button_add("+", &cgreen, 2, 1, remote->width, 1);
new_button_add("+", &cgreen, 2, 2 + remote->height, remote->width, 1);
@@ -464,19 +494,14 @@ edit_keymap(GtkButton *button, gpointer user_data)
rcb->on_hover = on_hover_delete;
}
- /*
- new_button_add("+", &cgreen, 5, 2, 1, 7);
- new_button_add("+", &cgreen, 2, 4, 1, 1);
- new_button_add("+", &cgreen, 2, 4, 10, 10);
- new_button_add("+", &cgreen, 2, 4, 10, 10);
- new_button_add("-", &cred, 2, 2, 0, 0);
- new_button_add("Del", &cred, 3, 3, 0, 0);
- */
-
gtk_widget_queue_draw(da);
} else {
- GList *l = remote->buttons;
+ GList *l;
+ remove_header_buttons();
+ create_header_button("Edit Keymap", "list-add", G_CALLBACK(edit_keymap), &remote);
+
+ l = remote->buttons;
while (l) {
GList *next = l->next;
struct rcbutton *rcb = l->data;
@@ -499,21 +524,14 @@ on_notebook_page_change(GtkNotebook *notebook, GtkWidget *page, guint new_page_n
gpointer user_data)
{
if (new_page_num != own_page_num) {
- if (header_button) {
- gtk_widget_destroy(header_button);
- header_button = NULL;
- remote->editing = false;
- }
+ remove_header_buttons();
+ remote->editing = false;
return;
}
- 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), &remote);
- gtk_widget_show_all(test);
- gtk_header_bar_pack_end(GTK_HEADER_BAR(global->header), test);
- header_button = test;
+ /* FIXME: call edit_keymap() instead */
+ create_header_button("Edit Keymap", "list-add", G_CALLBACK(edit_keymap), &remote);
+
g_print("Page change: %i -> %u\n", own_page_num, new_page_num);
}