Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
qbar
Commits
0cdc6187
Commit
0cdc6187
authored
5 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Implement support for adding blocks during runtime
parent
37239cb3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/Main.hs
+1
-1
1 addition, 1 deletion
app/Main.hs
src/QBar/Blocks.hs
+1
-2
1 addition, 2 deletions
src/QBar/Blocks.hs
src/QBar/DefaultConfig.hs
+1
-1
1 addition, 1 deletion
src/QBar/DefaultConfig.hs
src/QBar/Server.hs
+28
-14
28 additions, 14 deletions
src/QBar/Server.hs
with
31 additions
and
18 deletions
app/Main.hs
+
1
−
1
View file @
0cdc6187
...
...
@@ -12,6 +12,6 @@ main = parseOptions >>= runQBar
runQBar
::
MainOptions
->
IO
()
runQBar
options
@
MainOptions
{
barCommand
}
=
runCommand
barCommand
where
runCommand
BarServer
=
run
I3
BarConfiguration
generateDefaultBarConfig
options
runCommand
BarServer
=
runBarConfiguration
generateDefaultBarConfig
options
runCommand
NoFilter
=
sendIpc
options
$
SetFilter
$
StaticFilter
None
runCommand
RainbowFilter
=
sendIpc
options
$
SetFilter
$
AnimatedFilter
Rainbow
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/QBar/Blocks.hs
+
1
−
2
View file @
0cdc6187
...
...
@@ -33,5 +33,4 @@ dateBlockProducer barUpdateChannel = do
block
<-
dateBlock
void
$
atomically
$
send
output
block
updateBar
barUpdateChannel
update
output
update
output
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/QBar/DefaultConfig.hs
+
1
−
1
View file @
0cdc6187
...
...
@@ -23,4 +23,4 @@ generateDefaultBarConfig barUpdateChannel = do
let
volumeBlock
=
startPersistentBlockScript
barUpdateChannel
$
blockLocation
"volume-pulseaudio -S -F3"
let
battery
=
(
systemInfoInterval
$
blockScript
$
blockLocation
"battery2"
)
let
date
=
dateBlockProducer
barUpdateChannel
return
[
todo
,
wifi
,
networkEnvironment
,
cpu
,
ram
,
temperature
,
volumeBlock
,
battery
,
date
]
\ No newline at end of file
return
[
date
,
battery
,
volumeBlock
,
temperature
,
ram
,
cpu
,
networkEnvironment
,
wifi
,
todo
]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/QBar/Server.hs
+
28
−
14
View file @
0cdc6187
...
...
@@ -8,12 +8,12 @@ import QBar.Cli
import
QBar.ControlSocket
import
QBar.Filter
import
Control.Monad
(
forever
,
when
,
unless
)
import
Control.Monad
(
forever
,
when
,
unless
,
forM_
)
import
Control.Monad.STM
(
atomically
)
import
Control.Concurrent
(
threadDelay
,
forkFinally
)
import
Control.Concurrent.Async
import
Control.Concurrent.Event
as
Event
import
Control.Concurrent.STM.TChan
(
newTChanIO
,
readTChan
)
import
Control.Concurrent.STM.TChan
(
TChan
,
newTChanIO
,
readTChan
,
writeTChan
,
tryReadTChan
)
import
Data.Aeson
(
encode
,
decode
)
import
Data.ByteString.Lazy
(
hPut
)
import
qualified
Data.ByteString.Char8
as
BSSC8
...
...
@@ -45,11 +45,19 @@ runBlock producer = do
runBlocks
::
[
BlockProducer
]
->
IO
([
Block
],
[
BlockProducer
])
runBlocks
blockProducers
=
unzip
.
catMaybes
<$>
mapM
runBlock
blockProducers
renderLoop
::
MainOptions
->
Handle
->
BarUpdateEvent
->
BS
.
ByteString
->
[
BlockProducer
]
->
IO
()
renderLoop
options
handle
@
Handle
{
handleActiveFilter
}
barUpdateEvent
=
renderLoop'
renderLoop
::
MainOptions
->
Handle
->
BarUpdateEvent
->
BS
.
ByteString
->
TChan
BlockProducer
->
IO
()
renderLoop
options
handle
@
Handle
{
handleActiveFilter
}
barUpdateEvent
previousBarOutput
newBlockProducers
=
renderLoop'
previousBarOutput
[]
where
addNewBlockProducers
::
[
BlockProducer
]
->
IO
[
BlockProducer
]
addNewBlockProducers
blockProducers
=
do
maybeNewBlockProducer
<-
atomically
$
tryReadTChan
newBlockProducers
case
maybeNewBlockProducer
of
Nothing
->
return
blockProducers
Just
newBlockProducer
->
addNewBlockProducers
(
newBlockProducer
:
blockProducers
)
renderLoop'
::
BS
.
ByteString
->
[
BlockProducer
]
->
IO
()
renderLoop'
previousBarOutput
blockProducers
=
do
renderLoop'
previousBarOutput'
blockProducers
=
do
blockProducers'
<-
addNewBlockProducers
blockProducers
blockFilter
<-
readIORef
handleActiveFilter
-- Wait for an event (unless the filter is animated)
...
...
@@ -59,14 +67,14 @@ renderLoop options handle@Handle{handleActiveFilter} barUpdateEvent = renderLoop
threadDelay
10000
Event
.
clear
barUpdateEvent
(
blocks
,
blockProducers'
)
<-
runBlocks
blockProducers
(
blocks
,
blockProducers'
'
)
<-
runBlocks
blockProducers
'
currentBarOutput
<-
renderLine
options
handle
blockFilter
blocks
previousBarOutput
currentBarOutput
<-
renderLine
options
handle
blockFilter
blocks
previousBarOutput
'
-- Wait for 100ms after rendering a line to limit cpu load of rapid events
threadDelay
100000
renderLoop'
currentBarOutput
blockProducers'
renderLoop'
currentBarOutput
blockProducers'
'
renderLine
::
MainOptions
->
Handle
->
Filter
->
[
Block
]
->
BS
.
ByteString
->
IO
BS
.
ByteString
renderLine
MainOptions
{
verbose
}
Handle
{
handleActionList
}
blockFilter
blocks
previousEncodedOutput
=
do
...
...
@@ -141,8 +149,8 @@ installSignalHandlers barUpdateChannel = void $ installHandler sigCONT (Catch si
hPutStrLn
stderr
"SIGCONT received"
updateBar
barUpdateChannel
run
I3
BarConfiguration
::
(
BarUpdateChannel
->
IO
[
BlockProducer
])
->
MainOptions
->
IO
()
run
I3
BarConfiguration
generateBarConfig
options
=
do
runBarConfiguration
::
(
BarUpdateChannel
->
IO
[
BlockProducer
])
->
MainOptions
->
IO
()
runBarConfiguration
generateBarConfig
options
=
do
-- Create IORef for mouse click callbacks
actionList
<-
newIORef
[]
--link =<< async (handleStdin options actionList)
...
...
@@ -173,6 +181,15 @@ runI3BarConfiguration generateBarConfig options = do
(
barUpdateChannel
,
barUpdateEvent
)
<-
createBarUpdateChannel
blockProducers
<-
generateBarConfig
barUpdateChannel
-- Attach spinner indicator when verbose flag is set
let
blockProducers'
=
if
verbose
options
then
blockProducers
<>
[
renderIndicator
]
else
blockProducers
-- Create channel to send new block producers to render loop
newBlockProducers
<-
newTChanIO
-- Send initial block producers to render loop
forM_
blockProducers'
$
\
bp
->
atomically
$
writeTChan
newBlockProducers
bp
-- Install signal handler for SIGCONT
installSignalHandlers
barUpdateChannel
...
...
@@ -189,10 +206,7 @@ runI3BarConfiguration generateBarConfig options = do
updateBar
barUpdateChannel
link
socketUpdateAsync
-- Attach spinner indicator when verbose flag is set
let
blockProducers'
=
if
verbose
options
then
blockProducers
<>
[
renderIndicator
]
else
blockProducers
renderLoop
options
handle
barUpdateEvent
initialOutput
blockProducers'
renderLoop
options
handle
barUpdateEvent
initialOutput
newBlockProducers
createCommandChan
::
IO
CommandChan
createCommandChan
=
newTChanIO
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment