ecere/gui/drivers/XInterface: Fixed uninitialized warnings
[sdk] / ecere / src / gui / drivers / XInterface.ec
index a572f1a..e40f6a6 100644 (file)
@@ -1,11 +1,11 @@
 namespace gui::drivers;
 
 import "instance"
-#if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D) && !defined(ECERE_NOGL)
+#if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D) && !defined(ECERE_NOGL) && !defined(__ODROID__)
 import "OpenGLDisplayDriver"
 #endif
 
-#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX)
+#if (defined(__unix__) || defined(__APPLE__)) && !defined(ECERE_MINIGLX) && !defined(__EMSCRIPTEN__)
 
 #undef __BLOCKS__
 default:
@@ -50,16 +50,24 @@ typedef int X11Bool;
 
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
+#if !defined(__EMSCRIPTEN__)
 #include <X11/Xresource.h>
+#endif
 #include <X11/Xutil.h>
 #include <X11/XKBlib.h>
 #include <X11/keysym.h>
 #include <X11/cursorfont.h>
 #include <fcntl.h>
-#if !defined(ECERE_NO3D) && !defined(ECERE_NOGL)
+#if !defined(ECERE_NO3D) && !defined(ECERE_NOGL) //&& !defined(__ODROID__)
+#if defined(__EMSCRIPTEN__)
+#include <GL/glfw.h>
+#else
 #include <GL/glx.h>
 #endif
+#endif
+#if !defined(__EMSCRIPTEN__)
 #include <X11/extensions/Xrender.h>
+#endif
 #include <X11/extensions/XShm.h>
 
 #undef Bool
@@ -1759,9 +1767,9 @@ class XInterface : Interface
                   static Point lastPos[3];
 
                   Modifiers keyFlags = 0;
-                  bool doubleClick;
-                  uint button, buttonDouble, whichButton;
-                  uint buttonMask;
+                  bool doubleClick = false;
+                  uint button = 0, buttonDouble = 0, whichButton;
+                  uint buttonMask = 0;
                   int x = event->x_root, y = event->y_root;
                   timeStamp = event->time;
                   if(event->button == Button1)
@@ -1789,7 +1797,7 @@ class XInterface : Interface
                      keyFlags.right = true;
                      buttonsState.right = true;
                   }
-                  else
+                  else if(event->button == Button2)
                   {
                      button = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown;
                      buttonDouble = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick;
@@ -1801,14 +1809,17 @@ class XInterface : Interface
                   if(event->state & buttonMask)
                      break;
 
-                  doubleClick = event->time - lastTime[whichButton] < DBLCLICK_DELAY &&
-                     window == lastWindow[whichButton] &&
-                     Abs(event->x_root - lastPos[whichButton].x) < DBLCLICK_DELTA &&
-                     Abs(event->y_root - lastPos[whichButton].y) < DBLCLICK_DELTA;
-                  lastTime[whichButton] = doubleClick ? 0 : event->time;
-                  lastWindow[whichButton] = window;
-                  lastPos[whichButton].x = event->x_root;
-                  lastPos[whichButton].y = event->y_root;
+                  if(buttonMask)
+                  {
+                     doubleClick = event->time - lastTime[whichButton] < DBLCLICK_DELAY &&
+                        window == lastWindow[whichButton] &&
+                        Abs(event->x_root - lastPos[whichButton].x) < DBLCLICK_DELTA &&
+                        Abs(event->y_root - lastPos[whichButton].y) < DBLCLICK_DELTA;
+                     lastTime[whichButton] = doubleClick ? 0 : event->time;
+                     lastWindow[whichButton] = window;
+                     lastPos[whichButton].x = event->x_root;
+                     lastPos[whichButton].y = event->y_root;
+                  }
 
                   if(event->state & ShiftMask)     keyFlags.shift = true;
                   if(event->state & ControlMask)   keyFlags.ctrl = true;
@@ -1821,9 +1832,9 @@ class XInterface : Interface
                   incref window;
                   if(event->button == Button4 || event->button == Button5)
                   {
-                     window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, (event->button == Button4) ? wheelUp : wheelDown, 0);
+                     window.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit, { modifiers = keyFlags, code = (event->button == Button4) ? wheelUp : wheelDown }, 0);
                   }
-                  else
+                  else if(button)
                   {
                      if(doubleClick)
                      {
@@ -2206,7 +2217,7 @@ class XInterface : Interface
                         }
                      }
 
-                     window.Position(x, y, w, h, um /*false /*true*/, true, true, true, false, unmaximized);
+                     window.Position(x, y, w, h, um, true, true, true, false, unmaximized);
 
                      // Break the anchors for moveable/resizable windows
                      // Avoid doing this if the translation wasn't in sync as it will cause the window to move around
@@ -2445,7 +2456,7 @@ class XInterface : Interface
       attributes.override_redirect = (window.interim || (!atomsSupported[_net_wm_state] && !window.nativeDecorations)) ? True : False;
       attributes.event_mask = EVENT_MASK;
       //printf("%s\n", guiApp.defaultDisplayDriver);
-#if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D) && !defined(ECERE_NOGL)
+#if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D) && !defined(ECERE_NOGL) && !defined(__ODROID__)
       if(window.dispDriver == class(OpenGLDisplayDriver) || !strcmp(guiApp.defaultDisplayDriver, "OpenGL"))
       {
          int samples;
@@ -2544,6 +2555,20 @@ class XInterface : Interface
          };
          visualInfo = glXChooseVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay), attrList);
       }
+#elif defined(__ODROID__)
+      if(!visualInfo)
+      {
+         // System visual not working on ODROID?
+         int attrList[] =
+         {
+            GLX_USE_GL, GLX_DEPTH_SIZE, 1,
+            GLX_RGBA,
+            GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
+            GLX_DOUBLEBUFFER,
+            None
+         };
+         visualInfo = glXChooseVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay), attrList);
+      }
 #endif
       depth = visualInfo ? visualInfo->depth : (window.alphaBlend ? 32 : xSystemDepth);
       visual = visualInfo ? visualInfo->visual : (window.alphaBlend ? FindFullColorVisual (xGlobalDisplay, &depth) : xSystemVisual);