From 7dcfd1a840ac87f9f4306eaf08fc5f45f9e76c84 Mon Sep 17 00:00:00 2001 From: Andreas Tennert Date: Sat, 20 Feb 2021 17:51:08 +0100 Subject: [PATCH] #4 fix: fix layout update on size change --- CHANGELOG | 1 + .../atennert/lcarsde/statusbar/StatusBar.kt | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f934e80..f902ce7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ 21.2 * add linking for systems with /usr/lib64 instead of /usr/lib +* fix issue where the app is not redrawn on size changes 21.1 * rewrite in Kotlin diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt index 0466b29..af0a09b 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt @@ -21,7 +21,8 @@ class StatusBar { window.setStyling(cssProvider, "window") gSignalConnect(window, "realize", staticCFunction { w: CPointer? -> create(w) }) - gSignalConnect(window, "size-allocate", staticCFunction { w: CPointer? -> sizeAdjust(w) }) + gSignalConnect(window, "configure-event", + staticCFunction { w: CPointer?, e: CPointer? -> configure(w, e) }) gtk_grid_set_column_spacing(grid.reinterpret(), GAP_SIZE.convert()) gtk_grid_set_row_spacing(grid.reinterpret(), GAP_SIZE.convert()) @@ -48,16 +49,20 @@ class StatusBar { */ private fun create(widget: CPointer?) { val gdkWindow = gtk_widget_get_window(widget) + gdk_window_set_events(gdkWindow, GDK_STRUCTURE_MASK) gdk_x11_window_set_utf8_property(gdkWindow, LCARSDE_STATUS_BAR, LCARSDE_STATUS_BAR) } - private fun sizeAdjust(widget: CPointer?) { - val allocation = nativeHeap.alloc() - gtk_widget_get_allocation(widget, allocation.ptr) - if (allocation.width != currentWidth) { - currentWidth = allocation.width + private fun configure(widget: CPointer?, event: CPointer?) { + val configureData = event?.pointed?.configure + if (configureData != null) { + gtk_widget_set_size_request(widget, configureData.width, configureData.height) - updateLayout() + if (configureData.width != currentWidth) { + currentWidth = configureData.width + + updateLayout() + } } }