PaperWM icon indicating copy to clipboard operation
PaperWM copied to clipboard

Always Center

Open rawkode opened this issue 4 years ago • 6 comments

The more I use PaperWM, the more I play around with certain applications behind slightly different widths.

It would be really beneficial if there was an option to always center on the active window

rawkode avatar May 04 '20 22:05 rawkode

#150 might be close enough to this

CC @olejorgenb

rawkode avatar May 04 '20 22:05 rawkode

You can get something like this by turning up the horizontal margin (eg. to 1/2 the screen). It won't center the first and last window though, and the preference gui still has a bug which limits you to max 100px so you'll have to use eg. dconf-editor to set it higher.

Auto centering would absolutely be nice, especially on wide screens.

I guess there's a few options here:

  • add a «mode» that can be toggled
  • let windows inherit centering, ie. if the previous window was centered, center the new one. That might be workable as a default.

For a quick local fix this should work in user.js (and similarly for Space.switchLeft/Right):

    let orgSwitch = Tiling.Space.prototype.switchLinear;
    Tiling.Space.prototype.switchLinear = function (dir) {
        orgSwitch.call(this, dir);
        Tiling.centerWindowHorizontally(this.selectedWindow);
    }

hedning avatar May 04 '20 22:05 hedning

@hedning

how to properly paste the code in user.js ? inside enable function or outside ?

todiadiyatmo avatar May 23 '20 05:05 todiadiyatmo

The fix hedning suggested should go in the init function. (otherwise a new override layer would be added each time the screen was unlocked)

olejorgenb avatar May 23 '20 07:05 olejorgenb

can you descript it on details? it dooesn't work for me @olejorgenb

rien7 avatar Jun 10 '20 12:06 rien7

The init function in ".config/paperwm/user.js" should look like this: (you need to restart gnome shell after making the change)

function init() {
    // Runs _only_ once on startup

    // Initialize extension imports here to make gnome-shell-reload work
    Extension = imports.misc.extensionUtils.getCurrentExtension();
    Me = Extension.imports.user;
    Tiling = Extension.imports.tiling;
    Utils = Extension.imports.utils;
    Keybindings = Extension.imports.keybindings;
    Examples = Extension.imports.examples;
    App = Extension.imports.app;

    let orgSwitch = Tiling.Space.prototype.switchLinear;
    Tiling.Space.prototype.switchLinear = function (dir) {
        orgSwitch.call(this, dir);
        Tiling.centerWindowHorizontally(this.selectedWindow);
    }
}

Note: didn't actually test it myself though :) Note: it will only work for the linear keybindings (<Super>,/<Super>.) You need to add similar wrappers for the left/right actions.

olejorgenb avatar Jun 10 '20 17:06 olejorgenb

#482 does this. Well, it adds a persistent sticky centering mode (can set it at a workspace level). Just collecting feedback for this atm - after that (if no showstoppers) I'll merge it in.

jtaala avatar Mar 11 '23 06:03 jtaala