Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect window TopLeft coordinates (out of screen) after moving it at another space. #351

Closed
AlaxJI opened this issue Jul 4, 2024 · 11 comments
Labels

Comments

@AlaxJI
Copy link

AlaxJI commented Jul 4, 2024

  • Version: 4.0.1
  • macOS: 14.5
  • multiscreen

Incorrect (out of screen) window TopLeft coordinates after moving it at another space.

Screen index: 0
visibleFrame:
    'y' => "0"
    'x' => "0"
    'width' => "1920"
    'height' => "1055"

Screen index: 1
visibleFrame: 
    'y' => "-848"
    'x' => "1920"
    'width' => "1312"
    'height' => "818"

Screen index: 2
visibleFrame: 
    'y' => "0"
    'x' => "1920"
    'width' => "1920"
    'height' => "1055"

Moving window to space 11

space index: 11
visibleFrame: 
    'y' => "-848"
    'x' => "1920"
    'width' => "1312"
    'height' => "818"
window topLeft:
    'x' => "1920"
    'y' => "25"
@kasper
Copy link
Owner

kasper commented Jul 7, 2024

@AlaxJI Hey, thanks for reporting! I’m going to presume you get the coordinates for the window again after moving to the new space?

Sounds like it’s a regression created by #350 for multi-monitor setups. Also reported in: #348 (comment)

Unfortunately, I’m unsure how to fix it at the moment. @metakirby5 would you have any thoughts?

@metakirby5
Copy link
Contributor

Not really sure, I haven't experienced the issue with my multi-monitor setup 🤔

In System Settings > Desktop & Dock > Mission Control, do you have Displays have separate spaces on or off? I wonder if a difference in settings there is related.

Otherwise, it would help to have a minimal config to reproduce the issue.

(To be honest, I don't fully understand how the API I used in #350 works, since it's totally undocumented. I mostly just observed how other tools were using it and verified it worked on my end.)

@AlaxJI
Copy link
Author

AlaxJI commented Jul 18, 2024

In System Settings > Desktop & Dock > Mission Control, do you have Displays have separate spaces on or off? I wonder if a difference in settings there is related.

I have it on.

Otherwise, it would help to have a minimal config to reproduce the issue.

My javascript is poor, but this is my config:

const applicationMapToSpace = {
  "NetBeans": 6,
  "DBeaver": 7,
  "Telegram": 11,
  "Slack": 11,
  "WhatsApp": 11,
};

var getMainWindow = async function (app) {
  return new Promise((resolve, reject) => {
    if (typeof app.mainWindow() !== "undefined") {
      resolve(app.mainWindow());
    } else {
      setTimeout(() => {
        getMainWindow(app).then((resolveApp) => {resolve(resolveApp);});
      }, 1000);
    }
  });
};


var moveAppToSpace = function (app) {
  var entry = Object.entries(applicationMapToSpace).find(([key, value]) => app.name().indexOf(key) >= 0);
  if (typeof entry !== 'undefined') {
    var name = entry[0];
    var spaceNumber = entry[1];
    getMainWindow(app).then((window) => {
      var spaces = Space.all();
      var i = 0;
      for (let index = 0; index < spaces.length; index++) {
        if (!spaces[index].isFullScreen()) {
          i++;
        }
        if (i === spaceNumber) {
          var space = spaces[index];
          if (!window.spaces()[0].isEqual(space)) {
            space.moveWindows([window]);
            setTimeout(() => {
              window.focus();
              window.maximize();
            }, 500)
          }
        }
      }
      });
  }
}

const moverOnLaunch = Event.on('appDidLaunch', (app) => {
  moveAppToSpace(app);
});

const moverOnActivate = Event.on('appDidActivate', (app) => {
  moveAppToSpace(app);
});

This is my "Arrange Displays". Each display have five spaces.
2024-07-10_07-03-31

@metakirby5
Copy link
Contributor

@AlaxJI Thanks! I found that in my config, I had been updating the window via setTopLeft and setSize after moving it to a new screen, using values from the new screen's flippedVisibleFrame. Would you mind giving it a try too? It would probably go right after the call to space.moveWindows([window]).

@AlaxJI
Copy link
Author

AlaxJI commented Jul 21, 2024

@metakirby5 Thanks!

updating the window via setTopLeft and setSize after moving it

It's work!!!

@kasper kasper removed this from the 4.0.2 milestone Jul 21, 2024
@kasper kasper added question and removed bug labels Jul 21, 2024
@kasper
Copy link
Owner

kasper commented Jul 21, 2024

Glad to hear! Thanks @metakirby5 for assisting on this one. ❤️

@kasper
Copy link
Owner

kasper commented Jul 21, 2024

@dan-phantom Hey! Could you also confirm your code and post a snippet of the logic that was not working for you?

@dan-phantom
Copy link

dan-phantom commented Jul 25, 2024 via email

@dan-phantom
Copy link

More details, sorry for the delay @kasper

I have 3 screens, MBP + 2 externals, each of them has 4 spaces on it

This is the code

const loadConfig = () => {
  _.each(screens, (screen) => {
    const screenConfig = screenMap[screen.id];

    
    if (screenConfig && screen.raw.identifier() === screen.id) {
    
      _.each(screen.raw.spaces(), (space, idx) => {
        wait(1000);
        _.each(
          screenConfig.config?.[screens.length].spaces[idx]?.apps,
          (app) => {
            const appWins = App.get(app)?.windows() || [];
            console.log(
              `app space: ${app}  ${idx} ${space.hash()} ${appWins?.length}`
            );
            space.moveWindows(appWins);

            _.each(appWins, (win) => {
              wait(1000);

              win.maximize();
            });
          }
        );
      });
    }
  });


};

and screenMap is something like

const screenMap = {
  "37D8832A-2D66-02CA-blah": {
    name: "Macbook",
    config: {
      3: {
        spaces: [{ apps: ["Warp"] }],
      },
    },
  },
  "B19F092B-DEA3-422F-blah": {
    name: "Left",
    config: {
      3: {
        spaces: [
          { apps: ["Code"] },
          { apps: ["Linear"] },
          { apps: ["Notion"] },
          { apps: ["Rive", "ForkLift"] },
        ],
      },
    },
  },
  "CBFD144E-D4D8-4FF5-blah": {
    name: "Right",
    config: {
      3: {
        spaces: [
          {
            apps: [
              "Microsoft Edge",
              "Google Chrome",
              "Firefox",
              "Safari",
              "Brave Browser",
            ],
          },
          {
            apps: ["com.apple.iphonesimulator", "Vysor"],
          },
          { apps: ["Slack", "Gmail", "Google Calendar"] },
          { apps: ["Spotify"] },
        ],
      },
    },
  },
};

@dan-phantom
Copy link

@metakirby5 @kasper I can also confirm the setTopLeft works for me too , I call it before maximise ❤️

@kasper
Copy link
Owner

kasper commented Jul 31, 2024

@dan-phantom Perfect, great to hear! Thanks!

@kasper kasper closed this as completed Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants