[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:
parent
5bc5ad9e4c
commit
e8b3dfb4ef
5 changed files with 109 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
import bumblebee.module
|
||||
import bumblebee.util
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
@ -13,7 +15,30 @@ def parameters():
|
|||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
self._state = "off"
|
||||
|
||||
self._widgets = []
|
||||
|
||||
def toggle(self, event, widget):
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
toggle_cmd = "{}/../../bin/toggle-display.sh".format(path)
|
||||
|
||||
if widget.get("state") == "on":
|
||||
bumblebee.util.execute("{} --output {} --off".format(toggle_cmd, widget.get("display")))
|
||||
else:
|
||||
neighbor = None
|
||||
for w in self._widgets:
|
||||
if w.get("state") == "on":
|
||||
neighbor = w
|
||||
if event.get("button") == 1:
|
||||
break
|
||||
|
||||
if neighbor == None:
|
||||
bumblebee.util.execute("{} --output {} --auto".format(toggle_cmd,
|
||||
widget.get("display")))
|
||||
else:
|
||||
bumblebee.util.execute("{} --output {} --auto --{}-of {}".format(toggle_cmd,
|
||||
widget.get("display"), "left" if event.get("button") == 1 else "right",
|
||||
neighbor.get("display")))
|
||||
|
||||
def widgets(self):
|
||||
process = subprocess.Popen([ "xrandr", "-q" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
@ -21,29 +46,39 @@ class Module(bumblebee.module.Module):
|
|||
|
||||
widgets = []
|
||||
|
||||
# TODO: sort by position
|
||||
for line in output.split("\n"):
|
||||
if not " connected" in line:
|
||||
continue
|
||||
screen = line.split(" ", 2)[0]
|
||||
display = line.split(" ", 2)[0]
|
||||
m = re.search(r'\d+x\d+\+(\d+)\+\d+', line)
|
||||
|
||||
widget = bumblebee.output.Widget(self, screen)
|
||||
widget = bumblebee.output.Widget(self, display, instance=display)
|
||||
widget.set("display", display)
|
||||
|
||||
# not optimal (add callback once per interval), but since
|
||||
# add_callback() just returns if the callback has already
|
||||
# been registered, it should be "ok"
|
||||
self._output.add_callback(module=display, button=1,
|
||||
cmd=self.toggle)
|
||||
self._output.add_callback(module=display, button=3,
|
||||
cmd=self.toggle)
|
||||
if m:
|
||||
self._state = "on"
|
||||
widget.set("state", "on")
|
||||
widget.set("pos", int(m.group(1)))
|
||||
else:
|
||||
self._state = "off"
|
||||
widget.set("pos", sys.maxint());
|
||||
widget.set("state", "off")
|
||||
widget.set("pos", sys.maxint)
|
||||
|
||||
widgets.append(widget)
|
||||
|
||||
widgets.sort(key=lambda widget : widget.get("pos"))
|
||||
|
||||
self._widgets = widgets
|
||||
|
||||
return widgets
|
||||
|
||||
def state(self, widget):
|
||||
return self._state
|
||||
return widget.get("state", "off")
|
||||
|
||||
def warning(self, widget):
|
||||
return False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue