Skip to content

Commit

Permalink
Added ability to toggle the status bar per monitor (#205)
Browse files Browse the repository at this point in the history
* Basic statusbar toggling.

* Also hide/show the systray.

* Updated version and man page.
  • Loading branch information
avahe-kellenberger authored Jul 28, 2022
1 parent 40a3769 commit 7a18488
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 8 deletions.
4 changes: 4 additions & 0 deletions config.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ exec = [
keys = [ "r" ]
modifiers = [ "super" ]

[controls.toggleStatusBar]
keys = [ "b" ]
modifiers = [ "super" ]

# Example monitor settings:
# [monitors]
# [monitors.default.tags]
Expand Down
4 changes: 4 additions & 0 deletions doc/nimdow.1
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,7 @@ Moves the selected window to the scratchpad.
.TP
.BR --pop-scratchpad
Brings back the window most recently added to the scratchpad.
.
.TP
.BR --toggle-statusbar
Hides or shows the status bar on the selected monitor.
2 changes: 1 addition & 1 deletion nimdow.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package
version = "0.7.31"
version = "0.7.32"
author = "avahe-kellenberger"
description = "A window manager written in nim"
license = "GPL v2"
Expand Down
2 changes: 1 addition & 1 deletion src/nimdowpkg/ipc/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import
../wmcommands,
../logger

const version* = "v0.7.31"
const version* = "v0.7.32"
const commit* = getEnv("LATEST_COMMIT")

proc handleWMCommand(commandStr: string): bool =
Expand Down
37 changes: 33 additions & 4 deletions src/nimdowpkg/monitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type
display: PDisplay
rootWindow: Window
statusBar*: StatusBar
isStatusBarEnabled*: bool
systray*: Systray
area*: Area
config: Config
Expand Down Expand Up @@ -98,6 +99,8 @@ proc newMonitor*(
result.taggedClients,
result.monitorSettings.tagSettings
)

result.isStatusBarEnabled = true

########################################################
#### Helper procs, iterators, templates, and macros ####
Expand All @@ -115,6 +118,28 @@ template clients*(this: Monitor): DoublyLinkedList[Client] =
template clientSelection*(this: Monitor): seq[Client] =
this.taggedClients.clientSelection

proc enableStatusBar*(this: Monitor) =
this.layoutOffset = (this.statusBar.area.height, 0.uint, 0.uint, 0.uint)
this.statusBar.show()
if this.systray != nil:
this.systray.show(this.display, this.area)
this.isStatusBarEnabled = true
this.doLayout()

proc disableStatusBar*(this: Monitor) =
this.layoutOffset = (0.uint, 0.uint, 0.uint, 0.uint)
this.statusBar.hide()
if this.systray != nil:
this.systray.hide(this.display, this.area)
this.isStatusBarEnabled = false
this.doLayout()

proc toggleStatusBar*(this: Monitor) =
if this.isStatusBarEnabled:
this.disableStatusBar()
else:
this.enableStatusBar()

proc updateWindowBorders(this: Monitor) =
let currClient: Client = this.taggedClients.currClient
for n in this.taggedClients.currClientsIter:
Expand Down Expand Up @@ -306,21 +331,25 @@ proc doLayout*(this: Monitor, warpToClient, focusCurrClient: bool = true) =

if topmostFullscreenClient == nil:
# There are no fullscreen clients on viewable tags.
this.statusBar.show()
if this.isStatusBarEnabled:
this.statusBar.show()
for client in this.clients.mitems:
if client.tagIDs.anyIt(this.selectedTags.contains(it)):
client.show(this.display)
else:
client.hide(this.display)
if this.systray != nil:
if this.isStatusBarEnabled and this.systray != nil:
this.systray.show(this.display, this.statusBar.area)
else:
for client in this.clients.mitems:
# Only show the topmost fullscreen client.
if client.window != topmostFullscreenClient.window:
client.hide(this.display)
this.statusBar.hide()
if this.systray != nil:

if this.isStatusBarEnabled:
this.statusBar.hide()

if this.isStatusBarEnabled and this.systray != nil:
this.systray.hide(this.display, this.area)
this.focusClient(topmostFullscreenClient, true)

Expand Down
10 changes: 8 additions & 2 deletions src/nimdowpkg/statusbar.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type
StatusBar* = object
settings: BarSettings
tagSettings*: OrderedTable[TagID, TagSetting]
isHidden: bool
isMonitorSelected: bool
status: string
activeWindowTitle: string
Expand Down Expand Up @@ -195,24 +196,29 @@ proc configureBar(this: StatusBar) =
12
)

proc show*(this: StatusBar) =
proc show*(this: var StatusBar) =
## Moves the status bar off screen.
this.isHidden = false
discard XMoveWindow(
this.display,
this.barWindow,
this.area.x,
this.area.y
)

proc hide*(this: StatusBar) =
proc hide*(this: var StatusBar) =
## Moves the status bar off screen.
this.isHidden = true
discard XMoveWindow(
this.display,
this.barWindow,
this.area.width.int * -2,
this.area.y
)

proc isHidden*(this: StatusBar): lent bool =
this.isHidden

proc resizeForSystray*(this: var StatusBar, systrayWidth: int, redraw: bool = true) =
this.systrayWidth = systrayWidth
discard XMoveResizeWindow(
Expand Down
3 changes: 3 additions & 0 deletions src/nimdowpkg/windowmanager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ proc mapConfigActions*(this: WindowManager) =
createControl(keyCombo, $wmcRotateclients):
this.selectedMonitor.rotateClients()

createControl(keyCombo, $wmcToggleStatusBar):
this.selectedMonitor.toggleStatusBar()

proc focus*(this: WindowManager, client: Client, warpToClient: bool) =
for monitor in this.monitors.values():
for taggedClient in monitor.taggedClients.clients:
Expand Down
1 change: 1 addition & 0 deletions src/nimdowpkg/wmcommands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type
wmcMoveWindowToScratchpad = "movewindowtoscratchpad"
wmcPopScratchpad = "popscratchpad"
wmcRotateclients = "rotateclients"
wmcToggleStatusBar = "togglestatusbar"

proc parseCommand*(command: string): Option[WMCommand] =
try:
Expand Down

0 comments on commit 7a18488

Please sign in to comment.