Skip to content

Commit

Permalink
release(0.0.1): Now available on PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwrigh committed Apr 3, 2023
1 parent 4e258c1 commit ea10643
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ added to the `MutableScratch` group will be automatically converted to
floating. This emulates the scratch functionality of i3 as closely as possible.


## Installation

You can now install via `pip`:
```
pip install qtile_mutable_scratch
```

## Setup

Put the following default configuration in your `config.py`:
```python
## Setup MutableScratch
mutscr = MutableScratch()
groups.append(Group(''))
import qtile_mutable_scratch
...

mutscr = qtile_mutable_scratch.MutableScratch()
groups.append(Group('')) # Must be after `groups` is created

keys.extend( [
EzKey('M-S-<minus>', mutscr.add_current_window()),
EzKey('M-C-<minus>', mutscr.remove_current_window()),
EzKey('M-<minus>', mutscr.toggle()),
EzKey('M-C-<minus>', mutscr.remove()),
] )

hook.subscribe.startup_complete(mutscr.qtile_startup)
Expand Down
71 changes: 38 additions & 33 deletions src/MutableScratch.py → qtile_mutable_scratch/_MutableScratch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import libqtile
import libqtile.lazy
from libqtile.lazy import lazy
import libqtile.config
from libqtile.log_utils import logger
import libqtile.backend.base

# For type hints
from libqtile.core.manager import Qtile
from libqtile.group import _Group
from libqtile.backend import base


class MutableScratch(object):
Expand All @@ -20,25 +26,10 @@ def __init__(self, win_attr: str='mutscratch', grp_name: str=''):
Name of the group that holds the windows added to the scratch space
"""

self.win_attr = win_attr
self.grp_name = grp_name

self.win_stack = [] # Equivalent of focus_history
self.win_attr: str = win_attr
self.grp_name: str = grp_name


def add_current_window(self):
"""Add current window to the MutableScratch system"""
@lazy.function
def _add_current_window(qtile):
win = qtile.current_window
win.hide()
win.floating = True
setattr(win, self.win_attr, True)

win.togroup(self.grp_name)
self.win_stack.append(win)

return _add_current_window
self.win_stack: list = [] # Equivalent of focus_history


def qtile_startup(self):
Expand All @@ -52,18 +43,32 @@ def qtile_startup(self):
qtile = libqtile.qtile
group = qtile.groups_map[self.grp_name]

wins = list(group.windows)
for win in wins:
for win in group.windows:
win.floating = True
setattr(win, self.win_attr, True)

self.win_stack = list(group.windows)
self.win_stack = group.windows.copy()


def remove(self):
def add_current_window(self):
"""Add current window to the MutableScratch system"""
@lazy.function
def _add_current_window(qtile: Qtile):
win: base.Window = qtile.current_window
win.hide()
win.floating = True
setattr(win, self.win_attr, True)

win.togroup(self.grp_name)
self.win_stack.append(win)

return _add_current_window


def remove_current_window(self):
"""Remove current window from MutableScratch system"""
@lazy.function
def _remove(qtile):
def _remove(qtile: Qtile):
win = qtile.current_window
setattr(win, self.win_attr, False)

Expand All @@ -79,16 +84,16 @@ def toggle(self):
it isn't, show the next window in the stack.
"""
@lazy.function
def _toggle(qtile):
win = qtile.current_window
def _toggle(qtile: Qtile):
win: base.Window = qtile.current_window
if getattr(win, self.win_attr, False):
self._push(win)
else:
self._pop(qtile, win)
self._pop(qtile)
return _toggle


def _push(self, win: libqtile.backend.base.Window):
def _push(self, win: base.Window):
"""Hide and push window to stack
Parameters
Expand All @@ -100,7 +105,7 @@ def _push(self, win: libqtile.backend.base.Window):
self.win_stack.append(win)


def _pop(self, qtile, win: libqtile.backend.base.Window):
def _pop(self, qtile: Qtile):
"""Show and pop window from stack
Parameters
Expand All @@ -110,11 +115,11 @@ def _pop(self, qtile, win: libqtile.backend.base.Window):
win : libqtile.backend.base.Window
Window to pop from stack
"""
group = qtile.groups_map[self.grp_name]
if set(self.win_stack) != group.windows:
group: _Group = qtile.groups_map[self.grp_name]
if set(self.win_stack) != set(group.windows):
logger.warning(f"{self}'s win_stack and {group}'s windows have mismatching windows: "
f"{set(self.win_stack).symmetric_difference(group.windows)}")
self.win_stack = list(group.windows)
f"{set(self.win_stack).symmetric_difference(set(group.windows))}")
self.win_stack = group.windows.copy()
if self.win_stack:
win = self.win_stack.pop(0)
win.togroup(qtile.current_group.name)
1 change: 1 addition & 0 deletions qtile_mutable_scratch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._MutableScratch import MutableScratch

0 comments on commit ea10643

Please sign in to comment.