Into the DecorManager (Allocating Window Behavior)

Into the server window constructor, there was a class to the allocating window behavior as follows:

if (fFeel != kOffscreenWindowFeel)
		fWindowBehaviour.SetTo(gDecorManager.AllocateWindowBehaviour(this));

Here, gDecorManager is the global variable of type DecorManager

#1 AllocateWindowBehavior(Window)

This function is defined in the file at: src/servers/app/decorator/DecorManager.cpp

This function is responsible for allocating a WindowBehavior object for a given window.

WindowBehaviour*
DecorManager::AllocateWindowBehaviour(Window* window)
{
	if (!fCurrentDecor) {
		// We should *never* be here. If we do, it's a bug.
		debugger("DecorManager::AllocateDecorator has a NULL decorator");
		return NULL;
	}

	return fCurrentDecor->AllocateWindowBehaviour(window);
}

It first checks if fCurrentDecor (a pointer to the current decorator) is not null. If it is null, it implies there's an unexpected situation, and the debugger is invoked to halt program execution for debugging.

If fCurrentDecor is not null, it proceeds to call the AllocateWindowBehaviour method of the current decorator (fCurrentDecor). This method is expected to allocate and return a WindowBehaviour object tailored for the provided window.

Finally, the function returns the WindowBehaviour* returned by the AllocateWindowBehaviour method of the current decorator.

#2 DecorAddOn:: AllocateWindowBehaviour(Window*)

The function is defined here at: src/servers/app/decorators/DecorManager.cpp

WindowBehaviour*
DecorAddOn::AllocateWindowBehaviour(Window* window)
{
	return new (std::nothrow)SATWindowBehaviour(window,
		window->Desktop()->GetStackAndTile());
}
  • It allocates a new SATWindowBehaviour object using the new (std::nothrow) operator. This operator returns a null pointer if the allocation fails instead of throwing an exception.
  • The constructor of SATWindowBehaviour is called with two arguments:
    • window: A pointer to the window for which the behavior is being allocated.
    • window->Desktop()->GetStackAndTile(): This retrieves the stack and tile behavior associated with the desktop of the window.
  • The constructed SATWindowBehaviour object is returned. This object represents the behavior associated with the window within the context of the SAT decorator.

#3 SATWindowBehaviour::SATWindowBehaviour(Window*, StackAndTile*)

This function is defined at: src/servers/app/stackandtile/SATDecorator.cpp

SATWindowBehaviour::SATWindowBehaviour(Window* window, StackAndTile* sat)
	:
	DefaultWindowBehaviour(window),

	fStackAndTile(sat)
{
}
  • It initializes the base class DefaultWindowBehaviour using the constructor DefaultWindowBehaviour(window).
  • It initializes the fStackAndTile member variable with the provided StackAndTile* pointer sat. This member variable likely represents the stack and tile behavior associated with the window.

#3 DefaultWindowBehaviour::DefaultWindowBehaviour(Window*)

This is defined in the file: src/servers/app/decorator/DefaultWindowBehaviour.cpp

DefaultWindowBehaviour::DefaultWindowBehaviour(Window* window)
	:
	fWindow(window),
	fDesktop(window->Desktop()),
	fLastModifiers(0)
{
}
  • It initializes the fWindow member variable with the provided Window* pointer window. This member variable likely represents the window associated with this behavior.
  • It initializes the fDesktop member variable with the desktop associated with the provided window (window->Desktop()). This member variable likely represents the desktop where the window resides.
  • It initializes the fLastModifiers member variable to 0. This member variable may be used to store the state of the keyboard modifiers during certain events.