3 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
4 #define property _property
9 #define Window X11Window
10 #define Cursor X11Cursor
12 #define Display X11Display
14 #define KeyCode X11KeyCode
15 #define Picture X11Picture
17 #include <X11/Xutil.h>
34 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
35 #if defined(__WIN32__)
37 #define WIN32_LEAN_AND_MEAN
39 static WSADATA wsaData;
41 #elif defined(__unix__) || defined(__APPLE__)
49 #include <netinet/in.h>
51 #include <sys/socket.h>
53 #include <sys/types.h>
55 #include <arpa/inet.h>
62 typedef struct hostent HOSTENT;
63 typedef struct sockaddr SOCKADDR;
64 typedef struct sockaddr_in SOCKADDR_IN;
65 typedef struct in_addr IN_ADDR;
66 #define closesocket(s) close(s)
73 #if defined(__APPLE__)
74 import "CocoaInterface"
77 #if defined(__unix__) && !defined(__ANDROID__)
83 /*static */bool guiApplicationInitialized = false;
84 GuiApplication guiApp;
87 enum GuiErrorCode : ErrorCode
89 driverNotSupported = ErrorCode { VeryFatal, 1 },
90 windowCreationFailed = ErrorCode { VeryFatal, 2 },
91 graphicsLoadingFailed = ErrorCode { VeryFatal, 3 },
92 modeSwitchFailed = ErrorCode { VeryFatal, 4 }
95 static Array<String> errorMessages
98 $"Graphics driver not supported by any user interface system",
99 $"Window creation failed",
100 $"Window graphics loading failed",
101 $"Driver/Mode switch failed"
104 public class GuiApplication : Application
113 subclass(Interface) interfaceDriver;
114 subclass(Skin) currentSkin;
121 bool fullScreenMode; // Needs to start at true for the desktop to resize
124 Resolution resolution;
125 PixelFormat pixelFormat;
128 char * defaultDisplayDriver;
130 Cursor systemCursors[SystemCursor];
134 OldList customCursors;
137 OldList windowTimers;
140 Window prevWindow; // Used for OnMouseLeave
141 Window windowCaptured;
143 // Mouse based moving & resizing
145 Point windowMovingStart;
146 Point windowMovingBefore;
147 Size windowResizingBefore;
149 bool windowIsResizing;
150 bool resizeX, resizeEndX;
151 bool resizeY, resizeEndY;
153 // Mouse based scrolling
154 Window windowScrolling;
155 Point windowScrollingBefore, windowScrollingStart;
158 Bitmap cursorBackground { };
159 int cursorBackgroundX, cursorBackgroundY;
160 int cursorBackgroundW, cursorBackgroundH;
166 Window acquiredWindow;
167 int acquiredMouseX, acquiredMouseY;
169 Cursor currentCursor;
171 uint errorLevel, lastErrorCode;
179 Window interimWindow;
183 uint timerResolution;
186 Point virtualScreenPos;
194 mainThread = GetCurrentThreadID();
198 strcpy(appName, $"ECERE Application");
203 // customCursors.offset = OFFSET(Cursor, prev);
204 windowTimers.offset = (uint)&((Timer)0).prev;
206 for(c = 0; c<SystemCursor::enumSize; c++)
207 systemCursors[c] = Cursor { systemCursor = c; };
209 globalSystem.eventSemaphore = Semaphore { };
210 globalSystem.fileMonitorMutex = Mutex { };
211 globalSystem.fileMonitors.offset = (uint)&((FileMonitor)0).prev;
222 customCursors.Clear();
224 #if defined(__unix__) && !defined(__ANDROID__)
226 XUnlockDisplay(xGlobalDisplay);
229 #if !defined(__ANDROID__)
230 // Because destruction of app won't be from main thread
236 interfaceDriver.Terminate();
239 // interfaceDrivers.Free(null);
245 for(c = 0; c<SystemCursor::enumSize; c++)
246 delete systemCursors[c];
248 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
252 delete globalSystem.eventSemaphore;
253 delete globalSystem.fileMonitorMutex;
254 delete globalSystem.fileMonitorThread;
256 UnapplySkin(class(Window));
260 Timer timer, nextTimer;
261 for(timer = windowTimers.first; timer; timer = nextTimer)
263 nextTimer = timer.next;
272 Time time = GetTime();
275 for(timer = windowTimers.first; timer; timer = timer.next)
276 timer.dispatched = false;
279 for(timer = windowTimers.first; timer; timer = timer.next)
281 if(!timer.dispatched)
283 if((timer.delay - (Seconds)(time - timer.lastTime)) < Seconds { 0.00001 })
286 timer.lastTime = time;
287 if(timer.DelayExpired(timer.window))
289 timer.dispatched = true;
291 eInstance_DecRef(timer);
301 // --- Mouse-based window movement ---
302 void SetCurrentCursor(Cursor cursor)
304 currentCursor = cursor;
307 if(fullScreenMode && cursor.bitmap)
308 interfaceDriver.SetMouseCursor((SystemCursor)-1);
311 interfaceDriver.SetMouseCursor(cursor.systemCursor);
312 cursorBackground.Free();
318 void PreserveAndDrawCursor()
321 if(!acquiredWindow && cursorUpdate && currentCursor && currentCursor->bitmap)
325 Box against = {0,0, desktop.w-1,desktop.h-1};
326 Box box = {0, 0, currentCursor->bitmap->width,currentCursor->bitmap->height};
328 interfaceDriver->GetMousePosition(&mouseX, &mouseY);
330 mouseX -= currentCursor->hotSpotX;
331 mouseY -= currentCursor->hotSpotY;
333 // Preserve Background
334 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
336 cursorBackgroundX = mouseX;
337 cursorBackgroundY = mouseY;
338 cursorBackgroundW = currentCursor->bitmap->width;
339 cursorBackgroundH = currentCursor->bitmap->height;
340 eDisplay_Grab(desktop.display, cursorBackground,
341 mouseX, mouseY, cursorBackgroundW, cursorBackgroundH);
344 eBox_ClipOffset(&box, &against, mouseX, mouseY);
346 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
347 eDisplay_StartUpdate(desktop.display);
349 surface = eDisplay_GetSurface(desktop.display, mouseX, mouseY, &box);
352 eSurface_SetForeground(surface, WHITE);
353 eSurface_Blit(surface, currentCursor->bitmap, 0,0, 0,0,
354 currentCursor->bitmap->width,currentCursor->bitmap->height);
355 eInstance_Delete(surface);
357 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
362 box.bottom += mouseY;
363 eDisplay_Update(desktop.display, &box);
366 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
367 eDisplay_EndUpdate(desktop.display);
372 void RestoreCursorBackground()
375 // Restore Cursor Background
376 if(cursorBackground && desktop.active)
378 Box box = {0, 0, cursorBackgroundW-1,cursorBackgroundH-1};
379 Box against = {0,0, desktop.w-1,desktop.h-1};
382 eBox_ClipOffset(&box, &against, cursorBackgroundX, cursorBackgroundY);
383 if((surface = eDisplay_GetSurface(desktop.display, cursorBackgroundX,cursorBackgroundY, &box)))
385 eSurface_Blit(surface, cursorBackground, 0, 0, 0,0, cursorBackgroundW,cursorBackgroundH);
386 eInstance_Delete(surface);
392 bool IsModeSwitching()
394 return modeSwitching;
397 public bool SetDesktopPosition(int x, int y, int w, int h, bool moveChildren)
400 bool windowResized = desktop.size.w != w || desktop.size.h != h;
401 bool windowMoved = desktop.clientStart.x != x || desktop.clientStart.y != y;
403 if((windowResized || windowMoved) && moveChildren)
406 desktop.Position(x, y, w, h, true, true, true, true, false, false);
408 // Maximized native decorations windows suffer when we drag the dock around, so remaximize them
409 // It's a little jumpy, but oh well.
410 for(child = desktop.children.first; child; child = child.next)
412 if(child.nativeDecorations && child.rootWindow == child && child.state == maximized)
414 child.state = normal;
415 child.state = maximized;
418 /*for(child = desktop.children.first; child; child = child.next)
420 if(!child.systemParent)
425 child.ComputeAnchors(
426 child.ax, child.ay, child.aw, child.ah,
428 child.Position(x, y, w, h, true, true, true, true, false);
430 if(child.state == Maximized)
434 child.ComputeAnchors(,
435 A_LEFT,A_LEFT,A_OFFSET,A_OFFSET,
437 child.Position(, x, y, w, h, false, true, true, true, false);
443 desktop.display.Lock(true);
446 if(!desktop.display.Resize(desktop.size.w, desktop.size.h))
449 desktop.dirty = true;
450 if(!desktop.display.flags.flipping)
451 desktop.Update(null);
453 // When does the desktop have a display in not fullscreen mode?
454 if(!fullScreenMode && !modeSwitching)
455 desktop.UpdateDisplay();
456 desktop.display.Unlock();
460 desktop.SetPosition(x, y, w, h, false, false, false);
464 void SetAppFocus(bool state)
466 // Shouldn't be property here
467 desktop.active = state;
470 bool SelectSkin(char * skinName)
476 for(link = class(Skin).derivatives.first; link; link = link.next)
479 if(skin.name && !strcmp(skin.name, skinName))
482 if(!link) skin = null;
486 if(skin != currentSkin || !currentSkin)
488 // Try finding a driver to support this mode
489 if(skin.textMode != textMode)
495 bool needReload = false;
497 if(!modeSwitching && currentSkin)
499 modeSwitching = true;
500 desktop.UnloadGraphics(true);
504 UnapplySkin(class(Window));
508 ApplySkin(class(Window), skin.name, null);
512 if(desktop.SetupDisplay())
513 if(desktop.LoadGraphics(false, true))
515 modeSwitching = false;
527 void Initialize(bool switchMode)
530 // if(!initialized && eClass_IsDerived(__ecereModule->app->module.inst.class, guiApplicationClass))
531 if(!guiApplicationInitialized)
533 char * defaultDriver = null;
534 #if defined(ECERE_VANILLA) || defined(ECERE_ONEDRIVER)
535 char * driver = null;
538 // char * driver = getenv("ECERE_DRIVER");
539 char * driver = null;
540 static char driverStorage[1024];
541 GetEnvironment("ECERE_DRIVER", driverStorage, sizeof(driverStorage));
542 if(driverStorage[0]) driver = driverStorage;
544 guiApplicationInitialized = true;
546 fullScreenMode = true; // Needs to start at true for the desktop to resize
547 // Set this to true earlier so we can override it!
553 #if defined(__unix__) && !defined(__ANDROID__)
555 XLockDisplay(xGlobalDisplay);
561 desktop = Window { nativeDecorations = false };
564 desktop.childrenOrder.circ = true;
565 desktop.childrenCycle.circ = true;
566 desktop.background = blue;
567 desktop.rootWindow = desktop;
568 desktop.cursor = GetCursor(arrow);
569 desktop.caption = appName;
570 *&desktop.visible = true;
571 desktop.position = Point { };
572 desktop.mutex = Mutex { };
573 desktop.created = true;
576 #if defined(__WIN32__)
579 defaultDriver = driver;
580 else if(this.isGUIApp && !textMode)
581 defaultDriver = "GDI";
583 defaultDriver = "Win32Console";
585 #elif defined(__APPLE__)
588 defaultDriver = driver;
590 defaultDriver = "X"; //"CocoaOpenGL";
593 #elif defined(__ANDROID__)
596 defaultDriver = driver;
598 defaultDriver = "OpenGL";
601 if(this.isGUIApp && !textMode)
603 char * display = getenv("DISPLAY");
605 if(!display || !display[0] || !SwitchMode(false, "X", 0, 0, 0, null, true))
606 defaultDriver = "NCurses";
607 // SwitchMode(true, "NCurses", 0, PixelFormatText, 0, null, true);
611 defaultDriver = driver;
614 defaultDriver = "NCurses";
619 SwitchMode(false, defaultDriver, 0, 0, 0, null, true);
623 #if defined(__WIN32__)
624 SwitchMode(true, "Win32Console", 0, PixelFormatText, 0, null, true);
629 SwitchMode(true, "SVGA", Res640x480, PixelFormat8, 0, null, true);
632 #if defined(__APPLE__)
633 SwitchMode(true, "CocoaOpenGL", 0, 0, 0, null, true);
636 #if defined(__unix__)
637 #if defined(ECERE_MINIGLX)
638 SwitchMode(true, "OpenGL", 0, 0, 0, null, true);
643 guiApplicationInitialized = false;
646 defaultDisplayDriver = defaultDriver;
651 virtual bool Init(void);
652 virtual bool Cycle(bool idle);
653 virtual void Terminate(void);
663 // better solution when designing tab order/activated window etc, why do windows move in the list?
666 for(window = desktop.children.first; window; window = window.next)
668 if(window.autoCreate && !window.created)
682 while(desktop && interfaceDriver)
686 if(terminateX != terminated)
688 terminated = terminateX;
694 //printf("Resetting terminate X to 0\n");
698 for(child = desktop.children.first; child; child = child.next)
699 if(child.created && child.visible)
703 for(window = desktop.children.first; window; window = window.next)
704 if(window.mutex) window.mutex.Wait();
706 for(window = desktop.children.first; window; window = window.next)
707 if(window.mutex) window.mutex.Release();
708 wait = !ProcessInput(true);
710 if(lockMutex.owningThread != GetCurrentThreadID())
711 PrintLn("WARNING: ProcessInput returned unlocked GUI!");
720 #if defined(__unix__) && !defined(__ANDROID__)
722 XUnlockDisplay(xGlobalDisplay);
728 #if defined(__unix__) && !defined(__ANDROID__)
730 XLockDisplay(xGlobalDisplay);
734 eInstance_DecRef(desktop);
739 #if defined(__ANDROID__)
740 // Because destruction of GuiApp won't be from main thread
747 #if defined(__unix__) && !defined(__ANDROID__)
749 XUnlockDisplay(xGlobalDisplay);
757 interfaceDriver.Wait();
763 #if defined(__unix__) && !defined(__ANDROID__)
765 XLockDisplay(xGlobalDisplay);
769 bool ProcessInput(bool useProcessAll)
775 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
776 ProcessNetworkEvents();
780 result = interfaceDriver.ProcessInput(useProcessAll && processAll);
781 if(!desktop || !interfaceDriver) return;
785 for(child = app.desktop.children.first; child; child = child.next)
786 if(child.created && child.visible)
788 if(!child) return result;
791 result |= UpdateTimers();
792 result |= ProcessFileNotifications();
795 result |= ProcessFileNotifications();
796 result |= UpdateTimers();
797 result |= interfaceDriver.ProcessInput(useProcessAll && processAll);
804 void UpdateDisplay(void)
806 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
807 if(Desktop3DUpdateDisplay()) return;
812 if(fullScreenMode && desktop.display)
814 desktop.mutex.Wait();
817 desktop.display.Lock(true);
819 if(desktop.dirty || cursorUpdate)
821 if(desktop.display.flags.flipping)
822 desktop.Update(null);
823 desktop.UpdateDisplay();
826 if(cursorUpdate || desktop.dirty)
828 PreserveAndDrawCursor();
829 cursorUpdate = false;
830 desktop.dirty = false;
831 RestoreCursorBackground();
834 desktop.display.Unlock();
836 desktop.mutex.Release();
842 for(window = desktop.children.first; window; window = window.next)
844 if(window.mutex) window.mutex.Wait();
845 if(window.visible && window.dirty)
847 // Logf("Updating %s\n", window.name);
848 interfaceDriver.Lock(window);
851 if(window.display.current)
855 window.display.Lock(true);
856 window.UpdateDisplay();
857 window.display.Unlock();
860 window.dirty = false;
861 interfaceDriver.Unlock(window);
863 Log("--------------\n");
867 if(window.mutex) window.mutex.Release();
875 globalSystem.eventSemaphore.Wait();
878 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
879 bool ProcessNetworkEvents()
881 bool gotEvent = false;
882 #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
883 if(network.networkInitialized)
887 struct timeval tv = {0, 0};
892 PauseNetworkEvents();
893 network.mutex.Wait();
896 if(network.connectEvent || network.networkEvent)
897 Log("[P] [NProcess]\n");
899 rs = network.readSet;
900 ws = network.writeSet;
901 es = network.exceptSet;
903 if((network.ns && select(network.ns, &rs, &ws, &es, &tv)) || network.leftOverBytes)
905 network.leftOverBytes = false;
907 // Danger here? Why looping with a next and not unlocking anything?
908 for(socket = network.connectSockets.first; socket; socket = next)
911 if(!socket.processAlone && FD_ISSET(socket.s, &ws))
913 network.mutex.Release();
914 socket.connectThread.Wait();
915 network.mutex.Wait();
918 for(socket = network.sockets.first; socket; socket = next)
921 if(!socket.processAlone)
923 network.mutex.Release();
924 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
925 network.mutex.Wait();
929 for(service = network.services.first; service; service = nextService)
931 nextService = service.next;
932 if(!service.processAlone)
934 if(FD_ISSET(service.s, &rs))
937 Logf("[P] Accepting connection (%x)\n", service.s);
939 service.accepted = false;
941 if(!service.accepted)
945 int addrLen = sizeof(a);
946 s = accept(service.s,(SOCKADDR *)&a,&addrLen);
952 Log("[P] Connection accepted\n");
956 for(socket = service.sockets.first; socket; socket = next)
959 if(!socket.processAlone)
961 network.mutex.Release();
962 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
963 network.mutex.Wait();
968 if(network.connectEvent)
974 for(socket = network.connectSockets.first; socket; socket = next)
977 if(socket._connected && socket._connected != -2)
979 network.connectSockets.Remove(socket);
980 delete socket.connectThread;
982 // printf("%s is connected = %d\n", socket._class.name, socket._connected);
983 if(socket._connected == -1)
986 Logf("[P] Processing disconnected connect (%x)\n", socket.s);
989 if(socket.disconnectCode == ResolveFailed)
990 Logf("Error resolving address %s\n", socket.address);
992 if(socket.s == network.ns - 1)
993 Network_DetermineMaxSocket();
998 else if(socket._connected == 1)
1000 #ifdef DEBUG_SOCKETS
1001 Log("[P] Processing connected connect\n");
1003 FD_CLR(socket.s, &network.writeSet);
1004 FD_SET(socket.s, &network.readSet);
1005 FD_SET(socket.s, &network.exceptSet);
1006 network.mutex.Release();
1008 // printf("Calling OnConnect on %s\n", socket._class.name);
1010 network.mutex.Wait();
1011 network.sockets.Add(socket);
1019 network.connectEvent = false;
1021 if(network.networkEvent)
1023 network.networkEvent = false;
1024 network.selectSemaphore.Release();
1029 for(semPtr = network.mtSemaphores.first; semPtr; semPtr = semPtr.next)
1031 ((Semaphore)semPtr.data).Release();
1035 network.mutex.Release();
1036 ResumeNetworkEvents();
1042 void WaitNetworkEvent()
1044 if(network.networkInitialized)
1046 if(GetCurrentThreadID() == network.mainThreadID)
1052 Semaphore semaphore { };
1053 OldLink semPtr { data = semaphore };
1054 network.mutex.Wait();
1055 network.mtSemaphores.Add(semPtr);
1056 network.mutex.Release();
1058 ResumeNetworkEvents();
1060 PauseNetworkEvents();
1061 network.mutex.Wait();
1062 network.mtSemaphores.Delete(semPtr);
1063 network.mutex.Release();
1069 void PauseNetworkEvents()
1071 if(network.networkInitialized)
1073 network.processMutex.Wait();
1077 void ResumeNetworkEvents()
1079 if(network.networkInitialized)
1081 network.processMutex.Release();
1086 void SignalEvent(void)
1088 globalSystem.eventSemaphore.Release();
1091 // TODO: Might want to make this private with simpler public version?
1092 bool SwitchMode(bool fullScreen, char * driverName, Resolution resolution, PixelFormat colorDepth, int refreshRate, char * skinName, bool fallBack)
1094 bool result = false;
1097 bool fbFullScreen = 0;
1098 Resolution fbResolution = 0;
1099 PixelFormat fbColorDepth = 0;
1100 int fbRefreshRate = 0;
1101 subclass(Interface) inter;
1102 subclass(Skin) skin = null;
1108 for(link = class(Skin).derivatives.first; link; link = link.next)
1111 if(skin.name && !strcmp(skin.name, skinName))
1114 if(!link) skin = null;
1119 fbDriver = defaultDisplayDriver;
1120 inter = interfaceDriver;
1123 interfaceDriver.GetCurrentMode(&fbFullScreen, &fbResolution, &fbColorDepth, &fbRefreshRate);
1125 if(!driverName && !interfaceDriver)
1126 driverName = defaultDisplayDriver;
1128 if(driverName || (skin && skin.textMode != textMode))
1130 for(link = class(Interface).derivatives.first; link; link = link.next)
1132 bool foundDriver = false;
1134 char ** graphicsDrivers;
1137 graphicsDrivers = inter.GraphicsDrivers(&numDrivers);
1139 for(c=0; c<numDrivers; c++)
1140 if(!driverName || !strcmp(driverName, graphicsDrivers[c]))
1142 if(!skin || skin.textMode == IsDriverTextMode(graphicsDrivers[c]))
1144 driverName = graphicsDrivers[c];
1159 #if defined(__WIN32__)
1160 #if !defined(ECERE_VANILLA)
1161 if(!strcmp(driverName, "Win32Console")) inter = (subclass(Interface))class(Win32ConsoleInterface); else
1163 inter = (subclass(Interface))class(Win32Interface);
1165 if(!strcmp(driverName, "X")) inter = (subclass(Interface))class(XInterface);
1166 else inter = (subclass(Interface))class(NCursesInterface);
1171 if(interfaceDriver && (!driverName || (fbDriver && !strcmp(fbDriver, driverName))) &&
1172 fullScreen == fbFullScreen &&
1173 (!resolution || resolution == fbResolution) &&
1174 (!colorDepth || colorDepth == fbColorDepth) &&
1175 (!refreshRate || refreshRate == fbRefreshRate) &&
1176 (currentSkin && (!skinName || !strcmp(currentSkin.name, skinName))))
1180 bool wasFullScreen = fullScreenMode;
1181 subclass(Skin) oldSkin = currentSkin;
1184 modeSwitching = true;
1187 desktop.UnloadGraphics(true);
1189 if(inter != interfaceDriver)
1193 interfaceDriver.Terminate();
1195 result = inter.Initialize();
1203 interfaceDriver = inter;
1204 interfaceDriver.SetTimerResolution(timerResolution);
1205 inter.EnsureFullScreen(&fullScreen);
1206 fullScreenMode = fullScreen;
1208 if((!wasFullScreen && !fullScreen) ||
1209 inter.ScreenMode(fullScreen, resolution, colorDepth, refreshRate, &textMode))
1211 if(!fbDriver || (driverName && strcmp(fbDriver, driverName)))
1212 defaultDisplayDriver = driverName;
1214 if(!skinName || !SelectSkin(skinName))
1216 if(!currentSkin || currentSkin.textMode != textMode ||
1217 !SelectSkin(currentSkin.name))
1220 subclass(Skin) skin = null;
1222 for(link = class(Skin).derivatives.first; link; link = link.next)
1225 if(skin.textMode == textMode)
1228 if(!link) skin = null;
1231 #if !defined(__ANDROID__)
1232 SelectSkin(skin.name);
1239 if(currentSkin && desktop.SetupDisplay())
1241 desktop.active = true;
1245 desktop.display.Lock(false);
1246 desktop.display.Position(0,0);
1247 desktop.display.Unlock();
1250 if(desktop.LoadGraphics(false, oldSkin != currentSkin))
1254 desktop.UpdateDisplay();
1257 this.fullScreen = fullScreen;
1263 modeSwitching = false;
1265 LogErrorCode(modeSwitchFailed, driverName ? driverName : defaultDisplayDriver);
1268 LogErrorCode(driverNotSupported, driverName ? driverName : defaultDisplayDriver);
1270 if(!result && fallBack && fbDriver)
1272 if(!SwitchMode(fbFullScreen, fbDriver, fbResolution, fbColorDepth, fbRefreshRate, null, false))
1273 Log($"Error falling back to previous video mode.\n");
1278 bool ProcessFileNotifications()
1280 bool activity = false;
1281 FileMonitor monitor, next;
1282 static int reentrant = 0;
1284 // Reentrant FileNotification is asking for trouble since each monitor is spawning a Modal() MessageBox
1285 if(reentrant) return false;
1286 // printf("[%d] Waiting in ProcessFileNotifications for fileMonitor Mutex %x...\n", GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1287 globalSystem.fileMonitorMutex.Wait();
1289 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1293 next = monitor.next;
1298 if(!monitor.reentrant && !monitor.toBeFreed)
1300 monitor.reentrant = true;
1301 while((notify = monitor.fileNotifies.first))
1303 monitor.fileNotifies.Remove(notify);
1307 if(monitor.directory)
1309 if(!monitor.OnDirNotify(monitor.data, notify.action, notify.fileName, notify.param))
1310 monitor.StopMonitoring();
1314 if(!monitor.OnFileNotify(monitor.data, notify.action, notify.param))
1315 monitor.StopMonitoring();
1318 monitor.reentrant = false;
1324 monitor.reentrant = false;
1327 if(next && next._refCount > 1)
1335 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1337 next = monitor.next;
1338 if(monitor.toBeFreed && !monitor.reentrant)
1339 monitor.FreeMonitor();
1342 // printf("[%d] Releasing in ProcessFileNotifications fileMonitor Mutex %x...\n", GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1343 globalSystem.fileMonitorMutex.Release();
1350 #if defined(__unix__) && !defined(__ANDROID__)
1352 XLockDisplay(xGlobalDisplay);
1358 #if defined(__unix__) && !defined(__ANDROID__)
1360 XUnlockDisplay(xGlobalDisplay);
1362 lockMutex.Release();
1365 Cursor GetCursor(SystemCursor cursor)
1367 return systemCursors[cursor];
1370 bool GetKeyState(Key key)
1372 return interfaceDriver.GetKeyState(key);
1375 bool GetMouseState(MouseButtons * buttons, int * x, int * y)
1377 return interfaceDriver.GetMouseState(buttons, x, y);
1381 property char * appName
1385 strcpy(appName, value);
1386 if(desktop) desktop.text = appName;
1390 return (char *)(this ? appName : null);
1393 property Semaphore semaphore { get { return globalSystem.eventSemaphore; } };
1394 property bool alwaysEmptyInput{ set { processAll = value; } get { return processAll; } };
1395 property bool fullScreen
1399 SwitchMode(value, defaultDisplayDriver, resolution,
1400 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1402 get { return this ? fullScreen : false; }
1404 property char * driver
1408 SwitchMode( fullScreen, value, resolution, pixelFormat, refreshRate,
1409 currentSkin ? currentSkin.name : null, true);
1411 get { return this ? defaultDisplayDriver : null; }
1413 property Resolution resolution
1417 SwitchMode(fullScreen, defaultDisplayDriver, value, pixelFormat, refreshRate,
1418 currentSkin ? currentSkin.name : null, true);
1420 get { return this ? resolution : 0; }
1422 property PixelFormat pixelFormat
1426 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1427 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1429 get { return this ? pixelFormat : 0; }
1431 property int refreshRate
1435 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1436 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1438 get { return this ? refreshRate : 0; }
1440 property char * skin
1442 set { SelectSkin(value); }
1443 get { return (this && currentSkin) ? currentSkin.name : null; }
1445 property bool textMode
1447 set { textMode = value; } // TODO: Implement switching
1448 get { return this ? textMode : false; }
1450 property Window desktop { get { return this ? desktop : null; } };
1451 property char ** drivers { get { return null; } };
1452 property char ** skins { get { return null; } };
1453 property subclass(Skin) currentSkin { get { return this ? currentSkin : null; } };
1454 property int numDrivers { get { return 0; } };
1455 property int numSkins { get { return 0; } };
1456 property uint timerResolution
1458 set { timerResolution = value; if(interfaceDriver) interfaceDriver.SetTimerResolution(value); }