Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Set the floating window to the center of screen #249

Open
Piping opened this issue Aug 20, 2021 · 3 comments
Open

Set the floating window to the center of screen #249

Piping opened this issue Aug 20, 2021 · 3 comments

Comments

@Piping
Copy link

Piping commented Aug 20, 2021

Hi,

Is it possible to add a keyboard shortcut to center the floating window on the screen?

Currently I can bind a shortcut to make a tiling window into float mode, but I wish I could center the window right after set it to float mode.

Is it possible to accomplish the sequence in setting? If not, is there a way to do it programmatically?

Thanks

@faho faho closed this as completed Aug 20, 2021
@faho faho reopened this Aug 20, 2021
@Piping
Copy link
Author

Piping commented Aug 20, 2021

in code contents/code/tilingmanager.js I see I can write a new function like this

KWin.registerShortcut("TILING: Toggle Floating",
  "TILING: Toggle Floating and center the Application Window",
  "",
  function() {
      var client = workspace.activeClient;
      if (client == null) {
          print("No active client");
          return;
      }
      // This can be undefined if the client
      // has never been seen before
      if (client.tiling_floating
         || client.tiling_floating == null) {
          client.tiling_floating = false;
          self.tiles.addClient(client);
      } else {
          client.tiling_floating = true;
          self.tiles.untileClient(client);
         ///// maybe center the client here?
      }
  });

But I am not sure which api I can use to center the client

@faho
Copy link
Collaborator

faho commented Aug 20, 2021

The client's shape is stored in client.geometry. You'll have to set that so that the middle of that is the middle of the screenrectangle.

There is no specific api to "center". (Kwin's plugin api is old school, barebones and badly documented)

@Piping
Copy link
Author

Piping commented Aug 20, 2021

function() {
    var client = workspace.activeClient;
    if (client == null) {
        print("No active client");
        return;
    }
    // This can be undefined if the client
    // has never been seen before
    if (client.tiling_floating
       || client.tiling_floating == null) {
        client.tiling_floating = false;
        self.tiles.addClient(client);
    } else {
        client.tiling_floating = true;
        self.tiles.untileClient(client);
        var maxArea = workspace.clientArea(KWin.MaximizeArea, client);
        client.geometry = {
            x: maxArea.x + (maxArea.width - client.width) / 2,
            y: maxArea.y + (maxArea.height - client.height) / 2,
            width: client.width,
            height: client.height
        };
    }

I tried one online script, the logic seems to be working in
qdbus org.kde.plasmashell /PlasmaShell showInteractiveKWinConsole,

but inside tilingmanager.js, it only toggles the float, and does not move the window to the center of screen. Do you know if there is any state I am missing to configure?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants