summaryrefslogtreecommitdiff
path: root/rcm-client-receive.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2015-07-17 12:11:55 +0200
committerDavid Härdeman <david@hardeman.nu>2015-07-17 12:11:55 +0200
commit91f6ceff2e7ef574c30101707f1c8194fc620723 (patch)
tree51f35f18854db48ff9e27b3a0c60a7a052d9f55e /rcm-client-receive.c
parent0b9fa0713dd4e2297e5efc808178c0cd26d2842d (diff)
Implement remote layout resizing
Still need to implement the server-side functionality...
Diffstat (limited to 'rcm-client-receive.c')
-rw-r--r--rcm-client-receive.c84
1 files changed, 81 insertions, 3 deletions
diff --git a/rcm-client-receive.c b/rcm-client-receive.c
index 47a45ab..60e84f9 100644
--- a/rcm-client-receive.c
+++ b/rcm-client-receive.c
@@ -6,6 +6,7 @@
#include <inttypes.h>
#include <gtk/gtk.h>
+#include "shared.h"
#include "generated.h"
#include "rcm-client-main.h"
#include "rcm-client-receive.h"
@@ -302,7 +303,73 @@ remove_header_buttons(void)
static void toggle_edit_keymap(GtkButton *button, gpointer user_data);
static void
-resize_keymap(GtkButton *button, gpointer user_data)
+resize_layout(struct remote *remote, guint16 new_width, guint16 new_height)
+{
+ guint16 old_width = remote->width;
+ guint16 old_height = remote->height;
+ unsigned x, y;
+ GList *new_buttons = NULL;
+
+ printf("Resizing...\n");
+
+ if (new_width < old_width || new_height < old_height) {
+ GList *b = remote->buttons;
+
+ for (y = 0; y < old_height; y++) {
+ for (x = 0; x < old_width; x++) {
+ GList *delete = b;
+ struct rcbutton *rcb = delete->data;
+
+ b = b->next;
+ if (x < new_width && y < new_height)
+ continue;
+
+ printf("\tDeleting old button at %ux%u\n", x, y);
+ remote->buttons = g_list_remove_link(remote->buttons, delete);
+ gtk_widget_destroy(rcb->button);
+ g_free(rcb->name);
+ g_free(rcb);
+ g_list_free(delete);
+ }
+ }
+ }
+
+ for (y = 0; y < new_height; y++) {
+ for (x = 0; x < new_width; x++) {
+
+ if (x < old_width && y < old_height) {
+ GList *b;
+
+ b = remote->buttons;
+ remote->buttons = g_list_remove_link(remote->buttons, b);
+ new_buttons = g_list_concat(new_buttons, b);
+ printf("\tCopied button at %ux%u\n", x, y);
+ } else {
+ struct rcbutton *rcb;
+ rcb = new_blank_add(GTK_GRID(remote->grid), x, y);
+ new_buttons = g_list_append(new_buttons, rcb);
+ gtk_revealer_set_reveal_child(GTK_REVEALER(rcb->button), true);
+ printf("\tNew button at %ux%u\n", x, y);
+ }
+ }
+ }
+
+ g_assert(remote->buttons == NULL);
+
+ remote->buttons = new_buttons;
+ remote->width = new_width;
+ remote->height = new_height;
+
+ g_object_ref(remote->edit_button);
+ gtk_container_remove(GTK_CONTAINER(remote->grid), remote->edit_button);
+ gtk_grid_attach(GTK_GRID(remote->grid), remote->edit_button, 0, -1, remote->width, 1);
+ g_object_unref(remote->edit_button);
+
+ gtk_widget_show_all(remote->grid);
+}
+
+static void
+resize_layout_dialog(GtkButton *button, gpointer user_data)
{
struct remote *remote = user_data;
GtkWindow *parent = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button)));
@@ -355,7 +422,18 @@ resize_keymap(GtkButton *button, gpointer user_data)
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 keymap '%s' to to %ix%i\n", remote->name, width, height);
+
+ if (width < 1 || width > REMOTE_LAYOUT_MAX_WIDTH) {
+ printf("Invalid width: %i\n", width);
+ goto out;
+ }
+
+ if (height < 1 || height > REMOTE_LAYOUT_MAX_HEIGHT) {
+ printf("Invalid height: %i\n", height);
+ goto out;
+ }
+
+ resize_layout(remote, width, height);
out:
gtk_widget_destroy(dialog);
@@ -379,7 +457,7 @@ set_edit_keymap(bool editing)
if (editing) {
remote->edit_button = gtk_button_new_with_label("Resize");
- g_signal_connect(remote->edit_button, "clicked", G_CALLBACK(resize_keymap), remote);
+ g_signal_connect(remote->edit_button, "clicked", G_CALLBACK(resize_layout_dialog), remote);
gtk_grid_attach(GTK_GRID(remote->grid), remote->edit_button, 0, -1, remote->width, 1);
gtk_widget_show_all(remote->edit_button);
} else {