  #include <fs_attr.h>
  extern "C" {
  #include "content/content.h"
-@@ -571,6 +581,12 @@ NSBrowserWindow::NSBrowserWindow(BRect frame, struct beos_scaffolding *scaf)
- 	: BWindow(frame, "NetSurf", B_DOCUMENT_WINDOW, 0),
- 	fScaffolding(scaf)
- {
+@@ -458,7 +468,7 @@ NSBaseView::MessageReceived(BMessage *message)
+ 			nsbeos_pipe_message_top(message, NULL, fScaffolding);
+ 			break;
+ 		default:
+-		message->PrintToStream();
++			//message->PrintToStream();
+ 			BView::MessageReceived(message);
+ 	}
+ }
+@@ -539,6 +549,7 @@ void
+ NSBaseView::AllAttached()
+ {
+ 	BView::AllAttached();
++
+ 	struct beos_scaffolding *g = fScaffolding;
+ 	if (!g)
+ 		return;
+@@ -576,6 +587,8 @@ NSBrowserWindow::NSBrowserWindow(BRect frame, struct beos_scaffolding *scaf)
+ 
+ NSBrowserWindow::~NSBrowserWindow()
+ {
++	if(activeWindow == this)
++		activeWindow = NULL;
+ }
+ 
+ 
+@@ -621,6 +634,16 @@ NSBrowserWindow::QuitRequested(void)
+ }
+ 
+ 
++void
++NSBrowserWindow::WindowActivated(bool active)
++{
++	if(active)
++		activeWindow = this;
++	else if(activeWindow == this)
++		activeWindow = NULL;
++}
++
++
+ // #pragma mark - implementation
+ 
+ int32 nsbeos_replicant_main_thread(void *_arg)
+@@ -686,6 +709,10 @@ void nsbeos_scaffolding_update_colors(nsbeos_scaffolding *g)
+ }
+ 
+ 
++/*static*/ BWindow*
++NSBrowserWindow::activeWindow = NULL;
++
++
+ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *message)
+ {
+ 	int width, height;
+@@ -907,6 +934,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m
+ 			text = scaffold->url_bar->Text();
+ 			scaffold->url_bar->UnlockLooper();
+ 
++			NSBrowserWindow::activeWindow = scaffold->window;
+ 			browser_window_create(text.String(), bw, NULL, false, false);
+ 			break;
+ 		}
+@@ -1570,7 +1598,19 @@ void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view)
+ 		message->AddPointer("scaffolding", g);
+ 		g->window->AddShortcut('H', 0, message, view);
+ 
++
 +#if defined(__HAIKU__)
-+	if (stack == NULL)
-+		stack = new BWindowStack(this);
-+	else
-+		stack->AddWindow(this);
++		// Make sure the window is layouted and answering to events, but do not
++		// show it before it is actually resized
++		g->window->Hide();
++		g->window->Show();
++
++		if(NSBrowserWindow::activeWindow) {
++			BWindowStack(NSBrowserWindow::activeWindow).AddWindow(g->window);
++		}
 +#endif
- }
- 
- 
-@@ -621,6 +637,8 @@ NSBrowserWindow::QuitRequested(void)
- }
- 
- 
-+BWindowStack* NSBrowserWindow::stack = NULL;
-+
- // #pragma mark - implementation
- 
- int32 nsbeos_replicant_main_thread(void *_arg)
-@@ -1659,6 +1677,90 @@ static BMenuItem *make_menu_item(const char *name, BMessage *message)
+ 		g->window->Show();
++
+ 	} else {
+ 		if (g->top_view->Looper())
+ 			g->top_view->UnlockLooper();
+@@ -1659,6 +1699,90 @@ static BMenuItem *make_menu_item(const char *name, BMessage *message)
  	return item;
  }
  

+};
+
diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp
index 4003b09..c9a9d15 100644
--- a/beos/scaffolding.cpp
+++ b/beos/scaffolding.cpp
@@ -22,7 +22,9 @@

 	g->tool_bar->AddChild(g->home_button);
 	nButtons++;
 
@@ -2407,3 +2528,4 @@ void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where)
 {
 	g->popup_menu->Go(where);
 }
+
diff --git a/beos/scaffolding.h b/beos/scaffolding.h
index ae78391..bd13230 100644
--- a/beos/scaffolding.h
+++ b/beos/scaffolding.h
@@ -61,11 +61,15 @@ virtual	~NSBrowserWindow();
 virtual	void	DispatchMessage(BMessage *message, BHandler *handler);
 virtual void	MessageReceived(BMessage *message);
 virtual bool	QuitRequested(void);
+void			WindowActivated(bool active);
 
 struct beos_scaffolding *Scaffolding() const { return fScaffolding; };
 
+static BWindow* activeWindow;
 private:
 	struct beos_scaffolding *fScaffolding;
+
+
 };
 
 
