summaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-08-21 09:51:05 +0200
committerxengineering <me@xengineering.eu>2022-08-21 09:51:05 +0200
commit1f494e68fd0ce306079731bbf91667e6718e47ee (patch)
tree516cc0f08baf03820b20c427cb5be1b9d6d6a94c /gtk.c
parent4e61f83b432350303aee5635e98d3bc147e8fffa (diff)
downloadlimox-1f494e68fd0ce306079731bbf91667e6718e47ee.tar
limox-1f494e68fd0ce306079731bbf91667e6718e47ee.tar.zst
limox-1f494e68fd0ce306079731bbf91667e6718e47ee.zip
Introduce chat_widget_t in gtk.c
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/gtk.c b/gtk.c
index 6db2f33..da5b509 100644
--- a/gtk.c
+++ b/gtk.c
@@ -7,6 +7,12 @@
#include "data.h"
+typedef struct _chat_widget_t {
+ GtkWidget* page;
+ GtkWidget* content;
+} chat_widget_t;
+
+
// the GTK application is available as global variable
static GtkApplication* app;
@@ -158,9 +164,14 @@ static void to_roster(void) {
void gui_add_chat_widget(chat_t* chat) {
+ // allocate chat_widget_t and save as void* in given chat_t
+ chat_widget_t* chat_widget = malloc(sizeof(chat_widget_t));
+ chat->widget = (void*)chat_widget;
+
// create chat page (GtkBox) and add it to the stack
GtkWidget* chat_layout_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20);
gtk_stack_add_child(GTK_STACK(stack), chat_layout_box);
+ chat_widget->page = chat_layout_box;
// create and add back button
GtkWidget* back = gtk_button_new_with_label("back");
@@ -176,9 +187,7 @@ void gui_add_chat_widget(chat_t* chat) {
GtkWidget* chat_content_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled),
chat_content_box);
-
- // save widget pointer
- chat->widget = (void*)chat_content_box;
+ chat_widget->content = chat_content_box;
// create and add text input field
GtkWidget* text_entry = gtk_entry_new();
@@ -187,8 +196,8 @@ void gui_add_chat_widget(chat_t* chat) {
// create and add send button
GtkWidget* send_button = gtk_button_new_with_label("send");
gtk_box_append(GTK_BOX(chat_layout_box), send_button);
- //g_signal_connect_swapped(send_button, "clicked", G_CALLBACK(send_message),
- // chat); // TODO
+ // g_signal_connect_swapped(send_button, "clicked", G_CALLBACK(send_message),
+ // chat); // TODO
}
@@ -204,19 +213,16 @@ void gui_add_message_widget(message_t* message, chat_t* chat) {
gtk_label_set_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_selectable(GTK_LABEL(label), TRUE);
message->widget = (void*)label;
- gtk_box_append(GTK_BOX(chat->widget), label);
+ chat_widget_t* chat_widget = (chat_widget_t*)chat->widget;
+ gtk_box_append(GTK_BOX(chat_widget->content), label);
free(label_content);
}
static void to_chat(chat_t* chat) {
- //GtkWidget* chat_page = data_get_chat_page((void*)roster_item_widget);
- GtkWidget* chat_page = chat->widget; // initialize as a far child
- for (int i=0; i<3; i++) { // and then jump three levels up
- chat_page = gtk_widget_get_parent(chat_page);
- }
- gtk_stack_set_visible_child(GTK_STACK(stack), chat_page);
+ chat_widget_t* chat_widget = (chat_widget_t*)chat->widget;
+ gtk_stack_set_visible_child(GTK_STACK(stack), chat_widget->page);
}