Skip to content
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

Add "cycle orders" #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions quicktile/__main__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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