From 1fd451961e9573d5e5fc0c4f77cd1a3575d54e7a Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 28 Aug 2013 21:35:24 +0200 Subject: [PATCH] [DEV] start a compleate rework of the lib to support the multiple instance in one binary ==> not win at all (BREAK) --- sources/ewol/clipBoard.cpp | 9 +- sources/ewol/eObject/EObjectManager.cpp | 12 +- sources/ewol/eObject/EObjectManager.h | 30 +- sources/ewol/ewol.cpp | 16 +- sources/ewol/ewol.h | 70 +- sources/ewol/renderer/os/eSystem.cpp | 561 ++--- sources/ewol/renderer/os/eSystem.h | 360 ++- sources/ewol/renderer/os/eSystemInput.cpp | 13 +- sources/ewol/renderer/os/eSystemInput.h | 9 +- sources/ewol/renderer/os/gui.X11.cpp | 2426 ++++++++++----------- sources/ewol/renderer/os/gui.h | 99 - sources/lutin_ewol.py | 10 +- 12 files changed, 1729 insertions(+), 1886 deletions(-) diff --git a/sources/ewol/clipBoard.cpp b/sources/ewol/clipBoard.cpp index 2a03cf7b..3df74d97 100644 --- a/sources/ewol/clipBoard.cpp +++ b/sources/ewol/clipBoard.cpp @@ -89,7 +89,8 @@ void ewol::clipBoard::Set(ewol::clipBoard::clipboardListe_te _clipboardID, const if( ewol::clipBoard::clipboardStd == _clipboardID || ewol::clipBoard::clipboardSelection == _clipboardID) { - guiInterface::ClipBoardSet(_clipboardID); + //guiInterface::ClipBoardSet(_clipboardID); + EWOL_TODO("Set ClipBoard"); } } @@ -103,10 +104,12 @@ void ewol::clipBoard::Request(ewol::clipBoard::clipboardListe_te _clipboardID) if( ewol::clipBoard::clipboardStd == _clipboardID || ewol::clipBoard::clipboardSelection == _clipboardID) { - guiInterface::ClipBoardGet(_clipboardID); + //guiInterface::ClipBoardGet(_clipboardID); + EWOL_TODO("Get ClipBoard"); } else { // generate an event on the main thread ... - eSystem::ClipBoardArrive(_clipboardID); + //eSystem::ClipBoardArrive(_clipboardID); + EWOL_TODO("ClipBoard arrive"); } } diff --git a/sources/ewol/eObject/EObjectManager.cpp b/sources/ewol/eObject/EObjectManager.cpp index 508efd23..f0dd170f 100644 --- a/sources/ewol/eObject/EObjectManager.cpp +++ b/sources/ewol/eObject/EObjectManager.cpp @@ -13,15 +13,7 @@ #undef __class__ #define __class__ "EObjectManager" -static bool IsInit = false; - -// internal element of the widget manager : -static etk::Vector m_eObjectList; // all widget allocated ==> all time increment ... never removed ... -static etk::Vector m_eObjectAutoRemoveList; // all widget allocated - - - -void ewol::EObjectManager::Init(void) +ewol::EObjectManager::EObjectManager(void) { EWOL_DEBUG("==> Init EObject-Manager"); // Can create mlemory leak ... ==> but not predictable comportement otherwise ... @@ -30,7 +22,7 @@ void ewol::EObjectManager::Init(void) IsInit = true; } -void ewol::EObjectManager::UnInit(void) +ewol::EObjectManager::~EObjectManager(void) { EWOL_DEBUG("==> Un-Init EObject-Manager"); RemoveAllAutoRemove(); diff --git a/sources/ewol/eObject/EObjectManager.h b/sources/ewol/eObject/EObjectManager.h index 5b06a282..5891acc3 100644 --- a/sources/ewol/eObject/EObjectManager.h +++ b/sources/ewol/eObject/EObjectManager.h @@ -12,18 +12,24 @@ #include #include -namespace ewol { - namespace EObjectManager { - void Init(void); - void UnInit(void); - void Add(ewol::EObject* _object); - void Rm(ewol::EObject* _object); - int32_t GetNumberObject(void); - - void AutoRemove(ewol::EObject* _object); - void RemoveAllAutoRemove(void); - - ewol::EObject* Get(const etk::UString& _name); +namespace ewol +{ + class EObjectManager + { + private: + etk::Vector m_eObjectList; // all widget allocated ==> all time increment ... never removed ... + etk::Vector m_eObjectAutoRemoveList; // all widget allocated + public: + EObjectManager(void); + ~EObjectManager(void); + void Add(ewol::EObject* _object); + void Rm(ewol::EObject* _object); + int32_t GetNumberObject(void); + + void AutoRemove(ewol::EObject* _object); + void RemoveAllAutoRemove(void); + + ewol::EObject* Get(const etk::UString& _name); }; }; diff --git a/sources/ewol/ewol.cpp b/sources/ewol/ewol.cpp index 783b7e3e..352b973e 100644 --- a/sources/ewol/ewol.cpp +++ b/sources/ewol/ewol.cpp @@ -19,12 +19,12 @@ #include #undef __class__ #define __class__ "ewol" - +/* void ewol::SetFontSourcesFolder(bool _inOsSystem) { ewol::font::SetFontPropety(_inOsSystem); } - +*/ int32_t ewol::Run(int32_t _argc, const char* _argv[]) { if (NULL!=_argv) { @@ -60,14 +60,14 @@ int32_t ewol::Run(int32_t _argc, const char* _argv[]) } } // call standard RUN ... - int32_t error = guiInterface::main(_argc, _argv); + int32_t error = ewol::eSystem::main(_argc, _argv); ewol::commandLine::Clean(); return error; } - +/* void ewol::Stop(void) { guiInterface::Stop(); @@ -126,7 +126,7 @@ void ewol::SetTitle(const etk::UString& _title) etk::UString title = _title; guiInterface::SetTitle(title); } - +*/ etk::UString ewol::GetVersion(void) { #define FIRST_YEAR (2011) @@ -140,9 +140,9 @@ etk::UString ewol::GetVersion(void) int64_t ewol::GetTime(void) { - return guiInterface::GetTime(); + return ewol::eSystem::GetTime(); } - +/* void ewol::InputEventTransfertWidget(ewol::Widget* _source, ewol::Widget* _destination) { eSystem::InputEventTransfertWidget(_source, _destination); @@ -158,7 +158,7 @@ void ewol::SetIcon(const etk::UString& _icon) { guiInterface::SetIcon(_icon); } - +*/ diff --git a/sources/ewol/ewol.h b/sources/ewol/ewol.h index cc224ecf..c5f3a358 100644 --- a/sources/ewol/ewol.h +++ b/sources/ewol/ewol.h @@ -11,8 +11,6 @@ #include #include -#include -#include namespace ewol { @@ -28,51 +26,6 @@ namespace ewol * @return normal error int for the application error management */ int32_t Run(int32_t _argc, const char* _argv[]); - /** - * @brief Request the stop of the program (teminate all the process) no more call at hte application without APP_UnInit(); - */ - void Stop(void); - /** - * @brief Set a windows to diaplay - * @param[in] _windows The requested windows that migt be use for the display - */ - void WindowsSet(ewol::Windows* _windows); - /** - * @brief Add a PopUp at the current windows ==> this widget is display over the current element - * @param[in] _tmpWidget A pointer on the pop-up widget that might be displayed - */ - void WindowsPopUpAdd(ewol::Widget* _tmpWidget); - /** - * @brief Change the windows size - * @note work only on computer - * @param[in] _size The new windows size - */ - void ChangeSize(const ivec2& _size); - /** - * @brief Change the windows curent position - * @note work only on computer - * @param[in] _pos The new windows position - */ - void ChangePos(const ivec2& _pos); - /** - * @brief Generate the action of redrawing all the display. - */ - void ForceRedrawAll(void); - /** - * @brief Force the calculation of all the size of the widgets - */ - void RequestUpdateSize(void); - /** - * @brief Change the status of the Keyboard displat - * @note Specific for mobile platform - * @param[in] _hide Status of the visibility of the keyboard - */ - void Keyboard(bool _hide); - /** - * @brief Change the title display. - * @param[in] title the new title that might be displayed - */ - void SetTitle(const etk::UString& _title); /** * @brief Get EWOL version * @return The string that describe ewol version @@ -83,33 +36,18 @@ namespace ewol * @return The current time */ int64_t GetTime(void); - /** - * @brief This is to transfert the event from one widget to another one - * @param _source the widget where the event came from - * @param _destination the widget where the event mitgh be generated now - */ - void InputEventTransfertWidget(ewol::Widget* _source, ewol::Widget* _destination); typedef enum { SCREEN_ORIENTATION_AUTO = 0, SCREEN_ORIENTATION_LANDSCAPE, SCREEN_ORIENTATION_PORTRAIT, } orientation_te; - /** + /* + / ** * @brief Force a specific orientation for mobile devices * @param[in] orientation the requested position. - */ + * / void ForceOrientation(ewol::orientation_te _orientation); - /** - * @brief Set the Icon of the program - * @param[in] _icon new filename icon of the curent program. - * @note Does not work on Andoid - */ - void SetIcon(const etk::UString& _icon); - /** - * @brief Select the position of the font folder (in the OS path or in the DATA: path) - * @param[in] _inOsSystem Set at true if you want to select the os system folder. - */ - void SetFontSourcesFolder(bool _inOsSystem); + */ }; #endif diff --git a/sources/ewol/renderer/os/eSystem.cpp b/sources/ewol/renderer/os/eSystem.cpp index 6cf84d04..9855fb21 100644 --- a/sources/ewol/renderer/os/eSystem.cpp +++ b/sources/ewol/renderer/os/eSystem.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -25,105 +24,41 @@ #include #include #include -#include #include +#include + #include -static bool requestEndProcessing = false; -static bool isGlobalSystemInit = false; -static ewol::Windows* windowsCurrent = NULL; -static int64_t previousDisplayTime = 0; // this is to limit framerate ... in case... -static ivec2 windowsSize(320, 480); -static ewol::eSystemInput l_managementInput; -static ewol::Fps l_FpsSystemEvent( "Event ", false); -static ewol::Fps l_FpsSystemContext( "Context ", false); -static ewol::Fps l_FpsSystem( "Draw ", true); -static ewol::Fps l_FpsFlush( "Flush ", false); -void eSystem::InputEventTransfertWidget(ewol::Widget* source, ewol::Widget* destination) +void ewol::eSystem::InputEventTransfertWidget(ewol::Widget* source, ewol::Widget* destination) { - l_managementInput.TransfertEvent(source, destination); + m_managementInput.TransfertEvent(source, destination); } -void eSystem::InputEventGrabPointer(ewol::Widget* widget) +void ewol::eSystem::InputEventGrabPointer(ewol::Widget* widget) { - l_managementInput.GrabPointer(widget); + m_managementInput.GrabPointer(widget); } -void eSystem::InputEventUnGrabPointer(void) +void ewol::eSystem::InputEventUnGrabPointer(void) { - l_managementInput.UnGrabPointer(); + m_managementInput.UnGrabPointer(); } -typedef enum { - THREAD_NONE, - THREAD_INIT, - THREAD_RECALCULATE_SIZE, - THREAD_RESIZE, - THREAD_HIDE, - THREAD_SHOW, - - THREAD_INPUT_MOTION, - THREAD_INPUT_STATE, - - THREAD_KEYBORAD_KEY, - THREAD_KEYBORAD_MOVE, - - THREAD_CLIPBOARD_ARRIVE, -} theadMessage_te; - - - -class eSystemMessage { - public : - // specify the message type - theadMessage_te TypeMessage; - // can not set a union ... - ewol::clipBoard::clipboardListe_te clipboardID; - // InputId - ewol::keyEvent::type_te inputType; - int32_t inputId; - // generic dimentions - vec2 dimention; - // keyboard events : - bool repeateKey; //!< special flag for the repeating key on the PC interface - bool stateIsDown; - uniChar_t keyboardChar; - ewol::keyEvent::keyboard_te keyboardMove; - ewol::SpecialKey keyboardSpecial; - - eSystemMessage(void) : - TypeMessage(THREAD_NONE), - clipboardID(ewol::clipBoard::clipboardStd), - inputType(ewol::keyEvent::typeUnknow), - inputId(-1), - dimention(0,0), - repeateKey(false), - stateIsDown(false), - keyboardChar(0), - keyboardMove(ewol::keyEvent::keyboardUnknow) - { - - } -}; - -static etk::MessageFifo l_msgSystem; - - -void ewolProcessEvents(void) +void ewol::eSystem::ProcessEvents(void) { int32_t nbEvent = 0; //EWOL_DEBUG(" ******** Event"); eSystemMessage data; - while (l_msgSystem.Count()>0) + while (m_msgSystem.Count()>0) { nbEvent++; - l_msgSystem.Wait(data); + m_msgSystem.Wait(data); //EWOL_DEBUG("EVENT"); switch (data.TypeMessage) { case THREAD_INIT: @@ -135,17 +70,17 @@ void ewolProcessEvents(void) break; case THREAD_RESIZE: //EWOL_DEBUG("Receive MSG : THREAD_RESIZE"); - windowsSize = data.dimention; - ewol::dimension::SetPixelWindowsSize(vec2(windowsSize.x(),windowsSize.y())); + m_windowsSize = data.dimention; + ewol::dimension::SetPixelWindowsSize(m_windowsSize); eSystem::ForceRedrawAll(); break; case THREAD_INPUT_MOTION: //EWOL_DEBUG("Receive MSG : THREAD_INPUT_MOTION"); - l_managementInput.Motion(data.inputType, data.inputId, data.dimention); + m_managementInput.Motion(data.inputType, data.inputId, data.dimention); break; case THREAD_INPUT_STATE: //EWOL_DEBUG("Receive MSG : THREAD_INPUT_STATE"); - l_managementInput.State(data.inputType, data.inputId, data.stateIsDown, data.dimention); + m_managementInput.State(data.inputType, data.inputId, data.stateIsDown, data.dimention); break; case THREAD_KEYBORAD_KEY: case THREAD_KEYBORAD_MOVE: @@ -155,11 +90,11 @@ void ewolProcessEvents(void) specialCurrentKey = data.keyboardSpecial; //EWOL_DEBUG("newStatus Key" << specialCurrentKey); } - if (NULL != windowsCurrent) { - if (false==windowsCurrent->OnEventShortCut(data.keyboardSpecial, - data.keyboardChar, - data.keyboardMove, - data.stateIsDown) ) { + if (NULL != m_windowsCurrent) { + if (false==m_windowsCurrent->OnEventShortCut(data.keyboardSpecial, + data.keyboardChar, + data.keyboardMove, + data.stateIsDown) ) { // Get the current Focused Widget : ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet(); if (NULL != tmpWidget) { @@ -221,9 +156,7 @@ void ewolProcessEvents(void) } } - - -void eSystem::SetArchiveDir(int mode, const char* str) +void ewol::eSystem::SetArchiveDir(int mode, const char* str) { switch(mode) { @@ -250,345 +183,295 @@ void eSystem::SetArchiveDir(int mode, const char* str) - - - -void RequestInit(void) -{ - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_INIT; - l_msgSystem.Post(data); - } -} - - -void eSystem::Init(void) +ewol::eSystem::eSystem(void) : + m_previousDisplayTime(0), + m_managementInput(*this), + m_FpsSystemEvent( "Event ", false), + m_FpsSystemContext("Context ", false), + m_FpsSystem( "Draw ", true), + m_FpsFlush( "Flush ", false), + m_windowsCurrent(NULL), + m_windowsSize(320,480) { EWOL_INFO("==> Ewol System Init (BEGIN)"); - if (false == isGlobalSystemInit) { - l_msgSystem.Clean(); - requestEndProcessing = false; - - EWOL_INFO("v:" << ewol::GetVersion()); - EWOL_INFO("Build Date: " << date::GetYear() << "/" << date::GetMonth() << "/" << date::GetDay() << " " << date::GetHour() << "h" << date::GetMinute()); - etk::InitDefaultFolder("ewolApplNoName"); - ewol::openGL::Init(); - ewol::EObjectManager::Init(); - ewol::EObjectMessageMultiCast::Init(); - l_managementInput.Reset(); - ewol::resource::Init(); - ewol::widgetManager::Init(); - ewol::config::Init(); - isGlobalSystemInit = true; - // request the init of the application in the main context of openGL ... - RequestInit(); - // force a recalculation - ewol::RequestUpdateSize(); - #if defined(__EWOL_ANDROID_ORIENTATION_LANDSCAPE__) - ewol::ForceOrientation(ewol::SCREEN_ORIENTATION_LANDSCAPE); - #elif defined(__EWOL_ANDROID_ORIENTATION_PORTRAIT__) - ewol::ForceOrientation(ewol::SCREEN_ORIENTATION_PORTRAIT); - #else - ewol::ForceOrientation(ewol::SCREEN_ORIENTATION_AUTO); - #endif + EWOL_INFO("v:" << ewol::GetVersion()); + EWOL_INFO("Build Date: " << date::GetYear() << "/" << date::GetMonth() << "/" << date::GetDay() << " " << date::GetHour() << "h" << date::GetMinute()); + // TODO : Remove this ... + etk::InitDefaultFolder("ewolApplNoName"); + // TODO : Remove all of this gloabals ... + ewol::openGL::Init(); + ewol::EObjectManager::Init(); + ewol::EObjectMessageMultiCast::Init(); + m_managementInput.Reset(); + ewol::resource::Init(); + ewol::widgetManager::Init(); + ewol::config::Init(); + // request the init of the application in the main context of openGL ... + { + eSystemMessage data; + data.TypeMessage = THREAD_INIT; + m_msgSystem.Post(data); } + // force a recalculation + RequestUpdateSize(); + #if defined(__EWOL_ANDROID_ORIENTATION_LANDSCAPE__) + ForceOrientation(ewol::SCREEN_ORIENTATION_LANDSCAPE); + #elif defined(__EWOL_ANDROID_ORIENTATION_PORTRAIT__) + ForceOrientation(ewol::SCREEN_ORIENTATION_PORTRAIT); + #else + ForceOrientation(ewol::SCREEN_ORIENTATION_AUTO); + #endif EWOL_INFO("==> Ewol System Init (END)"); } -void eSystem::UnInit(void) +ewol::eSystem::~eSystem(void) { EWOL_INFO("==> Ewol System Un-Init (BEGIN)"); - if (true == isGlobalSystemInit) { - isGlobalSystemInit = false; - requestEndProcessing = true; - // unset all windows - ewol::WindowsSet(NULL); - // call application to uninit - APP_UnInit(); - ewol::widgetManager::UnInit(); - ewol::config::UnInit(); - ewol::EObjectMessageMultiCast::UnInit(); - ewol::EObjectManager::UnInit(); - ewol::resource::UnInit(); - ewol::openGL::UnInit(); - l_managementInput.Reset(); - l_msgSystem.Clean(); - } + // call application to uninit + APP_UnInit(); + // unset all windows + SetCurrentWindows(NULL); + ewol::widgetManager::UnInit(); + ewol::config::UnInit(); + ewol::EObjectMessageMultiCast::UnInit(); + ewol::EObjectManager::UnInit(); + ewol::resource::UnInit(); + ewol::openGL::UnInit(); + m_managementInput.Reset(); + m_msgSystem.Clean(); EWOL_INFO("==> Ewol System Un-Init (END)"); } -void eSystem::RequestUpdateSize(void) +void ewol::eSystem::RequestUpdateSize(void) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_RECALCULATE_SIZE; - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_RECALCULATE_SIZE; + m_msgSystem.Post(data); } -void eSystem::Resize(int w, int h ) +void ewol::eSystem::OS_Resize(const vec2& _size) { // TODO : Better in the thread ... ==> but generate some init error ... - ewol::dimension::SetPixelWindowsSize(vec2(w,h)); - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_RESIZE; - data.dimention.setValue(w,h); - l_msgSystem.Post(data); - } + ewol::dimension::SetPixelWindowsSize(_size); + eSystemMessage data; + data.TypeMessage = THREAD_RESIZE; + data.dimention = _size; + m_msgSystem.Post(data); } -void eSystem::Move(int w, int h ) +void ewol::eSystem::OS_Move(const vec2& _pos) { - if (true == isGlobalSystemInit) { - /* - eSystemMessage data; - data.TypeMessage = THREAD_RESIZE; - data.resize.w = w; - data.resize.h = h; - l_msgSystem.Post(data); - */ - } + /* + eSystemMessage data; + data.TypeMessage = THREAD_RESIZE; + data.resize.w = w; + data.resize.h = h; + m_msgSystem.Post(data); + */ } -void eSystem::SetInputMotion(int pointerID, float x, float y ) +void ewol::eSystem::OS_SetInputMotion(int _pointerID, const vec2& _pos ) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_INPUT_MOTION; - data.inputType = ewol::keyEvent::typeFinger; - data.inputId = pointerID; - data.dimention.setValue(x,y); - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_INPUT_MOTION; + data.inputType = ewol::keyEvent::typeFinger; + data.inputId = _pointerID; + data.dimention = _pos; + m_msgSystem.Post(data); } -void eSystem::SetInputState(int pointerID, bool isDown, float x, float y ) +void ewol::eSystem::OS_SetInputState(int _pointerID, bool _isDown, const vec2& _pos ) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_INPUT_STATE; - data.inputType = ewol::keyEvent::typeFinger; - data.inputId = pointerID; - data.stateIsDown = isDown; - data.dimention.setValue(x,y); - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_INPUT_STATE; + data.inputType = ewol::keyEvent::typeFinger; + data.inputId = _pointerID; + data.stateIsDown = _isDown; + data.dimention = _pos; + m_msgSystem.Post(data); } -void eSystem::SetMouseMotion(int pointerID, float x, float y ) +void ewol::eSystem::OS_SetMouseMotion(int _pointerID, const vec2& _pos ) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_INPUT_MOTION; - data.inputType = ewol::keyEvent::typeMouse; - data.inputId = pointerID; - data.dimention.setValue(x,y); - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_INPUT_MOTION; + data.inputType = ewol::keyEvent::typeMouse; + data.inputId = _pointerID; + data.dimention = _pos; + m_msgSystem.Post(data); } -void eSystem::SetMouseState(int pointerID, bool isDown, float x, float y ) +void ewol::eSystem::OS_SetMouseState(int _pointerID, bool _isDown, const vec2& _pos ) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_INPUT_STATE; - data.inputType = ewol::keyEvent::typeMouse; - data.inputId = pointerID; - data.stateIsDown = isDown; - data.dimention.setValue(x,y); - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_INPUT_STATE; + data.inputType = ewol::keyEvent::typeMouse; + data.inputId = _pointerID; + data.stateIsDown = _isDown; + data.dimention = _pos; + m_msgSystem.Post(data); } -void eSystem::SetKeyboard(ewol::SpecialKey& special, - uniChar_t myChar, - bool isDown, - bool isARepeateKey) +void ewol::eSystem::OS_SetKeyboard(ewol::SpecialKey& _special, + uniChar_t _myChar, + bool _isDown, + bool _isARepeateKey) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_KEYBORAD_KEY; - data.stateIsDown = isDown; - data.keyboardChar = myChar; - data.keyboardSpecial = special; - data.repeateKey = isARepeateKey; - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_KEYBORAD_KEY; + data.stateIsDown = _isDown; + data.keyboardChar = _myChar; + data.keyboardSpecial = _special; + data.repeateKey = _isARepeateKey; + m_msgSystem.Post(data); } -void eSystem::SetKeyboardMove(ewol::SpecialKey& special, - ewol::keyEvent::keyboard_te move, - bool isDown, - bool isARepeateKey) +void ewol::eSystem::OS_SetKeyboardMove(ewol::SpecialKey& _special, + ewol::keyEvent::keyboard_te _move, + bool _isDown, + bool _isARepeateKey) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_KEYBORAD_MOVE; - data.stateIsDown = isDown; - data.keyboardMove = move; - data.keyboardSpecial = special; - data.repeateKey = isARepeateKey; - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_KEYBORAD_MOVE; + data.stateIsDown = _isDown; + data.keyboardMove = _move; + data.keyboardSpecial = _special; + data.repeateKey = _isARepeateKey; + m_msgSystem.Post(data); } -void eSystem::Hide(void) +void ewol::eSystem::OS_Hide(void) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_HIDE; - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_HIDE; + m_msgSystem.Post(data); } -void eSystem::Show(void) +void ewol::eSystem::OS_Show(void) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_SHOW; - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_SHOW; + m_msgSystem.Post(data); } -void eSystem::ClipBoardArrive(ewol::clipBoard::clipboardListe_te clipboardID) +void ewol::eSystem::OS_ClipBoardArrive(ewol::clipBoard::clipboardListe_te _clipboardID) { - if (true == isGlobalSystemInit) { - eSystemMessage data; - data.TypeMessage = THREAD_CLIPBOARD_ARRIVE; - data.clipboardID = clipboardID; - l_msgSystem.Post(data); - } + eSystemMessage data; + data.TypeMessage = THREAD_CLIPBOARD_ARRIVE; + data.clipboardID = _clipboardID; + m_msgSystem.Post(data); } -bool eSystem::Draw(bool displayEveryTime) +bool ewol::eSystem::OS_Draw(bool _displayEveryTime) { int64_t currentTime = ewol::GetTime(); // this is to prevent the multiple display at the a high frequency ... #if (!defined(__TARGET_OS__Android) && !defined(__TARGET_OS__Windows)) - if(currentTime - previousDisplayTime < 1000000/120) { + if(currentTime - m_previousDisplayTime < 1000000/120) { usleep(1000); return false; } #endif - previousDisplayTime = currentTime; + m_previousDisplayTime = currentTime; - if (true == isGlobalSystemInit) { - // process the events -l_FpsSystemEvent.Tic(); - ewolProcessEvents(); - // call all the widget that neded to do something periodicly - ewol::widgetManager::PeriodicCall(currentTime); - // Remove all widget that they are no more usefull (these who decided to destroy themself) - ewol::EObjectManager::RemoveAllAutoRemove(); - ewol::Windows* tmpWindows = eSystem::GetCurrentWindows(); - // check if the user selected a windows - if (NULL != tmpWindows) { - // Redraw all needed elements - tmpWindows->OnRegenerateDisplay(); - } -l_FpsSystemEvent.IncrementCounter(); -l_FpsSystemEvent.Toc(); - bool needRedraw = ewol::widgetManager::IsDrawingNeeded(); - -l_FpsSystemContext.Tic(); - if (NULL != tmpWindows) { - if( true == needRedraw - || true == displayEveryTime) { - ewol::resource::UpdateContext(); -l_FpsSystemContext.IncrementCounter(); - } - } -l_FpsSystemContext.Toc(); - bool hasDisplayDone = false; -l_FpsSystem.Tic(); - if (NULL != tmpWindows) { - if( true == needRedraw - || true == displayEveryTime) { -l_FpsSystem.IncrementCounter(); - tmpWindows->SysDraw(); - hasDisplayDone = true; - } - } -l_FpsSystem.Toc(); - -l_FpsFlush.Tic(); -l_FpsFlush.IncrementCounter(); - glFlush(); - //glFinish(); -l_FpsFlush.Toc(); - -l_FpsSystemEvent.Draw(); -l_FpsSystemContext.Draw(); -l_FpsSystem.Draw(); -l_FpsFlush.Draw(); - return hasDisplayDone; + // process the events + m_FpsSystemEvent.Tic(); + ProcessEvents(); + // call all the widget that neded to do something periodicly + ewol::widgetManager::PeriodicCall(currentTime); + // Remove all widget that they are no more usefull (these who decided to destroy themself) + ewol::EObjectManager::RemoveAllAutoRemove(); + ewol::Windows* tmpWindows = eSystem::GetCurrentWindows(); + // check if the user selected a windows + if (NULL != tmpWindows) { + // Redraw all needed elements + tmpWindows->OnRegenerateDisplay(); } + m_FpsSystemEvent.IncrementCounter(); + m_FpsSystemEvent.Toc(); + bool needRedraw = ewol::widgetManager::IsDrawingNeeded(); + + m_FpsSystemContext.Tic(); + if (NULL != tmpWindows) { + if( true == needRedraw + || true == _displayEveryTime) { + ewol::resource::UpdateContext(); + m_FpsSystemContext.IncrementCounter(); + } + } + m_FpsSystemContext.Toc(); + bool hasDisplayDone = false; + m_FpsSystem.Tic(); + if (NULL != tmpWindows) { + if( true == needRedraw + || true == _displayEveryTime) { + m_FpsSystem.IncrementCounter(); + tmpWindows->SysDraw(); + hasDisplayDone = true; + } + } + m_FpsSystem.Toc(); + + m_FpsFlush.Tic(); + m_FpsFlush.IncrementCounter(); + glFlush(); + //glFinish(); + m_FpsFlush.Toc(); + + m_FpsSystemEvent.Draw(); + m_FpsSystemContext.Draw(); + m_FpsSystem.Draw(); + m_FpsFlush.Draw(); + return hasDisplayDone; return false; } - -void eSystem::OnObjectRemove(ewol::EObject * removeObject) +/* +void ewol::eSystem::OnObjectRemove(ewol::EObject * removeObject) { - l_managementInput.OnObjectRemove(removeObject); + m_managementInput.OnObjectRemove(removeObject); +} +*/ + +void ewol::eSystem::ResetIOEvent(void) +{ + m_managementInput.NewLayerSet(); } -void eSystem::ResetIOEvent(void) -{ - l_managementInput.NewLayerSet(); -} - - -void eSystem::OpenGlContextDestroy(void) +void ewol::eSystem::OS_OpenGlContextDestroy(void) { ewol::resource::ContextHasBeenDestroyed(); } -void eSystem::SetCurrentWindows(ewol::Windows * windows) +void ewol::eSystem::SetCurrentWindows(ewol::Windows* _windows) { // set the new pointer as windows system - windowsCurrent = windows; + m_windowsCurrent = _windows; // request all the widget redrawing - eSystem::ForceRedrawAll(); + ForceRedrawAll(); } -ewol::Windows* eSystem::GetCurrentWindows(void) +void ewol::eSystem::ForceRedrawAll(void) { - return windowsCurrent; -} - - -ivec2 eSystem::GetSize(void) -{ - return windowsSize; -} - - -void eSystem::ForceRedrawAll(void) -{ - ewol::Windows* tmpWindows = eSystem::GetCurrentWindows(); - if (NULL != tmpWindows) { - ivec2 systemSize = eSystem::GetSize(); - tmpWindows->CalculateSize(vec2(systemSize.x(), systemSize.y())); + if (NULL != m_windowsCurrent) { + m_windowsCurrent->CalculateSize(vec2(m_windowsSize.x(), m_windowsSize.y())); } } -void eSystem::OnKill(void) +void ewol::eSystem::OS_Stop(void) { - ewol::Windows* tmpWindows = eSystem::GetCurrentWindows(); - if (NULL != tmpWindows) { - tmpWindows->SysOnKill(); + if (NULL != m_windowsCurrent) { + m_windowsCurrent->SysOnKill(); } } diff --git a/sources/ewol/renderer/os/eSystem.h b/sources/ewol/renderer/os/eSystem.h index 806ac91b..c82b77b1 100644 --- a/sources/ewol/renderer/os/eSystem.h +++ b/sources/ewol/renderer/os/eSystem.h @@ -11,96 +11,292 @@ #include #include +#include #include #include +#include +#include +#include -namespace eSystem -{ - void Init(void); - void UnInit(void); + +// TODO : Remove this from here ... +typedef enum { + THREAD_NONE, + THREAD_INIT, + THREAD_RECALCULATE_SIZE, + THREAD_RESIZE, + THREAD_HIDE, + THREAD_SHOW, - void SetArchiveDir(int mode, const char* str); + THREAD_INPUT_MOTION, + THREAD_INPUT_STATE, - void Resize(int w, int h ); - void Move(int x, int y ); - void Hide(void); - void Show(void); + THREAD_KEYBORAD_KEY, + THREAD_KEYBORAD_MOVE, - void SetInputMotion(int pointerID, float x, float y); - void SetInputState(int pointerID, bool isDown, float x, float y); - - void SetMouseMotion(int pointerID, float x, float y); - void SetMouseState(int pointerID, bool isDown, float x, float y); - - void SetKeyboard(ewol::SpecialKey& special, - uniChar_t myChar, - bool isDown, - bool isARepeateKey=false); - void SetKeyboardMove(ewol::SpecialKey& special, - ewol::keyEvent::keyboard_te move, - bool isDown, - bool isARepeateKey=false); - - void ClipBoardArrive(ewol::clipBoard::clipboardListe_te clipboardID); - - void RequestUpdateSize(void); - - // return true if a flush is needed - bool Draw(bool displayEveryTime); - /** - * @brief Inform object that an other object is removed ... - * @param[in] removeObject Pointer on the EObject remeved ==> the user must remove all reference on this EObject - * @note : Sub classes must call this class - */ - void OnObjectRemove(ewol::EObject * removeObject); - /** - * @brief reset event management for the IO like Input ou Mouse or keyborad - */ - void ResetIOEvent(void); - /** - * @brief Inform the system that the OpenGL constext has been destroy ==> use to automaticly reload the texture and other thinks ... - */ - void OpenGlContextDestroy(void); - /** - * @brief Inform the system that the Application has been killed - */ - void OnKill(void); - /** - * @brief set the current windows to display : - * @param windows windows that might be displayed - */ - void SetCurrentWindows(ewol::Windows * windows); - /** - * @brief Get the current windows that is displayed - * @return the current handle on the windows (can be null) - */ - ewol::Windows* GetCurrentWindows(void); - /** - * @brief Get the current windows size - * @return the current size ... - */ - ivec2 GetSize(void); - /** - * @brief Redraw all the windows - */ - void ForceRedrawAll(void); - /** - * @brief This is to transfert the event from one widget to another one - * @param source the widget where the event came from - * @param destination the widget where the event mitgh be generated now - */ - void InputEventTransfertWidget(ewol::Widget* source, ewol::Widget* destination); - /** - * @brief This fonction lock the pointer properties to move in relative instead of absolute - * @param[in] widget The widget that lock the pointer events - */ - void InputEventGrabPointer(ewol::Widget* widget); - /** - * @brief This fonction un-lock the pointer properties to move in relative instead of absolute - */ - void InputEventUnGrabPointer(void); + THREAD_CLIPBOARD_ARRIVE, +} theadMessage_te; +// TODO : Remove this from here ... +class eSystemMessage { + public : + // specify the message type + theadMessage_te TypeMessage; + // can not set a union ... + ewol::clipBoard::clipboardListe_te clipboardID; + // InputId + ewol::keyEvent::type_te inputType; + int32_t inputId; + // generic dimentions + vec2 dimention; + // keyboard events : + bool repeateKey; //!< special flag for the repeating key on the PC interface + bool stateIsDown; + uniChar_t keyboardChar; + ewol::keyEvent::keyboard_te keyboardMove; + ewol::SpecialKey keyboardSpecial; + + eSystemMessage(void) : + TypeMessage(THREAD_NONE), + clipboardID(ewol::clipBoard::clipboardStd), + inputType(ewol::keyEvent::typeUnknow), + inputId(-1), + dimention(0,0), + repeateKey(false), + stateIsDown(false), + keyboardChar(0), + keyboardMove(ewol::keyEvent::keyboardUnknow) + { + + } }; +namespace ewol +{ + class eSystem + { + public: + eSystem(void); + virtual ~eSystem(void); + private: + int64_t m_previousDisplayTime; // this is to limit framerate ... in case... + ewol::eSystemInput m_managementInput; + etk::MessageFifo m_msgSystem; + ewol::Fps m_FpsSystemEvent; + ewol::Fps m_FpsSystemContext; + ewol::Fps m_FpsSystem; + ewol::Fps m_FpsFlush; + /** + * @brief Processing all the event arrived ... (commoly called in draw function) + */ + void ProcessEvents(void); + public: + + void SetArchiveDir(int _mode, const char* _str); + + + void OS_SetInputMotion(int _pointerID, const vec2& _pos); + void OS_SetInputState(int _pointerID, bool _isDown, const vec2& _pos); + + void OS_SetMouseMotion(int _pointerID, const vec2& _pos); + void OS_SetMouseState(int _pointerID, bool _isDown, const vec2& _pos); + + void OS_SetKeyboard(ewol::SpecialKey& _special, + uniChar_t _myChar, + bool _isDown, + bool _isARepeateKey=false); + void OS_SetKeyboardMove(ewol::SpecialKey& _special, + ewol::keyEvent::keyboard_te _move, + bool _isDown, + bool _isARepeateKey=false); + + void OS_SetClipBoard(ewol::clipBoard::clipboardListe_te _clipboardID); + + void RequestUpdateSize(void); + + // return true if a flush is needed + bool OS_Draw(bool _displayEveryTime); + /** + * @brief Inform object that an other object is removed ... + * @param[in] removeObject Pointer on the EObject remeved ==> the user must remove all reference on this EObject + * @note : Sub classes must call this class + */ + void OnObjectRemove(ewol::EObject * removeObject); + /** + * @brief reset event management for the IO like Input ou Mouse or keyborad + */ + void ResetIOEvent(void); + /** + * @brief The OS inform that the OpenGL constext has been destroy ==> use to automaticly reload the texture and other thinks ... + */ + void OS_OpenGlContextDestroy(void); + /** + * @brief The OS Inform that the Window has been killed + */ + void OS_Stop(void); + /** + * @brief The application request that the Window will be killed + */ + virtual void Stop(void); + private: + ewol::Windows* m_windowsCurrent; //!< curent displayed windows + public: + /** + * @brief set the current windows to display : + * @param _windows Windows that might be displayed + */ + void SetCurrentWindows(ewol::Windows* _windows); + /** + * @brief Get the current windows that is displayed + * @return the current handle on the windows (can be null) + */ + ewol::Windows* GetCurrentWindows(void) { return m_windowsCurrent; }; + private: + vec2 m_windowsSize; //!< current size of the system + public: + /** + * @brief Get the current windows size + * @return the current size ... + */ + const vec2& GetSize(void) { return m_windowsSize; }; + /** + * @brief The OS inform that the current windows has change his size. + * @param[in] _size new size of the windows. + */ + void OS_Resize(const vec2& _size); + /** + * @brief The application request a change of his curent size. + * @param[in] _size new Requested size of the windows. + */ + virtual void SetSize(const vec2& _size) { }; + /** + * @brief The OS inform that the current windows has change his position. + * @param[in] _pos New position of the Windows. + */ + void OS_Move(const vec2& _pos); + /** + * @brief The Application request that the current windows will change his position. + * @param[in] _pos New position of the Windows requested. + */ + virtual void SetPos(const vec2& _pos) { }; + /** + * @brief The OS inform that the Windows is now Hidden. + */ + void OS_Hide(void); + /** + * @brief The Application request that the Windows will be Hidden. + */ + virtual void Hide(void) { }; + /** + * @brief The OS inform that the Windows is now visible. + */ + void OS_Show(void); + /** + * @brief The Application request that the Windows will be visible. + */ + virtual void Show(void) { }; + /** + * @brief Redraw all the windows + */ + void ForceRedrawAll(void); + + // TODO : Later ... + /** + * @brief This is to transfert the event from one widget to another one + * @param source the widget where the event came from + * @param destination the widget where the event mitgh be generated now + */ + void InputEventTransfertWidget(ewol::Widget* _source, ewol::Widget* _destination); + /** + * @brief This fonction lock the pointer properties to move in relative instead of absolute + * @param[in] widget The widget that lock the pointer events + */ + void InputEventGrabPointer(ewol::Widget* _widget); + /** + * @brief This fonction un-lock the pointer properties to move in relative instead of absolute + */ + void InputEventUnGrabPointer(void); + + /** + * @brief Display the virtal keyboard (for touch system only) + */ + void KeyboardShow(void); + /** + * @brief Hide the virtal keyboard (for touch system only) + */ + void KeyboardHide(void); + + /** + * @brief Inform the Gui that we want to have a copy of the clipboard + * @param[in] _clipboardID ID of the clipboard (STD/SELECTION) only apear here + */ + virtual void ClipBoardGet(ewol::clipBoard::clipboardListe_te _clipboardID) { }; + /** + * @brief Inform the Gui that we are the new owner of the clipboard + * @param[in] _clipboardID ID of the clipboard (STD/SELECTION) only apear here + */ + virtual void ClipBoardSet(ewol::clipBoard::clipboardListe_te _clipboardID) { }; + /** + * @brief Call by the OS when a clipboard arrive to US (previously requested by a widget) + * @param[in] Id of the clipboard + */ + void OS_ClipBoardArrive(ewol::clipBoard::clipboardListe_te _clipboardID); + /** + * @brief Set the new title of the windows + * @param[in] title New desired title + */ + virtual void SetTitle(etk::UString& _title) { }; + /** + * @brief Force the screen orientation (availlable on portable elements ... + * @param[in] _orientation Selected orientation. + */ + virtual void ForceOrientation(ewol::orientation_te _orientation) { }; + /** + * @brief Get all the event from the X system + * @param[in] _isGrabbed "true" if all the event will be get, false if we want only ours. + * @param[in] _forcedPosition the position where the mouse might be reset at every events ... + */ + virtual void GrabPointerEvents(bool _isGrabbed, const vec2& _forcedPosition) { }; + /** + * @brief Set the cursor display type. + * @param[in] _newCursor selected new cursor. + */ + virtual void SetCursor(ewol::cursorDisplay_te _newCursor) { }; + /** + * @brief Set the Icon of the program + * @param[in] _inputFile new filename icon of the curent program. + */ + virtual void SetIcon(const etk::UString& _inputFile) { }; + /** + * @brief Get the curent time in micro-second + * @note : must be implemented in all system OS implementation + * @return The curent time of the process + */ + static int64_t GetTime(void); + private: + // TODO : Set user argument here .... + + public: + /** + * @brief This is the only one things the User might done in his main(); + * @note : must be implemented in all system OPS implementation + * @note To answare you before you ask the question, this is really simple: + * Due to the fect that the current system is multiple-platform, you "main" + * Does not exist in the android platform, then ewol call other start + * and stop function, to permit to have only one code + * @note The main can not be in the ewol, due to the fact thet is an librairy + * @param[in] _argc Standard argc + * @param[in] _argv Standard argv + * @return normal error int for the application error management + */ + static int main(int _argc, const char *_argv[]); + }; +}; + +//!< must be define in CPP by the application ... this are the main init and unInit of the Application + +ewol::Windows* APP_Init(void); +void APP_UnInit(void); + #endif diff --git a/sources/ewol/renderer/os/eSystemInput.cpp b/sources/ewol/renderer/os/eSystemInput.cpp index fe2ab6af..bb5d208a 100644 --- a/sources/ewol/renderer/os/eSystemInput.cpp +++ b/sources/ewol/renderer/os/eSystemInput.cpp @@ -136,13 +136,13 @@ void ewol::eSystemInput::GrabPointer(ewol::Widget* widget) return; } m_grabWidget = widget; - guiInterface::GrabPointerEvents(true, widget->GetOrigin() + ivec2(widget->GetSize().x()/2.0f, widget->GetSize().y()/2.0f) ); + m_system.GrabPointerEvents(true, widget->GetOrigin() + ivec2(widget->GetSize().x()/2.0f, widget->GetSize().y()/2.0f) ); } void ewol::eSystemInput::UnGrabPointer(void) { m_grabWidget = NULL; - guiInterface::GrabPointerEvents(false, vec2(0,0)); + m_system.GrabPointerEvents(false, vec2(0,0)); } void ewol::eSystemInput::OnObjectRemove(ewol::EObject * removeObject) @@ -179,8 +179,9 @@ void ewol::eSystemInput::Reset(void) } } -ewol::eSystemInput::eSystemInput(void) : - m_grabWidget(NULL) +ewol::eSystemInput::eSystemInput(ewol::eSystem& _system) : + m_grabWidget(NULL), + m_system(_system) { SetDpi(200); EWOL_INFO("Init (start)"); @@ -236,7 +237,7 @@ void ewol::eSystemInput::Motion(ewol::keyEvent::type_te type, int pointerID, vec // not manage input return; } - ewol::Windows* tmpWindows = eSystem::GetCurrentWindows(); + ewol::Windows* tmpWindows = m_system.GetCurrentWindows(); // special case for the mouse event 0 that represent the hover event of the system : if (type == ewol::keyEvent::typeMouse && pointerID == 0) { // this event is all time on the good widget ... and manage the enter and leave ... @@ -336,7 +337,7 @@ void ewol::eSystemInput::State(ewol::keyEvent::type_te type, int pointerID, bool } // get the curent time ... int64_t currentTime = ewol::GetTime(); - ewol::Windows* tmpWindows = eSystem::GetCurrentWindows(); + ewol::Windows* tmpWindows = m_system.GetCurrentWindows(); if (true == isDown) { EWOL_VERBOSE("GUI : Input ID=" << pointerID << "==>" << eventTable[pointerID].destinationInputId << " [DOWN] " << pos); diff --git a/sources/ewol/renderer/os/eSystemInput.h b/sources/ewol/renderer/os/eSystemInput.h index 1a6e24ce..00319d89 100644 --- a/sources/ewol/renderer/os/eSystemInput.h +++ b/sources/ewol/renderer/os/eSystemInput.h @@ -11,6 +11,8 @@ #include +#define MAX_MANAGE_INPUT (15) + namespace ewol { @@ -33,7 +35,7 @@ namespace ewol int32_t sepatateTime; int32_t DpiOffset; } inputLimit_ts; - + class eSystem; class eSystemInput { // special grab pointer mode : @@ -44,7 +46,6 @@ namespace ewol inputLimit_ts m_eventInputLimit; inputLimit_ts m_eventMouseLimit; void CalculateLimit(void); - #define MAX_MANAGE_INPUT (15) InputPoperty_ts m_eventInputSaved[MAX_MANAGE_INPUT]; InputPoperty_ts m_eventMouseSaved[MAX_MANAGE_INPUT]; void AbortElement(InputPoperty_ts *eventTable, int32_t idInput, ewol::keyEvent::type_te _type); @@ -74,8 +75,10 @@ namespace ewol int32_t localGetDestinationId(ewol::keyEvent::type_te type, ewol::Widget* destWidget, int32_t realInputId); + private: + ewol::eSystem& m_system; public: - eSystemInput(void); + eSystemInput(ewol::eSystem& _system); ~eSystemInput(void); void Reset(void); void SetDpi(int32_t newDPI); diff --git a/sources/ewol/renderer/os/gui.X11.cpp b/sources/ewol/renderer/os/gui.X11.cpp index 1da7fcfa..acf3aaba 100644 --- a/sources/ewol/renderer/os/gui.X11.cpp +++ b/sources/ewol/renderer/os/gui.X11.cpp @@ -52,7 +52,7 @@ bool hasDisplay = false; #define X11_INFO EWOL_VERBOSE #define X11_CRITICAL EWOL_VERBOSE #endif -int64_t guiInterface::GetTime(void) +int64_t ewol::eSystem::GetTime(void) { struct timespec now; int ret = clock_gettime(CLOCK_REALTIME, &now); @@ -65,9 +65,6 @@ int64_t guiInterface::GetTime(void) return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_nsec/(int64_t)1000); } -#undef __class__ -#define __class__ "guiInterface" - // attributes for a single buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer static int attrListSgl[] = { GLX_RGBA, @@ -89,9 +86,6 @@ static int attrListDbl[] = { None }; -static ewol::SpecialKey guiKeyBoardMode; - - extern "C" { typedef struct Hints { @@ -103,1241 +97,1186 @@ extern "C" { } Hints; } -// for double and triple click selection, we need to save the previous click up and down position , and the previous time ... -int32_t m_previousBouttonId = -1; -int32_t m_previousDown_x = 0; -int32_t m_previousDown_y = 0; -int32_t m_previous_x = 0; -int32_t m_previous_y = 0; -int64_t m_previousTime = 0; -bool m_previousDouble = 0; - -Atom m_delAtom; -Display * m_display = NULL;; -Window WindowHandle; -int32_t m_originX = 0; -int32_t m_originY = 0; -int32_t m_cursorEventX = 0; -int32_t m_cursorEventY = 0; -int32_t m_currentHeight = 0; -int32_t m_currentWidth = 0; -XVisualInfo * m_visual = NULL; -bool m_doubleBuffered = 0; -bool m_run = 0; -//forcing the position -bool m_grabAllEvent = false; //!< grab mode enable... -vec2 m_forcePos = vec2(0,0); //!< position to reset the cursor -bool m_positionChangeRequested = false; //!< the position modifiquation has been requested -vec2 m_curentGrabDelta = vec2(0,0); //!< the position in X11 will arrive by pool - -bool inputIsPressed[20]; - -// internal copy of the clipBoard ... -static bool l_clipBoardRequestPrimary = false; // if false : request the copy/past buffer, if true : request current selection -static bool l_clipBoardOwnerPrimary = false; // we are the owner of the current selection -static bool l_clipBoardOwnerStd = false; // we are the owner of the current copy buffer -// Atom access... -static Atom XAtomeSelection = 0; -static Atom XAtomeClipBoard = 0; -static Atom XAtomeTargetString = 0; -static Atom XAtomeTargetStringUTF8 = 0; -static Atom XAtomeTargetTarget = 0; -static Atom XAtomeEWOL = 0; -static Atom XAtomeDeleteWindows = 0; - - - - - -bool CreateX11Context(void) -{ - X11_INFO("X11: CreateX11Context"); - int x,y, attr_mask; - XSizeHints hints; - XWMHints *StartupState; - XTextProperty textprop; - XSetWindowAttributes attr; - // basic title of the windows ... - static char *title = (char*)"Ewol"; - - // Connect to the X server - m_display = XOpenDisplay(NULL); - if(NULL == m_display) { - EWOL_CRITICAL("Could not open display X."); - exit(-1); - } else { - EWOL_INFO("Display opened."); - } - int Xscreen = DefaultScreen(m_display); - // set the DPI for the current screen : - ewol::dimension::SetPixelRatio(vec2((float)DisplayWidth(m_display, Xscreen)/(float)DisplayWidthMM(m_display, Xscreen), - (float)DisplayHeight(m_display, Xscreen)/(float)DisplayHeightMM(m_display, Xscreen)), - ewol::Dimension::Millimeter); - // get an appropriate visual - m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl); - if (NULL == m_visual) { - m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl); - m_doubleBuffered = false; - EWOL_INFO("GL-X singlebuffered rendering will be used, no doublebuffering available"); - } else { - m_doubleBuffered = true; - EWOL_INFO("GL-X doublebuffered rendering available"); - } - { - int32_t glxMajor, glxMinor; - glXQueryVersion(m_display, &glxMajor, &glxMinor); - EWOL_INFO("GLX-Version " << glxMajor << "." << glxMinor); - } - // Create a colormap - only needed on some X clients, eg. IRIX - Window Xroot = RootWindow(m_display, Xscreen); - attr.colormap = XCreateColormap(m_display, Xroot, m_visual->visual, AllocNone); - - attr.border_pixel = 0; - attr.event_mask = StructureNotifyMask - | SubstructureNotifyMask - | EnterWindowMask - | LeaveWindowMask - | ExposureMask - | ButtonPressMask - | ButtonReleaseMask - | OwnerGrabButtonMask - | KeyPressMask - | KeyReleaseMask - | PointerMotionMask - | FocusChangeMask - | SubstructureRedirectMask; - - // set no background at the gui - attr.background_pixmap = None; - - // select internal attribute - attr_mask = CWBackPixmap | CWColormap | CWBorderPixel | CWEventMask; - // Create the window - int32_t tmp_width = 640;//DisplayWidth(m_display, DefaultScreen(m_display))/2; - int32_t tmp_height = 480;//DisplayHeight(m_display, DefaultScreen(m_display))/2; - eSystem::Resize(tmp_width, tmp_height); - x=20; - y=20; - m_originX = x; - m_originY = y; - EWOL_INFO("X11 request creating windows at pos=(" << m_originX << "," << m_originY << ") size=(" << tmp_width << "," << tmp_height << ")" ); - // Real create of the window - WindowHandle = XCreateWindow(m_display, - Xroot, - x, y, tmp_width, tmp_height, - 1, - m_visual->depth, - InputOutput, - m_visual->visual, - attr_mask, &attr); - - if( !WindowHandle ) { - EWOL_CRITICAL("Couldn't create the window"); - exit(-1); - } - - /* Configure it... (ok, ok, this next bit isn't "minimal") */ - textprop.value = (unsigned char*)title; - textprop.encoding = XA_STRING; - textprop.format = 8; - textprop.nitems = strlen(title); - - hints.x = x; - hints.y = y; - hints.width = tmp_width; - hints.height = tmp_height; - hints.flags = USPosition|USSize; - - StartupState = XAllocWMHints(); - StartupState->initial_state = NormalState; - StartupState->flags = StateHint; - - XSetWMProperties(m_display, WindowHandle,&textprop, &textprop,/* Window title/icon title*/ - NULL, 0,/* Argv[], argc for program*/ - &hints, /* Start position/size*/ - StartupState,/* Iconised/not flag */ - NULL); - - XFree(StartupState); - - /* Open it, wait for it to appear */ - XMapWindow(m_display, WindowHandle); - //XIfEvent(m_display, &event, WaitForMapNotify, (char*)&WindowHandle); - - // Set the kill atom so we get a message when the user tries to close the window - if ((m_delAtom = XInternAtom(m_display, "WM_DELETE_WINDOW", 0)) != None) { - XSetWMProtocols(m_display, WindowHandle, &m_delAtom, 1); - } - - ivec2 tmpSize(400, 300); - guiInterface::ChangeSize(tmpSize); - - return true; -} - - -/** - * @brief Set the new title of the windows - * @param title New desired title - * @return --- - */ -void guiInterface::SetTitle(etk::UString& title) -{ - X11_INFO("X11: Set Title (START)"); - XTextProperty tp; - etk::Char tmpChar = title.c_str(); - tp.value = (unsigned char *)((const char*)tmpChar); - tp.encoding = XA_WM_NAME; - tp.format = 8; - tp.nitems = strlen((const char*)tp.value); - XSetWMName(m_display, WindowHandle, &tp); - XStoreName(m_display, WindowHandle, (const char*)tp.value); - XSetIconName(m_display, WindowHandle, (const char*)tp.value); - XSetWMIconName(m_display, WindowHandle, &tp); - X11_INFO("X11: Set Title (END)"); -} - #include -void guiInterface::SetIcon(etk::UString _inputFile) -{ - egami::Image dataImage; - // load data - if (false == egami::Load(dataImage, _inputFile)) { - EWOL_ERROR("Error when loading Icon"); - return; - } - int32_t depth = DefaultDepth(m_display, DefaultScreen(m_display) ); - EWOL_DEBUG("X11 Create icon Size=(" << dataImage.GetWidth() << "," << dataImage.GetHeight() << ") depth=" << depth); - switch(depth) { - case 8: - EWOL_CRITICAL("Not manage pixmap in 8 bit... ==> no icon ..."); - return; - case 16: - break; - case 24: - break; - case 32: - break; - default: - EWOL_CRITICAL("Unknow thys type of bitDepth : " << depth); - return; - } - char* tmpVal = new char[4*dataImage.GetWidth()*dataImage.GetHeight()]; - if (NULL == tmpVal) { - EWOL_CRITICAL("Allocation error ..."); - return; - } - char* tmpPointer = tmpVal; - switch(depth) { - case 16: - for(ivec2 pos(0,0); pos.y() tmpColor = dataImage.Get(pos); - int16_t tmpVal = (((uint16_t)((uint16_t)tmpColor.r()>>3))<<11) - + (((uint16_t)((uint16_t)tmpColor.g()>>2))<<5) - + ((uint16_t)((uint16_t)tmpColor.b()>>3)); - *tmpPointer++ = (uint8_t)(tmpVal>>8); - *tmpPointer++ = (uint8_t)(tmpVal&0x00FF); - } - } - break; - case 24: - for(ivec2 pos(0,0); pos.y() tmpColor = dataImage.Get(pos); - *tmpPointer++ = tmpColor.b(); - *tmpPointer++ = tmpColor.g(); - *tmpPointer++ = tmpColor.r(); - tmpPointer++; - } - } - break; - case 32: - for(ivec2 pos(0,0); pos.y() tmpColor = dataImage.Get(pos); - *tmpPointer++ = tmpColor.a(); - *tmpPointer++ = tmpColor.b(); - *tmpPointer++ = tmpColor.g(); - *tmpPointer++ = tmpColor.r(); - } - } - break; - default: - return; - } - - XImage* myImage = XCreateImage(m_display, - m_visual->visual, - depth, - ZPixmap, - 0, - (char*)tmpVal, - dataImage.GetWidth(), - dataImage.GetHeight(), - 32, - 0); - - Pixmap tmpPixmap = XCreatePixmap(m_display, WindowHandle, dataImage.GetWidth(), dataImage.GetHeight(), depth); - switch(tmpPixmap) { - case BadAlloc: - EWOL_ERROR("X11: BadAlloc"); - break; - case BadDrawable: - EWOL_ERROR("X11: BadDrawable"); - break; - case BadValue: - EWOL_ERROR("X11: BadValue"); - break; - default: - EWOL_DEBUG("Create Pixmap OK"); - break; - } - GC tmpGC = DefaultGC(m_display, DefaultScreen(m_display) ); - int error = XPutImage(m_display, tmpPixmap, tmpGC, myImage, 0, 0, 0, 0, dataImage.GetWidth(), dataImage.GetHeight()); - switch(error) { - case BadDrawable: - EWOL_ERROR("X11: BadDrawable"); - break; - case BadGC: - EWOL_ERROR("X11: BadGC"); - break; - case BadMatch: - EWOL_ERROR("X11: BadMatch"); - break; - case BadValue: - EWOL_ERROR("X11: BadValue"); - break; - default: - EWOL_DEBUG("insert image OK"); - break; - } - // allocate a WM hints structure. - XWMHints* win_hints = XAllocWMHints(); - if (!win_hints) { - EWOL_ERROR("XAllocWMHints - out of memory"); - return; - } - // initialize the structure appropriately. first, specify which size hints we want to fill in. in our case - setting the icon's pixmap. - win_hints->flags = IconPixmapHint; - // next, specify the desired hints data. in our case - supply the icon's desired pixmap. - win_hints->icon_pixmap = tmpPixmap; - // pass the hints to the window manager. - XSetWMHints(m_display, WindowHandle, win_hints); - EWOL_INFO(" ==> might be done "); - // finally, we can free the WM hints structure. - XFree(win_hints); - - // Note when we free the pixmap ... the icon is removed ... ==> this is a real memory leek ... - //XFreePixmap(m_display, tmpPixmap); - - myImage->data = NULL; - XDestroyImage(myImage); - delete[] tmpVal; - -} - - -void RemoveDecoration(void) -{ - X11_INFO("X11:RemoveDecoration"); - Hints hints; - Atom property; - hints.flags = 2;// Specify that we're changing the window decorations. - hints.decorations = 0;// 0 (false) means that window decorations should go bye-bye - property = XInternAtom(m_display, "_MOTIF_WM_HINTS", true); - if (0 != property) { - XChangeProperty(m_display,WindowHandle,property,property,32,PropModeReplace,(unsigned char *)&hints,5); - XMapWindow(m_display, WindowHandle); - } else { - EWOL_ERROR("Can not get the property for the rmoving decoration of the X11 system ...."); - } -} - -void AddDecoration(void) -{ - X11_INFO("X11:AddDecoration"); - Hints hints; - Atom property; - hints.flags = 2;// Specify that we're changing the window decorations. - hints.decorations = 1;// 1 (true) means that window decorations should enable - property = XInternAtom(m_display, "_MOTIF_WM_HINTS", true); - if (0 != property) { - XChangeProperty(m_display,WindowHandle,property,property,32,PropModeReplace,(unsigned char *)&hints,5); - XMapWindow(m_display, WindowHandle); - } else { - EWOL_ERROR("Can not get the property for the rmoving decoration of the X11 system ...."); - } -} - -static void setVSync(bool sync) -{ - // Function pointer for the wgl extention function we need to enable/disable - typedef int32_t (APIENTRY *PFNWGLSWAPINTERVALPROC)( int ); - PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0; - const char *extensions = (char*)glGetString( GL_EXTENSIONS ); - if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 ) { - EWOL_ERROR("Can not set the vertical synchronisation status" << sync << " (1)"); - return; - } else { - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glXGetProcAddress( (const GLubyte *)"wglSwapIntervalEXT" ); - if(wglSwapIntervalEXT) { - wglSwapIntervalEXT(sync); - } else { - EWOL_ERROR("Can not set the vertical synchronisation status" << sync << " (2)"); - } - } -} - -bool CreateOGlContext(void) -{ - X11_INFO("X11:CreateOGlContext"); - /* create a GLX context */ - GLXContext RenderContext = glXCreateContext(m_display, m_visual, 0, GL_TRUE); - /* connect the glx-context to the window */ - glXMakeCurrent(m_display, WindowHandle, RenderContext); - if (glXIsDirect(m_display, RenderContext)) { - EWOL_INFO("XF86 DRI enabled\n"); - } else { - EWOL_INFO("XF86 DRI NOT available\n"); - } - - // Enable vertical synchronisation : (some computer has synchronisation disable) - setVSync(true); - - return true; -} - -void X11_Init(void) -{ - X11_INFO("X11:INIT"); - if (m_doubleBuffered) { - glXSwapBuffers(m_display, WindowHandle); - XSync (m_display,0); - } - m_visual = NULL; - m_previousBouttonId = 0; - m_previousDown_x = -1; - m_previousDown_y = -1; - m_previous_x = -1; - m_previous_y = -1; - m_previousTime = 0; - m_previousDouble = false; - m_originX = 0; - m_originY = 0; - m_cursorEventX = 0; - m_cursorEventY = 0; - CreateX11Context(); - CreateOGlContext(); - // reset clipBoard - l_clipBoardRequestPrimary = false; - l_clipBoardOwnerPrimary = false; - l_clipBoardOwnerStd = false; - // reset the Atom properties ... - XAtomeSelection = XInternAtom(m_display, "PRIMARY", 0); - XAtomeClipBoard = XInternAtom(m_display, "CLIPBOARD", 0); - XAtomeTargetString = XInternAtom(m_display, "STRING", 0); - XAtomeTargetStringUTF8 = XInternAtom(m_display, "UTF8_STRING", 0); - XAtomeTargetTarget = XInternAtom(m_display, "TARGETS", 0); - XAtomeEWOL = XInternAtom(m_display, "EWOL", 0); - XAtomeDeleteWindows = XInternAtom(m_display, "WM_DELETE_WINDOW", 0); - - m_run = true; -} - - -void X11_Run(void) -{ - bool specialEventThatNeedARedraw = false; - // main cycle - while(true == m_run) { - //EWOL_ERROR("plop1"); - XEvent event; - XEvent respond; - // main X boucle : - while (XPending(m_display)) { - XNextEvent(m_display, &event); - switch (event.type) - { - case ClientMessage: - { - X11_INFO("Receive : ClientMessage"); - if(XAtomeDeleteWindows == (int64_t)event.xclient.data.l[0]) { - EWOL_INFO(" ==> Kill Requested ..."); - eSystem::OnKill(); - m_run = false; - } - } - break; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Selection AREA // - /////////////////////////////////////////////////////////////////////////////////////////////////////////////// - case SelectionClear: - // Selection has been done on an other program ==> clear ours ... - X11_INFO("X11 event SelectionClear"); - { - #ifdef DEBUG_X11_EVENT - { - XSelectionRequestEvent *req=&(event.xselectionrequest); - char * atomNameProperty = XGetAtomName(m_display, req->property); - char * atomNameTarget = XGetAtomName(m_display, req->target); - EWOL_INFO("X11 property: \"" << atomNameProperty << "\""); - EWOL_INFO("X11 target: \"" << atomNameTarget << "\""); - if (NULL != atomNameProperty) { XFree(atomNameProperty); } - if (NULL != atomNameTarget) { XFree(atomNameTarget); } - } - #endif - if (true == l_clipBoardOwnerPrimary) { - l_clipBoardOwnerPrimary = false; - } else if (true == l_clipBoardOwnerStd) { - l_clipBoardOwnerStd = false; - } else { - EWOL_ERROR("X11 event SelectionClear ==> but no selection requested anymore ..."); - } - } - break; - case SelectionNotify: - X11_INFO("X11 event SelectionNotify"); - if (event.xselection.property == None) { - EWOL_VERBOSE(" ==> no data ..."); - } else { - unsigned char *buf = 0; - Atom type; - int format; - unsigned long nitems, bytes; - XGetWindowProperty(m_display, - WindowHandle, - event.xselection.property, - 0, // offset - (~0L), // length - False, // delete - AnyPropertyType, // reg_type - &type,// *actual_type_return, - &format,// *actual_format_return - &nitems,// *nitems_return - &bytes, // *bytes_after_return - &buf// **prop_return); - ); - if (true == l_clipBoardRequestPrimary) { - etk::UString tmpppp((char*)buf); - ewol::clipBoard::SetSystem(ewol::clipBoard::clipboardSelection, tmpppp); - // just transmit an event , we have the data in the system - eSystem::ClipBoardArrive(ewol::clipBoard::clipboardSelection); - } else { - etk::UString tmpppp((char*)buf); - ewol::clipBoard::SetSystem(ewol::clipBoard::clipboardStd, tmpppp); - // just transmit an event , we have the data in the system - eSystem::ClipBoardArrive(ewol::clipBoard::clipboardStd); - } - } - break; - case SelectionRequest: - X11_INFO("X11 event SelectionRequest"); - { - XSelectionRequestEvent *req=&(event.xselectionrequest); - #ifdef DEBUG_X11_EVENT - { - char * atomNameProperty = XGetAtomName(m_display, req->property); - char * atomNameSelection = XGetAtomName(m_display, req->selection); - char * atomNameTarget = XGetAtomName(m_display, req->target); - EWOL_INFO(" from: " << atomNameProperty << " request=" << atomNameSelection << " in " << atomNameTarget); - if (NULL != atomNameProperty) { XFree(atomNameProperty); } - if (NULL != atomNameSelection) { XFree(atomNameSelection); } - if (NULL != atomNameTarget) { XFree(atomNameTarget); } - } - #endif - - etk::UString tmpData = ""; - if (req->selection == XAtomeSelection) { - tmpData = ewol::clipBoard::Get(ewol::clipBoard::clipboardSelection); - } else if (req->selection == XAtomeClipBoard) { - tmpData = ewol::clipBoard::Get(ewol::clipBoard::clipboardStd); - } - etk::Char tmpValueStoredTimeToSend = tmpData.c_str(); - const char * magatTextToSend = tmpValueStoredTimeToSend; - Atom listOfAtom[4]; - if(strlen(magatTextToSend) == 0 ) { - respond.xselection.property= None; - } else if(XAtomeTargetTarget == req->target) { - // We need to generate the list of the possibles target element of atom - int32_t nbAtomSupported = 0; - listOfAtom[nbAtomSupported++] = XAtomeTargetTarget; - listOfAtom[nbAtomSupported++] = XAtomeTargetString; - listOfAtom[nbAtomSupported++] = XAtomeTargetStringUTF8; - listOfAtom[nbAtomSupported++] = None; - XChangeProperty( m_display, - req->requestor, - req->property, - XA_ATOM, - 32, - PropModeReplace, - (unsigned char*)listOfAtom, - nbAtomSupported ); - respond.xselection.property=req->property; - EWOL_INFO(" ==> Respond ... (test)"); - } else if(XAtomeTargetString == req->target) { - XChangeProperty( m_display, - req->requestor, - req->property, - req->target, - 8, - PropModeReplace, - (unsigned char*)magatTextToSend, - strlen(magatTextToSend)); - respond.xselection.property=req->property; - EWOL_INFO(" ==> Respond ..."); - } else if (XAtomeTargetStringUTF8 == req->target) { - XChangeProperty( m_display, - req->requestor, - req->property, - req->target, - 8, - PropModeReplace, - (unsigned char*)magatTextToSend, - strlen(magatTextToSend)); - respond.xselection.property=req->property; - EWOL_INFO(" ==> Respond ..."); - } else { - respond.xselection.property= None; - } - respond.xselection.type= SelectionNotify; - respond.xselection.display= req->display; - respond.xselection.requestor= req->requestor; - respond.xselection.selection=req->selection; - respond.xselection.target= req->target; - respond.xselection.time = req->time; - XSendEvent (m_display, req->requestor,0,0,&respond); - // Flush the message on the pipe ... - XFlush (m_display); - } - break; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////// - case Expose: - X11_INFO("X11 event Expose"); - specialEventThatNeedARedraw=true; - break; - case GraphicsExpose: - X11_INFO("X11 event GraphicsExpose"); - specialEventThatNeedARedraw=true; - break; - case NoExpose: - X11_INFO("X11 event NoExpose"); - break; - case CreateNotify: - X11_INFO("X11 event CreateNotify"); - break; - case DestroyNotify: - X11_INFO("X11 event DestroyNotify"); - break; - case GravityNotify: - X11_INFO("X11 event GravityNotify"); - break; - case VisibilityNotify: - X11_INFO("X11 event VisibilityNotify"); - break; - case CirculateNotify: - X11_INFO("X11 event CirculateNotify"); - break; - case ReparentNotify: - X11_INFO("X11 event ReparentNotify"); - break; - case PropertyNotify: - specialEventThatNeedARedraw=true; - X11_INFO("X11 event PropertyNotify"); - break; - case ConfigureNotify: - specialEventThatNeedARedraw=true; - X11_INFO("X11 event ConfigureNotify"); - if (m_display == event.xconfigure.display) { - //EWOL_INFO("X11 event ConfigureNotify event=" << (int32_t)event.xconfigure.event << " Window=" << (int32_t)event.xconfigure.window << " above=" << (int32_t)event.xconfigure.above << " border_width=" << (int32_t)event.xconfigure.border_width ); - m_originX = event.xconfigure.x; - m_originY = event.xconfigure.y; - X11_INFO("X11 configure windows position : (" << m_originX << "," << m_originY << ")"); - m_currentHeight = event.xconfigure.height; - m_currentWidth = event.xconfigure.width; - X11_INFO("X11 configure windows size : (" << m_currentHeight << "," << m_currentWidth << ")"); - eSystem::Resize(event.xconfigure.width, event.xconfigure.height); - } - break; - case ButtonPress: - X11_INFO("X11 event ButtonPress"); - m_cursorEventX = event.xbutton.x; - m_cursorEventY = (m_currentHeight-event.xbutton.y); - if (event.xbutton.button < NB_MAX_INPUT) { - inputIsPressed[event.xbutton.button] = true; - } - eSystem::SetMouseState(event.xbutton.button, true, (float)event.xbutton.x, (float)m_cursorEventY); - break; - case ButtonRelease: - X11_INFO("X11 event ButtonRelease"); - m_cursorEventX = event.xbutton.x; - m_cursorEventY = (m_currentHeight-event.xbutton.y); - if (event.xbutton.button < NB_MAX_INPUT) { - inputIsPressed[event.xbutton.button] = false; - } - eSystem::SetMouseState(event.xbutton.button, false, (float)event.xbutton.x, (float)m_cursorEventY); - break; - case EnterNotify: - X11_INFO("X11 event EnterNotify"); - m_cursorEventX = event.xcrossing.x; - m_cursorEventY = (m_currentHeight-event.xcrossing.y); - //EWOL_DEBUG("X11 event : " << event.type << " = \"EnterNotify\" (" << (float)event.xcrossing.x << "," << (float)event.xcrossing.y << ")"); - //gui_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_ENTER, (float)event.xcrossing.x, (float)event.xcrossing.y); - m_curentGrabDelta -= vec2(m_originX, -m_originY); - EWOL_DEBUG("change grab delta of : " << vec2(m_originX, m_originY) ); - break; - case LeaveNotify: - X11_INFO("X11 event LeaveNotify"); - m_cursorEventX = event.xcrossing.x; - m_cursorEventY = (m_currentHeight-event.xcrossing.y); - //EWOL_DEBUG("X11 event : " << event.type << " = \"LeaveNotify\" (" << (float)event.xcrossing.x << "," << (float)event.xcrossing.y << ")"); - m_curentGrabDelta += vec2(m_originX, -m_originY); - EWOL_DEBUG("change grab delta of : " << vec2(m_originX, m_originY) ); - break; - case MotionNotify: - X11_INFO("X11 event MotionNotify"); - if( true==m_grabAllEvent - && event.xmotion.x == (int32_t)m_forcePos.x() - && event.xmotion.y == (int32_t)m_forcePos.y()) { - X11_VERBOSE("X11 reject mouse move (grab mode)"); - // we get our requested position... - m_positionChangeRequested = false; - m_curentGrabDelta = vec2(0,0); - } else { - m_cursorEventX = event.xmotion.x; - m_cursorEventY = (m_currentHeight-event.xmotion.y); - if(true==m_grabAllEvent) { - m_cursorEventX -= m_forcePos.x(); - m_cursorEventY -= (m_currentHeight-m_forcePos.y()); - } - vec2 newDelta = vec2(m_cursorEventX, m_cursorEventY); - if(true==m_grabAllEvent) { - m_cursorEventX -= m_curentGrabDelta.x(); - m_cursorEventY -= m_curentGrabDelta.y(); - } - m_curentGrabDelta = newDelta; - // For compatibility of the Android system : - bool findOne = false; - for (int32_t iii=0; iii0) { - // transform it in unicode - uniChar_t tmpChar = 0; - unicode::convertIsoToUnicode(unicode::EDN_CHARSET_ISO_8859_15, buf[0], tmpChar); - //EWOL_INFO("event Key : " << event.xkey.keycode << " char=\"" << buf << "\"'len=" << strlen(buf) << " unicode=" << unicodeValue); - eSystem::SetKeyboard(guiKeyBoardMode, tmpChar, (event.type==KeyPress), thisIsAReapeateKey); - if (true==thisIsAReapeateKey) { - eSystem::SetKeyboard(guiKeyBoardMode, tmpChar, !(event.type==KeyPress), thisIsAReapeateKey); - } - } else { - EWOL_WARNING("Unknow event Key : " << event.xkey.keycode); - } - } - break; - } - if (true == find) { - //EWOL_DEBUG("eventKey Move type : " << GetCharTypeMoveEvent(keyInput) ); - eSystem::SetKeyboardMove(guiKeyBoardMode, keyInput, (event.type==KeyPress), thisIsAReapeateKey); - if (true==thisIsAReapeateKey) { - eSystem::SetKeyboardMove(guiKeyBoardMode, keyInput, !(event.type==KeyPress), thisIsAReapeateKey); - } - } - } - } - break; - //case DestroyNotify: - // break; - case MapNotify: - X11_INFO("X11 event : MapNotify"); - specialEventThatNeedARedraw=true; - eSystem::Show(); - break; - case UnmapNotify: - X11_INFO("X11 event : UnmapNotify"); - specialEventThatNeedARedraw=true; - eSystem::Hide(); - break; - default: - X11_INFO("X11 event : " << event.type << " = \"???\""); - break; - } - } - if(true == m_run) { - if (m_doubleBuffered && hasDisplay) { - glXSwapBuffers(m_display, WindowHandle); - XSync(m_display,0); - } - // draw after switch the previous windows ... - //EWOL_DEBUG("specialEventThatNeedARedraw"< #undef __class__ -#define __class__ "guiInterface" +#define __class__ "x11Interface" - -void guiInterface::Stop(void) +class X11Interface : public ewol::eSystem { - X11_INFO("X11-API: Stop"); - m_run = false; -} - -void guiInterface::KeyboardShow(void) -{ - // nothing to do : No keyboard on computer ... -} - - -void guiInterface::KeyboardHide(void) -{ - // nothing to do : No keyboard on computer ... -} - - -void guiInterface::ChangeSize(ivec2 size) -{ - X11_INFO("X11-API: ChangeSize=" << size); - m_currentHeight = size.y(); - m_currentWidth = size.x(); - XResizeWindow(m_display, WindowHandle, size.x(), size.y()); -} - - -void guiInterface::ChangePos(ivec2 pos) -{ - X11_INFO("X11-API: ChangePos=" << pos); - XMoveWindow(m_display, WindowHandle, pos.x(), pos.y()); - m_originX = pos.x(); - m_originY = pos.y(); -} - - -void guiInterface::GetAbsPos(ivec2& pos) -{ - X11_INFO("X11-API: GetAbsPos"); - int tmp; - unsigned int tmp2; - Window fromroot, tmpwin; - XQueryPointer(m_display, WindowHandle, &fromroot, &tmpwin, &pos.m_floats[0], &pos.m_floats[1], &tmp, &tmp, &tmp2); -} - -#include -// select the current cursor to display : -static ewol::cursorDisplay_te l_currentCursor = ewol::cursorArrow; - -void guiInterface::SetCursor(ewol::cursorDisplay_te newCursor) -{ - if (newCursor != l_currentCursor) { - X11_DEBUG("X11-API: Set New Cursor : " << newCursor); - // undefine previous cursors ... - XUndefineCursor(m_display, WindowHandle); - // set the new one : - l_currentCursor = newCursor; - Cursor myCursor = None; - switch (l_currentCursor) { - case ewol::cursorNone: - { - Pixmap bitmapNoData; - XColor black; - static char noData[] = { 0,0,0,0,0,0,0,0 }; - black.red = 0; - black.green = 0; - black.blue = 0; - bitmapNoData = XCreateBitmapFromData(m_display, WindowHandle, noData, 8, 8); - myCursor = XCreatePixmapCursor(m_display, bitmapNoData, bitmapNoData, - &black, &black, 0, 0); - } - break; - case ewol::cursorLeftArrow: - myCursor = XCreateFontCursor(m_display, XC_top_left_arrow); - break; - case ewol::cursorInfo: - myCursor = XCreateFontCursor(m_display, XC_hand1); - break; - case ewol::cursorDestroy: - myCursor = XCreateFontCursor(m_display, XC_pirate); - break; - case ewol::cursorHelp: - myCursor = XCreateFontCursor(m_display, XC_question_arrow); - break; - case ewol::cursorCycle: - myCursor = XCreateFontCursor(m_display, XC_exchange); - break; - case ewol::cursorSpray: - myCursor = XCreateFontCursor(m_display, XC_spraycan); - break; - case ewol::cursorWait: - myCursor = XCreateFontCursor(m_display, XC_watch); - break; - case ewol::cursorText: - myCursor = XCreateFontCursor(m_display, XC_xterm); - break; - case ewol::cursorCrossHair: - myCursor = XCreateFontCursor(m_display, XC_crosshair); - break; - case ewol::cursorSlideUpDown: - myCursor = XCreateFontCursor(m_display, XC_sb_v_double_arrow); - break; - case ewol::cursorSlideLeftRight: - myCursor = XCreateFontCursor(m_display, XC_sb_h_double_arrow); - break; - case ewol::cursorResizeUp: - myCursor = XCreateFontCursor(m_display, XC_top_side); - break; - case ewol::cursorResizeDown: - myCursor = XCreateFontCursor(m_display, XC_bottom_side); - break; - case ewol::cursorResizeLeft: - myCursor = XCreateFontCursor(m_display, XC_left_side); - break; - case ewol::cursorResizeRight: - myCursor = XCreateFontCursor(m_display, XC_right_side); - break; - case ewol::cursorCornerTopLeft: - myCursor = XCreateFontCursor(m_display, XC_top_left_corner); - break; - case ewol::cursorCornerTopRight: - myCursor = XCreateFontCursor(m_display, XC_top_right_corner); - break; - case ewol::cursorCornerButtomLeft: - myCursor = XCreateFontCursor(m_display, XC_bottom_right_corner); - break; - case ewol::cursorCornerButtomRight: - myCursor = XCreateFontCursor(m_display, XC_bottom_left_corner); - break; - default : - // nothing to do ... basic pointer ... - break; - } - if (myCursor != None) { - XDefineCursor(m_display,WindowHandle, myCursor); - XFreeCursor(m_display, myCursor); - } - } -} - -void guiInterface::GrabPointerEvents(bool isGrabbed, vec2 forcedPosition) -{ - if (true == isGrabbed) { - X11_DEBUG("X11-API: Grab Events"); - int32_t test = XGrabPointer(m_display,RootWindow(m_display, DefaultScreen(m_display)), True, - ButtonPressMask | - ButtonReleaseMask | - PointerMotionMask | - FocusChangeMask | - EnterWindowMask | - LeaveWindowMask, - GrabModeAsync, - GrabModeAsync, - RootWindow(m_display, DefaultScreen(m_display)), - None, - CurrentTime); - - if (GrabSuccess != test) + private: + ewol::SpecialKey m_guiKeyBoardMode; + // for double and triple click selection, we need to save the previous click up and down position , and the previous time ... + Atom m_delAtom; + Display* m_display; + Window m_WindowHandle; + int32_t m_originX; + int32_t m_originY; + int32_t m_cursorEventX; + int32_t m_cursorEventY; + int32_t m_currentHeight; + int32_t m_currentWidth; + XVisualInfo* m_visual; + bool m_doubleBuffered; + bool m_run; + //forcing the position + bool m_grabAllEvent; //!< grab mode enable... + vec2 m_forcePos; //!< position to reset the cursor + bool m_positionChangeRequested; //!< the position modifiquation has been requested + vec2 m_curentGrabDelta; //!< the position in X11 will arrive by pool + bool m_inputIsPressed[MAX_MANAGE_INPUT]; + // internal copy of the clipBoard ... + bool m_clipBoardRequestPrimary; //!< if false : request the copy/past buffer, if true : request current selection + bool m_clipBoardOwnerPrimary; //!< we are the owner of the current selection + bool m_clipBoardOwnerStd; //!< we are the owner of the current copy buffer + // Atom access... + Atom XAtomeSelection; + Atom XAtomeClipBoard; + Atom XAtomeTargetString; + Atom XAtomeTargetStringUTF8; + Atom XAtomeTargetTarget; + Atom XAtomeEWOL; + Atom XAtomeDeleteWindows; + ewol::cursorDisplay_te m_currentCursor; //!< select the current cursor to display : + public: + X11Interface(void) : + m_display(NULL), + m_originX(0), + m_originY(0), + m_cursorEventX(0), + m_cursorEventY(0), + m_currentHeight(0), + m_currentWidth(0), + m_visual(NULL), + m_doubleBuffered(0), + m_run(false), + m_grabAllEvent(false), + m_forcePos(0,0), + m_positionChangeRequested(false), + m_curentGrabDelta(0,0), + m_clipBoardRequestPrimary(false), + m_clipBoardOwnerPrimary(false), + m_clipBoardOwnerStd(false), + XAtomeSelection(0), + XAtomeClipBoard(0), + XAtomeTargetString(0), + XAtomeTargetStringUTF8(0), + XAtomeTargetTarget(0), + XAtomeEWOL(0), + XAtomeDeleteWindows(0), + m_currentCursor(ewol::cursorArrow) { - EWOL_CRITICAL("Display error " << test); - switch (test) + X11_INFO("X11:INIT"); + for (int32_t iii=0; iii Kill Requested ..."); + eSystem::OS_Stop(); + m_run = false; + } + } + break; + /////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Selection AREA // + /////////////////////////////////////////////////////////////////////////////////////////////////////////////// + case SelectionClear: + // Selection has been done on an other program ==> clear ours ... + X11_INFO("X11 event SelectionClear"); + { + #ifdef DEBUG_X11_EVENT + { + XSelectionRequestEvent *req=&(event.xselectionrequest); + char * atomNameProperty = XGetAtomName(m_display, req->property); + char * atomNameTarget = XGetAtomName(m_display, req->target); + EWOL_INFO("X11 property: \"" << atomNameProperty << "\""); + EWOL_INFO("X11 target: \"" << atomNameTarget << "\""); + if (NULL != atomNameProperty) { XFree(atomNameProperty); } + if (NULL != atomNameTarget) { XFree(atomNameTarget); } + } + #endif + if (true == m_clipBoardOwnerPrimary) { + m_clipBoardOwnerPrimary = false; + } else if (true == m_clipBoardOwnerStd) { + m_clipBoardOwnerStd = false; + } else { + EWOL_ERROR("X11 event SelectionClear ==> but no selection requested anymore ..."); + } + } + break; + case SelectionNotify: + X11_INFO("X11 event SelectionNotify"); + if (event.xselection.property == None) { + EWOL_VERBOSE(" ==> no data ..."); + } else { + unsigned char *buf = 0; + Atom type; + int format; + unsigned long nitems, bytes; + XGetWindowProperty(m_display, + m_WindowHandle, + event.xselection.property, + 0, // offset + (~0L), // length + False, // delete + AnyPropertyType, // reg_type + &type,// *actual_type_return, + &format,// *actual_format_return + &nitems,// *nitems_return + &bytes, // *bytes_after_return + &buf// **prop_return); + ); + if (true == m_clipBoardRequestPrimary) { + etk::UString tmpppp((char*)buf); + ewol::clipBoard::SetSystem(ewol::clipBoard::clipboardSelection, tmpppp); + // just transmit an event , we have the data in the system + OS_ClipBoardArrive(ewol::clipBoard::clipboardSelection); + } else { + etk::UString tmpppp((char*)buf); + ewol::clipBoard::SetSystem(ewol::clipBoard::clipboardStd, tmpppp); + // just transmit an event , we have the data in the system + OS_ClipBoardArrive(ewol::clipBoard::clipboardStd); + } + } + break; + case SelectionRequest: + X11_INFO("X11 event SelectionRequest"); + { + XSelectionRequestEvent *req=&(event.xselectionrequest); + #ifdef DEBUG_X11_EVENT + { + char * atomNameProperty = XGetAtomName(m_display, req->property); + char * atomNameSelection = XGetAtomName(m_display, req->selection); + char * atomNameTarget = XGetAtomName(m_display, req->target); + EWOL_INFO(" from: " << atomNameProperty << " request=" << atomNameSelection << " in " << atomNameTarget); + if (NULL != atomNameProperty) { XFree(atomNameProperty); } + if (NULL != atomNameSelection) { XFree(atomNameSelection); } + if (NULL != atomNameTarget) { XFree(atomNameTarget); } + } + #endif + + etk::UString tmpData = ""; + if (req->selection == XAtomeSelection) { + tmpData = ewol::clipBoard::Get(ewol::clipBoard::clipboardSelection); + } else if (req->selection == XAtomeClipBoard) { + tmpData = ewol::clipBoard::Get(ewol::clipBoard::clipboardStd); + } + etk::Char tmpValueStoredTimeToSend = tmpData.c_str(); + const char * magatTextToSend = tmpValueStoredTimeToSend; + Atom listOfAtom[4]; + if(strlen(magatTextToSend) == 0 ) { + respond.xselection.property= None; + } else if(XAtomeTargetTarget == req->target) { + // We need to generate the list of the possibles target element of atom + int32_t nbAtomSupported = 0; + listOfAtom[nbAtomSupported++] = XAtomeTargetTarget; + listOfAtom[nbAtomSupported++] = XAtomeTargetString; + listOfAtom[nbAtomSupported++] = XAtomeTargetStringUTF8; + listOfAtom[nbAtomSupported++] = None; + XChangeProperty( m_display, + req->requestor, + req->property, + XA_ATOM, + 32, + PropModeReplace, + (unsigned char*)listOfAtom, + nbAtomSupported ); + respond.xselection.property=req->property; + EWOL_INFO(" ==> Respond ... (test)"); + } else if(XAtomeTargetString == req->target) { + XChangeProperty( m_display, + req->requestor, + req->property, + req->target, + 8, + PropModeReplace, + (unsigned char*)magatTextToSend, + strlen(magatTextToSend)); + respond.xselection.property=req->property; + EWOL_INFO(" ==> Respond ..."); + } else if (XAtomeTargetStringUTF8 == req->target) { + XChangeProperty( m_display, + req->requestor, + req->property, + req->target, + 8, + PropModeReplace, + (unsigned char*)magatTextToSend, + strlen(magatTextToSend)); + respond.xselection.property=req->property; + EWOL_INFO(" ==> Respond ..."); + } else { + respond.xselection.property= None; + } + respond.xselection.type= SelectionNotify; + respond.xselection.display= req->display; + respond.xselection.requestor= req->requestor; + respond.xselection.selection=req->selection; + respond.xselection.target= req->target; + respond.xselection.time = req->time; + XSendEvent (m_display, req->requestor,0,0,&respond); + // Flush the message on the pipe ... + XFlush (m_display); + } + break; + /////////////////////////////////////////////////////////////////////////////////////////////////////////////// + case Expose: + X11_INFO("X11 event Expose"); + specialEventThatNeedARedraw=true; + break; + case GraphicsExpose: + X11_INFO("X11 event GraphicsExpose"); + specialEventThatNeedARedraw=true; + break; + case NoExpose: + X11_INFO("X11 event NoExpose"); + break; + case CreateNotify: + X11_INFO("X11 event CreateNotify"); + break; + case DestroyNotify: + X11_INFO("X11 event DestroyNotify"); + break; + case GravityNotify: + X11_INFO("X11 event GravityNotify"); + break; + case VisibilityNotify: + X11_INFO("X11 event VisibilityNotify"); + break; + case CirculateNotify: + X11_INFO("X11 event CirculateNotify"); + break; + case ReparentNotify: + X11_INFO("X11 event ReparentNotify"); + break; + case PropertyNotify: + specialEventThatNeedARedraw=true; + X11_INFO("X11 event PropertyNotify"); + break; + case ConfigureNotify: + specialEventThatNeedARedraw=true; + X11_INFO("X11 event ConfigureNotify"); + if (m_display == event.xconfigure.display) { + //EWOL_INFO("X11 event ConfigureNotify event=" << (int32_t)event.xconfigure.event << " Window=" << (int32_t)event.xconfigure.window << " above=" << (int32_t)event.xconfigure.above << " border_width=" << (int32_t)event.xconfigure.border_width ); + m_originX = event.xconfigure.x; + m_originY = event.xconfigure.y; + X11_INFO("X11 configure windows position : (" << m_originX << "," << m_originY << ")"); + m_currentHeight = event.xconfigure.height; + m_currentWidth = event.xconfigure.width; + X11_INFO("X11 configure windows size : (" << m_currentHeight << "," << m_currentWidth << ")"); + OS_Resize(vec2(event.xconfigure.width, event.xconfigure.height)); + } + break; + case ButtonPress: + X11_INFO("X11 event ButtonPress"); + m_cursorEventX = event.xbutton.x; + m_cursorEventY = (m_currentHeight-event.xbutton.y); + if (event.xbutton.button < MAX_MANAGE_INPUT) { + m_inputIsPressed[event.xbutton.button] = true; + } + OS_SetMouseState(event.xbutton.button, true, vec2(event.xbutton.x, m_cursorEventY)); + break; + case ButtonRelease: + X11_INFO("X11 event ButtonRelease"); + m_cursorEventX = event.xbutton.x; + m_cursorEventY = (m_currentHeight-event.xbutton.y); + if (event.xbutton.button < MAX_MANAGE_INPUT) { + m_inputIsPressed[event.xbutton.button] = false; + } + OS_SetMouseState(event.xbutton.button, false, vec2(event.xbutton.x, m_cursorEventY)); + break; + case EnterNotify: + X11_INFO("X11 event EnterNotify"); + m_cursorEventX = event.xcrossing.x; + m_cursorEventY = (m_currentHeight-event.xcrossing.y); + //EWOL_DEBUG("X11 event : " << event.type << " = \"EnterNotify\" (" << (float)event.xcrossing.x << "," << (float)event.xcrossing.y << ")"); + //gui_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_ENTER, (float)event.xcrossing.x, (float)event.xcrossing.y); + m_curentGrabDelta -= vec2(m_originX, -m_originY); + EWOL_DEBUG("change grab delta of : " << vec2(m_originX, m_originY) ); + break; + case LeaveNotify: + X11_INFO("X11 event LeaveNotify"); + m_cursorEventX = event.xcrossing.x; + m_cursorEventY = (m_currentHeight-event.xcrossing.y); + //EWOL_DEBUG("X11 event : " << event.type << " = \"LeaveNotify\" (" << (float)event.xcrossing.x << "," << (float)event.xcrossing.y << ")"); + m_curentGrabDelta += vec2(m_originX, -m_originY); + EWOL_DEBUG("change grab delta of : " << vec2(m_originX, m_originY) ); + break; + case MotionNotify: + X11_INFO("X11 event MotionNotify"); + if( true==m_grabAllEvent + && event.xmotion.x == (int32_t)m_forcePos.x() + && event.xmotion.y == (int32_t)m_forcePos.y()) { + X11_VERBOSE("X11 reject mouse move (grab mode)"); + // we get our requested position... + m_positionChangeRequested = false; + m_curentGrabDelta = vec2(0,0); + } else { + m_cursorEventX = event.xmotion.x; + m_cursorEventY = (m_currentHeight-event.xmotion.y); + if(true==m_grabAllEvent) { + m_cursorEventX -= m_forcePos.x(); + m_cursorEventY -= (m_currentHeight-m_forcePos.y()); + } + vec2 newDelta = vec2(m_cursorEventX, m_cursorEventY); + if(true==m_grabAllEvent) { + m_cursorEventX -= m_curentGrabDelta.x(); + m_cursorEventY -= m_curentGrabDelta.y(); + } + m_curentGrabDelta = newDelta; + // For compatibility of the Android system : + bool findOne = false; + for (int32_t iii=0; iii0) { + // transform it in unicode + uniChar_t tmpChar = 0; + unicode::convertIsoToUnicode(unicode::EDN_CHARSET_ISO_8859_15, buf[0], tmpChar); + //EWOL_INFO("event Key : " << event.xkey.keycode << " char=\"" << buf << "\"'len=" << strlen(buf) << " unicode=" << unicodeValue); + OS_SetKeyboard(m_guiKeyBoardMode, tmpChar, (event.type==KeyPress), thisIsAReapeateKey); + if (true==thisIsAReapeateKey) { + OS_SetKeyboard(m_guiKeyBoardMode, tmpChar, !(event.type==KeyPress), thisIsAReapeateKey); + } + } else { + EWOL_WARNING("Unknow event Key : " << event.xkey.keycode); + } + } + break; + } + if (true == find) { + //EWOL_DEBUG("eventKey Move type : " << GetCharTypeMoveEvent(keyInput) ); + OS_SetKeyboardMove(m_guiKeyBoardMode, keyInput, (event.type==KeyPress), thisIsAReapeateKey); + if (true==thisIsAReapeateKey) { + OS_SetKeyboardMove(m_guiKeyBoardMode, keyInput, !(event.type==KeyPress), thisIsAReapeateKey); + } + } + } + } + break; + //case DestroyNotify: + // break; + case MapNotify: + X11_INFO("X11 event : MapNotify"); + specialEventThatNeedARedraw=true; + OS_Show(); + break; + case UnmapNotify: + X11_INFO("X11 event : UnmapNotify"); + specialEventThatNeedARedraw=true; + OS_Hide(); + break; + default: + X11_INFO("X11 event : " << event.type << " = \"???\""); + break; + } + } + if(true == m_run) { + if (m_doubleBuffered && hasDisplay) { + glXSwapBuffers(m_display, m_WindowHandle); + XSync(m_display,0); + } + // draw after switch the previous windows ... + //EWOL_DEBUG("specialEventThatNeedARedraw"<visual, AllocNone); + + attr.border_pixel = 0; + attr.event_mask = StructureNotifyMask + | SubstructureNotifyMask + | EnterWindowMask + | LeaveWindowMask + | ExposureMask + | ButtonPressMask + | ButtonReleaseMask + | OwnerGrabButtonMask + | KeyPressMask + | KeyReleaseMask + | PointerMotionMask + | FocusChangeMask + | SubstructureRedirectMask; + + // set no background at the gui + attr.background_pixmap = None; + + // select internal attribute + attr_mask = CWBackPixmap | CWColormap | CWBorderPixel | CWEventMask; + // Create the window + int32_t tmp_width = 640;//DisplayWidth(m_display, DefaultScreen(m_display))/2; + int32_t tmp_height = 480;//DisplayHeight(m_display, DefaultScreen(m_display))/2; + OS_Resize(vec2(tmp_width, tmp_height)); + x=20; + y=20; + m_originX = x; + m_originY = y; + EWOL_INFO("X11 request creating windows at pos=(" << m_originX << "," << m_originY << ") size=(" << tmp_width << "," << tmp_height << ")" ); + // Real create of the window + m_WindowHandle = XCreateWindow(m_display, + Xroot, + x, y, tmp_width, tmp_height, + 1, + m_visual->depth, + InputOutput, + m_visual->visual, + attr_mask, &attr); + + if( !m_WindowHandle ) { + EWOL_CRITICAL("Couldn't create the window"); + exit(-1); + } + + /* Configure it... (ok, ok, this next bit isn't "minimal") */ + textprop.value = (unsigned char*)title; + textprop.encoding = XA_STRING; + textprop.format = 8; + textprop.nitems = strlen(title); + + hints.x = x; + hints.y = y; + hints.width = tmp_width; + hints.height = tmp_height; + hints.flags = USPosition|USSize; + + StartupState = XAllocWMHints(); + StartupState->initial_state = NormalState; + StartupState->flags = StateHint; + + XSetWMProperties(m_display, m_WindowHandle,&textprop, &textprop,/* Window title/icon title*/ + NULL, 0,/* Argv[], argc for program*/ + &hints, /* Start position/size*/ + StartupState,/* Iconised/not flag */ + NULL); + + XFree(StartupState); + + /* Open it, wait for it to appear */ + XMapWindow(m_display, m_WindowHandle); + //XIfEvent(m_display, &event, WaitForMapNotify, (char*)&m_WindowHandle); + + // Set the kill atom so we get a message when the user tries to close the window + if ((m_delAtom = XInternAtom(m_display, "WM_DELETE_WINDOW", 0)) != None) { + XSetWMProtocols(m_display, m_WindowHandle, &m_delAtom, 1); + } + + vec2 tmpSize(400, 300); + OS_Resize(tmpSize); + + return true; + } + /****************************************************************************************/ + void SetIcon(const etk::UString& _inputFile) + { + egami::Image dataImage; + // load data + if (false == egami::Load(dataImage, _inputFile)) { + EWOL_ERROR("Error when loading Icon"); + return; + } + int32_t depth = DefaultDepth(m_display, DefaultScreen(m_display) ); + EWOL_DEBUG("X11 Create icon Size=(" << dataImage.GetWidth() << "," << dataImage.GetHeight() << ") depth=" << depth); + switch(depth) { + case 8: + EWOL_CRITICAL("Not manage pixmap in 8 bit... ==> no icon ..."); + return; + case 16: + break; + case 24: + break; + case 32: + break; + default: + EWOL_CRITICAL("Unknow thys type of bitDepth : " << depth); + return; + } + char* tmpVal = new char[4*dataImage.GetWidth()*dataImage.GetHeight()]; + if (NULL == tmpVal) { + EWOL_CRITICAL("Allocation error ..."); + return; + } + char* tmpPointer = tmpVal; + switch(depth) { + case 16: + for(ivec2 pos(0,0); pos.y() tmpColor = dataImage.Get(pos); + int16_t tmpVal = (((uint16_t)((uint16_t)tmpColor.r()>>3))<<11) + + (((uint16_t)((uint16_t)tmpColor.g()>>2))<<5) + + ((uint16_t)((uint16_t)tmpColor.b()>>3)); + *tmpPointer++ = (uint8_t)(tmpVal>>8); + *tmpPointer++ = (uint8_t)(tmpVal&0x00FF); + } + } + break; + case 24: + for(ivec2 pos(0,0); pos.y() tmpColor = dataImage.Get(pos); + *tmpPointer++ = tmpColor.b(); + *tmpPointer++ = tmpColor.g(); + *tmpPointer++ = tmpColor.r(); + tmpPointer++; + } + } + break; + case 32: + for(ivec2 pos(0,0); pos.y() tmpColor = dataImage.Get(pos); + *tmpPointer++ = tmpColor.a(); + *tmpPointer++ = tmpColor.b(); + *tmpPointer++ = tmpColor.g(); + *tmpPointer++ = tmpColor.r(); + } + } + break; + default: + return; + } + + XImage* myImage = XCreateImage(m_display, + m_visual->visual, + depth, + ZPixmap, + 0, + (char*)tmpVal, + dataImage.GetWidth(), + dataImage.GetHeight(), + 32, + 0); + + Pixmap tmpPixmap = XCreatePixmap(m_display, m_WindowHandle, dataImage.GetWidth(), dataImage.GetHeight(), depth); + switch(tmpPixmap) { + case BadAlloc: + EWOL_ERROR("X11: BadAlloc"); + break; + case BadDrawable: + EWOL_ERROR("X11: BadDrawable"); break; case BadValue: - EWOL_CRITICAL(" BadValue"); + EWOL_ERROR("X11: BadValue"); break; - case BadWindow: - EWOL_CRITICAL(" BadWindow"); + default: + EWOL_DEBUG("Create Pixmap OK"); + break; + } + GC tmpGC = DefaultGC(m_display, DefaultScreen(m_display) ); + int error = XPutImage(m_display, tmpPixmap, tmpGC, myImage, 0, 0, 0, 0, dataImage.GetWidth(), dataImage.GetHeight()); + switch(error) { + case BadDrawable: + EWOL_ERROR("X11: BadDrawable"); + break; + case BadGC: + EWOL_ERROR("X11: BadGC"); + break; + case BadMatch: + EWOL_ERROR("X11: BadMatch"); + break; + case BadValue: + EWOL_ERROR("X11: BadValue"); + break; + default: + EWOL_DEBUG("insert image OK"); + break; + } + // allocate a WM hints structure. + XWMHints* win_hints = XAllocWMHints(); + if (!win_hints) { + EWOL_ERROR("XAllocWMHints - out of memory"); + return; + } + // initialize the structure appropriately. first, specify which size hints we want to fill in. in our case - setting the icon's pixmap. + win_hints->flags = IconPixmapHint; + // next, specify the desired hints data. in our case - supply the icon's desired pixmap. + win_hints->icon_pixmap = tmpPixmap; + // pass the hints to the window manager. + XSetWMHints(m_display, m_WindowHandle, win_hints); + EWOL_INFO(" ==> might be done "); + // finally, we can free the WM hints structure. + XFree(win_hints); + + // Note when we free the pixmap ... the icon is removed ... ==> this is a real memory leek ... + //XFreePixmap(m_display, tmpPixmap); + + myImage->data = NULL; + XDestroyImage(myImage); + delete[] tmpVal; + + } + /****************************************************************************************/ + static void setVSync(bool _sync) + { + // Function pointer for the wgl extention function we need to enable/disable + typedef int32_t (APIENTRY *PFNWGLSWAPINTERVALPROC)( int ); + PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0; + const char *extensions = (char*)glGetString( GL_EXTENSIONS ); + if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 ) { + EWOL_ERROR("Can not set the vertical synchronisation status" << _sync << " (1)"); + return; + } else { + wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glXGetProcAddress( (const GLubyte *)"wglSwapIntervalEXT" ); + if(wglSwapIntervalEXT) { + wglSwapIntervalEXT(_sync); + } else { + EWOL_ERROR("Can not set the vertical synchronisation status" << _sync << " (2)"); + } + } + } + /****************************************************************************************/ + bool CreateOGlContext(void) + { + X11_INFO("X11:CreateOGlContext"); + /* create a GLX context */ + GLXContext RenderContext = glXCreateContext(m_display, m_visual, 0, GL_TRUE); + /* connect the glx-context to the window */ + glXMakeCurrent(m_display, m_WindowHandle, RenderContext); + if (glXIsDirect(m_display, RenderContext)) { + EWOL_INFO("XF86 DRI enabled\n"); + } else { + EWOL_INFO("XF86 DRI NOT available\n"); + } + + // Enable vertical synchronisation : (some computer has synchronisation disable) + setVSync(true); + + return true; + } + /****************************************************************************************/ + void SetTitle(etk::UString& title) + { + X11_INFO("X11: Set Title (START)"); + XTextProperty tp; + etk::Char tmpChar = title.c_str(); + tp.value = (unsigned char *)((const char*)tmpChar); + tp.encoding = XA_WM_NAME; + tp.format = 8; + tp.nitems = strlen((const char*)tp.value); + XSetWMName(m_display, m_WindowHandle, &tp); + XStoreName(m_display, m_WindowHandle, (const char*)tp.value); + XSetIconName(m_display, m_WindowHandle, (const char*)tp.value); + XSetWMIconName(m_display, m_WindowHandle, &tp); + X11_INFO("X11: Set Title (END)"); + } + /****************************************************************************************/ + void ClipBoardGet(ewol::clipBoard::clipboardListe_te _clipboardID) + { + switch (_clipboardID) + { + case ewol::clipBoard::clipboardSelection: + if (false == m_clipBoardOwnerPrimary) { + m_clipBoardRequestPrimary = true; + // Generate a request on X11 + XConvertSelection(m_display, + XAtomeSelection, + XAtomeTargetStringUTF8, + XAtomeEWOL, + m_WindowHandle, + CurrentTime); + } else { + // just transmit an event , we have the data in the system + OS_ClipBoardArrive(_clipboardID); + } + break; + case ewol::clipBoard::clipboardStd: + if (false == m_clipBoardOwnerStd) { + m_clipBoardRequestPrimary = false; + // Generate a request on X11 + XConvertSelection(m_display, + XAtomeClipBoard, + XAtomeTargetStringUTF8, + XAtomeEWOL, + m_WindowHandle, + CurrentTime); + } else { + // just transmit an event , we have the data in the system + OS_ClipBoardArrive(_clipboardID); + } + break; + default: + EWOL_ERROR("Request an unknow ClipBoard ..."); break; } } - m_forcePos = forcedPosition; - m_forcePos.setY(m_currentHeight - m_forcePos.y()); - m_grabAllEvent = true; - // change the pointer position to generate a good mouving at the start ... - X11_DEBUG("X11-API: Set pointer position : " << m_forcePos); - XWarpPointer(m_display, None, WindowHandle, 0,0, 0, 0, m_forcePos.x(), m_forcePos.y()); - XFlush(m_display); - m_positionChangeRequested = true; - m_curentGrabDelta = vec2(0,0); - } else { - X11_DEBUG("X11-API: Un-Grab Events"); - XUngrabPointer(m_display, CurrentTime); - m_grabAllEvent = false; - m_forcePos = vec2(0,0); - m_curentGrabDelta = vec2(0,0); - } -} + /****************************************************************************************/ + void ClipBoardSet(ewol::clipBoard::clipboardListe_te _clipboardID) + { + switch (_clipboardID) + { + case ewol::clipBoard::clipboardSelection: + // Request the selection : + if (false == m_clipBoardOwnerPrimary) { + XSetSelectionOwner(m_display, XAtomeSelection, m_WindowHandle, CurrentTime); + m_clipBoardOwnerPrimary = true; + } + break; + case ewol::clipBoard::clipboardStd: + // Request the clipBoard : + if (false == m_clipBoardOwnerStd) { + XSetSelectionOwner(m_display, XAtomeClipBoard, m_WindowHandle, CurrentTime); + m_clipBoardOwnerStd = true; + } + break; + default: + EWOL_ERROR("Request an unknow ClipBoard ..."); + break; + } + } +}; /** @@ -1345,28 +1284,15 @@ void guiInterface::GrabPointerEvents(bool isGrabbed, vec2 forcedPosition) * @param std IO * @return std IO */ -int guiInterface::main(int argc, const char *argv[]) +int ewol::eSystem::main(int _argc, const char *_argv[]) { - - for (int32_t iii=0; iiiRun(); + delete(interface); + interface = NULL; + return retValue; } diff --git a/sources/ewol/renderer/os/gui.h b/sources/ewol/renderer/os/gui.h index bede4935..e69de29b 100644 --- a/sources/ewol/renderer/os/gui.h +++ b/sources/ewol/renderer/os/gui.h @@ -1,99 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license BSD v3 (see license file) - */ - -#ifndef __GUI_INTERFACE_H__ -#define __GUI_INTERFACE_H__ - -#include -#include -#include -#include -#include -#include - - -namespace guiInterface -{ - int main(int argc, const char *argv[]); - /** - * @brief Get the curent time in micro-second - */ - int64_t GetTime(void); - /** - * @brief Stop the current program - */ - void Stop(void); - /** - * @brief Change the current Windows size - * @param size The requested size - */ - void ChangeSize(ivec2 size); - /** - * @brief Change the current Windows position - * @param pos The position where the winsdows might be placed. - */ - void ChangePos(ivec2 pos); - /** - * @brief Get the current Windows position - * @param pos The position where the winsdows is. - */ - void GetAbsPos(ivec2& pos); - /** - * @brief Display the virtal keyboard (for touch system only) - */ - void KeyboardShow(void); - /** - * @brief Hide the virtal keyboard (for touch system only) - */ - void KeyboardHide(void); - /** - * @brief Inform the Gui that we want to have a copy of the clipboard - * @param ID of the clipboard (STD/SELECTION) only apear here - */ - void ClipBoardGet(ewol::clipBoard::clipboardListe_te clipboardID); - /** - * @brief Inform the Gui that we are the new owner of the clipboard - * @param ID of the clipboard (STD/SELECTION) only apear here - */ - void ClipBoardSet(ewol::clipBoard::clipboardListe_te clipboardID); - /** - * @brief Set the new title of the windows - * @param title New desired title - */ - void SetTitle(etk::UString& title); - /** - * @brief Force the screen orientation (availlable on portable elements ... - * @param orientation Selected orientation. - */ - void ForceOrientation(ewol::orientation_te orientation); - /** - * @brief Get all the event from the X system - * @param[in] isGrabbed "true" if all the event will be get, false if we want only ours. - * @param[in] forcedPosition the position where the mouse might be reset at every events ... - */ - void GrabPointerEvents(bool isGrabbed, vec2 forcedPosition); - /** - * @brief Set the cursor display type. - * @param[in] newCursor selected new cursor. - */ - void SetCursor(ewol::cursorDisplay_te newCursor); - /** - * @brief Set the Icon of the program - * @param[in] inputFile new filename icon of the curent program. - */ - void SetIcon(etk::UString inputFile); -}; - - -//!< must be define in CPP by the application ... this are the main init and unInit of the Application -void APP_Init(void); -void APP_UnInit(void); - -#define NB_MAX_INPUT (20) - -#endif diff --git a/sources/lutin_ewol.py b/sources/lutin_ewol.py index a54f9ea5..c9467762 100755 --- a/sources/lutin_ewol.py +++ b/sources/lutin_ewol.py @@ -42,7 +42,7 @@ def Create(target): myModule.AddSrcFile([ 'ewol/renderer/os/eSystem.cpp', 'ewol/renderer/os/eSystemInput.cpp']) - + """ # renderer : myModule.AddSrcFile([ 'ewol/renderer/resources/Shader.cpp', @@ -121,7 +121,7 @@ def Create(target): myModule.AddSrcFile([ 'ewol/widget/Scene.cpp', 'ewol/game/Camera.cpp']) - + """ myModule.CopyFolder('../data/theme/default/widgetEntry.*','theme/default') myModule.CopyFolder('../data/theme/rounded/widgetEntry.*','theme/rounded') @@ -140,15 +140,9 @@ def Create(target): myModule.CopyFolder('../data/textured3D2.*','') myModule.CopyFolder('../data/textured3D.*','') - # add the configuration files - #myModule.SetConfig(['Config.in','ConfigLinux.in']) - # name of the dependency myModule.AddModuleDepend(['etk', 'freetype', 'exml', 'ejson', 'egami', 'date']) - #ifeq ("$(CONFIG_BUILD_BULLET)","y") - #myModule.AddModuleDepend('bullet') - #endif #ifeq ("$(CONFIG_BUILD_LUA)","y") #myModule.AddModuleDepend('lua') #endif