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

Hotkey to force restore #5

Open
okgolove opened this issue Feb 14, 2022 · 11 comments
Open

Hotkey to force restore #5

okgolove opened this issue Feb 14, 2022 · 11 comments

Comments

@okgolove
Copy link

Hello! Thank you for the great app!
It would be very helpful if I was able to use some keys combination to trigger restoring. That would partially resolve issue related to spaces.

@relikd
Copy link
Owner

relikd commented Feb 14, 2022

Hi, lets think this through first. Can you list the steps how you would like to restore windows? Currently all window positions are saved whenever a monitor is plugged in/out. After that, restore the windows from a previous session with less/more monitors. I am not sure if it would help to manually trigger a restore-windows-function. 'Cause at this point either the wrong positions are already saved, or the restore did actually restore the windows. Do you want a “save” as well as “restore” hotkey? – or to put it differently: how do you think a manual restore will help you? vs. automatically triggering the same action as soon as the monitor count changes?
The windows in a space should be restored as soon as the space becomes active.

@okgolove
Copy link
Author

DisplayMaid works the next way: you save your windows position (for every space) and then you can restore the state using hotkey combination on every space. That was the main idea.

I'm still not able to understand how memmon works with spaces. I'm on space 2, disconnect ex. display, switch to space 3, then connect display, it restores nothing. As soon as I switch to space 1 it restores windows properly. Switch to space 2 or 3 again - nothing happens. Should it restore windows automatically for every space as soon as I switch to them?
If this part worked as expected I would not think about manually functionality.

@relikd
Copy link
Owner

relikd commented Feb 14, 2022

Yes, it should work exactly that way. Memmon should save the stat of all windows of all spaces as soon as you unplug or attach a new monitor. But it will only restore the windows of a space as soon as you navigate to that space (limitations of AXUIElement). This is also what DisplayMaid says:

"Display Maid can’t save or restore positions for windows that are not in the currently active space. This is because there isn't currently a way provided to interact with windows that are in hidden spaces. "

But, Memmon should indeed restore the windows once you visit a space. Can you check whether all windows are "forgotten" or if it happens only to specific apps? I noticed that Firefox / Chrome may have issues with restoring the windows. But Finder windows should work fine.

@okgolove
Copy link
Author

This is about all windows. Btw, do you use separate spaces per display?

@relikd
Copy link
Owner

relikd commented Feb 15, 2022

As of now I have no access to an external monitor. So I can't really debug what is going on. What do you mean with seperate spaces per display? If you use spaces, each display will have the same number of spaces. Or in other words, each space has as many display as are connected. During my testing a few months ago I had a setup with one external display and my internal Macbook display. I would place my windows, with the display attached, in two spaces. Then I detach the external display and all the windows get moved to the internal display. I also tested what happens if I switch between spaces at this stage and after the next stage. Next, I reattach the display and the windows of the current space get re-set again to their original position. If I switch to another space, the windows do get re-set there too. However it took one or two seconds before macOS got the notification that a space-change was performed (always a little shock fearing it wouldnt fix it).

@relikd
Copy link
Owner

relikd commented Feb 15, 2022

You can try this snippet out to see if a manual restore will help:

self.statusItem.menu!.addItem(withTitle: "Restore Now", action: #selector(self.testme), keyEquivalent: "r")

@objc func testme() {
	let spaceWinNums = self.getWinIds()
	for (pid, bounds) in self.state[self.numScreens] ?? [:] {
		self.setWindowSizes(pid, bounds.filter{ spaceWinNums.contains($0.0) })
	}
}

Put the first line e.g., after line 41 in main.swift and the remaining function somewhere after line 43 or so.

You can run the script with swift main.swift

The hotkey will only work when the status menu is open but for testing purposes it suffices. If that helps, we can talk about adding a global hotkey ... that is too much trouble for now.

@okgolove
Copy link
Author

I'm talking about this setting
image

Will try to test this code soon, thank you for responsiveness!

@relikd
Copy link
Owner

relikd commented Feb 15, 2022

Ah, oh! Yeah, I can imagine that my space enumeration hack may not work with this option enabled, though I am not sure. I will have to test it once I get my hands on an external display again. If the manual restore works, then it is only a notification issue. If not, I'll have to dig into the space detection algorithm. Keep me posted on your result 👍

@okgolove
Copy link
Author

I've tried to run modified app but it stopped work at all.

@relikd
Copy link
Owner

relikd commented Feb 16, 2022

ah, yeah, you'll need to add Terminal (or whatever app you are using to run the script) to "System Preference" > "Security & Privacy" > "Accessibility".

@okgolove
Copy link
Author

I've already done it. Still no luck.

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

No branches or pull requests

2 participants