From 073ae904c6530653e5ad18a7bb56dff6287160f7 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 16 Mar 2016 21:42:49 +0100 Subject: [PATCH] [DEV] review interface (step 1) --- gale/Application.cpp | 6 ++ gale/Application.h | 9 ++- gale/context/Context.cpp | 19 ++--- gale/context/X11/Context.cpp | 133 ++++++++++++++++++----------------- 4 files changed, 86 insertions(+), 81 deletions(-) diff --git a/gale/Application.cpp b/gale/Application.cpp index 86a2989..ba4c799 100644 --- a/gale/Application.cpp +++ b/gale/Application.cpp @@ -66,8 +66,14 @@ void gale::Application::onDestroy(gale::Context& _context) { GALE_VERBOSE("Destroy Gale Application"); } +void gale::Application::onKillDemand(gale::Context& _context) { + GALE_INFO("Gale request auto destroy ==> no applification specification"); + exit(0); +} + void gale::Application::exit(int32_t _value) { GALE_VERBOSE("Exit Requested"); + gale::getContext().stop(); } void gale::Application::onPointer(enum gale::key::type _type, int32_t _pointerID, const vec2& _pos, gale::key::status _state) { diff --git a/gale/Application.h b/gale/Application.h index 2402321..66e5e71 100644 --- a/gale/Application.h +++ b/gale/Application.h @@ -60,12 +60,17 @@ namespace gale { */ virtual void onStop(gale::Context& _context); /** - * @brief The application is remoed (call destructor just adter it.). + * @brief The application is removed (call destructor just adter it.). * @param[in] _context Current gale context. */ virtual void onDestroy(gale::Context& _context); /** - * @brief Exit the application (not availlable on IOs, ==> the user will not understand the comportement. He will think the application crash) + * @brief The user request application removing. + * @param[in] _context Current gale context. + */ + virtual void onKillDemand(gale::Context& _context); + /** + * @brief Exit the application (not availlable on IOs, ==> the user will not understand the comportement. He will think the application has crashed (Apple philosophie)) * @param[in] _value value to return on the program */ virtual void exit(int32_t _value); diff --git a/gale/context/Context.cpp b/gale/context/Context.cpp index 9586c6d..030b787 100644 --- a/gale/context/Context.cpp +++ b/gale/context/Context.cpp @@ -635,11 +635,11 @@ void gale::Context::OS_Stop() { // set the curent interface : lockContext(); GALE_INFO("OS_Stop..."); - #if 0 - if (m_windowsCurrent != nullptr) { - m_windowsCurrent->sysOnKill(); + if (m_application == nullptr) { + stop(); + return; } - #endif + m_application->onKillDemand(*this); // release the curent interface : unLockContext(); } @@ -732,14 +732,3 @@ void gale::Context::keyboardHide() { GALE_INFO("keyboardHide: NOT implemented ..."); } -#if 0 -bool gale::Context::systemKeyboradEvent(enum gale::key::keyboardSystem _key, bool _down) { - if (m_windowsCurrent == nullptr) { - return false; - } - lockContext(); - bool ret = m_windowsCurrent->onEventHardwareInput(_key, _down); - unLockContext(); - return ret; -} -#endif diff --git a/gale/context/X11/Context.cpp b/gale/context/X11/Context.cpp index 56e06a7..30b56e6 100644 --- a/gale/context/X11/Context.cpp +++ b/gale/context/X11/Context.cpp @@ -213,7 +213,8 @@ class X11Interface : public gale::Context { if(XAtomeDeleteWindows == (uint64_t)event.xclient.data.l[0]) { GALE_INFO(" == > Kill Requested ..."); OS_Stop(); - m_run = false; + // We do not close here but in the application only: + //m_run = false; } break; } @@ -246,9 +247,9 @@ class X11Interface : public gale::Context { } } #endif - if (true == m_clipBoardOwnerPrimary) { + if (m_clipBoardOwnerPrimary == true) { m_clipBoardOwnerPrimary = false; - } else if (true == m_clipBoardOwnerStd) { + } else if (m_clipBoardOwnerStd == true) { m_clipBoardOwnerStd = false; } else { GALE_ERROR("X11 event SelectionClear == > but no selection requested anymore ..."); @@ -277,7 +278,7 @@ class X11Interface : public gale::Context { &bytes, // *bytes_after_return &buf// **prop_return); ); - if (true == m_clipBoardRequestPrimary) { + if (m_clipBoardRequestPrimary == true) { std::string tmpppp((char*)buf); gale::context::clipBoard::setSystem(gale::context::clipBoard::clipboardSelection, tmpppp); // just transmit an event , we have the data in the system @@ -383,11 +384,11 @@ class X11Interface : public gale::Context { /////////////////////////////////////////////////////////////////////////////////////////////////////////////// case Expose: X11_INFO("X11 event Expose"); - specialEventThatNeedARedraw=true; + specialEventThatNeedARedraw = true; break; case GraphicsExpose: X11_INFO("X11 event GraphicsExpose"); - specialEventThatNeedARedraw=true; + specialEventThatNeedARedraw = true; break; case NoExpose: X11_INFO("X11 event NoExpose"); @@ -471,9 +472,9 @@ class X11Interface : public gale::Context { 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()) { + if( m_grabAllEvent == true + && 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; @@ -481,12 +482,12 @@ class X11Interface : public gale::Context { } else { m_cursorEventX = event.xmotion.x; m_cursorEventY = (m_currentHeight-event.xmotion.y); - if(true == m_grabAllEvent) { + if(m_grabAllEvent == true) { m_cursorEventX -= m_forcePos.x(); m_cursorEventY -= (m_currentHeight-m_forcePos.y()); } vec2 newDelta = vec2(m_cursorEventX, m_cursorEventY); - if(true == m_grabAllEvent) { + if(m_grabAllEvent == true) { m_cursorEventX -= m_curentGrabDelta.x(); m_cursorEventY -= m_curentGrabDelta.y(); } @@ -494,7 +495,7 @@ class X11Interface : public gale::Context { // For compatibility of the Android system : bool findOne = false; for (int32_t iii=0; iii= 0) { // repeated kay from previous element : - if (count>0) { + if (count > 0) { // transform it in unicode m_lastKeyPressed = utf8::convertChar32(buf); } @@ -732,7 +733,7 @@ class X11Interface : public gale::Context { (event.type==KeyPress?gale::key::status_down:gale::key::status_up), thisIsAReapeateKey, m_lastKeyPressed); - if (true == thisIsAReapeateKey) { + if (thisIsAReapeateKey == true) { OS_setKeyboard(m_guiKeyBoardMode, gale::key::keyboard_char, (event.type!=KeyPress?gale::key::status_down:gale::key::status_up), @@ -745,13 +746,13 @@ class X11Interface : public gale::Context { } break; } - if (true == find) { + if (find == true) { //GALE_DEBUG("eventKey Move type : " << getCharTypeMoveEvent(keyInput) ); OS_setKeyboard(m_guiKeyBoardMode, keyInput, (event.type==KeyPress?gale::key::status_down:gale::key::status_up), thisIsAReapeateKey); - if (true == thisIsAReapeateKey) { + if (thisIsAReapeateKey == true) { OS_setKeyboard(m_guiKeyBoardMode, keyInput, (event.type!=KeyPress?gale::key::status_down:gale::key::status_up), @@ -778,7 +779,7 @@ class X11Interface : public gale::Context { break; } } - if(true == m_run) { + if(m_run == true) { if (m_doubleBuffered && hasDisplay) { glXSwapBuffers(m_display, m_WindowHandle); XSync(m_display,0); @@ -912,7 +913,7 @@ class X11Interface : public gale::Context { } /****************************************************************************************/ void grabPointerEvents(bool _isGrabbed, const vec2& _forcedPosition) { - if (true == _isGrabbed) { + if (_isGrabbed == true) { X11_DEBUG("X11-API: Grab Events"); int32_t test = XGrabPointer(m_display,RootWindow(m_display, DefaultScreen(m_display)), True, ButtonPressMask | @@ -926,12 +927,9 @@ class X11Interface : public gale::Context { RootWindow(m_display, DefaultScreen(m_display)), None, CurrentTime); - - if (GrabSuccess != test) - { + if (GrabSuccess != test) { GALE_CRITICAL("Display error " << test); - switch (test) - { + switch (test) { case BadCursor: GALE_CRITICAL(" BadCursor"); break; @@ -973,7 +971,7 @@ class X11Interface : public gale::Context { // Connect to the X server m_display = XOpenDisplay(nullptr); - if(nullptr == m_display) { + if(m_display == nullptr) { GALE_CRITICAL("Could not open display X."); exit(-1); } else { @@ -986,7 +984,7 @@ class X11Interface : public gale::Context { gale::Dimension::Millimeter); // get an appropriate visual m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl); - if (nullptr == m_visual) { + if (m_visual == nullptr) { m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl); m_doubleBuffered = false; GALE_INFO("GL-X singlebuffered rendering will be used, no doublebuffering available"); @@ -1034,15 +1032,15 @@ class X11Interface : public gale::Context { GALE_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); + Xroot, + x, y, tmp_width, tmp_height, + 1, + m_visual->depth, + InputOutput, + m_visual->visual, + attr_mask, &attr); - if( !m_WindowHandle ) { + if(!m_WindowHandle) { GALE_CRITICAL("Couldn't create the window"); exit(-1); } @@ -1064,10 +1062,10 @@ class X11Interface : public gale::Context { StartupState->flags = StateHint; XSetWMProperties(m_display, m_WindowHandle,&textprop, &textprop,/* Window title/icon title*/ - nullptr, 0,/* Argv[], argc for program*/ - &hints, /* Start position/size*/ - StartupState,/* Iconised/not flag */ - nullptr); + nullptr, 0,/* Argv[], argc for program*/ + &hints, /* Start position/size*/ + StartupState,/* Iconised/not flag */ + nullptr); XFree(StartupState); @@ -1181,17 +1179,21 @@ class X11Interface : public gale::Context { } XImage* myImage = XCreateImage(m_display, - m_visual->visual, - depth, - ZPixmap, - 0, - (char*)tmpVal, - dataImage.getWidth(), - dataImage.getHeight(), - 32, - 0); + 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); + Pixmap tmpPixmap = XCreatePixmap(m_display, + m_WindowHandle, + dataImage.getWidth(), + dataImage.getHeight(), + depth); switch(tmpPixmap) { case BadAlloc: GALE_ERROR("X11: BadAlloc"); @@ -1207,7 +1209,13 @@ class X11Interface : public gale::Context { 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()); + int error = XPutImage(m_display, + tmpPixmap, + tmpGC, + myImage, + 0, 0, 0, 0, + dataImage.getWidth(), + dataImage.getHeight()); switch(error) { case BadDrawable: GALE_ERROR("X11: BadDrawable"); @@ -1227,7 +1235,7 @@ class X11Interface : public gale::Context { } // allocate a WM hints structure. XWMHints* win_hints = XAllocWMHints(); - if (!win_hints) { + if (win_hints == nullptr) { GALE_ERROR("XAllocWMHints - out of memory"); return; } @@ -1255,7 +1263,7 @@ class X11Interface : public gale::Context { typedef int32_t (APIENTRY *PFNWGLSWAPINTERVALPROC)( int ); PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0; const char *extensions = (char*)glGetString( GL_EXTENSIONS ); - if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 ) { + if (strstr( extensions, "WGL_EXT_swap_control" ) == 0) { GALE_ERROR("Can not set the vertical synchronisation status" << _sync << " (1)"); return; } else { @@ -1279,10 +1287,8 @@ class X11Interface : public gale::Context { } else { GALE_INFO("XF86 DRI NOT available\n"); } - // enable vertical synchronisation : (some computer has synchronisation disable) setVSync(true); - return true; } /****************************************************************************************/ @@ -1299,7 +1305,6 @@ class X11Interface : public gale::Context { XSetWMIconName(m_display, m_WindowHandle, &tp); X11_INFO("X11: set Title (END)"); } - void openURL(const std::string& _url) { std::string req = "xdg-open "; req += _url; @@ -1310,7 +1315,7 @@ class X11Interface : public gale::Context { void clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) { switch (_clipboardID) { case gale::context::clipBoard::clipboardSelection: - if (false == m_clipBoardOwnerPrimary) { + if (m_clipBoardOwnerPrimary == false) { m_clipBoardRequestPrimary = true; // generate a request on X11 XConvertSelection(m_display, @@ -1325,7 +1330,7 @@ class X11Interface : public gale::Context { } break; case gale::context::clipBoard::clipboardStd: - if (false == m_clipBoardOwnerStd) { + if (m_clipBoardOwnerStd == false) { m_clipBoardRequestPrimary = false; // generate a request on X11 XConvertSelection(m_display, @@ -1349,14 +1354,14 @@ class X11Interface : public gale::Context { switch (_clipboardID) { case gale::context::clipBoard::clipboardSelection: // Request the selection : - if (false == m_clipBoardOwnerPrimary) { + if (m_clipBoardOwnerPrimary == false) { XSetSelectionOwner(m_display, XAtomeSelection, m_WindowHandle, CurrentTime); m_clipBoardOwnerPrimary = true; } break; case gale::context::clipBoard::clipboardStd: // Request the clipBoard : - if (false == m_clipBoardOwnerStd) { + if (m_clipBoardOwnerStd == false) { XSetSelectionOwner(m_display, XAtomeClipBoard, m_WindowHandle, CurrentTime); m_clipBoardOwnerStd = true; }