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
38 #define String _String
41 static WSADATA wsaData;
43 #elif defined(__unix__) || defined(__APPLE__)
50 #include <sys/select.h>
52 #include <netinet/in.h>
54 #include <sys/socket.h>
56 #include <sys/types.h>
58 #include <arpa/inet.h>
65 typedef struct hostent HOSTENT;
66 typedef struct sockaddr SOCKADDR;
67 typedef struct sockaddr_in SOCKADDR_IN;
68 typedef struct in_addr IN_ADDR;
69 #define closesocket(s) close(s)
76 #if defined(__APPLE__) && !defined(ECERE_VANILLA)
77 import "CocoaInterface"
80 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
86 /*static */bool guiApplicationInitialized = false;
87 GuiApplication guiApp;
90 enum GuiErrorCode : ErrorCode
92 driverNotSupported = ErrorCode { VeryFatal, 1 },
93 windowCreationFailed = ErrorCode { VeryFatal, 2 },
94 graphicsLoadingFailed = ErrorCode { VeryFatal, 3 },
95 modeSwitchFailed = ErrorCode { VeryFatal, 4 }
98 static Array<String> errorMessages
101 $"Graphics driver not supported by any user interface system",
102 $"Window creation failed",
103 $"Window graphics loading failed",
104 $"Driver/Mode switch failed"
107 public class GuiApplication : Application
116 subclass(Interface) interfaceDriver;
117 subclass(Skin) currentSkin;
124 bool fullScreenMode; // Needs to start at true for the desktop to resize
127 Resolution resolution;
128 PixelFormat pixelFormat;
131 char * defaultDisplayDriver;
133 Cursor systemCursors[SystemCursor];
137 OldList customCursors;
140 OldList windowTimers;
143 Window prevWindow; // Used for OnMouseLeave
144 Window windowCaptured;
146 // Mouse based moving & resizing
148 Point windowMovingStart;
149 Point windowMovingBefore;
150 Size windowResizingBefore;
152 bool windowIsResizing;
153 bool resizeX, resizeEndX;
154 bool resizeY, resizeEndY;
156 // Mouse based scrolling
157 Window windowScrolling;
158 Point windowScrollingBefore, windowScrollingStart;
161 Bitmap cursorBackground { };
162 int cursorBackgroundX, cursorBackgroundY;
163 int cursorBackgroundW, cursorBackgroundH;
169 Window acquiredWindow;
170 int acquiredMouseX, acquiredMouseY;
172 Cursor currentCursor;
174 uint errorLevel, lastErrorCode;
182 Window interimWindow;
186 uint timerResolution;
189 Point virtualScreenPos;
197 mainThread = GetCurrentThreadID();
201 strcpy(appName, $"ECERE Application");
206 // customCursors.offset = OFFSET(Cursor, prev);
207 windowTimers.offset = (uint)&((Timer)0).prev;
209 for(c = 0; c<SystemCursor::enumSize; c++)
210 systemCursors[c] = Cursor { systemCursor = c; };
212 globalSystem.eventSemaphore = Semaphore { };
213 globalSystem.fileMonitorMutex = Mutex { };
214 globalSystem.fileMonitors.offset = (uint)&((FileMonitor)0).prev;
225 customCursors.Clear();
227 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
229 XUnlockDisplay(xGlobalDisplay);
232 #if !defined(__ANDROID__)
233 // Because destruction of app won't be from main thread
234 if(guiApplicationInitialized)
240 interfaceDriver.Terminate();
243 // interfaceDrivers.Free(null);
249 for(c = 0; c<SystemCursor::enumSize; c++)
250 delete systemCursors[c];
252 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
256 delete globalSystem.eventSemaphore;
257 delete globalSystem.fileMonitorMutex;
258 delete globalSystem.fileMonitorThread;
260 UnapplySkin(class(Window));
264 Timer timer, nextTimer;
265 for(timer = windowTimers.first; timer; timer = nextTimer)
267 nextTimer = timer.next;
276 Time time = GetTime();
279 for(timer = windowTimers.first; timer; timer = timer.next)
280 timer.dispatched = false;
283 for(timer = windowTimers.first; timer; timer = timer.next)
285 if(!timer.dispatched)
287 if((timer.delay - (Seconds)(time - timer.lastTime)) < Seconds { 0.00001 })
290 timer.lastTime = time;
291 if(timer.DelayExpired(timer.window))
293 timer.dispatched = true;
295 eInstance_DecRef(timer);
305 // --- Mouse-based window movement ---
306 void SetCurrentCursor(Window window, Cursor cursor)
308 currentCursor = cursor;
311 if(fullScreenMode && cursor.bitmap)
312 interfaceDriver.SetMouseCursor(window ? window : desktop, (SystemCursor)-1);
315 interfaceDriver.SetMouseCursor(window ? window : desktop, cursor.systemCursor);
316 cursorBackground.Free();
322 void PreserveAndDrawCursor()
325 if(!acquiredWindow && cursorUpdate && currentCursor && currentCursor->bitmap)
329 Box against = {0,0, desktop.w-1,desktop.h-1};
330 Box box = {0, 0, currentCursor->bitmap->width,currentCursor->bitmap->height};
332 interfaceDriver->GetMousePosition(&mouseX, &mouseY);
334 mouseX -= currentCursor->hotSpotX;
335 mouseY -= currentCursor->hotSpotY;
337 // Preserve Background
338 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
340 cursorBackgroundX = mouseX;
341 cursorBackgroundY = mouseY;
342 cursorBackgroundW = currentCursor->bitmap->width;
343 cursorBackgroundH = currentCursor->bitmap->height;
344 eDisplay_Grab(desktop.display, cursorBackground,
345 mouseX, mouseY, cursorBackgroundW, cursorBackgroundH);
348 eBox_ClipOffset(&box, &against, mouseX, mouseY);
350 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
351 eDisplay_StartUpdate(desktop.display);
353 surface = eDisplay_GetSurface(desktop.display, mouseX, mouseY, &box);
356 eSurface_SetForeground(surface, WHITE);
357 eSurface_Blit(surface, currentCursor->bitmap, 0,0, 0,0,
358 currentCursor->bitmap->width,currentCursor->bitmap->height);
359 eInstance_Delete(surface);
361 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
366 box.bottom += mouseY;
367 eDisplay_Update(desktop.display, &box);
370 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
371 eDisplay_EndUpdate(desktop.display);
376 void RestoreCursorBackground()
379 // Restore Cursor Background
380 if(cursorBackground && desktop.active)
382 Box box = {0, 0, cursorBackgroundW-1,cursorBackgroundH-1};
383 Box against = {0,0, desktop.w-1,desktop.h-1};
386 eBox_ClipOffset(&box, &against, cursorBackgroundX, cursorBackgroundY);
387 if((surface = eDisplay_GetSurface(desktop.display, cursorBackgroundX,cursorBackgroundY, &box)))
389 eSurface_Blit(surface, cursorBackground, 0, 0, 0,0, cursorBackgroundW,cursorBackgroundH);
390 eInstance_Delete(surface);
396 bool IsModeSwitching()
398 return modeSwitching;
401 public bool SetDesktopPosition(int x, int y, int w, int h, bool moveChildren)
404 bool windowResized = desktop.size.w != w || desktop.size.h != h;
405 bool windowMoved = desktop.clientStart.x != x || desktop.clientStart.y != y;
407 if((windowResized || windowMoved) && moveChildren)
410 desktop.Position(x, y, w, h, true, true, true, true, false, false);
412 // Maximized native decorations windows suffer when we drag the dock around, so remaximize them
413 // It's a little jumpy, but oh well.
415 // Made this Windows only as it was causing occasional wrong stacking of windows in X11/Cinnamon
416 // when switching debugged app from full-screen
418 for(child = desktop.children.first; child; child = child.next)
420 if(child.nativeDecorations && child.rootWindow == child && child.state == maximized)
422 #if defined(__WIN32__)
423 child.state = normal;
424 child.state = maximized;
428 child.state = normal;
429 child.state = maximized;
432 child.requireRemaximize = true;
436 /*for(child = desktop.children.first; child; child = child.next)
438 if(!child.systemParent)
443 child.ComputeAnchors(
444 child.ax, child.ay, child.aw, child.ah,
446 child.Position(x, y, w, h, true, true, true, true, false);
448 if(child.state == Maximized)
452 child.ComputeAnchors(,
453 A_LEFT,A_LEFT,A_OFFSET,A_OFFSET,
455 child.Position(, x, y, w, h, false, true, true, true, false);
461 desktop.display.Lock(true);
464 if(!desktop.display.Resize(desktop.size.w, desktop.size.h))
467 desktop.dirty = true;
468 if(!desktop.display.flags.flipping)
469 desktop.Update(null);
471 // When does the desktop have a display in not fullscreen mode?
472 if(!fullScreenMode && !modeSwitching)
473 desktop.UpdateDisplay();
474 desktop.display.Unlock();
478 desktop.SetPosition(x, y, w, h, false, false, false);
482 void SetAppFocus(bool state)
484 // Shouldn't be property here
485 desktop.active = state;
488 bool SelectSkin(char * skinName)
494 for(link = class(Skin).derivatives.first; link; link = link.next)
497 if(skin.name && !strcmp(skin.name, skinName))
500 if(!link) skin = null;
504 if(skin != currentSkin || !currentSkin)
506 // Try finding a driver to support this mode
507 if(skin.textMode != textMode)
513 bool needReload = false;
515 if(!modeSwitching && currentSkin)
517 modeSwitching = true;
518 desktop.UnloadGraphics(true);
522 UnapplySkin(class(Window));
526 ApplySkin(class(Window), skin.name, null);
530 if(desktop.SetupDisplay())
531 if(desktop.LoadGraphics(false, true))
533 modeSwitching = false;
545 void Initialize(bool switchMode)
548 // if(!initialized && eClass_IsDerived(__ecereModule->app->module.inst.class, guiApplicationClass))
549 if(!guiApplicationInitialized)
551 char * defaultDriver = null;
552 #if defined(ECERE_VANILLA) || defined(ECERE_ONEDRIVER)
553 char * driver = null;
556 // char * driver = getenv("ECERE_DRIVER");
557 char * driver = null;
558 static char driverStorage[1024];
559 GetEnvironment("ECERE_DRIVER", driverStorage, sizeof(driverStorage));
560 if(driverStorage[0]) driver = driverStorage;
562 guiApplicationInitialized = true;
564 fullScreenMode = true; // Needs to start at true for the desktop to resize
565 // Set this to true earlier so we can override it!
571 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
573 XLockDisplay(xGlobalDisplay);
579 desktop = Window { nativeDecorations = false };
582 desktop.childrenOrder.circ = true;
583 desktop.childrenCycle.circ = true;
584 desktop.background = blue;
585 desktop.rootWindow = desktop;
586 desktop.cursor = GetCursor(arrow);
587 desktop.caption = appName;
588 *&desktop.visible = true;
589 desktop.position = Point { };
590 desktop.mutex = Mutex { };
591 desktop.created = true;
594 #if defined(__WIN32__)
597 defaultDriver = driver;
598 else if((this.isGUIApp & 1) && !textMode)
599 defaultDriver = "GDI";
601 defaultDriver = "Win32Console";
603 #elif defined(__APPLE__)
606 defaultDriver = driver;
608 defaultDriver = "X"; //"CocoaOpenGL";
611 #elif defined(__ANDROID__)
614 defaultDriver = driver;
616 defaultDriver = "OpenGL";
619 if((this.isGUIApp & 1) && !textMode)
621 char * display = getenv("DISPLAY");
623 if(!display || !display[0] || !SwitchMode(false, "X", 0, 0, 0, null, true))
624 defaultDriver = "NCurses";
625 // SwitchMode(true, "NCurses", 0, PixelFormatText, 0, null, true);
629 defaultDriver = driver;
632 defaultDriver = "NCurses";
637 SwitchMode(false, defaultDriver, 0, 0, 0, null, true);
641 #if defined(__WIN32__)
642 SwitchMode(true, "Win32Console", 0, PixelFormatText, 0, null, true);
647 SwitchMode(true, "SVGA", Res640x480, PixelFormat8, 0, null, true);
650 #if defined(__APPLE__)
651 SwitchMode(true, "X" /*"CocoaOpenGL"*/, 0, 0, 0, null, true);
654 #if defined(__unix__)
655 #if defined(ECERE_MINIGLX)
656 SwitchMode(true, "OpenGL", 0, 0, 0, null, true);
661 guiApplicationInitialized = false;
664 defaultDisplayDriver = defaultDriver;
669 virtual bool Init(void);
670 virtual bool Cycle(bool idle);
671 virtual void Terminate(void);
681 // better solution when designing tab order/activated window etc, why do windows move in the list?
684 for(window = desktop.children.first; window; window = window.next)
686 if(window.autoCreate && !window.created)
701 while(desktop && interfaceDriver)
705 if(terminateX != terminated)
707 terminated = terminateX;
713 //printf("Resetting terminate X to 0\n");
717 for(child = desktop.children.first; child; child = child.next)
718 if(child.created && child.visible)
722 for(window = desktop.children.first; window; window = window.next)
723 if(window.mutex) window.mutex.Wait();
725 for(window = desktop.children.first; window; window = window.next)
726 if(window.mutex) window.mutex.Release();
727 wait = !ProcessInput(true);
729 if(lockMutex.owningThread != GetCurrentThreadID())
730 PrintLn("WARNING: ProcessInput returned unlocked GUI!");
739 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
741 XUnlockDisplay(xGlobalDisplay);
747 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
749 XLockDisplay(xGlobalDisplay);
753 eInstance_DecRef(desktop);
758 #if defined(__ANDROID__)
759 // Because destruction of GuiApp won't be from main thread
766 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
768 XUnlockDisplay(xGlobalDisplay);
776 interfaceDriver.Wait();
782 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
784 XLockDisplay(xGlobalDisplay);
788 bool ProcessInput(bool useProcessAll)
794 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
795 ProcessNetworkEvents();
799 result = interfaceDriver.ProcessInput(useProcessAll && processAll);
800 if(!desktop || !interfaceDriver) return;
804 for(child = app.desktop.children.first; child; child = child.next)
805 if(child.created && child.visible)
807 if(!child) return result;
810 result |= UpdateTimers();
811 result |= ProcessFileNotifications();
814 result |= ProcessFileNotifications();
815 result |= UpdateTimers();
816 result |= interfaceDriver.ProcessInput(useProcessAll && processAll);
823 void UpdateDisplay(void)
825 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
826 if(Desktop3DUpdateDisplay()) return;
831 if(fullScreenMode && desktop.display)
833 desktop.mutex.Wait();
836 desktop.display.Lock(true);
838 if(desktop.dirty || cursorUpdate)
840 if(desktop.display.flags.flipping)
841 desktop.Update(null);
842 desktop.UpdateDisplay();
845 if(cursorUpdate || desktop.dirty)
847 PreserveAndDrawCursor();
848 cursorUpdate = false;
849 desktop.dirty = false;
850 RestoreCursorBackground();
853 desktop.display.Unlock();
855 desktop.mutex.Release();
861 for(window = desktop.children.first; window; window = window.next)
863 if(window.mutex) window.mutex.Wait();
864 if(window.visible && window.dirty)
866 // Logf("Updating %s\n", window.name);
867 interfaceDriver.Lock(window);
870 if(window.display.current)
874 window.display.Lock(true);
875 window.UpdateDisplay();
876 window.display.Unlock();
879 window.dirty = false;
880 interfaceDriver.Unlock(window);
882 Log("--------------\n");
886 if(window.mutex) window.mutex.Release();
894 globalSystem.eventSemaphore.Wait();
897 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
898 bool ProcessNetworkEvents()
900 bool gotEvent = false;
901 #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
902 if(network.networkInitialized)
906 struct timeval tv = {0, 0};
911 PauseNetworkEvents();
912 network.mutex.Wait();
915 if(network.connectEvent || network.networkEvent)
916 Log("[P] [NProcess]\n");
918 rs = network.readSet;
919 ws = network.writeSet;
920 es = network.exceptSet;
922 if((network.ns && select(network.ns, &rs, &ws, &es, &tv)) || network.leftOverBytes)
924 network.leftOverBytes = false;
926 // Danger here? Why looping with a next and not unlocking anything?
927 for(socket = network.connectSockets.first; socket; socket = next)
930 if(!socket.processAlone && FD_ISSET(socket.s, &ws))
932 network.mutex.Release();
933 socket.connectThread.Wait();
934 network.mutex.Wait();
937 for(socket = network.sockets.first; socket; socket = next)
940 if(!socket.processAlone)
942 network.mutex.Release();
943 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
944 network.mutex.Wait();
948 for(service = network.services.first; service; service = nextService)
950 nextService = service.next;
951 if(!service.processAlone)
953 if(FD_ISSET(service.s, &rs))
956 Logf("[P] Accepting connection (%x)\n", service.s);
958 service.accepted = false;
960 if(!service.accepted)
964 int addrLen = sizeof(a);
965 s = accept(service.s,(SOCKADDR *)&a,&addrLen);
971 Log("[P] Connection accepted\n");
975 for(socket = service.sockets.first; socket; socket = next)
978 if(!socket.processAlone)
980 network.mutex.Release();
981 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
982 network.mutex.Wait();
987 if(network.connectEvent)
993 for(socket = network.connectSockets.first; socket; socket = next)
996 if(socket._connected && socket._connected != -2)
998 network.connectSockets.Remove(socket);
999 delete socket.connectThread;
1001 // printf("%s is connected = %d\n", socket._class.name, socket._connected);
1002 if(socket._connected == -1)
1004 #ifdef DEBUG_SOCKETS
1005 Logf("[P] Processing disconnected connect (%x)\n", socket.s);
1008 if(socket.disconnectCode == ResolveFailed)
1009 Logf("Error resolving address %s\n", socket.address);
1011 if(socket.s == network.ns - 1)
1012 Network_DetermineMaxSocket();
1017 else if(socket._connected == 1)
1019 #ifdef DEBUG_SOCKETS
1020 Log("[P] Processing connected connect\n");
1022 FD_CLR(socket.s, &network.writeSet);
1023 FD_SET(socket.s, &network.readSet);
1024 FD_SET(socket.s, &network.exceptSet);
1025 network.mutex.Release();
1027 // printf("Calling OnConnect on %s\n", socket._class.name);
1029 network.mutex.Wait();
1030 if(socket._connected)
1031 network.sockets.Add(socket);
1039 network.connectEvent = false;
1041 if(network.networkEvent)
1043 network.networkEvent = false;
1044 network.selectSemaphore.Release();
1049 for(semPtr = network.mtSemaphores.first; semPtr; semPtr = semPtr.next)
1051 ((Semaphore)semPtr.data).Release();
1055 network.mutex.Release();
1056 ResumeNetworkEvents();
1062 void WaitNetworkEvent()
1064 if(network.networkInitialized)
1066 if(GetCurrentThreadID() == network.mainThreadID)
1072 Semaphore semaphore { };
1073 OldLink semPtr { data = semaphore };
1074 network.mutex.Wait();
1075 network.mtSemaphores.Add(semPtr);
1076 network.mutex.Release();
1078 ResumeNetworkEvents();
1080 PauseNetworkEvents();
1081 network.mutex.Wait();
1082 network.mtSemaphores.Delete(semPtr);
1083 network.mutex.Release();
1089 void PauseNetworkEvents()
1091 if(network.networkInitialized)
1093 network.processMutex.Wait();
1097 void ResumeNetworkEvents()
1099 if(network.networkInitialized)
1101 network.processMutex.Release();
1106 void SignalEvent(void)
1108 globalSystem.eventSemaphore.Release();
1111 // TODO: Might want to make this private with simpler public version?
1112 bool SwitchMode(bool fullScreen, char * driverName, Resolution resolution, PixelFormat colorDepth, int refreshRate, char * skinName, bool fallBack)
1114 bool result = false;
1117 bool fbFullScreen = 0;
1118 Resolution fbResolution = 0;
1119 PixelFormat fbColorDepth = 0;
1120 int fbRefreshRate = 0;
1121 subclass(Interface) inter;
1122 subclass(Skin) skin = null;
1128 for(link = class(Skin).derivatives.first; link; link = link.next)
1131 if(skin.name && !strcmp(skin.name, skinName))
1134 if(!link) skin = null;
1139 fbDriver = defaultDisplayDriver;
1140 inter = interfaceDriver;
1143 interfaceDriver.GetCurrentMode(&fbFullScreen, &fbResolution, &fbColorDepth, &fbRefreshRate);
1145 if(!driverName && !interfaceDriver)
1146 driverName = defaultDisplayDriver;
1148 if(driverName || (skin && skin.textMode != textMode))
1150 for(link = class(Interface).derivatives.first; link; link = link.next)
1152 bool foundDriver = false;
1154 char ** graphicsDrivers;
1157 graphicsDrivers = inter.GraphicsDrivers(&numDrivers);
1159 for(c=0; c<numDrivers; c++)
1160 if(!driverName || !strcmp(driverName, graphicsDrivers[c]))
1162 if(!skin || skin.textMode == IsDriverTextMode(graphicsDrivers[c]))
1164 driverName = graphicsDrivers[c];
1179 #if defined(__WIN32__)
1180 #if !defined(ECERE_VANILLA)
1181 if(!strcmp(driverName, "Win32Console")) inter = (subclass(Interface))class(Win32ConsoleInterface); else
1183 inter = (subclass(Interface))class(Win32Interface);
1185 if(!strcmp(driverName, "X")) inter = (subclass(Interface))class(XInterface);
1186 else inter = (subclass(Interface))class(NCursesInterface);
1191 if(interfaceDriver && (!driverName || (fbDriver && !strcmp(fbDriver, driverName))) &&
1192 fullScreen == fbFullScreen &&
1193 (!resolution || resolution == fbResolution) &&
1194 (!colorDepth || colorDepth == fbColorDepth) &&
1195 (!refreshRate || refreshRate == fbRefreshRate) &&
1196 (currentSkin && (!skinName || !strcmp(currentSkin.name, skinName))))
1200 bool wasFullScreen = fullScreenMode;
1201 subclass(Skin) oldSkin = currentSkin;
1204 modeSwitching = true;
1207 desktop.UnloadGraphics(true);
1209 if(inter != interfaceDriver)
1213 interfaceDriver.Terminate();
1215 result = inter.Initialize();
1223 interfaceDriver = inter;
1224 interfaceDriver.SetTimerResolution(timerResolution);
1225 inter.EnsureFullScreen(&fullScreen);
1226 fullScreenMode = fullScreen;
1228 if((!wasFullScreen && !fullScreen) ||
1229 inter.ScreenMode(fullScreen, resolution, colorDepth, refreshRate, &textMode))
1231 if(!fbDriver || (driverName && strcmp(fbDriver, driverName)))
1232 defaultDisplayDriver = driverName;
1234 if(!skinName || !SelectSkin(skinName))
1236 if(!currentSkin || currentSkin.textMode != textMode ||
1237 !SelectSkin(currentSkin.name))
1240 subclass(Skin) skin = null;
1242 for(link = class(Skin).derivatives.first; link; link = link.next)
1245 if(skin.textMode == textMode)
1248 if(!link) skin = null;
1251 #if !defined(__ANDROID__)
1252 SelectSkin(skin.name);
1259 if(currentSkin && desktop.SetupDisplay())
1261 desktop.active = true;
1265 desktop.display.Lock(false);
1266 desktop.display.Position(0,0);
1267 desktop.display.Unlock();
1270 if(desktop.LoadGraphics(false, oldSkin != currentSkin))
1274 desktop.UpdateDisplay();
1277 this.fullScreen = fullScreen;
1283 modeSwitching = false;
1285 LogErrorCode(modeSwitchFailed, driverName ? driverName : defaultDisplayDriver);
1288 LogErrorCode(driverNotSupported, driverName ? driverName : defaultDisplayDriver);
1290 if(!result && fallBack && fbDriver)
1292 if(!SwitchMode(fbFullScreen, fbDriver, fbResolution, fbColorDepth, fbRefreshRate, null, false))
1293 Log($"Error falling back to previous video mode.\n");
1298 bool ProcessFileNotifications()
1300 bool activity = false;
1301 FileMonitor monitor, next;
1302 static int reentrant = 0;
1304 // Reentrant FileNotification is asking for trouble since each monitor is spawning a Modal() MessageBox
1305 if(reentrant) return false;
1306 // printf("[%d] Waiting in ProcessFileNotifications for fileMonitor Mutex %x...\n", (int)GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1307 globalSystem.fileMonitorMutex.Wait();
1309 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1313 next = monitor.next;
1318 if(!monitor.reentrant && !monitor.toBeFreed)
1320 monitor.reentrant = true;
1321 while((notify = monitor.fileNotifies.first))
1323 monitor.fileNotifies.Remove(notify);
1327 if(monitor.directory)
1329 if(!monitor.OnDirNotify(monitor.data, notify.action, notify.fileName, notify.param))
1330 monitor.StopMonitoring();
1334 if(!monitor.OnFileNotify(monitor.data, notify.action, notify.param))
1335 monitor.StopMonitoring();
1338 monitor.reentrant = false;
1344 monitor.reentrant = false;
1347 if(next && next._refCount > 1)
1355 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1357 next = monitor.next;
1358 if(monitor.toBeFreed && !monitor.reentrant)
1359 monitor.FreeMonitor();
1362 // printf("[%d] Releasing in ProcessFileNotifications fileMonitor Mutex %x...\n", (int)GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1363 globalSystem.fileMonitorMutex.Release();
1370 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
1372 XLockDisplay(xGlobalDisplay);
1378 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
1380 XUnlockDisplay(xGlobalDisplay);
1382 lockMutex.Release();
1385 Cursor GetCursor(SystemCursor cursor)
1387 return systemCursors[cursor];
1390 bool GetKeyState(Key key)
1392 return interfaceDriver.GetKeyState(key);
1395 bool GetMouseState(MouseButtons * buttons, int * x, int * y)
1397 return interfaceDriver.GetMouseState(buttons, x, y);
1401 property char * appName
1405 strcpy(appName, value);
1406 if(desktop) desktop.text = appName;
1410 return (char *)(this ? appName : null);
1413 property Semaphore semaphore { get { return globalSystem.eventSemaphore; } };
1414 property bool alwaysEmptyInput{ set { processAll = value; } get { return processAll; } };
1415 property bool fullScreen
1419 SwitchMode(value, defaultDisplayDriver, resolution,
1420 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1422 get { return this ? fullScreen : false; }
1424 property char * driver
1428 SwitchMode( fullScreen, value, resolution, pixelFormat, refreshRate,
1429 currentSkin ? currentSkin.name : null, true);
1431 get { return this ? defaultDisplayDriver : null; }
1433 property Resolution resolution
1437 SwitchMode(fullScreen, defaultDisplayDriver, value, pixelFormat, refreshRate,
1438 currentSkin ? currentSkin.name : null, true);
1440 get { return this ? resolution : 0; }
1442 property PixelFormat pixelFormat
1446 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1447 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1449 get { return this ? pixelFormat : 0; }
1451 property int refreshRate
1455 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1456 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1458 get { return this ? refreshRate : 0; }
1460 property char * skin
1462 set { SelectSkin(value); }
1463 get { return (this && currentSkin) ? currentSkin.name : null; }
1465 property bool textMode
1467 set { textMode = value; } // TODO: Implement switching
1468 get { return this ? textMode : false; }
1470 property Window desktop { get { return this ? desktop : null; } };
1471 property char ** drivers { get { return null; } };
1472 property char ** skins { get { return null; } };
1473 property subclass(Skin) currentSkin { get { return this ? currentSkin : null; } };
1474 property int numDrivers { get { return 0; } };
1475 property int numSkins { get { return 0; } };
1476 property uint timerResolution
1478 set { timerResolution = value; if(interfaceDriver) interfaceDriver.SetTimerResolution(value); }