summaryrefslogtreecommitdiff
path: root/rcm-client-receive.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2015-07-10 17:18:44 +0200
committerDavid Härdeman <david@hardeman.nu>2015-07-10 17:18:44 +0200
commit165ba73d1ee88661cac144cda605e1d18d6f5928 (patch)
tree801da6692f45ba776eea71381923a9e5f637d079 /rcm-client-receive.c
parent645161cce4c6c8480a60fc73f7ceb0a410a131cf (diff)
Add a proper resize dialog
Diffstat (limited to 'rcm-client-receive.c')
-rw-r--r--rcm-client-receive.c88
1 files changed, 76 insertions, 12 deletions
diff --git a/rcm-client-receive.c b/rcm-client-receive.c
index e1969b2..5ae1af3 100644
--- a/rcm-client-receive.c
+++ b/rcm-client-receive.c
@@ -418,27 +418,92 @@ remove_header_buttons(void)
remote->header_buttons = NULL;
}
+static void toggle_edit_keymap(GtkButton *button, gpointer user_data);
+
static void
-edit_keymap(GtkButton *button, gpointer user_data)
+resize_keymap(GtkButton *button, gpointer user_data)
{
- //struct remote *remote = user_data;
+ GtkWindow *parent = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button)));
+ GtkWidget *dialog;
+ GtkWidget *content_area;
+ GtkWidget *grid;
+ GtkWidget *width_label;
+ GtkAdjustment *width_adj;
+ GtkWidget *width_input;
+ GtkWidget *height_label;
+ GtkAdjustment *height_adj;
+ GtkWidget *height_input;
+ gint r;
+ gint width;
+ gint height;
+
+ dialog = gtk_dialog_new_with_buttons("Resize Keymap", parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+ "OK", GTK_RESPONSE_ACCEPT,
+ "Cancel", GTK_RESPONSE_REJECT,
+ NULL);
+
+ grid = gtk_grid_new();
+ gtk_grid_set_column_spacing(GTK_GRID(grid), 12);
+ gtk_grid_set_row_spacing(GTK_GRID(grid), 12);
+ gtk_container_set_border_width(GTK_CONTAINER(grid), 12);
+
+ width_label = gtk_label_new("Width:");
+ gtk_widget_set_halign(width_label, GTK_ALIGN_END);
+ width_adj = gtk_adjustment_new(remote->width, 1.0, 100.0, 1.0, 5.0, 0.0);
+ width_input = gtk_spin_button_new(width_adj, 1.0, 0);
+ gtk_grid_attach(GTK_GRID(grid), width_label, 1, 1, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), width_input, 2, 1, 1, 1);
+
+ height_label = gtk_label_new("Height:");
+ gtk_widget_set_halign(height_label, GTK_ALIGN_END);
+ height_adj = gtk_adjustment_new(remote->height, 1.0, 100.0, 1.0, 5.0, 0.0);
+ height_input = gtk_spin_button_new(height_adj, 1.0, 0);
+ gtk_grid_attach(GTK_GRID(grid), height_label, 1, 2, 1, 1);
+ gtk_grid_attach(GTK_GRID(grid), height_input, 2, 2, 1, 1);
+
+ content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ gtk_container_set_border_width(GTK_CONTAINER(content_area), 12);
+ gtk_container_add(GTK_CONTAINER(content_area), grid);
+ gtk_widget_show_all(dialog);
+
+ r = gtk_dialog_run(GTK_DIALOG(dialog));
+ if (r != GTK_RESPONSE_ACCEPT)
+ goto out;
- g_print("Button clicked\n");
- g_print("Remote width: %u x %u\n", remote->width, remote->height);
+ width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(width_input));
+ height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(height_input));
+ printf("Asked to resize keylayout to %ix%i\n", width, height);
+
+out:
+ gtk_widget_destroy(dialog);
+}
+
+static void
+set_edit_keymap(bool editing)
+{
if (remote->width < 1 || remote->height < 1)
return;
remove_header_buttons();
- if (!remote->editing)
- create_header_button("Done Editing Keymap", "gtk-apply", G_CALLBACK(edit_keymap), &remote);
- else
- create_header_button("Edit Keymap", "list-add", G_CALLBACK(edit_keymap), &remote);
- remote->editing = !remote->editing;
+ if (editing) {
+ create_header_button("Apply", "gtk-apply", G_CALLBACK(toggle_edit_keymap), &remote);
+ create_header_button("Resize", "document-page-setup", G_CALLBACK(resize_keymap), &remote);
+ } else
+ create_header_button("Edit", "list-add", G_CALLBACK(toggle_edit_keymap), &remote);
+
gtk_widget_queue_draw(da);
}
static void
+toggle_edit_keymap(GtkButton *button, gpointer user_data)
+{
+ remote->editing = !remote->editing;
+ set_edit_keymap(remote->editing);
+}
+
+static void
on_notebook_page_change(GtkNotebook *notebook, GtkWidget *page, guint new_page_num,
gpointer user_data)
{
@@ -448,9 +513,8 @@ on_notebook_page_change(GtkNotebook *notebook, GtkWidget *page, guint new_page_n
return;
}
- /* FIXME: call edit_keymap() instead */
- create_header_button("Edit Keymap", "list-add", G_CALLBACK(edit_keymap), &remote);
-
+ remote->editing = false;
+ set_edit_keymap(remote->editing);
g_print("Page change: %i -> %u\n", own_page_num, new_page_num);
}