[modules/xrandr] Add display on/off toggling

This one is a bit tricky:
* Clicking on an active xrandr output will disable it
* Clicking on a disabled xrandr output will enable it -> if
  it is a left-click, it will put it as the left-most display
  if it is a right-click, as the right-most display

Also, it will reload the i3 bars (using a script that allows
you to write custom pieces of an i3 configuration that is applied
conditionally depending on the screens you have).

It goes like this:
* Base config is in ~/.i3/config.template
* Output-specific config is in ~/.i3/config.<screen name>
* Output-specific config when other screens are also active is in
  ~/.i3/config.<screen>-<other-screens-in-alphabetic-order>

For instance:
$ ls ~/.i3
config.template
config.eDP1 -> will be applied to eDP1 (always)
config.VGA1-eDP1 -> will be applied to VGA1, if eDP1 is also active
config.VGA1 -> will be applied to VGA1 (if eDP1 is inactive)

fixes #19
This commit is contained in:
Tobi-wan Kenobi 2016-11-26 13:57:33 +01:00
parent 5bc5ad9e4c
commit e8b3dfb4ef
5 changed files with 109 additions and 14 deletions

View file

@ -15,6 +15,8 @@ class Widget(object):
self._store = {}
self._instance = instance
obj._output.register_widget(self.instance(), self)
def set(self, key, value):
self._store[key] = value
@ -40,17 +42,22 @@ class Widget(object):
return self._text
class Command(object):
def __init__(self, command):
def __init__(self, command, event, widget):
self._command = command
self._event = event
self._widget = widget
def __call__(self, *args, **kwargs):
if not isinstance(self._command, list):
self._command = [ self._command ]
for cmd in self._command:
c = cmd.format(*args, **kwargs)
DEVNULL = open(os.devnull, 'wb')
subprocess.Popen(shlex.split(c), stdout=DEVNULL, stderr=DEVNULL).communicate()
if inspect.ismethod(cmd):
cmd(self._event, self._widget)
else:
c = cmd.format(*args, **kwargs)
DEVNULL = open(os.devnull, 'wb')
subprocess.Popen(shlex.split(c), stdout=DEVNULL, stderr=DEVNULL).communicate()
class Output(object):
def __init__(self, config):
@ -58,6 +65,10 @@ class Output(object):
self._callbacks = {}
self._wait = threading.Condition()
self._wait.acquire()
self._widgets = {}
def register_widget(self, identity, widget):
self._widgets[identity] = widget
def redraw(self):
self._wait.acquire()
@ -84,9 +95,9 @@ class Output(object):
event.get("button", -1),
event.get("instance", event.get("name", None)),
), cb)
if inspect.isfunction(cb) or cb is None: return cb
return Command(cb)
identity = event.get("instance", event.get("name", None))
return Command(cb, event, self._widgets.get(identity, None))
def wait(self):
self._wait.wait(self._config.parameter("interval", 1))