Index: code/branches/resource2/src/core/Core.cc
===================================================================
--- code/branches/resource2/src/core/Core.cc	(revision 5669)
+++ code/branches/resource2/src/core/Core.cc	(revision 5670)
@@ -41,5 +41,4 @@
 #include <cstdio>
 #include <boost/filesystem.hpp>
-#include <OgreRenderWindow.h>
 
 #ifdef ORXONOX_PLATFORM_WINDOWS
@@ -309,13 +308,10 @@
         graphicsManager_->upgradeToGraphics();
 
-        // The render window width and height are used to set up the mouse movement.
-        size_t windowHnd = 0;
-        graphicsManager_->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
-
         // Calls the InputManager which sets up the input devices.
-        inputManager_.reset(new InputManager(windowHnd));
+        inputManager_.reset(new InputManager());
 
         // load the CEGUI interface
-        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow()));
+        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
+            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
 
         unloader.Dismiss();
@@ -331,5 +327,13 @@
 
         // Load Ogre::Root again, but without the render system
-        this->graphicsManager_.reset(new GraphicsManager(false));
+        try
+            { this->graphicsManager_.reset(new GraphicsManager(false)); }
+        catch (...)
+        {
+            COUT(0) << "An exception occurred during 'new GraphicsManager' while "
+                    << "another exception was being handled. This will lead to undefined behaviour!" << std::endl
+                    << "Terminating the program." << std::endl;
+            abort();
+        }
 
         bGraphicsLoaded_ = false;
Index: code/branches/resource2/src/core/GUIManager.cc
===================================================================
--- code/branches/resource2/src/core/GUIManager.cc	(revision 5669)
+++ code/branches/resource2/src/core/GUIManager.cc	(revision 5670)
@@ -37,4 +37,5 @@
 #include <CEGUIExceptions.h>
 #include <CEGUIInputEvent.h>
+#include <CEGUIMouseCursor.h>
 #include <CEGUIResourceProvider.h>
 #include <CEGUISystem.h>
@@ -96,5 +97,5 @@
     @return true if success, otherwise false
     */
-    GUIManager::GUIManager(Ogre::RenderWindow* renderWindow)
+    GUIManager::GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen)
         : renderWindow_(renderWindow)
         , resourceProvider_(0)
@@ -127,4 +128,13 @@
         rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
         this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
+
+        // Align CEGUI mouse with OIS mouse
+        guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+        // Hide the mouse cursor unless playing in fullscreen mode
+        if (!bFullScreen)
+            CEGUI::MouseCursor::getSingleton().hide();
+#endif
     }
 
@@ -254,5 +264,5 @@
     void GUIManager::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
     {
-        guiSystem_->injectMouseMove(static_cast<float>(rel.x), static_cast<float>(rel.y));
+        guiSystem_->injectMousePosition(static_cast<float>(abs.x), static_cast<float>(abs.y));
     }
     void GUIManager::mouseScrolled(int abs, int rel)
Index: code/branches/resource2/src/core/GUIManager.h
===================================================================
--- code/branches/resource2/src/core/GUIManager.h	(revision 5669)
+++ code/branches/resource2/src/core/GUIManager.h	(revision 5670)
@@ -60,5 +60,5 @@
         friend class Singleton<GUIManager>;
     public:
-        GUIManager(Ogre::RenderWindow* renderWindow);
+        GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen);
         ~GUIManager();
 
Index: code/branches/resource2/src/core/GraphicsManager.cc
===================================================================
--- code/branches/resource2/src/core/GraphicsManager.cc	(revision 5669)
+++ code/branches/resource2/src/core/GraphicsManager.cc	(revision 5670)
@@ -128,4 +128,5 @@
     GraphicsManager::~GraphicsManager()
     {
+        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
         // TODO: Destroy the console command
     }
@@ -337,4 +338,28 @@
     }
 
+    size_t GraphicsManager::getRenderWindowHandle()
+    {
+        size_t windowHnd = 0;
+        renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
+        return windowHnd;
+    }
+
+    bool GraphicsManager::isFullScreen() const
+    {
+        Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions();
+        if (options.find("Full Screen") != options.end())
+        {
+            if (options["Full Screen"].currentValue == "Yes")
+                return true;
+            else
+                return false;
+        }
+        else
+        {
+            COUT(0) << "Could not find 'Full Screen' render system option. Fix This!!!" << std::endl;
+            return false;
+        }
+    }
+
     void GraphicsManager::printScreen()
     {
Index: code/branches/resource2/src/core/GraphicsManager.h
===================================================================
--- code/branches/resource2/src/core/GraphicsManager.h	(revision 5669)
+++ code/branches/resource2/src/core/GraphicsManager.h	(revision 5670)
@@ -67,4 +67,6 @@
         Ogre::Viewport* getViewport()         { return this->viewport_; }
         Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
+        size_t getRenderWindowHandle();
+        bool isFullScreen() const;
 
         void upgradeToGraphics();
Index: code/branches/resource2/src/core/input/InputManager.cc
===================================================================
--- code/branches/resource2/src/core/input/InputManager.cc	(revision 5669)
+++ code/branches/resource2/src/core/input/InputManager.cc	(revision 5670)
@@ -41,4 +41,5 @@
 #include <boost/foreach.hpp>
 
+#include "util/Convert.h"
 #include "util/Exception.h"
 #include "util/ScopeGuard.h"
@@ -49,4 +50,5 @@
 #include "core/CommandLine.h"
 #include "core/Functor.h"
+#include "core/GraphicsManager.h"
 
 #include "InputBuffer.h"
@@ -82,9 +84,9 @@
     // ##########                                        ##########
     // ############################################################
-    InputManager::InputManager(size_t windowHnd)
+    InputManager::InputManager()
         : internalState_(Bad)
         , oisInputManager_(0)
         , devices_(2)
-        , windowHnd_(0)
+        , bExclusiveMouse_(false)
         , emptyState_(0)
         , keyDetector_(0)
@@ -97,5 +99,5 @@
         this->setConfigValues();
 
-        this->loadDevices(windowHnd);
+        this->loadDevices();
 
         // Lowest priority empty InputState
@@ -147,6 +149,4 @@
         Creates the OIS::InputMananger, the keyboard, the mouse and
         the joys ticks. If either of the first two fail, this method throws an exception.
-    @param windowHnd
-        The window handle of the render window
     @param windowWidth
         The width of the render window
@@ -154,7 +154,7 @@
         The height of the render window
     */
-    void InputManager::loadDevices(size_t windowHnd)
-    {
-        CCOUT(3) << "Loading input devices..." << std::endl;
+    void InputManager::loadDevices()
+    {
+        CCOUT(4) << "Loading input devices..." << std::endl;
 
         // When loading the devices they should not already be loaded
@@ -164,18 +164,15 @@
         assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
 
-        // store handle internally so we can reload OIS
-        windowHnd_ = windowHnd;
-
+        // Fill parameter list
         OIS::ParamList paramList;
-        std::ostringstream windowHndStr;
-
-        // Fill parameter list
-        windowHndStr << static_cast<unsigned int>(windowHnd);
-        paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
+        size_t windowHnd = GraphicsManager::getInstance().getRenderWindowHandle();
+        paramList.insert(std::make_pair(std::string("WINDOW"), multi_cast<std::string>(windowHnd)));
 #if defined(ORXONOX_PLATFORM_WINDOWS)
-        //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
-        //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
-        //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
-        //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
+        // Load in non exclusive mode and change later
+        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
+            paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_EXCLUSIVE")));
+        else
+            paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
+        paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
 #elif defined(ORXONOX_PLATFORM_LINUX)
         paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
@@ -212,5 +209,4 @@
         }
 
-        // TODO: Remove the two parameters
         this->loadMouse();
         this->loadJoySticks();
@@ -219,5 +215,5 @@
         this->updateActiveStates();
 
-        CCOUT(3) << "Input devices loaded." << std::endl;
+        CCOUT(4) << "Input devices loaded." << std::endl;
     }
 
@@ -275,5 +271,5 @@
     InputManager::~InputManager()
     {
-        CCOUT(4) << "Destroying..." << std::endl;
+        CCOUT(3) << "Destroying..." << std::endl;
 
         // Destroy calibrator helper handler and state
@@ -293,5 +289,5 @@
             this->destroyDevices();
 
-        CCOUT(4) << "Destruction complete." << std::endl;
+        CCOUT(3) << "Destruction complete." << std::endl;
     }
 
@@ -304,5 +300,5 @@
     void InputManager::destroyDevices()
     {
-        CCOUT(3) << "Destroying devices..." << std::endl;
+        CCOUT(4) << "Destroying devices..." << std::endl;
 
         BOOST_FOREACH(InputDevice*& device, devices_)
@@ -336,5 +332,5 @@
 
         internalState_ |= Bad;
-        CCOUT(3) << "Destroyed devices." << std::endl;
+        CCOUT(4) << "Destroyed devices." << std::endl;
     }
 
@@ -365,9 +361,9 @@
 
         this->destroyDevices();
-        this->loadDevices(windowHnd_);
+        this->loadDevices();
 
         internalState_ &= ~Bad;
         internalState_ &= ~ReloadRequest;
-        CCOUT(3) << "Reloading complete." << std::endl;
+        CCOUT(4) << "Reloading complete." << std::endl;
     }
 
@@ -481,4 +477,5 @@
     void InputManager::updateActiveStates()
     {
+        assert((internalState_ & InputManager::Ticking) == 0);
         // temporary resize
         for (unsigned int i = 0; i < devices_.size(); ++i)
@@ -512,4 +509,16 @@
         for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
             activeStatesTicked_.push_back(*it);
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+        // Check whether we have to change the mouse mode
+        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
+        if (mouseStates.empty() && bExclusiveMouse_ ||
+            !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_)
+        {
+            bExclusiveMouse_ = !bExclusiveMouse_;
+            if (!GraphicsManager::getInstance().isFullScreen())
+                this->reloadInternal();
+        }
+#endif
     }
 
@@ -556,6 +565,18 @@
     }
 
-    // ############################################################
-    // #####                    Iput States                   #####
+    std::pair<int, int> InputManager::getMousePosition() const
+    {
+        Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]);
+        if (mouse != NULL)
+        {
+            const OIS::MouseState state = mouse->getOISDevice()->getMouseState();
+            return std::make_pair(state.X.abs, state.Y.abs);
+        }
+        else
+            return std::make_pair(0, 0);
+    }
+
+    // ############################################################
+    // #####                    Input States                  #####
     // ##########                                        ##########
     // ############################################################
Index: code/branches/resource2/src/core/input/InputManager.h
===================================================================
--- code/branches/resource2/src/core/input/InputManager.h	(revision 5669)
+++ code/branches/resource2/src/core/input/InputManager.h	(revision 5670)
@@ -84,5 +84,5 @@
             the constructor fails with an std::exception.
         */
-        InputManager(size_t windowHnd);
+        InputManager();
         //! Destroys all devices AND all input states!
         ~InputManager();
@@ -167,6 +167,6 @@
             { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
         //! Returns a pointer to the OIS InputManager. Only you if you know what you're doing!
-        OIS::InputManager* getOISInputManager()
-            { return this->oisInputManager_; }
+        OIS::InputManager* getOISInputManager() { return this->oisInputManager_; }
+        std::pair<int, int> getMousePosition() const;
 
     private: // functions
@@ -175,5 +175,5 @@
 
         // Intenal methods
-        void loadDevices(size_t windowHnd);
+        void loadDevices();
         void loadMouse();
         void loadJoySticks();
@@ -193,6 +193,5 @@
         OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
         std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
-        // TODO: Get this from the GraphicsManager during reload
-        size_t                              windowHnd_;            //!< Render window handle (used to reload the InputManager)
+        bool                                bExclusiveMouse_;      //!< Currently applied mouse mode
 
         // some internally handled states and handlers
Index: code/branches/resource2/src/core/input/InputState.cc
===================================================================
--- code/branches/resource2/src/core/input/InputState.cc	(revision 5669)
+++ code/branches/resource2/src/core/input/InputState.cc	(revision 5670)
@@ -37,4 +37,5 @@
         , bAlwaysGetsInput_(bAlwaysGetsInput)
         , bTransparent_(bTransparent)
+        , bExclusiveMouse_(true)
         , bExpired_(true)
         , handlers_(2)
Index: code/branches/resource2/src/core/input/InputState.h
===================================================================
--- code/branches/resource2/src/core/input/InputState.h	(revision 5669)
+++ code/branches/resource2/src/core/input/InputState.h	(revision 5670)
@@ -75,6 +75,5 @@
           not influence ony other InputState at all.
 
-        Priorities
-        **********
+    @par Priorities
         Every InputState has a priority when on the stack, but mostly this
         priority is dynamic (InputStatePriority::Dynamic) which means that a state
@@ -83,4 +82,11 @@
         a high priority (InputStatePriority::HighPriority). These 'special' ones
         are used for features like the KeyDetector or the console. Use with care!
+
+    @par Exclusive/Non-Exclusive mouse Mode
+        You can select a specific mouse mode that tells whether the application
+        should have exclusive accessto it or not.
+        When in non-exclusive mode, you can move the mouse out of the window
+        like with any other normal window (only for windowed mode!).
+        The setting is dictated by the topmost InputState that gets mouse events.
     */
     class _CoreExport InputState : public JoyStickQuantityListener
@@ -114,4 +120,7 @@
         void setHandler        (InputHandler* handler);
 
+        void setIsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }
+        bool getIsExclusiveMouse() const { return bExclusiveMouse_; }
+
         //! Returns the name of the state (which is unique!)
         const std::string& getName() const { return name_; }
@@ -165,4 +174,5 @@
         const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
         const bool                  bTransparent_;          //!< See class declaration for explanation
+        bool                        bExclusiveMouse_;       //!< See class declaration for explanation
         int                         priority_;              //!< Current priority (might change)
         bool                        bExpired_;              //!< See hasExpired()
Index: code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc	(revision 5669)
+++ code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc	(revision 5670)
@@ -52,4 +52,5 @@
         inputState_->setHandler(GUIManager::getInstancePtr());
         inputState_->setJoyStickHandler(&InputHandler::EMPTY);
+        inputState_->setIsExclusiveMouse(false);
 
         // create an empty Scene
