Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Detect monitor changes automatically #130

Closed
purcell opened this Issue · 14 comments

4 participants

@purcell

It would be great if Slate could apply the appropriate default layouts automatically when monitors are connected/disconnected. Right now it's necessary to click "Load Config" in the menu item, which is clunky.

Sample code for requesting the corresponding notifications can be found in the ControlPlane source code:

https://github.com/dustinrue/ControlPlane/blob/master/Source/MonitorEvidenceSource.m

@jigish jigish was assigned
@jigish
Owner

So this already exists using the "default" directive. If you are already using it an it doesn't work please link me your .slate file so I can take a look.

@btaylor

This doesn't seem to work for me when I plug or unplug my 2012 Macbook Air to my external monitor. Here's my .slate file: http://github.com/btaylor/dotfiles/blob/master/slate/slate.symlink

@purcell

I'm also on a 2012 MBA plus a DisplayPort external display, and the plug/unplug detection doesn't work. Here's my .slate: https://gist.github.com/3874862

@btaylor

Oh, I should also mention that I'm on Mountain Lion 10.8.2.

@purcell

Ah yes, me too.

@jigish
Owner

O boy. I really hope they didn't kill the events that I use in 10.8.2. I have Mountain Lion on another box (not my Slate dev box) so I'll try it out soon. And by soon I mean most likely this weekend.

@jigish
Owner

Also, you are saying "Load Config" causes it to snap to your layout? If so it definitely seems like the event is no longer fired which means I'll have to look for a new one.

@purcell

Yes, that's right; I can force the layout detection based on monitor presence by running "Load Config".

@btaylor

For the time being, I just bound my layouts to keyboard shortcuts, so it's not that bad, but certainly less than ideal.

@purcell

As an additional data point, I just tried setting up some ControlPlane rules based on the attached monitor: it responds immediately and correctly to the plug/unplug events. I can't tell, however, whether it's receiving system notifications or just polling frequently.

@btaylor

Any updates on this? I may try to find some time over the holidays to play with this if no one has put any work into it.

@cmsj

This may not be the most suitable way to do things, I am by no means an expert on the OS X SDK, however, I did find a way to detect screen changes with Quartz and it's an official API that's pretty stable (available since 10.3):

diff --git a/Slate/SlateConfig.h b/Slate/SlateConfig.h
index ae93e45..3e1d29e 100644
--- a/Slate/SlateConfig.h
+++ b/Slate/SlateConfig.h
@@ -71,3 +71,5 @@
 + (NSURL *)snapshotsFile;

 @end
+
+void onDisplayReconfiguration (CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo);
diff --git a/Slate/SlateConfig.m b/Slate/SlateConfig.m
index 6a283d7..f5071ab 100644
--- a/Slate/SlateConfig.m
+++ b/Slate/SlateConfig.m
@@ -71,6 +71,9 @@ static SlateConfig *_instance = nil;
     NSNotificationCenter *nc = [NSDistributedNotificationCenter defaultCenter];
     [nc addObserver:self selector:@selector(onScreenChange:) name:NOTIFICATION_SCREEN_CHANGE object:nil];
     [nc addObserver:self selector:@selector(onScreenChange:) name:NOTIFICATION_SCREEN_CHANGE_LION object:nil];
+    
+    // Listen for screen change notifications with Quartz
+    CGDisplayRegisterReconfigurationCallback(onDisplayReconfiguration, (__bridge void *)(self));
     //[nc addObserver:self selector:@selector(processNotification:) name:nil object:nil];
   }
   return self;
@@ -569,3 +572,8 @@ static SlateConfig *_instance = nil;
 }

 @end
+
+void onDisplayReconfiguration (CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo) {
+    NSLog(@"onDisplayReconfiguration");
+    [(__bridge id)userInfo onScreenChange:nil];
+}
@jigish
Owner

This should be fixed by Pull Request #166. I'll close this when that is merged.

@jigish
Owner

just merged the pull request and tested on Mountain Lion and Lion. According to the docs it should work for Snow Leopard as well. I'll push a new build later today.

@jigish jigish closed this
@jigish jigish referenced this issue from a commit
Jigish Patel [Issue #130] remove useless screen config changes 3a26cc6
@jigish jigish referenced this issue from a commit
Jigish Patel Version 1.0.17
- Merge Pull Request #191 - (Fix Issue #190)
- Merge Pull Request #166 - (Fix Issue #130)
- Merge Pull Request #204
- Merge Pull Request #185
5620a30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.