gerritdevriese / kzones

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

shift modifier to select multiple zones #43

Open imthenachoman opened 11 months ago

imthenachoman commented 11 months ago

Once we define zones, a window can only be dropped into a specific zone.

It would be nice if, while dragging a window around, you can press shift or ctrl or something to select multiple zones.

For example, you drag to one zone, then press shift/ctrl and drag to another zone and let go. Then the window would drop to a new "meta zone".

I can give more examples if needed.

gerritdevriese commented 11 months ago

As we don't have modifiers (yet), maybe it's an idea to add a small "hitbox" between zones, so when you hover over it, it automatically picks the two neighboring zones to snap into?

Something like this: image

jbtrystram commented 7 months ago

As we don't have modifiers (yet), maybe it's an idea to add a small "hitbox" between zones, so when you hover over it, it automatically picks the two neighboring zones to snap into?

I think the modifier key would be more intuitive to use

jbtrystram commented 7 months ago

I think this feature would be an awesome addition. I started looking at the code, to see if I could contribute that. I've never wrote any kwin scripts before, so bear with me :)

I'm writing my thought process here, in case @gerritdevriese want to give some feedback.

From what I understand, the script is designed this way (in a nutshell):

So a way to make that work would be something like :

I'll give this a go and see how this ends up :)

gerritdevriese commented 6 months ago

I am also in favor of modifier keys instead of hitboxes, but at that time I hadn't found a good way to handle key presses using the KWin API. Maybe it's possible now, but haven't looked in to it recently.

@jbtrystram You can definitely try to tackle this if you want, your thought process looks alright.

irasponsible commented 4 months ago

As a short-term alternative to do something similar, for anyone like me who might be looking, you can make overlapping zones. Only works consistently if you have the snapping set to only when over the icon.

{
"name": "Multiple Offsets",
"padding": 0,
"zones": [
        {
            "x": 0,
            "y": 0,
            "height": 100,
            "width": 30
        },
        {
            "x": 0,
            "y": 0,
            "height": 100,
            "width": 70
        },
        {
            "x": 30,
            "y": 0,
            "height": 100,
            "width": 70
        },
        {
            "x": 70,
            "y": 0,
            "height": 100,
            "width": 30
        }
        ]
}
fynzhak commented 2 months ago

@irasponsible , that's a brilliant idea! I've implemented it for myself and it's working quite well. Unfortunately, the rendering of the zones shows all the overlaps, so it looks bad. I hacked together something that only renders the target zone and it looks pretty good that way. zonetargets

@gerritdevriese , is this something you'd be interested in supporting? It is kind of a weird scenario and I'm not sure of the best way to handle it. An option to only render the target zone? It is a slight improvement at least for my layout, but I'm debating if it's worth the extra complexity in general.

SinanAkkoyun commented 2 months ago

https://github.dev/SinanAkkoyun/kde-kzones/tree/clean-overlapping-zones https://github.dev/SinanAkkoyun/kde-kzones/tree/clean-overlapping-zones-plasma-5

For everyone that wants the quick hack that @fynzhak showed (I just changed 2 lines of code, there is no option to disable the change)

SinanAkkoyun commented 2 months ago
{
        "name": "Super Grid",
        "padding": 26,
        "zones": [
            {
                "x": 25,
                "y": 0,
                "height": 100,
                "width": 50
            },
            {
                "x": 25,
                "y": 0,
                "height": 100,
                "width": 25
            },
            {
                "x": 50,
                "y": 0,
                "height": 100,
                "width": 25
            },
            {
                "x": 0,
                "y": 0,
                "height": 100,
                "width": 25
            },
            {
                "x": 75,
                "y": 0,
                "height": 100,
                "width": 25
            },
            {
                "x": 0,
                "y": 0,
                "height": 50,
                "width": 25
            },
            {
                "x": 0,
                "y": 50,
                "height": 50,
                "width": 25
            },
            {
                "x": 75,
                "y": 0,
                "height": 50,
                "width": 25
            },
            {
                "x": 75,
                "y": 50,
                "height": 50,
                "width": 25
            }
        ]
    },
fynzhak commented 2 months ago

Thanks for sharing that @SinanAkkoyun !

I finally had some time this morning to dig into it a little bit too. Here's a branch that adds an option to choose to render only the target zone or all zones on the overlay: https://github.com/fynzhak/kzones/tree/target_only

I have mine set up to disable the Zone Selector and render only the target zone. That gives me the effect in the screenshot above.

The problem is that if you do have the Zone Selector enabled, it will still render all the overlapping zones and looks bad. I'm not sure what can be done about that. Maybe it's the price to pay for wanting the overlap?

Also, in case anyone is interested, here's my layout:

{
    "name": "AllZones",
    "padding": 0,
    "zones": [
        {
            "x": 0,
            "y": 0,
            "height": 100,
            "width": 25
        },
        {
            "x": 25,
            "y": 0,
            "height": 100,
            "width": 25
        },
        {
            "x": 50,
            "y": 0,
            "height": 100,
            "width": 25
        },
        {
            "x": 75,
            "y": 0,
            "height": 100,
            "width": 25
        },
        {
            "x": 25,
            "y": 0,
            "height": 100,
            "width": 50
        },
        {
            "x": 0,
            "y": 0,
            "height": 50,
            "width": 25
        },
        {
            "x": 25,
            "y": 0,
            "height": 50,
            "width": 25
        },
        {
            "x": 50,
            "y": 0,
            "height": 50,
            "width": 25
        },
        {
            "x": 75,
            "y": 0,
            "height": 50,
            "width": 25
        },
        {
            "x": 0,
            "y": 50,
            "height": 50,
            "width": 25
        },
        {
            "x": 25,
            "y": 50,
            "height": 50,
            "width": 25
        },
        {
            "x": 50,
            "y": 50,
            "height": 50,
            "width": 25
        },
        {
            "x": 75,
            "y": 50,
            "height": 50,
            "width": 25
        },
        {
            "x": 0,
            "y": 0,
            "height": 100,
            "width":50
        },
        {
            "x": 50,
            "y": 0,
            "height": 100,
            "width":50
        }
    ]
}
SinanAkkoyun commented 2 months ago

That's awesome! Thank you for sharing :)

imthenachoman commented 4 weeks ago

Creating a layouts file with overlapping zones is pretty clever!

imthenachoman commented 4 weeks ago

@fynzhak I cloned your repo https://github.com/fynzhak/kzones/tree/target_only and I see the option to only render the target zone but it still renders all of them. Is there something else I have to do?

image

imthenachoman commented 4 weeks ago

@fynzhak Scratch that. I rebooted and now it's working as expected. It's a thing of beauty!

fynzhak commented 4 weeks ago

@imthenachoman , good to hear! I was worried I forgot to commit something. :sweat_smile: I'm glad it's working for you!

Making any changes requires reloading the script. I usually just toggle the script off in the kwin script manager, hit apply, then toggle the script back on.

imthenachoman commented 4 weeks ago

Yeah, I just toggled it but it didn't work. A reboot fixed it.

It's a lovely thing now. The only thing I'd like is if the background darkened/dimmed/blurred when the overlay is active, so it's easier to see the layout boxes -- but that's minor.