Giter Site home page Giter Site logo

nwg-piotr / autotiling Goto Github PK

View Code? Open in Web Editor NEW
864.0 11.0 29.0 106 KB

Script for sway and i3 to automatically switch the horizontal / vertical window split orientation

License: GNU General Public License v3.0

Python 90.71% Makefile 9.29%
sway swaywm i3 i3wm i3-gaps tiling-scripts tiling-extension

autotiling's Introduction

autotiling

This script uses the i3ipc-python library to switch the layout splith/splitv depending on the currently focused window dimensions. It works on both sway and i3 window managers.

Inspired by https://github.com/olemartinorg/i3-alternating-layout.

See on YouTube:

Auto-tiling in action

PLEASE DO READ THIS

The script does one thing: it checks the window height / width ratio, and executes the equivalent of either swaymsg splitv or swaymsg splith. Nothing 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 or outputs only. For instance, you could configure autotiling to be enabled on odd workspaces, but not on even ones:

### Autostart
  exec_always autotiling -w 1 3 5 7 9

Another option you can try, is setting --limit and only use stacking or tabbing on the lowest level. A good place to start would be --limit 2. Open four windows with the third and fourth window in the same container as two. This might mimic a master-stack layout, and you should now be able to switch to stacking or tabbed. Beware that the decision on how to split is still based on the height / width ratio.

Installation

The script has been packaged for the following distributions:

Packaging status

PyPI version

Installing manually:

  1. Install the python-i3ipc>=2.0.1 package (or whatever it's called in your Linux distribution);
  2. save the main.py file anywhere, rename to autotiling, make executable, move to your bin folder;
  3. add exec_always autotiling to the ~/.config/sway/config or exec_always --no-startup-id autotiling to the ~/.config/i3/config file.

Usage

$ autotiling -h
usage: main.py [-h] [-d] [-v] [-o [OUTPUTS ...]] [-w [WORKSPACES ...]]
               [-l LIMIT] [-sw SPLITWIDTH] [-sh SPLITHEIGHT] [-sr SPLITRATIO]
               [-e [EVENTS ...]]

options:
  -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
  -l LIMIT, --limit LIMIT
                        limit how often autotiling will split a container; try
                        "2" if you like master-stack layouts; default: 0 (no
                        limit)
  -sw SPLITWIDTH, --splitwidth SPLITWIDTH
                        set the width of the vertical split (as factor);
                        default: 1.0;
  -sh SPLITHEIGHT, --splitheight SPLITHEIGHT
                        set the height of the horizontal split (as factor);
                        default: 1.0;
  -sr SPLITRATIO, --splitratio SPLITRATIO
                        Split direction ratio - based on window height/width;
                        default: 1;try "1.61", for golden ratio - window has
                        to be 61% wider for left/right split; default: 1.0;
  -e [EVENTS ...], --events [EVENTS ...]
                        list of events to trigger switching split orientation;
                        default: WINDOW MODE

Events

Changing event subscription has already been the objective of several pull request. To avoid doing this again and again, starting from v1.6 you may specify them in the -e | --events argument. If no value given, the script will subscribe to Event.WINDOW and Event.MODE, as if it was executed with autotiling -e WINDOW MODE. See
altdesktop/i3ipc-python` for event enumeration.

autotiling's People

Contributors

0-kala-0 avatar alpheratz0 avatar ammgws avatar dpgraham4401 avatar erikreider avatar josch avatar joseconseco avatar lqp1 avatar morten-b avatar mtshrmn avatar nschloe avatar nwg-piotr avatar syphdias avatar tmpecho avatar travankor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autotiling's Issues

Keybinding to cycle through all windows of a workspace

New to sway, used i3 briefly in the past but prefer dynamic tiling. This script gives me almost everything I need, except I can't figure out a way to get a key binding that just cycles focus through all windows of the current workspace. The focus prev|next [sibling] doesn't work like I want, I don't care about containers or stacks or whatever. I just want to cycle focus, in the forward and backward direction, through ALL windows of the workspace. If this isn't possible by default in sway (as I suspect), would it be something you'd be willing to implement here?

Thanks for making sway usable ;)

Problem moving windows after opened (using i3-gaps, 4.18)

Thanks for your work!

I have one little problem that all the others auto tiling scripts have: if I open a window, I have to press twice to move the window horizontally.

I'm using i3-gaps, 4.18.

Example in a clean workspace:

  • Open window 1
  • Open window 2
  • They both open aside each other
|----------------| 
|        |       |
|   1    |  2    |
|        |       |
|----------------|
  • Now, try to move window 2 to the left
  • It doesnt move
  • Try again and it moves

Could you try to reproduce this? Maybe it has to do with some of my configuration.

expose width/height factor

It would be great to have parameter for width/height ratio like so:
new_layout = "splitv" if con.rect.height > **fac***con.rect.width else "splith"
With this set to, for example, 1.5 - auto-tile we would have wider windows, before they would be split in top/down. When coding, I prefer my windows to be slightly wider than tall.

Script not working properly on ultrawide monitors?

hello,

i'm using 2 ultrawide monitors and tried to use autotiling with sway, but the container never starts vertical splitting until a third column is opened, even when i run it with --limit 2. i'm assuming this has something to do with how the script determines when to split based on width/height, and the extra width of an ultrawide monitor probably messes that up. is there anything that can be done to solve that? i do use dynamic tilers to solve this, but i still love i3/sway as well, but the manual tiling is killing me lol.

Breaks stacking and tabbed layouts on Sway 1.5.1

First of all, I have been looking for this solution and it works great! Thank you.

Though I've noticed that while this script is running, I am unable to switch layouts using my key bindings. Even after killing the script I can't get it to work. I have to comment exec autotiling and restart sway in order for these layouts to work.

I've tested both versions 1.1, and autotiling-git (aur). I am running sway 1.5.1. Any additional information I could provide, or help please let me know.

Thanks again :)

First three containers opened are vertical

I made some themes for sway with a script: https://github.com/indicozy/sway-dotfiles-script

And only on a MacOSBigSur theme, there is an issue with managing containers, image explains itself:

screenshot-2021-05-10-00-51-57

I checked it with every other theme and it worked fine. This issue is created only in this specific config. I will test that on my Linux Virtual Machine and will report any issue later.

How to replicate: Just download my script (or MacOSBigSur config) and try it yourself

Resizing window doesn't update autotiling

Steps to reproduce:
(lets assume we have a regular monitor of 16x9 resolution)

  1. open new window A
  2. open new window B (we now have two windows side by side with the width of 8 and a height of 9)
  3. resize window B to be of width 10 (and a height of 9)
  4. open new window C

Current behavior - window C opens in a horizontal configuration
Expected behavior - window C should open in a vertical configuration

This is happening because when resizing a window the event Event.WINDOW_FOCUS doesn't fire. There's no resize event in the API for a simple solution. Therefore I was able to "hack" it by adding another listener for the Event.TICK event and firing this event each time I resize a window.

NOTE: This was tested on i3-gaps, but I assume it's no different in i3 or sway.

i3 config snippet:

bindsym $mod+r resize set width 927 px; exec --no-startup-id i3-msg -t send_tick

source code manipulation:

diff --git a/autotiling/main.py b/autotiling/main.py
index 896034b..fae9164 100644
--- a/autotiling/main.py
+++ b/autotiling/main.py
@@ -114,6 +114,7 @@ def main():
     handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces)
     i3 = Connection()
     i3.on(Event.WINDOW_FOCUS, handler)
+    i3.on(Event.TICK, handler)
     i3.main()

I'm submitting this issue because my solution is bad and hopefuly someone can find a better one.

Cant Chnage Layout To Tabbed Or Stacking

im using i3, and i dont know if this is an intended feature, but after installing autotiling, i cant execute the layout command at all, this may be another issue tho.

Autotiling does not start with sway but starting from terminal

Hi
Just installed autotiling. Added it to config and it does not start with session.
When I'm starting it from terminal, it works properly.
openSUSE Tumbleweed here.
Autotiling installed via pip but it also does not start installed manually.

#edit
Nevermind... It just started, ehh...

I cant get it to do anything when running from sway config.

I'm running exec_always autotiling as the first line in my config and it doesn't do anything. When I run autotiling in a terminal window it works perfectly. Im on fedora 40 with autotiling version 1.9.1 installed using pip and python 3.12.3.

(sway) Incorrectly determines container as fullscreen

Lately I've found that autotiling isn't working in some situations. For example right now I have two monitors, with Firefox open on one workspace and a terminal open in the other. Opening some terminals on the Firefox workspace results in autotiling working correctly. However on the other workspace, autotiling does not work at all.

I added some extra debug output code to further investigate and found that non-fullscreen containers are being incorrectly flagged as being fullscreen. The screenshot shows 3 vertical containers side by side, and autotiling is reporting each of them as fullscreen:
image

I will look into it a bit further and possibly submit a patch.

Override autotiling

Looks great! I think 90% of the time this is what I would want it to do.

But when I sometimes to want e.g. 6 vertical terminals below each other visibly... how could I achieve it?

autotiling executable: permission denied

Linux noob here, running Mint 20.3.

I moved the main.py into my /usr/bin directory and renamed it 'autotiling.' i set my i3 config file to exec_always --no-startup-id autotiling, but my windows still load the old way. When I type in 'autotiling' into my terminal, it tells me "Permission denied." I have the i3ip-python dependency already installed. Not sure what I'm doing wrong here.

autotiling from i3 config

Am using autotiling under i3 in Arch I run it as per README but I am wondering if I need '&' at end of command to background it?

Have noticed that it was not working correctly recently until I added '&'

Is this correct or am I running command incorrectly?

Wrong manual install instructions and AUR package

Manual install is not possible according to instructions because of #14

==> Checking for dependencies
==> Making package: autotiling-git r64.126c07d-1 (Ne 23. srpna 2020, 00:15:53)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Updating autotiling git repo...
Fetching origin
==> Validating source files with md5sums...
    autotiling ... Skipped
==> Extracting sources...
  -> Creating working copy of autotiling git repo...
Switched to a new branch 'makepkg'
==> Starting pkgver()...
==> Removing existing $pkgdir/ directory...
==> Entering fakeroot environment...
==> Starting package()...
install: cannot stat 'autotiling.py': No such file or directory
==> ERROR: A failure occurred in package().
    Aborting...

Please update the version on PyPI

I am the maintainer of the FreeBSD port of this package.

On FreeBSD, we prefer to draw Python packages from PyPI. Unfortunately, the autotiling package is still on 1.8 over there. Please check if you can upload the newest version of the package to PyPI.

Moving containers become stuck

Testing autotile on the latest sway+wlroots git, I noticed that moving containers with the keyboard sometimes will be broken (moving containers with mouse still works). The only way to be able to move containers again is to kill the autotile script when this happens. Not sure how this happens exactly, but wanted to ask if anyone knows.

Running the manual version in case that's relevant.

The license_file parameter is deprecated, use license_files instead.

Hi,

I'm currently packaging autotiling for Debian and I saw this in my build log:

I: pybuild base:311: python3.11 -m build --skip-dependency-check --no-isolation --wheel --outdir /<<PKGBUILDDIR>>/.pybuild/cpython3_3.11  
* Building wheel...
/usr/lib/python3/dist-packages/setuptools/config/setupcfg.py:293: _DeprecatedConfig: Deprecated config in `setup.cfg`
!!

        ********************************************************************************
        The license_file parameter is deprecated, use license_files instead.

        This deprecation is overdue, please update your project and remove deprecated
        calls to avoid build errors in the future.

        See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.
        ********************************************************************************

!!
  parsed = self.parsers.get(option_name, lambda x: x)(value)

Changelog stops after v1.5

Not sure if this is intentional? If so maybe a note to tell people to go to the releases page or something. Just a small nit.

Can't make a manual install of autotiling anymore

Hello!

I'm not sure since when, but I noticed my autotiling setup was not starting anymore. Here's how I setup it:

  • clone the repo
  • start main.py using python3 interpreter.

I manually tried to run it, and here's what it says:

python main.py       
Traceback (most recent call last):
  File "main.py", line 21, in <module>
    from .__about__ import __version__
ImportError: attempted relative import with no known parent package

Could it be related to #14? I'm not sure how to workaround it?

If it's not possible anymore, can you update the README for future users please?

Thanks in advance for you inputs.

Br

importlib.metadata.PackageNotFoundError: autotiling

autotiling fails to execute after updating. autotiling-git-r97.dbdbfa1-1 version works.


 ~  autotiling
Traceback (most recent call last):
  File "/usr/bin/autotiling", line 33, in <module>
    sys.exit(load_entry_point('autotiling==1.6', 'console_scripts', 'autotiling')())
  File "/usr/bin/autotiling", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.9/importlib/metadata.py", line 524, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.9/importlib/metadata.py", line 187, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: autotiling
yay -Qi autotiling
Name            : autotiling
Version         : 1.6-2
Description     : Script for sway and i3 to
                  automatically switch the horizontal /
                  vertical window split orientation
Architecture    : x86_64
URL             : https://github.com/nwg-piotr/autotiling
Licenses        : GPL3
Groups          : None
Provides        : None
Depends On      : python-i3ipc
Optional Deps   : None
Required By     : None
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 18.50 KiB
Packager        : Chaotic-AUR Wild Bear Node
                  <[email protected]>
Build Date      : Mon 13 Dec 2021 06:39:28 IST
Install Date    : Mon 13 Dec 2021 11:33:05 IST
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature

Python Error when starting the script with Python 3.11

This error is shown when I run autotiling on Manjaro Linux (up to date) with Python 3.11.3:

Traceback (most recent call last):
  File "/usr/lib/python3.11/importlib/metadata/__init__.py", line 563, in from_name
    return next(cls.discover(name=name))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/autotiling", line 33, in <module>
    sys.exit(load_entry_point('autotiling==1.8', 'console_scripts', 'autotiling')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/autotiling", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/metadata/__init__.py", line 981, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/metadata/__init__.py", line 565, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for autotiling

Can no longer move containers laterally between halves of screen

If I have my splits like so and try to move the bottom right container leftward,

|     |     |
|     |_____|
|     |\\\\\|
|     |\\\\\|

I get this and the container becomes stuck and can't be moved leftward any further

|   |\\\|   |
|   |\\\|   |         (Actual)
|   |\\\|   |
|   |\\\|   |


|     |     |
|_____|     |         (Desired)
|\\\\\|     |
|\\\\\|     |

I'm using sway 1.6, wlroots 0.13, and the autotiling script manually copied from repo

Feature-request: Flip existing layout when moving workspace to output in different orientation

When spawning new containers, this project accounts for the output dimensions which are present at that given time.

What I miss is autotiling 'reorienting' or rather flipping the configuration when moving a workspace from a workspace that is wide to one that is tall.

I'm not sure if this is a known bug or just behaviour that I experience, but the default binding for i3wm; bindsym $mod+e layout toggle split, does not flip the current container orientation when pressed after installing autotiling.

Interestingly, in0ni mentioned this recently: #20 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.