Skip to content

command chaining functionality in config #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion quicktile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def main(): # type: () -> None
winman.screen.force_update()

for arg in args:
commands.commands.call(arg, winman)
commands.commands.call_multiple(arg, winman)
while gtk.events_pending(): # pylint: disable=no-member
gtk.main_iteration() # pylint: disable=no-member
elif not opts.show_args and not opts.show_binds:
Expand Down
28 changes: 24 additions & 4 deletions quicktile/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def decorate(func):

def call(self, command, winman, *args, **kwargs):
# type: (str, WindowManager, *Any, **Any) -> bool
"""Resolve a textual positioning command and execute it."""
"""Check if the command is valid and execute it."""
cmd = self.commands.get(command, None)

if cmd:
Expand All @@ -183,6 +183,21 @@ def call(self, command, winman, *args, **kwargs):
logging.error("Unrecognized command: %s", command)
return False

def call_multiple(self, command, winman, *args, **kwargs):
# type: (str, WindowManager, *Any, **Any) -> bool
"""Resolve a textual positioning command and execute it.
Accepts a comma seperated string as the command."""
cmds = [] #type: List[str]
success = True
if ',' in command:
cmds = [i.strip() for i in command.split(',')]
for cmd in cmds:
success = self.call(cmd, winman, *args, **kwargs)
else:
return self.call(command, winman, *args, **kwargs)

return success


#: The instance of L{CommandRegistry} to be used in 99.9% of use cases.
commands = CommandRegistry()
Expand Down Expand Up @@ -341,12 +356,17 @@ def move_to_position(winman, # type: WindowManager
winman.reposition(win, result, use_rect, gravity=gravity,
geometry_mask=gravity_mask)

@commands.add('bordered-set', True)
@commands.add('bordered-unset', False)
@commands.add('bordered')
def toggle_decorated(winman, win, state): # pylint: disable=unused-argument
# type: (WindowManager, wnck.Window, Any) -> None
def toggle_decorated(winman, win, state, decoration=None): # pylint: disable=unused-argument
# type: (WindowManager, wnck.Window, Any, Optional[bool]) -> None
"""Toggle window decoration state on the active window."""
win = gtk.gdk.window_foreign_new(win.get_xid())
win.set_decorations(not win.get_decorations())
if decoration is not None:
win.set_decorations(decoration)
else:
win.set_decorations(not win.get_decorations())

@commands.add('show-desktop', windowless=True)
def toggle_desktop(winman, win, state): # pylint: disable=unused-argument
Expand Down
4 changes: 2 additions & 2 deletions quicktile/dbus_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def doCommand(self, command): # type: (str) -> bool
"""Execute a QuickTile tiling command

@todo 1.0.0: Expose a proper, introspectable D-Bus API"""
return self.commands.call(command, self.winman)
# FIXME: self.commands.call always returns None
return self.commands.call_multiple(command, self.winman)
# FIXME: self.commands.call_multiple always returns None

def init(commands, # type: CommandRegistry
winman # type: WindowManager
Expand Down
2 changes: 1 addition & 1 deletion quicktile/keybinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def init(modmask, # type: Optional[str]
def call(func=func):
"""Closure to resolve `func` and call it on a
`WindowManager` instance"""
commands.call(func, winman)
commands.call_multiple(func, winman)

keybinder.bind(modmask + key, call)
return keybinder