forked from n8gray/QLColorCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDMWindowMemoryController.m
More file actions
116 lines (102 loc) · 3.24 KB
/
DMWindowMemoryController.m
File metadata and controls
116 lines (102 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// DMWindowMemoryController.m
// DMWindowMemory
//
// Created by Nathaniel Gray on 5/25/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "DMWindowMemoryController.h"
#import "Notifications.h"
@implementation DMWindowMemoryController
- someMethod {
}
- someOtherMethod
{}
- foo : (baz) bar {
}
+ blah {
}
- (NSString*) name {
return @"Window Memory Plugin";
}
- (NSString*) description {
return @"A plugin to save and restore the positions of your windows when your screen configuration changes";
}
- (int) interfaceVersion {
return 1;
}
- (NSBundle*) preferencesBundle {
return nil;
}
/* This is in response to notification that the screen geometry has changed */
- (void) handleScreenChange: (NSNotification *)notif {
NSLog(@"*** handleScreenChange\n");
[mConfigurationLock lock];
NSEnumerator *configEnum = [mConfigurations objectEnumerator];
ScreenConfiguration *config;
BOOL found = NO;
while (config = [configEnum nextObject]) {
if ([config matchesCurrentConfig]) {
NSLog(@"Found matching config: %@", config);
mCurrentConfig = config;
[config restoreWindowLayout];
found = YES;
break;
}
}
if (!found) {
config = [ScreenConfiguration configWithCurrent];
[mConfigurations insertObject:config
atIndex:0];
mCurrentConfig = config;
NSLog(@"Added new config: %@", config);
}
[mConfigurationLock unlock];
}
/* This is in response to the periodic updates to the window layout on screen */
- (void) handleWindowChanges: (NSNotification *)notif {
//NSLog(@"handleWindowChanges\n");
[mConfigurationLock lock];
[mCurrentConfig updateWindowLayout];
[mConfigurationLock unlock];
}
- (void) pluginLoaded: (DMController*) controller withBundle: (NSBundle*) thisBundle
{
NSLog(@"DMWindowMemoryController pluginLoaded\n");
mController = controller;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
mConfigurationLock = [[NSLock alloc] init];
[mConfigurationLock lock];
// Find out when screens are added/removed
[nc addObserver: self
selector: @selector(handleScreenChange:)
name: NSApplicationDidChangeScreenParametersNotification
object: nil];
// Get the periodic window layout updates
[nc addObserver: self
selector: @selector(handleWindowChanges:)
name: NOTIFICATION_WINDOWLAYOUTUPDATED
object: nil];
mCurrentConfig = [ScreenConfiguration configWithCurrent];
mConfigurations = [[NSMutableArray arrayWithObject:mCurrentConfig] retain];
[mConfigurationLock unlock];
NSLog(@"Finished initializing plugin\n");
}
- (void) dealloc {
[mConfigurationLock lock];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self];
// We don't release mCurrentConfig because we never actually retain it.
if (mConfigurations) {
[mConfigurations release];
mConfigurations = nil;
}
if (mController) {
[mController release];
mController = nil;
}
[mConfigurationLock unlock];
[mConfigurationLock release];
[super dealloc];
}
@end