From b2e130de1fa023b053b0a6c136eb56a8ea0d50dd Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Tue, 19 Sep 2023 16:08:40 +0200 Subject: [PATCH] Proof-of-concept dynamic panel creation --- drivers/g-wolves/htx/htx.c | 2 +- src/ui/main-window.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/g-wolves/htx/htx.c b/drivers/g-wolves/htx/htx.c index 7604e30..f4e9195 100644 --- a/drivers/g-wolves/htx/htx.c +++ b/drivers/g-wolves/htx/htx.c @@ -27,5 +27,5 @@ char* driver_get_name(void) char* driver_get_image(void) { - return "g-wolves/htx/htx_0.png"; + return "drivers/g-wolves/htx/htx_0.png"; } diff --git a/src/ui/main-window.c b/src/ui/main-window.c index 549bfa1..96c8099 100644 --- a/src/ui/main-window.c +++ b/src/ui/main-window.c @@ -2,6 +2,7 @@ #include "main-window.h" #include "panels/empty-panel.h" +#include "panels/mouse-panel.h" #include "device/device.h" #include @@ -163,6 +164,25 @@ void main_window_add_all_devices(MainWindow* self) main_window_add_device_to_list(self, array_get(devices, i)); } +void main_window_device_selected(GtkListBox* self, GtkListBoxRow* row, gpointer user_data) +{ + MainWindow* main_window = (MainWindow*) gtk_widget_get_root(GTK_WIDGET(self)); + + // Selection cleared + if(!row) + { + // TODO: set to empty panel ? + return; + } + + device_t* device = (device_t*) g_object_get_data(G_OBJECT(row), "ginput_device"); + MousePanel* mp = (Panel*) mouse_panel_new(); + mouse_panel_set_device(mp, device); + + // TODO : change and use already added child if possible + activate_panel(main_window, GINPUT_PANEL(mp), device_get_name(device)); +} + static void main_window_constructed(GObject* object) { @@ -257,6 +277,8 @@ main_window_init(MainWindow* self) G_BINDING_SYNC_CREATE); activate_panel(self, empty_panel_new(), "empty"); + + g_signal_connect(self->device_list, "row_selected", G_CALLBACK(main_window_device_selected), NULL); } // TODO use translation @@ -285,6 +307,7 @@ void main_window_add_device_to_list(MainWindow* self, device_t* device) gtk_widget_set_margin_top(GTK_WIDGET(label), 7); gtk_widget_set_margin_bottom(GTK_WIDGET(label), 7); gtk_list_box_row_set_child(row, GTK_WIDGET(label)); + g_object_set_data(G_OBJECT(row), "ginput_device", device); // Add row to listbox gtk_list_box_append(GTK_LIST_BOX(self->device_list), GTK_WIDGET(row));