Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set the colour of a tag which has windows on it, and to disable the indicator #232

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/nimdowpkg/config/configloader.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ type
height*: uint
windowTitlePosition*: WindowTitlePosition
fonts*: seq[string]
showIndicator*: bool
# Hex values
fgColor*, bgColor*, selectionColor*, urgentColor*: int
fgColor*, bgColor*, selectionColor*, urgentColor*, hasWindowsColor: int
transparency*: uint8
ScratchpadSettings* = object
width*: int
Expand Down Expand Up @@ -203,10 +204,12 @@ proc populateDefaultMonitorSettings(this: Config, display: PDisplay) =
"monospace:size=10:antialias=true",
"NotoColorEmoji:size=10:antialias=true"
],
showIndicator: true,
fgColor: 0xfce8c3,
bgColor: 0x1c1b19,
selectionColor: 0x519f50,
urgentColor: 0xef2f27
urgentColor: 0xef2f27,
hasWindowsColor: 0xfce8c3
)

this.defaultMonitorSettings.layoutSettings = LayoutSettings(
Expand Down Expand Up @@ -405,6 +408,17 @@ proc populateBarSettings*(this: Config, barSettings: var BarSettings, settingsTa
if barTransparency.kind == TomlValueKind.Int:
barSettings.transparency = clamp(barTransparency.intVal, 0, 255).uint8

let hasWindowsColor= this.loadHexValue(settingsTable, "barHasWindowsColor")
if hasWindowsColor!= -1:
barSettings.hasWindowsColor= hasWindowsColor
else:
barSettings.hasWindowsColor = fgColor

if settingsTable.hasKey("barShowIndicator"):
let showIndicator = settingsTable["barShowIndicator"]
if showIndicator.kind == TomlValueKind.Bool:
barSettings.showIndicator = showIndicator.boolVal

if settingsTable.hasKey("barHeight"):
let barHeight = settingsTable["barHeight"]
if barHeight.kind == TomlValueKind.Int:
Expand Down
21 changes: 13 additions & 8 deletions src/nimdowpkg/statusbar.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type
visual: PVisual
depth: int
colormap: Colormap
fgColor*, bgColor*, selectionColor*, urgentColor*: XftColor
fgColor*, bgColor*, selectionColor*, urgentColor*, hasWindowsColor*: XftColor
area*: Area
systrayWidth: int
clickables: seq[tuple[start: int, stop: int, characters: seq[int]]]
Expand Down Expand Up @@ -269,6 +269,7 @@ proc freeAllColors(this: StatusBar) =
this.freeColor(this.bgColor.unsafeAddr)
this.freeColor(this.selectionColor.unsafeAddr)
this.freeColor(this.urgentColor.unsafeAddr)
this.freeColor(this.hasWindowsColor.unsafeAddr)

proc toRGB(hex: int): RGB =
return (
Expand All @@ -292,6 +293,7 @@ proc configureColors(this: StatusBar) =
this.configureColor(this.settings.bgColor, this.bgColor, this.settings.transparency)
this.configureColor(this.settings.selectionColor, this.selectionColor)
this.configureColor(this.settings.urgentColor, this.urgentColor)
this.configureColor(this.settings.hasWindowsColor, this.hasWindowsColor)

proc configureFont(this: StatusBar, fontString: string): PXftFont =
result = XftFontOpenXlfd(this.display, this.screen, fontString)
Expand Down Expand Up @@ -740,9 +742,6 @@ proc renderTags(this: var StatusBar): int =
tagHasCurrentClient = false
tagIsUrgent = false

if this.selectedTags.contains(tagID):
fgColor = this.selectionColor

for node in this.taggedClients.clientWithTagIter(tagID):
tagIsEmpty = false
let client = node.value
Expand All @@ -752,6 +751,11 @@ proc renderTags(this: var StatusBar): int =
if tagIsUrgent:
break

if this.selectedTags.contains(tagID):
fgColor = this.selectionColor
elif not tagIsEmpty:
fgColor = this.hasWindowsColor

let text = tagSettings.displayString
let stringLength = this.forEachCharacter(text, textXPos, fgColor)

Expand All @@ -766,10 +770,11 @@ proc renderTags(this: var StatusBar): int =
stringLength + boxWidth * 4,
this.area.height.cuint
)
XftDrawRect(this.draw, fgColor.addr, boxXLoc, 0, 4, 4)
if not tagHasCurrentClient:
var bgColor = if tagIsUrgent: this.urgentColor else: this.bgColor
XftDrawRect(this.draw, bgColor.addr, boxXLoc + 1, 1, 2, 2)
if this.settings.showIndicator:
XftDrawRect(this.draw, fgColor.addr, boxXLoc, 0, 4, 4)
if not tagHasCurrentClient:
var bgColor = if tagIsUrgent: this.urgentColor else: this.bgColor
XftDrawRect(this.draw, bgColor.addr, boxXLoc + 1, 1, 2, 2)

let stringInfo = this.renderString(text, fgColor, textXPos)
this.clickables.add (start: textXPos - boxWidth*2, stop: textXPos + stringLength + boxWidth*2, characters: stringInfo.characters)
Expand Down