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

windows are not properly sized when moved to another screen #84

Closed
aaronjensen opened this issue Mar 25, 2016 · 6 comments
Closed

windows are not properly sized when moved to another screen #84

aaronjensen opened this issue Mar 25, 2016 · 6 comments
Assignees
Labels
Milestone

Comments

@aaronjensen
Copy link

For some reason this only appears to apply to some windows. For me, emacs is one such window that cannot be moved to another screen and resized at the same time.

To repro, you need two monitors of different sizes (I have a dell 30" and a 15" Retina MBP). My laptop is to the left of my monitor and positioned about 300px down from the top of the 30"

Using this code:

function p(obj) {
  Phoenix.log(JSON.stringify(obj))
  return obj
}

function move_window(rect, screen) {
  screen = screen || Window.focusedWindow().screen()
  var scr = screen.visibleFrameInRectangle();
  p(scr)
  var r = {
    x: Math.round(scr.x + rect.x * scr.width),
    y: Math.round(scr.y + rect.y * scr.height),
    width: Math.round(scr.width * rect.width),
    height: Math.round(scr.height * rect.height),
  };
  p(r)
  var before = Window.focusedWindow().frame()
  p(before)
  Window.focusedWindow().setFrame(r);
  var after = Window.focusedWindow().frame()
  p("after:")
  p(after)

  if (isRectEqual(before, after)) {
    move_window(rect, screen.next())
  }
}

function isRectEqual(a, b) {
  return a.x === b.x &&
    a.y === b.y &&
    a.width === b.width &&
    a.height === b.height
}

keys.push(Phoenix.bind('h', ['cmd', 'ctrl'], function () {
  move_window({ x: 0, y: 0, width: 0.5, height: 1.0 })
}))

Open Emacs, press cmd+ctrl+h twice. The second press should move to the other monitor, and it should only be taking half the width, but instead it maintains the same width it had on the 30" monitor.

I'm on El Capitan

Logs:

Mar 25 08:10:47 aaronmbp Phoenix[99758]: {"y":23,"x":0,"width":2560,"height":1573}
Mar 25 08:10:47 aaronmbp Phoenix[99758]: {"x":0,"y":23,"width":1280,"height":1573}
Mar 25 08:10:47 aaronmbp Phoenix[99758]: {"y":25,"x":127,"width":1276,"height":1566}
Mar 25 08:10:47 aaronmbp Phoenix[99758]: "after:"
Mar 25 08:10:47 aaronmbp Phoenix[99758]: {"y":23,"x":0,"width":1276,"height":1566}
Mar 25 08:10:48 aaronmbp Phoenix[99758]: {"y":23,"x":0,"width":2560,"height":1573}
Mar 25 08:10:48 aaronmbp Phoenix[99758]: {"x":0,"y":23,"width":1280,"height":1573}
Mar 25 08:10:48 aaronmbp Phoenix[99758]: {"y":23,"x":0,"width":1276,"height":1566}
Mar 25 08:10:48 aaronmbp Phoenix[99758]: "after:"
Mar 25 08:10:48 aaronmbp Phoenix[99758]: {"y":23,"x":0,"width":1276,"height":1566}
Mar 25 08:10:48 aaronmbp Phoenix[99758]: {"y":311,"x":-1440,"width":1440,"height":900}
Mar 25 08:10:48 aaronmbp Phoenix[99758]: {"x":-1440,"y":311,"width":720,"height":900}
Mar 25 08:10:48 aaronmbp Phoenix[99758]: {"y":23,"x":0,"width":1276,"height":1566}
Mar 25 08:10:49 aaronmbp Phoenix[99758]: "after:"
Mar 25 08:10:49 aaronmbp Phoenix[99758]: {"y":311,"x":-1440,"width":1276,"height":1306}

One curious thing is that once the Emacs window has moved, I cannot resize it horizontally by dragging unless I first resize it vertically and move it up so that the bottom of the window is visible. This could be a bug in Emacs, but I have a very similar config with slate.js and it does not have this problem.

For what it's worth, slate.js appears to resize the window prior to moving to the other screen.

@kasper
Copy link
Owner

kasper commented Mar 25, 2016

I’ve indeed wondered on numerous cases when resizing before moving would be required and haven’t personally found any of these cases. This is why I removed the secondary resize on refactor. Obviously you may have found a case and maybe this should be reinstated.

What I’ve however noticed, that some apps (mainly Adobe) do not support the Accessibility API properly and do weird things that can affect resizing. If Emacs works in Slate.js, this shouldn’t be the case.

Could you try out your theory? Use setTopLeft() and setSize() to simulate a setFrame(). Particularly in the sequence: 1. setSize, 2. setTopLeft and again 3. setSize.

@aaronjensen
Copy link
Author

Hi, I believe I tried that and it didn't actually work. It seemed like it happened too quickly. I'll try it again when I get home. I'll also try w/ two different bindings to see if it indeed a race condition thing

@kasper
Copy link
Owner

kasper commented Mar 25, 2016

@aaronjensen Great, thanks! It’s a shame that Apple hasn’t implemented a way to set the frame in one API-call, which would solve these types of issues.

@aaronjensen
Copy link
Author

That worked! I guess I hadn't tried exactly that.

@kasper
Copy link
Owner

kasper commented Mar 26, 2016

@aaronjensen Nice! I’ll fix this in the next release. Thanks for the extremely thorough report and debugging. It always helps. :)

@kasper kasper added the bug label Mar 26, 2016
@kasper kasper added this to the 2.1 milestone Mar 26, 2016
@kasper kasper self-assigned this Mar 26, 2016
kasper added a commit that referenced this issue Apr 13, 2016
@kasper
Copy link
Owner

kasper commented Apr 13, 2016

This is now fixed in master.

@kasper kasper closed this as completed Apr 13, 2016
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

2 participants