Skip to content

Commit

Permalink
Merge pull request #42 from Syphdias/limit-output
Browse files Browse the repository at this point in the history
Add option to limit to outputs
  • Loading branch information
nwg-piotr authored Nov 8, 2022
2 parents 2eb65ae + 017bea9 commit 2c36a6e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ less, nothing more. This may make stack and tabbed layouts behave oddly.
Unfortunately, there is nothing that can be done about it – please, do not
submit issues about it –, but there are two workaround that you can try.

One option is, to enable autotiling on certain workspaces only. For instance,
you could configure autotiling to be enabled on odd workspaces, but not on
even ones:
One option is, to enable autotiling on certain workspaces or outputs only.
For instance, you could configure autotiling to be enabled on odd workspaces,
but not on even ones:

```text
### Autostart
Expand Down Expand Up @@ -61,6 +61,9 @@ optional arguments:
-h, --help show this help message and exit
-d, --debug print debug messages to stderr
-v, --version display version information
-o [OUTPUTS ...], --outputs [OUTPUTS ...]
restricts autotiling to certain output; example: autotiling --output DP-1
HDMI-0
-w [WORKSPACES ...], --workspaces [WORKSPACES ...]
restricts autotiling to certain workspaces; example: autotiling --workspaces 8
9
Expand Down
41 changes: 39 additions & 2 deletions autotiling/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,30 @@ def save_string(string, file):
print(e)


def switch_splitting(i3, e, debug, workspaces, depth_limit):
def output_name(con):
if con.type == "root":
return None

if p := con.parent:
if p.type == "output":
return p.name
else:
return output_name(p)


def switch_splitting(i3, e, debug, outputs, workspaces, depth_limit):
try:
con = i3.get_tree().find_focused()
output = output_name(con)
# Stop, if outputs is set and current output is not in the selection
if outputs and output not in outputs:
if debug:
print(
"Debug: Autotiling turned off on output {}".format(output),
file=sys.stderr,
)
return

if con and not workspaces or (str(con.workspace().num) in workspaces):
if con.floating:
# We're on i3: on sway it would be None
Expand Down Expand Up @@ -120,6 +141,13 @@ def main():
action="version",
version="%(prog)s {}, Python {}".format(__version__, sys.version),
help="display version information", )
parser.add_argument("-o",
"--outputs",
help="restricts autotiling to certain output; "
"example: autotiling --output DP-1 HDMI-0",
nargs="*",
type=str,
default=[], )
parser.add_argument("-w",
"--workspaces",
help="restricts autotiling to certain workspaces; example: autotiling --workspaces 8 9",
Expand All @@ -145,6 +173,9 @@ def main():

args = parser.parse_args()

if args.debug and args.outputs:
print("autotiling is only active on outputs:", ",".join(args.outputs))

if args.debug and args.workspaces:
print("autotiling is only active on workspaces:", ','.join(args.workspaces))

Expand All @@ -160,7 +191,13 @@ def main():
print("No events specified", file=sys.stderr)
sys.exit(1)

handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces, depth_limit=args.limit)
handler = partial(
switch_splitting,
debug=args.debug,
outputs=args.outputs,
workspaces=args.workspaces,
depth_limit=args.limit,
)
i3 = Connection()
for e in args.events:
try:
Expand Down

0 comments on commit 2c36a6e

Please sign in to comment.