Skip to content

Commit

Permalink
#4 fix: fix layout update on size change
Browse files Browse the repository at this point in the history
  • Loading branch information
atennert committed Feb 20, 2021
1 parent 7f50a9e commit 7dcfd1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 12 additions & 7 deletions src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class StatusBar {
window.setStyling(cssProvider, "window")

gSignalConnect(window, "realize", staticCFunction { w: CPointer<GtkWidget>? -> create(w) })
gSignalConnect(window, "size-allocate", staticCFunction { w: CPointer<GtkWidget>? -> sizeAdjust(w) })
gSignalConnect(window, "configure-event",
staticCFunction { w: CPointer<GtkWidget>?, e: CPointer<GdkEvent>? -> configure(w, e) })

gtk_grid_set_column_spacing(grid.reinterpret(), GAP_SIZE.convert())
gtk_grid_set_row_spacing(grid.reinterpret(), GAP_SIZE.convert())
Expand All @@ -48,16 +49,20 @@ class StatusBar {
*/
private fun create(widget: CPointer<GtkWidget>?) {
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<GtkWidget>?) {
val allocation = nativeHeap.alloc<GtkAllocation>()
gtk_widget_get_allocation(widget, allocation.ptr)
if (allocation.width != currentWidth) {
currentWidth = allocation.width
private fun configure(widget: CPointer<GtkWidget>?, event: CPointer<GdkEvent>?) {
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()
}
}
}

Expand Down

0 comments on commit 7dcfd1a

Please sign in to comment.