Giter Club home page Giter Club logo

sticky-window-snapping's Introduction

Sticky Window Snapping

KWin script to let snapped window edges stick together when one window is resized.

The script provides an easy to use configuration dialog, which can be reached via systemsettings. (However, note section “Bugs and Workarounds”.)

When windows stick accidentally, you can release them by shaking the mouse while still resizing. The exact behavior is configurable. This feature can also be disabled.

Additionally, the script registers two global shortcuts: one for enabling/disabling the script permanently, and one for enabling/disabling the script only for the next resize. By default, no key combinations are assigned. You can change this using systemsettings (or kcmshell6 keys); the shortcuts are associated with the component “KWin”. Their names are prefixed by “KWin Script: Sticky Window Snapping”.

Bugs and Workarounds

  • If the configuration dialog is not reachable via systemsettings, then try running the following included script and restart systemsettings:

    ~/.local/share/kwin/scripts/sticky-window-snapping/backwards-compatibility/metadata-backwards-compatibility-fix.bash
    
  • If the script does not work, the options under the “Fine Tuning” tab in the configuration dialog might help.

Known issues

  • There is no optical feedback when a shortcut is pressed. I do not know how to initiate a KNotify notification from a KWin script. There is the function callDBus, but I do not know if or how it can be used for that purpose. KNotify provides the method event via D-Bus, but it expects arguments of types for which I do not know how to produce values with JavaScript.
  • Currently, not only snapped window edges are considered as connected, but even edges which are only on the same row/column are considered as connected. I have not decided yet if this is a bug or a feature.

sticky-window-snapping's People

Contributors

flupp avatar zren avatar zzag 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

sticky-window-snapping's Issues

Resizing from another kwin script / wmctrl

So I really wanted to have some grow and shrink shortcuts. I experimented a bit with wmctrl -r :ACTIVE: -e 0,0,0,700,5 made a script and all that. Then I retooled this kwin script a bit, like so

function shrinkCurrentWindow() {
  var win = workspace.activeClient;
  win.geometry = {
      x: win.x + 25,
      y: win.y + 25,
      width: win.width - 50,
      height: win.height - 50,
  }
}

The problem is that the windows resize when you are using the mouse to resize, not some script (kwin, or bash), otherwise the window that is being resized simply goes beyond the edges/borders of the adjacent windows, making this kwin script have no effect at all.

The idea with this is basically replicate a more tiling sorta thing. I am very aware there are some kwin scripts for that too, but KWin script to let snapped window edges stick together when one window is resized. here I have a window that is being resized :)

In KWin5 this no longer works with quick-tiled windows

In kwin 4.x it works perfect, in 5.x you will have the problem that a window which is quick tiled can't be easily resized (it snaps back when you resize it). So the awesome thing you can do in 4.x where you quick tile a window to the left, then one to the right, then you just resize in the middle to change the percent each has - that doesn't work in KWin 5.x.

Here's a gif of how it doesn't work anymore... (and at the end - that was what I was hoping to accomplish)
sticky-snapping

Only consider window edges that transitively touch each other

There is the following longstanding deficiency:

Currently, not only snapped window edges are considered as connected, but even edges which are only on the same row/column are considered as connected. I have not decided yet if this is a bug or a feature.

A not too inefficient algorithm to find exactly those windows that transitively touch the moved edge might look as follows; we assume a vertical edge is moved:

  • Let W be the set of all windows.
  • Let S = {the resized window}.
  • Let TODO = WS.
  • Let x be the current horizontal position of the moved vertical edge.
  • Let l be the vertical position of the lower edge of the resized window.
  • Let u be the vertical position of the upper edge of the resized window.
  • While TODO ≠ ∅:
    • Choose cTODO.
    • TODO = TODOc.
    • If c has a vertical edge that has horizontal position x and that touches the interval (l, u), then:
      • Let S = S ∪ {c}.
      • Let l = min(l, vertical position of the lower edge of c).
      • Let u = max(u, vertical position of the upper edge of c).
      • Let TODO = WS.
  • Now S should contain exactly those windows that transitively stick to the moved edge.

Runtime presumably is in O(|W|²).

Do not resize over lapping windows

For example, if there is a window maximized, and another window tiled to left, resize the top edge will resize both window, but IMHO, resize overlapped window is not a common use case and could be annoying.

Configuration file not in "expected location"

Hi! I installed the Sticky Window Snapping extension and ran the commands bellow so that the configuration dialog would appear in System Settings.

mkdir --parents ~/.local/share/kservices5/
ln --relative --symbolic ~/.local/share/kwin/scripts/sticky-window-snapping/metadata.desktop ~/.local/share/kservices5/kwin-script-sticky-window-snapping.desktop

After restarting System Settings the "Configure" button does appear, but when I click it I get the following error message: "Plugin does not provide configuration file in expected location".
Sticky_edges

The plugin itself is working, but I cannot change any settings.

I installed version 1.0.1 of the plugin. Below is my system info:

Operating System: Kubuntu 21.10
KDE Plasma Version: 5.24.0
KDE Frameworks Version: 5.90.0
Qt Version: 5.15.2
Kernel Version: 5.13.0-28-generic (64-bit)
Graphics Platform: X11
Processors: 16 × AMD Ryzen 7 3700X 8-Core Processor
Memory: 15,6 GiB of RAM
Graphics Processor: NVIDIA GeForce GTX 1660/PCIe/SSE2

How to debug non-working script

Don't want to open a seperate issue just yet - but is trying to figure out why it doesn't work on my system (Opensuse TW, Plasma 5.22.2, Framework 5.83, Wayland + Intel) and not certain its related to Sticky Window Snapping, but something else - hence commenting here...
Tried reinstalling it, enabling/reenabling, reboot etc.

Is there a good way to get proper info about what may be going wrong to provide a better bug report?

Originally posted by @ohyrans in #14 (comment)

new release for plasma 5.22

the kde store still uses the release from 2018, since most users will install this via the get new stuff button, we should use a new release for that.

Incompatible with KWin Wayland

I noticed that this script was not compatible with KWin on Wayland when I tried it a few months ago. Is this still the case?

Not working on plasma 5.21

It was working before, but after I update it to version 5.21, it stopped working. I already tried to reinstall, change settings, but nothing works. Is there a way I can debug or get any kind of log to find out what's going on?

Not working on plasma 5.22 beta

Since I upgraded to this version of the plasma the script is no longer working.

I did a test on a virtual machine with KDE Neon unstable to check if it was a specific problem with my system but the problem also happened there.

The test was done with the version available at store.kde.org and that of github.

Across desktops...

So, I wanted to make this work across desktops.
Commenting out one line didn't work:
// if (c.desktop !== workspace.currentDesktop && !c.onAllDesktops) continue;
I had to also comment out the c.screen line:
// if (c.screen !== client.screen) continue;

I was going to add this as an option to a fork, but wanted to ask about the above change (which would be made into a condition of course), first; annnd, I didn't want to waste my time unless you thought it might be an acceptable PR if done properly.

Not working with Plasma 5.26 beta

SUMMARY
This script no longer seems to work with kwin 5.25.90 (but it works if I downgrade kwin to 5.25.5). I have checked in a VM and using a different user account.

STEPS TO REPRODUCE

  1. Upgrade to kwin 5.25.90 (beta of 5.26)
  2. Install this script
  3. Enable this script in System Settings > Window Management > Kwin Scripts
  4. Reboot
  5. Tile two windows to the left half and right half of the screen respectively, and try to resize them.

OBSERVED RESULTS
Only one of the windows is resized.
I find many error messages like this in the journalctl output:

kwin_x11[2964]: file:///usr/share/kwin/scripts/sticky-window-snapping/contents/code/main.js:349: Error: Cannot assign QJSValue to QRectF

EXPECTED RESULTS
Both windows should be resized since their borders touch

SOFTWARE VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 5.25.90
KDE Frameworks Version: 5.98.0
Qt Version: 5.15.6
Kernel Version: 5.15.68-1-lts (64-bit)
Graphics Platform: X11

ADDITIONAL INFORMATION
I have installed the script using this AUR package: https://aur.archlinux.org/packages/kwin-scripts-sticky-window-snapping-git

The script neither works on on X11 nor on Wayland.

Shortcuts not appearing in Global Shortcuts

Just installed this lovely script alongside Excquisite (the only other Kwin script I have), I had the issue where I couldn't see settings, so fixed that thanks to your instructions, however I still can't see the 2 added shortcuts you speak of. Popped some info below let me know if you need anything else.

Operating System: Kubuntu 22.04
KDE Plasma Version: 5.24.7
KDE Frameworks Version: 5.92.0
Qt Version: 5.15.3
Kernel Version: 5.15.0-53-generic (64-bit)
Graphics Platform: X11

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.