-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathX11Restorable.m
115 lines (102 loc) · 2.99 KB
/
X11Restorable.m
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
//
// X11Restorable.m
// FMN
//
// Created by Nathaniel Gray on 8/16/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "X11Restorable.h"
#import "X11WindowOrientation.h"
@implementation X11Restorable
- (id) initWithBridge:(X11Bridge *) bridge
{
self = [super init];
if (!self) {
return nil;
}
Window wDummy, *children;
unsigned int nChildren;
mWindows = nil;
mX11Bridge = [bridge retain];
if (![bridge openDisplay])
return nil;
Display *disp = [bridge display];
NSDate *startDate = [NSDate date];
Window root = DefaultRootWindow(disp);
if (XQueryTree( disp, root, &wDummy, &wDummy, &children, &nChildren )) {
mWindows = [[NSMutableArray alloc] init];
int i;
for (i=0; i<nChildren; ++i) {
Window wClient = XmuClientWindow( disp, children[i] );
if( wClient == children[i] ) {
//NSLog(@"No client window found for X11 window 0x%x\n", wClient);
continue;
}
X11WindowOrientation *xwo =
[[X11WindowOrientation alloc]
initWithXWindow:wClient onDisplay:disp];
if (xwo == nil) {
NSLog(@"Couldn't make X11WindowOrientation for X Window 0x%x\n", wClient);
continue;
}
[mWindows addObject:xwo];
[xwo release];
}
if (nChildren) {
XFree(children);
}
} else {
NSLog(@"XQueryTree Failed!");
}
[bridge closeDisplay];
NSLog(@"Saved orientations for %i X11 windows in %f seconds",
[mWindows count], -[startDate timeIntervalSinceNow]);
return self;
}
- (void) dealloc
{
if (mX11Bridge)
[mX11Bridge release];
if (mWindows)
[mWindows release];
[super dealloc];
}
- (void) restoreWithContext : (NSDictionary*) context
{
if ([mX11Bridge openDisplay]) {
NSDate *startDate = [NSDate date];
Display *disp = [mX11Bridge display];
NSEnumerator* enumerator = [mWindows objectEnumerator];
X11WindowOrientation *window;
int i = 0;
while (window = [enumerator nextObject]) {
@try {
[window restoreOnDisplay:disp];
++i;
}
@catch (NSException* ex) {
NSLog([ex reason]);
}
}
[mX11Bridge closeDisplay];
NSLog(@"Restored orientations for %i X11 windows in %f seconds",
i, -[startDate timeIntervalSinceNow]);
}
}
- (int) priority
{
return kRestorableDefaultPriority;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:mX11Bridge forKey:@"X11Bridge"];
[encoder encodeObject:mWindows forKey:@"X11Windows"];
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];
mX11Bridge = [[decoder decodeObjectForKey:@"X11Bridge"] retain];
mWindows = [[decoder decodeObjectForKey:@"X11Windows"] retain];
return self;
}
@end