gerritdevriese / kzones

KDE KWin Script for snapping windows into zones
https://store.kde.org/p/1909220
GNU General Public License v3.0
285 stars 16 forks source link

Feature Request: layouts per display #4

Closed smolypawa closed 1 month ago

smolypawa commented 2 years ago

It would be nice to see layout per display (monitor) feature. Great script btw!

Bstiler commented 1 year ago

Actually, I have a more helpful suggestion: a new property monitor for the zones. The biggest challenge in my view would be finding a way to identify monitors uniquely. I don't know what APIs plasma provides for this. But if we could identify each individual hardware monitor, things would be interesting.

Just think about it, instead of memorizing a specific keybinding to move a window to another monitor and another one for tiling it, we could just use the tiling keybindings. This way, multi-monitor setups would work more seamlessly on linux.

For zones without the monitor property, the current behavior still applies. Just tile it on the current monitor.

BadCo-NZ commented 1 year ago

Came here looking for this, hopefully this gets implemented soon, otherwise the script looks good!

jmta commented 1 year ago

I've got a single line fix for this if you are happy to just have a single layout per display and not swap between layouts.

Firstly, have however many layouts you have as monitors, with the first for the monitor identified as 0, second for 1, etc... Then, add a line in the refreshClientArea function, "currentLayout = workspace.activeScreen". This means each time the monitor the window is currently on the layout swaps to the one related to that screen.

ghost commented 1 year ago

I've got a single line fix for this if you are happy to just have a single layout per display and not swap between layouts.

Firstly, have however many layouts you have as monitors, with the first for the monitor identified as 0, second for 1, etc... Then, add a line in the refreshClientArea function, "currentLayout = workspace.activeScreen". This means each time the monitor the window is currently on the layout swaps to the one related to that screen.

I can assure that it functions properly on the following system.

                   ./sssso-                ---------------- 
                 `:osssssss+-              OS: EndeavourOS Linux x86_64 
               `:+sssssssssso/.            Host: Z370 AORUS Ultra Gaming 
             `-/ossssssssssssso/.          Kernel: 6.1.6-arch1-3 
           `-/+sssssssssssssssso+:`        Uptime: 23 mins 
         `-:/+sssssssssssssssssso+/.       Packages: 1142 (pacman) 
       `.://osssssssssssssssssssso++-      Shell: bash 5.1.16 
      .://+ssssssssssssssssssssssso++:     Resolution: 2560x1440, 1440x2560 
    .:///ossssssssssssssssssssssssso++:    DE: Plasma 5.26.5 
  `:////ssssssssssssssssssssssssssso+++.   WM: KWin 
`-////+ssssssssssssssssssssssssssso++++-   Theme: [Plasma], Breeze [GTK2/3] 
 `..-+oosssssssssssssssssssssssso+++++/`   Icons: [Plasma], breeze [GTK2/3] 
   ./++++++++++++++++++++++++++++++/:.     Terminal: konsole 
  `:::::::::::::::::::::::::------``       CPU: Intel i7-8700K (12) @ 4.700GHz 
                                           GPU: NVIDIA GeForce GTX 1070 Ti 
                                           Memory: 3261MiB / 32039MiB 

P.S.: Is it possible to add a donations link? : )

Farmerbrown87 commented 1 year ago

I've got a single line fix for this if you are happy to just have a single layout per display and not swap between layouts.

Firstly, have however many layouts you have as monitors, with the first for the monitor identified as 0, second for 1, etc... Then, add a line in the refreshClientArea function, "currentLayout = workspace.activeScreen". This means each time the monitor the window is currently on the layout swaps to the one related to that screen.

I'm a bit new at this... Which file would you add that line too?

thanks in advance

jmta commented 1 year ago

contents/ui/main.qml

I should really try and find a bit of time at some point to put together a PR for this.

@gerritdevriese - Any preference on an implementation for this, mine isn't ideal as you lose a bit of functionality with regards to changeable layouts.

I have thought of a few ideas, multiplying monitor id by configuration number for example. Or a configuration for each display. Are either, or an alternative more in keeping with your design philosophy?

Farmerbrown87 commented 1 year ago

Thank you, I have found it.

I have added the line to the refreshClientArea function as below, and I have labelled by layouts as "0", "1" and "2".

    function refreshClientArea() {
        activeScreen = workspace.activeScreen
        clientArea = workspace.clientArea(KWin.FullScreenArea, workspace.activeScreen, workspace.currentDesktop)
        currentLayout = workspace.activeScreen
    }

Then I have disabled/applied/enabled/applied the script in KWin scripts. However, the only change is the Layout is labelled "0" on all monitors.

I'm not sure if I'm missing something which supports this option or whether I have entered something incorrectly at this stage.

dkomljenovic2502 commented 1 year ago

Reboot your pc! That also confused me. Or there is a test with running kwin something in the terminal (i dont remember the command, and i am not by my pc to check). But that was just executed til i ctrl+c it Also i had issues with a freezing window which worked when i resized when my screem was 25-75% on the left, but 26-74% was no freezing

jmta commented 1 year ago

Install via KDE Store or clone this repo and run the ./build script.

Running the build script was all I needed from memory

Farmerbrown87 commented 1 year ago

Reboot your pc! That also confused me. Or there is a test with running kwin something in the terminal (i dont remember the command, and i am not by my pc to check). But that was just executed til i ctrl+c it Also i had issues with a freezing window which worked when i resized when my screem was 25-75% on the left, but 26-74% was no freezing

Rebooting worked! Thank you.

I have an issue with the way I have set up my third monitor, I'll enable debug mode later on and see if I can fix. I'm sure it's just a confusion with the monitor positioning or positive/neg y positioning.

dkomljenovic2502 commented 1 year ago

If you can write how you will debug it and solve that would be nice!

Farmerbrown87 commented 1 year ago

I located problem between the keyboard and chair. The squishy part controlling the keyboard managed to enter several values in the json incorrectly. I'd advise others to correctly caffeinate themselves whilst entering the layout values. Corrected json below.

[
    {
        "name": "0",
        "padding": 10,
        "zones": [
            {
                "name": "1",
                "x": 0,
                "y": 0,
                "height": 100,
                "width": 25
            },
            {
                "name": "2",
                "x": 25,
                "y": 0,
                "height": 100,
                "width": 50
            },
            {
                "name": "3",
                "x": 75,
                "y": 0,
                "height": 100,
                "width": 25
            }
        ]
    },
    {
        "name": "1",
        "padding": 10,
        "zones": [
            {
                "name": "1",
                "x": 0,
                "y": 0,
                "height": 30,
                "width": 100
            },
            {
                "name": "2",
                "x": 0,
                "y": 30,
                "height": 40,
                "width": 100
            },
            {
                "name": "3",
                "x": 0,
                "y": 70,
                "height": 30,
                "width": 100
            }
        ]
    },
    {
        "name": "2",
        "padding": 10,
        "zones": [
            {
                "name": "1",
                "x": 0,
                "y": 0,
                "height": 100,
                "width": 25
            },
            {
                "name": "2",
                "x": 25,
                "y": 0,
                "height": 100,
                "width": 50
            },
            {
                "name": "3",
                "x": 75,
                "y": 0,
                "height": 100,
                "width": 25
            }
        ]
    }
]
ghost commented 1 year ago

I'm a bit new at this... Which file would you add that line too?

thanks in advance

Hi there! Sorry for the delayed response, I just received the notification. It seems that you were able to resolve the issue on your own. Although, when windows are snapped on the primary display they dont resize at all. It may be related to X11 idk.. I will try to create a bug report in the coming days.

trivoldus28 commented 1 year ago

Hi all I think I got layout per display/virtual desktop/activity to work with the pull req above ;). It's a hack, nothing fancy, and pretty rudimentary but works for my needs. I think it should be working correctly but maybe more testing is needed. If you want you can try the feature before it merged with my fork of the script (https://github.com/trivoldus28/kzones/tree/layout_per_screen2).

ldsands commented 8 months ago

Hi all I think I got layout per display/virtual desktop/activity to work with the pull req above ;). It's a hack, nothing fancy, and pretty rudimentary but works for my needs. I think it should be working correctly but maybe more testing is needed. If you want you can try the feature before it merged with my fork of the script (https://github.com/trivoldus28/kzones/tree/layout_per_screen2).

I just tried this out and it seems to work fine. Any chance that this could lead to a release?

gerritdevriese commented 8 months ago

@trivoldus28 Can you create a PR for this?

sesu-tech commented 8 months ago

+1, just adding my voice here. I'm maining KZones and it's the best replacement for FancyZones for me on Linux! :)

ldsands commented 8 months ago

This should probably be a new issue, but until the Trivoldus28's feature/hack is merged, I thought this may be a better place for it.

I've noticed that KZones (using trivoldus28's feature/hack) doesn't remember which layout I chose per monitor. To illustrate with an example, I have one monitor horizontal and one vertical (on its side). To accommodate this, I have two layouts. Each time I restart, both monitors default to the first layout specified in my .json file. I also use virtual desktops so that could be related.

trivoldus28 commented 7 months ago

Sorry people, just got time now to get to this, made a PR for review @gerritdevriese : https://github.com/gerritdevriese/kzones/pull/60

@ldsands Do you mean you want the selected layout to be remembered across reboots?

ldsands commented 7 months ago

Sorry people, just got time now to get to this, made a PR for review @gerritdevriese : #60

@ldsands Do you mean you want the selected layout to be remembered across reboots?

Yup, that would be ideal.

gerritdevriese commented 1 month ago

Hi all, the following branch should be able to track layouts between different monitors: https://github.com/gerritdevriese/kzones/tree/layouts-per-monitor (extra config option, disabled by default)

If anyone can test & provide feedback that would be great.

SoyDiego commented 1 month ago

Hi all, the following branch should be able to track layouts between different monitors: https://github.com/gerritdevriese/kzones/tree/layouts-per-monitor (extra config option, disabled by default)

If anyone can test & provide feedback that would be great.

I can test it. Could you guide me how to test from this branch because I don't know and will be my first time doing like this.

Thanks

gerritdevriese commented 1 month ago

Sure, run the following in a temp directory:

git clone --branch layouts-per-monitor https://github.com/gerritdevriese/kzones
cd kzones && make

If the config option doesn't show up right away, restart your system.

SoyDiego commented 1 month ago

Sure, run the following in a temp directory:

git clone --branch layouts-per-monitor https://github.com/gerritdevriese/kzones
cd kzones && make

If the config option doesn't show up right away, restart your system.

Great and I need to uninstall the version 0.8 that I have in this moment to test this branch? Will not have conflicts?

I will try following your instructions.

Thanks again

gerritdevriese commented 1 month ago

Great and I need to uninstall the version 0.8 that I have in this moment to test this branch? Will not have conflicts?

No, the makefile will just update the script if it is already installed.

SoyDiego commented 1 month ago

Great and I need to uninstall the version 0.8 that I have in this moment to test this branch? Will not have conflicts?

No, the makefile will just update the script if it is already installed.

Ok I did all the steps that you told me and in my terminal I can see this information:

      ~/Desktop/test-kzones/kzones     layouts-per-monitor  make                                                                                               ✔ 
mkdir -p pkg
mkdir -p pkg/contents/code
mkdir pkg/contents/config
mkdir pkg/contents/ui
cp -rf src/metadata.json pkg/
cp -rf src/contents/* pkg/contents/
zip -r kzones.kwinscript pkg
  adding: pkg/ (stored 0%)
  adding: pkg/contents/ (stored 0%)
  adding: pkg/contents/code/ (stored 0%)
  adding: pkg/contents/code/main.js (stored 0%)
  adding: pkg/contents/ui/ (stored 0%)
  adding: pkg/contents/ui/components/ (stored 0%)
  adding: pkg/contents/ui/components/Indicator.qml (deflated 64%)
  adding: pkg/contents/ui/components/Shadow.qml (deflated 41%)
  adding: pkg/contents/ui/config.ui (deflated 88%)
  adding: pkg/contents/ui/main.qml (deflated 82%)
  adding: pkg/contents/config/ (stored 0%)
  adding: pkg/contents/config/main.xml (deflated 82%)
  adding: pkg/metadata.json (deflated 53%)
kpackagetool6 --type=KWin/Script -i kzones.kwinscript || kpackagetool6 --type=KWin/Script -u kzones.kwinscript
Error: Installation of /home/diego/Desktop/test-kzones/kzones/kzones.kwinscript failed: /home/diego/.local/share/kwin/scripts/kzones already exists
Upgrading package from file: /home/diego/Desktop/test-kzones/kzones/kzones.kwinscript
Successfully upgraded /home/diego/.local/share/kwin/scripts/kzones/
rm -r pkg
rm kzones.kwinscript
if [ "$XDG_SESSION_TYPE" = "x11" ]; then \
    kwin_x11 --replace & disown; \
elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then \
    kwin_wayland --replace & disown; \
else \
    echo "Unknown session type"; \
fi
kwriteconfig6 --file kwinrc --group Plugins --key kzonesEnabled true
qdbus org.kde.KWin /KWin reconfigure
      ~/Desktop/test-kzones/kzones     layouts-per-monitor  Module 'org.kde.kwin.decoration' does not contain a module identifier directive - it cannot be protected from external registrations.
OpenGL vendor string:                   Intel
OpenGL renderer string:                 Mesa Intel(R) Graphics (RPL-S)
OpenGL version string:                  4.6 (Compatibility Profile) Mesa 24.1.6-arch1.1
OpenGL shading language version string: 4.60
Driver:                                 Intel
GPU class:                              Unknown
OpenGL version:                         4.6
GLSL version:                           4.60
Mesa version:                           24.1.6
Requires strict binding:                yes
Virtual Machine:                        no
Timer query support:                    yes

And I can see fast window appearing but it's closing inmediately. I cannot see nothing, and also I restarted. is it normal? If i'm not doing something ok, let me know and we can continue testing =)

gerritdevriese commented 1 month ago

I don't see anything out of the ordinary, it should be installed now. Can you open the script settings and let me know if you have the "Track active layout per screen" checkbox?

SoyDiego commented 1 month ago

I don't see anything out of the ordinary, it should be installed now. Can you open the script settings and let me know if you have the "Track active layout per screen" checkbox?

Yes I have the option. It was not checked and I did, but is not tracking the monitors.

image

Also I tried to deactivated and activated kzones to see if the changes are applying but it's not working.

I can help you with more tests, let me know and I will pass the things that i'm trying.

SoyDiego commented 1 month ago

After two or three tries, it looks like the monitors are being tracked properly, and I think it’s working well. On my vertical monitor, I have my vertical layout, and on my second monitor, I have my horizontal layout. I will continue testing, and I’ll report here if I notice anything wrong @gerritdevriese. Good job!

SoyDiego commented 1 month ago

Hi @gerritdevriese, I noticed that when you use the shortcut meta + num [0-9], the window moves correctly, but the layout is wrong. It seems like it’s not tracking properly.

You can reproduce the issue this way:

  1. Go to your Layout 1 (Monitor 1).
  2. Move the window to a different zone within Layout 1 using meta + num [0-9].
  3. Now, switch to Layout 2 (Monitor 2) and move the window to a different zone using meta + num [0-9].
  4. You'll notice the window will be move with the design of the Layout 1 instead of Layout 2.

Sorry for my english if it's not perfect. Maybe we should create a new issue to avoid continuing the discussion here (Let me know and I can move this post to a new issue if you prefer)

Thanks again!

gerritdevriese commented 1 month ago

Nice catch! I pushed a fix to the same branch, you can rerun the same steps as before to install.

We can keep the discussion here as it is still on topic.

SoyDiego commented 1 month ago

Nice catch! I pushed a fix to the same branch, you can rerun the same steps as before to install.

We can keep the discussion here as it is still on topic.

Hi @gerritdevriese, now it's working perfectly! Good job again!

I only have one question: Is it not possible to detect the layout automatically in the monitor that you are? Or do we always have to select the layout on the monitor we're currently using for the first time, and only then will it be tracked?

First time in monitor 1 or monitor 2 I need to go to the top, select the layout and in that moment is tracking the layout. I need to check if I restart my machine, continue tracking or I need to do it again (I will check it right now and I will write about that later).

Anyway, good job and thanks for continue working in this kwin script, it's great :)

Let me know if you need any more help!

SoyDiego commented 1 month ago

I restarted my laptop and yes, it is not remembering. the layout selected. After restart, I need to go to the top, select the layout per monitor and in that moment it is start tracking...

I hope this information helps @gerritdevriese! :)

gerritdevriese commented 1 month ago

I restarted my laptop and yes, it is not remembering. the layout selected. After restart, I need to go to the top, select the layout per monitor and in that moment it is start tracking...

Correct, it won't, maybe I (or someone else) can further improve multi monitor support, but it's not something I have a lot of time for right now.

I only use a single monitor myself so it's quite difficult to test these things 😁

SoyDiego commented 1 month ago

I restarted my laptop and yes, it is not remembering. the layout selected. After restart, I need to go to the top, select the layout per monitor and in that moment it is start tracking...

Correct, it won't, maybe I (or someone else) can further improve multi monitor support, but it's not something I have a lot of time for right now.

I only use a single monitor myself so it's quite difficult to test these things 😁

I can test it when you need help or something and also If I can help or try to do a PR, I will do it, but I have never create kwin scripts or coding Linux things, only a little bit of bash haha.

But it's a good start. I don't know why a lot of people was asking and writing about this feature and now I'm the only one testing or trying to help.

Anyway, thanks again for your work and this feature and open the apps in specific zone were the things that I was waiting haha. I'm happy now.

If you need any help or test let me know or you can find me in Discord too with the nickname zer0byte :)