[core/engine] Option to disable workspace wrap

Add a new parameter engine.workspacewrap (default to true) that, if set
to false, makes the workspace change via mouse wheel stop when hitting
the first/last workspace of an output (identical to how i3wm bar itself
behaves).

fixes #188
This commit is contained in:
Tobias Witek 2017-10-21 13:06:36 +02:00
parent abd58d2fba
commit 57064dcf54

View file

@ -1,6 +1,7 @@
"""Core application engine"""
import os
import json
import pkgutil
import logging
import importlib
@ -118,13 +119,51 @@ class Engine(object):
self._current_module = None
if bumblebee.util.asbool(config.get("engine.workspacewheel", "true")):
self.input.register_callback(None, bumblebee.input.WHEEL_UP,
"i3-msg workspace prev_on_output")
self.input.register_callback(None, bumblebee.input.WHEEL_DOWN,
"i3-msg workspace next_on_output")
if bumblebee.util.asbool(config.get("engine.workspacewrap", "true")):
self.input.register_callback(None, bumblebee.input.WHEEL_UP,
"i3-msg workspace prev_on_output")
self.input.register_callback(None, bumblebee.input.WHEEL_DOWN,
"i3-msg workspace next_on_output")
else:
self.input.register_callback(None, bumblebee.input.WHEEL_UP,
cmd=self._prev_workspace)
self.input.register_callback(None, bumblebee.input.WHEEL_DOWN,
cmd=self._next_workspace)
self.input.start()
def _prev_workspace(self, event):
self._change_workspace(-1)
def _next_workspace(self, event):
self._change_workspace(1)
def _change_workspace(self, amount):
try:
active_output = None
active_index = -1
output_workspaces = {}
data = json.loads(bumblebee.util.execute("i3-msg -t get_workspaces"))
for workspace in data:
output_workspaces.setdefault(workspace["output"], []).append(workspace)
if workspace["focused"]:
active_output = workspace["output"]
active_index = len(output_workspaces[workspace["output"]]) - 1
if (active_index + amount) < 0:
return
if (active_index + amount) >= len(output_workspaces[active_output]):
return
while amount != 0:
if amount > 0:
bumblebee.util.execute("i3-msg workspace next_on_output")
amount = amount - 1
if amount < 0:
bumblebee.util.execute("i3-msg workspace prev_on_output")
amount = amount + 1
except Exception as e:
log.error("failed to change workspace: {}".format(e))
def modules(self):
return self._modules