Skip to content

Commit

Permalink
Make $screensaver available
Browse files Browse the repository at this point in the history
Relates: nomeata#39
  • Loading branch information
liskin committed Dec 6, 2020
1 parent 728d147 commit fe55826
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions categorize.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ aliases (
-- causes this sample to be ignored by default.
$idle > 60 ==> tag inactive,

-- TODO
$screensaver ==> tag inactive,

-- A rule that matches on a list of strings
current window $program == ["Navigator","galeon"] ==> tag Web,

Expand Down
5 changes: 5 additions & 0 deletions doc/arbtt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
<command>arbtt-stats</command>, as can be seen in <xref linkend="catex"/>.
</para>

<para>
The variable <literal>$screensaver</literal> …
</para>

<para>
When applying the rules, the categorizer has a notion of
the <emphasis>window in scope</emphasis>, and the variables
Expand Down Expand Up @@ -421,6 +425,7 @@
<nonterminal def="#g-timediff"/> </rhs>
<rhs> <nonterminal def="#g-date"/> <nonterminal def="#g-cmpop"/>
<nonterminal def="#g-date"/> </rhs>
<rhs> <quote>$screensaver</quote> </rhs>
<rhs> <quote>current window</quote> <nonterminal def="#g-cond"/> </rhs>
<rhs> <quote>any window</quote> <nonterminal def="#g-cond"/> </rhs>
<rhs> <quote>$</quote> Literal </rhs>
Expand Down
7 changes: 7 additions & 0 deletions src/Categorize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ data TimeVar = TvTime | TvSampleAge

data NumVar = NvIdle

data BoolVar = BvScreenSaver

runParserStack :: Stream s (ReaderT r Identity) t
=> r
-> ParsecT s () (ReaderT r Identity) a
Expand Down Expand Up @@ -141,6 +143,7 @@ lang = makeTokenParser LanguageDef
, "date"
, "now"
, "desktop"
, "screensaver"
]
, caseSensitive = True
}
Expand Down Expand Up @@ -412,6 +415,7 @@ parseCondPrim = choice
, reserved lang "date" >> return (CondDate (getDateVar DvDate))
, reserved lang "now" >> return (CondDate (getDateVar DvNow))
, reserved lang "desktop" >> return (CondString (getVar "desktop"))
, reserved lang "screensaver" >> return (CondCond (checkBoolVar BvScreenSaver))
, do varname <- identifier lang
inEnvironment <- (lift (asks (Map.lookup varname . snd)))
case inEnvironment of
Expand Down Expand Up @@ -551,6 +555,9 @@ getDateVar :: DateVar -> CtxFun UTCTime
getDateVar DvDate = Just . tlTime . cNow
getDateVar DvNow = Just . cCurrentTime

checkBoolVar :: BoolVar -> Cond
checkBoolVar BvScreenSaver ctx = guard (cScreenSaver (tlData (cNow ctx))) >> return []

findActive :: [(Bool, t, t1)] -> Maybe (Bool, t, t1)
findActive = find (\(a,_,_) -> a)

Expand Down

0 comments on commit fe55826

Please sign in to comment.