Skip to content

Commit

Permalink
refactor: add some minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
atennert committed Mar 16, 2021
1 parent 30b2e5e commit f4aebbf
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>()
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -20,7 +20,7 @@ private fun doUserSettingsExist(): Boolean {
return access("${userConfigPath}$SETTINGS_FILE", F_OK) != -1
}

fun readConfiguration(): Set<WidgetConfiguration> {
fun readConfiguration(settingsFilePath: String): Set<WidgetConfiguration> {
val document = xmlReadFile(settingsFilePath, null, 0)
?: return emptySet()

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MemoryWidget(widgetConfiguration: WidgetConfiguration, cssProvider: CPoint
cairo_fill(context)
}

private fun createBorderPath(widget: MemoryWidget, context: CPointer<cairo_t>) {
private fun createBorderPath(widget: StatusWidget, context: CPointer<cairo_t>) {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class StatusFillerWidget(widgetConfiguration: WidgetConfiguration, cssProvider:
}
}

private fun createBorderPath(context: CPointer<cairo_t>, widget: StatusFillerWidget) {
private fun createBorderPath(context: CPointer<cairo_t>, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GtkCssProvider>) {

fun createWidget(configuration: WidgetConfiguration): StatusWidget? = when (configuration.name) {
Expand All @@ -17,7 +20,7 @@ class WidgetFactory(private val cssProvider: CPointer<GtkCssProvider>) {
"LcarsdeWifiStatus" -> WifiWidget(configuration, cssProvider)
"LcarsdeEthStatus" -> EthernetWidget(configuration, cssProvider)
"LcarsdeStatusAudio" -> AudioWidget(configuration, cssProvider)
"LcarsdeStatusMemory" -> MemoryWidget(configuration, cssProvider)
"LcarsdeStatusMemory" -> MemoryWidget(configuration, cssProvider)
else -> null
}
}

0 comments on commit f4aebbf

Please sign in to comment.