Ivan Vučica avatar Ivan Vučica committed d766157

Added mapping of preexisting windows. Upon mapping, windows are animated with a zoom animation. Windows are also resized to fullscreen (unless they prevent that by setting minimum width and height).

Comments (0)

Files changed (4)

FPManagedWindow.h

 	BOOL _isMapped;
 
 	float _timeAlive;
+	float _mappedAtTimeAlive;
 
 	FPWindowManager * _manager; // non-owning reference
 }
 -(id)initWithWindow:(Window)window manager:(FPWindowManager*)manager;
+-(void)performWindowMapping;
 -(void)drawWindow;
 @end

FPManagedWindow.m

 	if(!_hasOutput)
 		return self;
 
+	if(_isMapped)
+		[self performWindowMapping];		
+
 	return self;
 }
 -(void)dealloc
 		{
 			NSLog(@"Managed Window %lp is mapped", _window);
 			if(_isMapped)
-				break;
-			[self _freeResources];
-			[self _collectAttributes];
-			[self _buildResources];
-			_isMapped = YES;
-			XSelectInput (display, _window, PropertyChangeMask);
-			XShapeSelectInput (display, _window, ShapeNotifyMask);
+				return;
+			_mappedAtTimeAlive = _timeAlive;
+			[self performWindowMapping];
 		}
 		break;
 		
 		break;
 	}
 }
+-(void)_forceWindowToFullScreen
+{
+	FPX11Display * mainDisplay = [FPX11Display mainDisplay];
+
+	//XWindowAttributes winAttr;
+	XSizeHints sizeHints;
+	long userSuppliedHints;
+	int hasMinSize = 0, hasMaxSize = 0, hasIncrement = 0;
+
+	/* Get window attributes */
+	//XGetWindowAttributes([mainDisplay display], _window, &winAttr);
+
+	/* Get size hints for the window */
+	XGetWMNormalHints([mainDisplay display], _window, &sizeHints, &userSuppliedHints);
+	if (sizeHints.flags & PMinSize)
+		hasMinSize = 1;
+	if (sizeHints.flags & PMaxSize)
+		hasMaxSize = 1;
+	if (sizeHints.flags & PResizeInc)
+		hasIncrement = 1;
+
+	float newW = [mainDisplay widthForScreen:[mainDisplay screen]];
+	float newH = [mainDisplay heightForScreen:[mainDisplay screen]];
+	if(hasMaxSize)
+	{
+		NSLog(@"MaxW: %d, MaxH: %d", sizeHints.max_width, sizeHints.max_height);
+		newW = MIN(newW, sizeHints.max_width);
+		newH = MIN(newW, sizeHints.max_height);
+	}
+	if(hasMinSize)
+	{
+		newW = MAX(newW, sizeHints.min_width);
+		newH = MAX(newH, sizeHints.min_height);
+	}
+
+	// TODO: center
+	XMoveResizeWindow([mainDisplay display], _window, 0, 0, newW, newH);
+
+	// it is expected that, at this point, someone will
+	// free resources, collect attributes, and build resources.
+
+	// this is only natural, considering we just moved and resized the window
+}
+-(void)performWindowMapping
+{
+	// used to handle MapNotify event
+	// used to handle preexisting windows
+	FPX11Display * mainDisplay = [FPX11Display mainDisplay];
+	Display * display = [mainDisplay display];
+
+	[self _forceWindowToFullScreen];
+
+	[self _freeResources];
+	[self _collectAttributes];
+	[self _buildResources];
+	_isMapped = YES;
+	XSelectInput (display, _window, PropertyChangeMask);
+	XShapeSelectInput (display, _window, ShapeNotifyMask);
+
+		
+}
 -(void)drawWindow
 {
 
 #if 1
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix ();
+		
+		/////
+
+		float scale = 1.;
+		const float appearSpeed = 2; // 1/2 sec
+		scale = MIN((_timeAlive - _mappedAtTimeAlive)*appearSpeed, 1);
+
+		glTranslatef (_width/2, _height/2, 0);
+		glScalef(scale, scale, scale);
+		glTranslatef (-_width/2, -_height/2, 0);
+
+		////
+
 		glTranslatef (_x, _y, _z);
 		/*
 		extent_clip (0, 0, mirror->w, mirror->h);

FPWindowManager.m

 	_wasExposed = NO;
 }
 
+-(void)_addPreexistingWindows
+{
+	FPX11Display * mainDisplay = [FPX11Display mainDisplay];
+	Display * display = [mainDisplay display];
+	int screen = [mainDisplay screen];
+	int width = [mainDisplay width];
+	int height = [mainDisplay height];
+	int depth = [mainDisplay depth];
+	Visual * visual = [mainDisplay visual];
+	Window rootWindow = [mainDisplay rootWindow];
+
+	Window * children = NULL;
+	unsigned int nChildren = 0;
+	Window returningRootWindow = 0, returningParentWindow = 0;
+
+	XQueryTree(display, rootWindow, &returningRootWindow, &returningParentWindow, &children, &nChildren);
+	for(int i = 0; i < nChildren; i++)
+	{
+		Window * window = children[i];
+		if(window != _stage && window != _root && window != _overlay)
+		{
+			FPManagedWindow * managedWindow = [[FPManagedWindow alloc] initWithWindow:window manager:self];
+			[_managedWindows addObject:managedWindow];
+			[managedWindow release];
+		}
+		
+	}
+}
+
 -(void)handleXEvent:(XEvent)event
 {
 	NSLog(@"Event %d", event.type);
 		[self render];
 		if(!_wasExposed)
 		{
-			[self _execCommand:@"/usr/bin/xterm"];
+			[self _addPreexistingWindows];
+			//[self _execCommand:@"/usr/bin/xterm"];
 		}
 		_wasExposed = YES;
+
+		
 		break;
 
 		case ConfigureNotify:

test-with-preexisting-window.sh

+./run-xephyr &
+sleep 1
+DISPLAY=:3 ./Fireplace.app/Fireplace
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.