diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt index 198b584..7b03f32 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/StatusBar.kt @@ -2,12 +2,10 @@ package de.atennert.lcarsde.statusbar import de.atennert.lcarsde.statusbar.configuration.WidgetConfiguration import de.atennert.lcarsde.statusbar.configuration.readConfiguration +import de.atennert.lcarsde.statusbar.configuration.settingsFilePath import de.atennert.lcarsde.statusbar.extensions.gSignalConnect import de.atennert.lcarsde.statusbar.extensions.setStyling -import de.atennert.lcarsde.statusbar.widgets.EmptyWidget -import de.atennert.lcarsde.statusbar.widgets.StatusFillerWidget -import de.atennert.lcarsde.statusbar.widgets.StatusWidget -import de.atennert.lcarsde.statusbar.widgets.WidgetFactory +import de.atennert.lcarsde.statusbar.widgets.* import kotlinx.cinterop.* import statusbar.* @@ -32,7 +30,7 @@ class StatusBar { @ThreadLocal companion object { - private val configuration = readConfiguration() + private val configuration = readConfiguration(settingsFilePath) private val cssProvider = gtk_css_provider_get_default()!! private val grid = gtk_grid_new()!! private val widgetFactory = WidgetFactory(cssProvider) diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/WidgetConfiguration.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/WidgetConfiguration.kt index 971019b..e037206 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/WidgetConfiguration.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/WidgetConfiguration.kt @@ -4,14 +4,14 @@ package de.atennert.lcarsde.statusbar.configuration * Widget entry of the status bar configuration. */ data class WidgetConfiguration( - val name: String, - val x: Int, - val y: Int, - val width: Int, - val height: Int + val name: String, + val x: Int, + val y: Int, + val width: Int, + val height: Int ) { var addedPx = 0 - private set + private set var properties = emptyMap() private set diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/readConfiguration.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/readConfiguration.kt index c445222..422ed85 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/readConfiguration.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/configuration/readConfiguration.kt @@ -11,7 +11,7 @@ import statusbar.* private val userConfigPath = getenv("XDG_CONFIG_HOME")?.toKString() private const val SETTINGS_FILE = "/lcarsde/status-config.xml" -private val settingsFilePath = when { +val settingsFilePath = when { doUserSettingsExist() -> "${userConfigPath}$SETTINGS_FILE" else -> "/etc$SETTINGS_FILE" } @@ -20,7 +20,7 @@ private fun doUserSettingsExist(): Boolean { return access("${userConfigPath}$SETTINGS_FILE", F_OK) != -1 } -fun readConfiguration(): Set { +fun readConfiguration(settingsFilePath: String): Set { val document = xmlReadFile(settingsFilePath, null, 0) ?: return emptySet() diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/FillerAnimation.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/FillerAnimation.kt similarity index 91% rename from src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/FillerAnimation.kt rename to src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/FillerAnimation.kt index d544fea..f378d72 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/FillerAnimation.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/FillerAnimation.kt @@ -1,6 +1,5 @@ -package de.atennert.lcarsde.statusbar +package de.atennert.lcarsde.statusbar.widgets -import de.atennert.lcarsde.statusbar.widgets.StatusFillerWidget import kotlinx.coroutines.* import kotlin.random.Random diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/MemoryWidget.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/MemoryWidget.kt index 1ffab54..3973193 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/MemoryWidget.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/MemoryWidget.kt @@ -113,7 +113,7 @@ class MemoryWidget(widgetConfiguration: WidgetConfiguration, cssProvider: CPoint cairo_fill(context) } - private fun createBorderPath(widget: MemoryWidget, context: CPointer) { + private fun createBorderPath(widget: StatusWidget, context: CPointer) { cairo_arc(context, 20.0, 20.0, 20.0, 1.0 * PI, 1.5 * PI) cairo_line_to(context, widget.widthPx - 20.0, 0.0) cairo_arc(context, widget.widthPx - 20.0, 20.0, 20.0, 1.5 * PI, 2.0 * PI) diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/StatusFillerWidget.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/StatusFillerWidget.kt index 96178df..b53a1bc 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/StatusFillerWidget.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/StatusFillerWidget.kt @@ -70,7 +70,7 @@ class StatusFillerWidget(widgetConfiguration: WidgetConfiguration, cssProvider: } } - private fun createBorderPath(context: CPointer, widget: StatusFillerWidget) { + private fun createBorderPath(context: CPointer, widget: StatusWidget) { cairo_arc(context, 20.0, 20.0, 20.0, 1.0 * PI, 1.5 * PI) cairo_line_to(context, widget.widthPx - 20.0, 0.0) cairo_arc(context, widget.widthPx - 20.0, 20.0, 20.0, 1.5 * PI, 2.0 * PI) diff --git a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/WidgetFactory.kt b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/WidgetFactory.kt index 2a7b69e..52262f4 100644 --- a/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/WidgetFactory.kt +++ b/src/nativeMain/kotlin/de/atennert/lcarsde/statusbar/widgets/WidgetFactory.kt @@ -4,6 +4,9 @@ import de.atennert.lcarsde.statusbar.configuration.WidgetConfiguration import kotlinx.cinterop.CPointer import statusbar.GtkCssProvider +/** + * Used to create a widget based on a configuration entry. + */ class WidgetFactory(private val cssProvider: CPointer) { fun createWidget(configuration: WidgetConfiguration): StatusWidget? = when (configuration.name) { @@ -17,7 +20,7 @@ class WidgetFactory(private val cssProvider: CPointer) { "LcarsdeWifiStatus" -> WifiWidget(configuration, cssProvider) "LcarsdeEthStatus" -> EthernetWidget(configuration, cssProvider) "LcarsdeStatusAudio" -> AudioWidget(configuration, cssProvider) - "LcarsdeStatusMemory" -> MemoryWidget(configuration, cssProvider) + "LcarsdeStatusMemory" -> MemoryWidget(configuration, cssProvider) else -> null } } \ No newline at end of file