[core/config] Allow modules to be hidden when in critical/error state

When a module is in critical state, the user can now hide the module
(e.g. if pulseaudio fails to load).

fixes #746
This commit is contained in:
tobi-wan-kenobi 2021-01-17 15:21:40 +01:00
parent 45c0a382c9
commit beca26c2bf
2 changed files with 19 additions and 3 deletions

View file

@ -172,6 +172,13 @@ class Config(util.store.Store):
default=[], default=[],
help="Specify a list of modules to hide when not in warning/error state", help="Specify a list of modules to hide when not in warning/error state",
) )
parser.add_argument(
"-e",
"--errorhide",
nargs="+",
default=[],
help="Specify a list of modules that are hidden when in state error"
)
parser.add_argument( parser.add_argument(
"-d", "--debug", action="store_true", help="Add debug fields to i3 output" "-d", "--debug", action="store_true", help="Add debug fields to i3 output"
) )
@ -302,14 +309,21 @@ class Config(util.store.Store):
def iconset(self): def iconset(self):
return self.__args.iconset return self.__args.iconset
"""Returns which modules should be hidden if their state is not warning/critical """Returns whether a module should be hidden if their state is not warning/critical
:return: list of modules to hide automatically :return: True if module should be hidden automatically, False otherwise
:rtype: list of strings :rtype: bool
""" """
def autohide(self, name): def autohide(self, name):
return name in self.__args.autohide return name in self.__args.autohide
"""Returns which modules should be hidden if they are in state error
:return: returns True if name should be hidden, False otherwise
:rtype: bool
"""
def errorhide(self, name):
return name in self.__args.errorhide
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -216,6 +216,8 @@ class i3(object):
continue continue
if module.hidden(): if module.hidden():
continue continue
if "critical" in widget.state() and self.__config.errorhide(widget.module.name):
continue
blocks.extend(self.separator_block(module, widget)) blocks.extend(self.separator_block(module, widget))
blocks.append(self.__content_block(module, widget)) blocks.append(self.__content_block(module, widget))
core.event.trigger("next-widget") core.event.trigger("next-widget")