Skip to content

Commit

Permalink
Merge ab13a1d into 647eaf0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Marston committed Feb 20, 2020
2 parents 647eaf0 + ab13a1d commit e99a56e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
13 changes: 10 additions & 3 deletions quicktile/__main__.py
Expand Up @@ -47,7 +47,7 @@
from gi.repository import GLib, Gtk, Wnck

from . import commands, layout
from .util import fmt_table, XInitError
from .util import fmt_table, XInitError, CycleOrder
from .version import __version__
from .wm import WindowManager

Expand All @@ -72,7 +72,8 @@
# Use Ctrl+Alt as the default base for key combinations
'ModMask': '<Ctrl><Alt>',
'MovementsWrap': True,
'ColumnCount': 3
'ColumnCount': 3,
'CycleOrder': 'default'
},
'keys': {
"KP_Enter": "monitor-switch",
Expand Down Expand Up @@ -224,6 +225,10 @@ def load_config(path) -> ConfigParser:
config.set('general', key, str(val))
dirty = True

order = str(config.get('general', 'CycleOrder'))
if order.upper() not in list(x.name for x in CycleOrder):
raise TypeError("CycleOrder is invalid")

mk_raw = config.get('general', 'ModMask')
modkeys = mk_raw.strip() # pylint: disable=E1101
if ' ' in modkeys and '<' not in modkeys:
Expand Down Expand Up @@ -356,8 +361,10 @@ def main() -> None:
first_run = not os.path.exists(cfg_path)
config = load_config(cfg_path)

columns = config.getint('general', 'ColumnCount')
order = CycleOrder[config.get('general', 'CycleOrder').upper()]
commands.cycle_dimensions = commands.commands.add_many(
layout.make_winsplit_positions(config.getint('general', 'ColumnCount'))
layout.make_winsplit_positions(columns, order)
)(commands.cycle_dimensions)
commands.commands.extra_state = {'config': config}

Expand Down
13 changes: 9 additions & 4 deletions quicktile/layout.py
Expand Up @@ -10,7 +10,7 @@

import math

from .util import Gravity, Rectangle
from .util import Gravity, Rectangle, CycleOrder

# -- Type-Annotation Imports --
from typing import Dict, List, Union
Expand Down Expand Up @@ -141,7 +141,8 @@ def __call__(self,
round(height - (self.margin_y * 2), 3))


def make_winsplit_positions(columns: int) -> Dict[str, List[PercentRectTuple]]:
def make_winsplit_positions(columns: int, order: CycleOrder) -> \
Dict[str, List[PercentRectTuple]]:
"""Generate the classic WinSplit Revolution tiling presets
:params columns: The number of columns that each tiling preset should be
Expand All @@ -162,8 +163,12 @@ def make_winsplit_positions(columns: int) -> Dict[str, List[PercentRectTuple]]:
cycle_steps = tuple(round(col_width * x, 3)
for x in range(1, columns))

center_steps = (1.0,) + cycle_steps
edge_steps = (0.5,) + cycle_steps
if order is CycleOrder.DEFAULT:
center_steps = (1.0,) + cycle_steps
edge_steps = (0.5,) + cycle_steps
elif order is CycleOrder.SMALL_FIRST:
center_steps = cycle_steps + (1.0,)
edge_steps = cycle_steps[0:1] + (0.5,) + cycle_steps[1:]

positions = {
'center': [gvlay(width, 1, 'center') for width in center_steps],
Expand Down
6 changes: 6 additions & 0 deletions quicktile/util.py
Expand Up @@ -65,6 +65,12 @@ class Gravity(Enum): # pylint: disable=too-few-public-methods
BOTTOM_RIGHT = (1.0, 1.0)


class CycleOrder(IntEnum):
"""Window position cycling orders."""
DEFAULT = 0
SMALL_FIRST = 1


def clamp_idx(idx: int, stop: int, wrap: bool=True) -> int:
"""Ensure a 0-based index is within a given range [0, stop).
Expand Down

0 comments on commit e99a56e

Please sign in to comment.