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.
414 for(child = desktop.children.first; child; child = child.next)
416 if(child.nativeDecorations && child.rootWindow == child && child.state == maximized)
418 child.state = normal;
419 child.state = maximized;
422 /*for(child = desktop.children.first; child; child = child.next)
424 if(!child.systemParent)
429 child.ComputeAnchors(
430 child.ax, child.ay, child.aw, child.ah,
432 child.Position(x, y, w, h, true, true, true, true, false);
434 if(child.state == Maximized)
438 child.ComputeAnchors(,
439 A_LEFT,A_LEFT,A_OFFSET,A_OFFSET,
441 child.Position(, x, y, w, h, false, true, true, true, false);
447 desktop.display.Lock(true);
450 if(!desktop.display.Resize(desktop.size.w, desktop.size.h))
453 desktop.dirty = true;
454 if(!desktop.display.flags.flipping)
455 desktop.Update(null);
457 // When does the desktop have a display in not fullscreen mode?
458 if(!fullScreenMode && !modeSwitching)
459 desktop.UpdateDisplay();
460 desktop.display.Unlock();
464 desktop.SetPosition(x, y, w, h, false, false, false);
468 void SetAppFocus(bool state)
470 // Shouldn't be property here
471 desktop.active = state;
474 bool SelectSkin(char * skinName)
480 for(link = class(Skin).derivatives.first; link; link = link.next)
483 if(skin.name && !strcmp(skin.name, skinName))
486 if(!link) skin = null;
490 if(skin != currentSkin || !currentSkin)
492 // Try finding a driver to support this mode
493 if(skin.textMode != textMode)
499 bool needReload = false;
501 if(!modeSwitching && currentSkin)
503 modeSwitching = true;
504 desktop.UnloadGraphics(true);
508 UnapplySkin(class(Window));
512 ApplySkin(class(Window), skin.name, null);
516 if(desktop.SetupDisplay())
517 if(desktop.LoadGraphics(false, true))
519 modeSwitching = false;
531 void Initialize(bool switchMode)
534 // if(!initialized && eClass_IsDerived(__ecereModule->app->module.inst.class, guiApplicationClass))
535 if(!guiApplicationInitialized)
537 char * defaultDriver = null;
538 #if defined(ECERE_VANILLA) || defined(ECERE_ONEDRIVER)
539 char * driver = null;
542 // char * driver = getenv("ECERE_DRIVER");
543 char * driver = null;
544 static char driverStorage[1024];
545 GetEnvironment("ECERE_DRIVER", driverStorage, sizeof(driverStorage));
546 if(driverStorage[0]) driver = driverStorage;
548 guiApplicationInitialized = true;
550 fullScreenMode = true; // Needs to start at true for the desktop to resize
551 // Set this to true earlier so we can override it!
557 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
559 XLockDisplay(xGlobalDisplay);
565 desktop = Window { nativeDecorations = false };
568 desktop.childrenOrder.circ = true;
569 desktop.childrenCycle.circ = true;
570 desktop.background = blue;
571 desktop.rootWindow = desktop;
572 desktop.cursor = GetCursor(arrow);
573 desktop.caption = appName;
574 *&desktop.visible = true;
575 desktop.position = Point { };
576 desktop.mutex = Mutex { };
577 desktop.created = true;
580 #if defined(__WIN32__)
583 defaultDriver = driver;
584 else if((this.isGUIApp & 1) && !textMode)
585 defaultDriver = "GDI";
587 defaultDriver = "Win32Console";
589 #elif defined(__APPLE__)
592 defaultDriver = driver;
594 defaultDriver = "X"; //"CocoaOpenGL";
597 #elif defined(__ANDROID__)
600 defaultDriver = driver;
602 defaultDriver = "OpenGL";
605 if((this.isGUIApp & 1) && !textMode)
607 char * display = getenv("DISPLAY");
609 if(!display || !display[0] || !SwitchMode(false, "X", 0, 0, 0, null, true))
610 defaultDriver = "NCurses";
611 // SwitchMode(true, "NCurses", 0, PixelFormatText, 0, null, true);
615 defaultDriver = driver;
618 defaultDriver = "NCurses";
623 SwitchMode(false, defaultDriver, 0, 0, 0, null, true);
627 #if defined(__WIN32__)
628 SwitchMode(true, "Win32Console", 0, PixelFormatText, 0, null, true);
633 SwitchMode(true, "SVGA", Res640x480, PixelFormat8, 0, null, true);
636 #if defined(__APPLE__)
637 SwitchMode(true, "X" /*"CocoaOpenGL"*/, 0, 0, 0, null, true);
640 #if defined(__unix__)
641 #if defined(ECERE_MINIGLX)
642 SwitchMode(true, "OpenGL", 0, 0, 0, null, true);
647 guiApplicationInitialized = false;
650 defaultDisplayDriver = defaultDriver;
655 virtual bool Init(void);
656 virtual bool Cycle(bool idle);
657 virtual void Terminate(void);
667 // better solution when designing tab order/activated window etc, why do windows move in the list?
670 for(window = desktop.children.first; window; window = window.next)
672 if(window.autoCreate && !window.created)
687 while(desktop && interfaceDriver)
691 if(terminateX != terminated)
693 terminated = terminateX;
699 //printf("Resetting terminate X to 0\n");
703 for(child = desktop.children.first; child; child = child.next)
704 if(child.created && child.visible)
708 for(window = desktop.children.first; window; window = window.next)
709 if(window.mutex) window.mutex.Wait();
711 for(window = desktop.children.first; window; window = window.next)
712 if(window.mutex) window.mutex.Release();
713 wait = !ProcessInput(true);
715 if(lockMutex.owningThread != GetCurrentThreadID())
716 PrintLn("WARNING: ProcessInput returned unlocked GUI!");
725 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
727 XUnlockDisplay(xGlobalDisplay);
733 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
735 XLockDisplay(xGlobalDisplay);
739 eInstance_DecRef(desktop);
744 #if defined(__ANDROID__)
745 // Because destruction of GuiApp won't be from main thread
752 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
754 XUnlockDisplay(xGlobalDisplay);
762 interfaceDriver.Wait();
768 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
770 XLockDisplay(xGlobalDisplay);
774 bool ProcessInput(bool useProcessAll)
780 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
781 ProcessNetworkEvents();
785 result = interfaceDriver.ProcessInput(useProcessAll && processAll);
786 if(!desktop || !interfaceDriver) return;
790 for(child = app.desktop.children.first; child; child = child.next)
791 if(child.created && child.visible)
793 if(!child) return result;
796 result |= UpdateTimers();
797 result |= ProcessFileNotifications();
800 result |= ProcessFileNotifications();
801 result |= UpdateTimers();
802 result |= interfaceDriver.ProcessInput(useProcessAll && processAll);
809 void UpdateDisplay(void)
811 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
812 if(Desktop3DUpdateDisplay()) return;
817 if(fullScreenMode && desktop.display)
819 desktop.mutex.Wait();
822 desktop.display.Lock(true);
824 if(desktop.dirty || cursorUpdate)
826 if(desktop.display.flags.flipping)
827 desktop.Update(null);
828 desktop.UpdateDisplay();
831 if(cursorUpdate || desktop.dirty)
833 PreserveAndDrawCursor();
834 cursorUpdate = false;
835 desktop.dirty = false;
836 RestoreCursorBackground();
839 desktop.display.Unlock();
841 desktop.mutex.Release();
847 for(window = desktop.children.first; window; window = window.next)
849 if(window.mutex) window.mutex.Wait();
850 if(window.visible && window.dirty)
852 // Logf("Updating %s\n", window.name);
853 interfaceDriver.Lock(window);
856 if(window.display.current)
860 window.display.Lock(true);
861 window.UpdateDisplay();
862 window.display.Unlock();
865 window.dirty = false;
866 interfaceDriver.Unlock(window);
868 Log("--------------\n");
872 if(window.mutex) window.mutex.Release();
880 globalSystem.eventSemaphore.Wait();
883 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
884 bool ProcessNetworkEvents()
886 bool gotEvent = false;
887 #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
888 if(network.networkInitialized)
892 struct timeval tv = {0, 0};
897 PauseNetworkEvents();
898 network.mutex.Wait();
901 if(network.connectEvent || network.networkEvent)
902 Log("[P] [NProcess]\n");
904 rs = network.readSet;
905 ws = network.writeSet;
906 es = network.exceptSet;
908 if((network.ns && select(network.ns, &rs, &ws, &es, &tv)) || network.leftOverBytes)
910 network.leftOverBytes = false;
912 // Danger here? Why looping with a next and not unlocking anything?
913 for(socket = network.connectSockets.first; socket; socket = next)
916 if(!socket.processAlone && FD_ISSET(socket.s, &ws))
918 network.mutex.Release();
919 socket.connectThread.Wait();
920 network.mutex.Wait();
923 for(socket = network.sockets.first; socket; socket = next)
926 if(!socket.processAlone)
928 network.mutex.Release();
929 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
930 network.mutex.Wait();
934 for(service = network.services.first; service; service = nextService)
936 nextService = service.next;
937 if(!service.processAlone)
939 if(FD_ISSET(service.s, &rs))
942 Logf("[P] Accepting connection (%x)\n", service.s);
944 service.accepted = false;
946 if(!service.accepted)
950 int addrLen = sizeof(a);
951 s = accept(service.s,(SOCKADDR *)&a,&addrLen);
957 Log("[P] Connection accepted\n");
961 for(socket = service.sockets.first; socket; socket = next)
964 if(!socket.processAlone)
966 network.mutex.Release();
967 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
968 network.mutex.Wait();
973 if(network.connectEvent)
979 for(socket = network.connectSockets.first; socket; socket = next)
982 if(socket._connected && socket._connected != -2)
984 network.connectSockets.Remove(socket);
985 delete socket.connectThread;
987 // printf("%s is connected = %d\n", socket._class.name, socket._connected);
988 if(socket._connected == -1)
991 Logf("[P] Processing disconnected connect (%x)\n", socket.s);
994 if(socket.disconnectCode == ResolveFailed)
995 Logf("Error resolving address %s\n", socket.address);
997 if(socket.s == network.ns - 1)
998 Network_DetermineMaxSocket();
1003 else if(socket._connected == 1)
1005 #ifdef DEBUG_SOCKETS
1006 Log("[P] Processing connected connect\n");
1008 FD_CLR(socket.s, &network.writeSet);
1009 FD_SET(socket.s, &network.readSet);
1010 FD_SET(socket.s, &network.exceptSet);
1011 network.mutex.Release();
1013 // printf("Calling OnConnect on %s\n", socket._class.name);
1015 network.mutex.Wait();
1016 if(socket._connected)
1017 network.sockets.Add(socket);
1025 network.connectEvent = false;
1027 if(network.networkEvent)
1029 network.networkEvent = false;
1030 network.selectSemaphore.Release();
1035 for(semPtr = network.mtSemaphores.first; semPtr; semPtr = semPtr.next)
1037 ((Semaphore)semPtr.data).Release();
1041 network.mutex.Release();
1042 ResumeNetworkEvents();
1048 void WaitNetworkEvent()
1050 if(network.networkInitialized)
1052 if(GetCurrentThreadID() == network.mainThreadID)
1058 Semaphore semaphore { };
1059 OldLink semPtr { data = semaphore };
1060 network.mutex.Wait();
1061 network.mtSemaphores.Add(semPtr);
1062 network.mutex.Release();
1064 ResumeNetworkEvents();
1066 PauseNetworkEvents();
1067 network.mutex.Wait();
1068 network.mtSemaphores.Delete(semPtr);
1069 network.mutex.Release();
1075 void PauseNetworkEvents()
1077 if(network.networkInitialized)
1079 network.processMutex.Wait();
1083 void ResumeNetworkEvents()
1085 if(network.networkInitialized)
1087 network.processMutex.Release();
1092 void SignalEvent(void)
1094 globalSystem.eventSemaphore.Release();
1097 // TODO: Might want to make this private with simpler public version?
1098 bool SwitchMode(bool fullScreen, char * driverName, Resolution resolution, PixelFormat colorDepth, int refreshRate, char * skinName, bool fallBack)
1100 bool result = false;
1103 bool fbFullScreen = 0;
1104 Resolution fbResolution = 0;
1105 PixelFormat fbColorDepth = 0;
1106 int fbRefreshRate = 0;
1107 subclass(Interface) inter;
1108 subclass(Skin) skin = null;
1114 for(link = class(Skin).derivatives.first; link; link = link.next)
1117 if(skin.name && !strcmp(skin.name, skinName))
1120 if(!link) skin = null;
1125 fbDriver = defaultDisplayDriver;
1126 inter = interfaceDriver;
1129 interfaceDriver.GetCurrentMode(&fbFullScreen, &fbResolution, &fbColorDepth, &fbRefreshRate);
1131 if(!driverName && !interfaceDriver)
1132 driverName = defaultDisplayDriver;
1134 if(driverName || (skin && skin.textMode != textMode))
1136 for(link = class(Interface).derivatives.first; link; link = link.next)
1138 bool foundDriver = false;
1140 char ** graphicsDrivers;
1143 graphicsDrivers = inter.GraphicsDrivers(&numDrivers);
1145 for(c=0; c<numDrivers; c++)
1146 if(!driverName || !strcmp(driverName, graphicsDrivers[c]))
1148 if(!skin || skin.textMode == IsDriverTextMode(graphicsDrivers[c]))
1150 driverName = graphicsDrivers[c];
1165 #if defined(__WIN32__)
1166 #if !defined(ECERE_VANILLA)
1167 if(!strcmp(driverName, "Win32Console")) inter = (subclass(Interface))class(Win32ConsoleInterface); else
1169 inter = (subclass(Interface))class(Win32Interface);
1171 if(!strcmp(driverName, "X")) inter = (subclass(Interface))class(XInterface);
1172 else inter = (subclass(Interface))class(NCursesInterface);
1177 if(interfaceDriver && (!driverName || (fbDriver && !strcmp(fbDriver, driverName))) &&
1178 fullScreen == fbFullScreen &&
1179 (!resolution || resolution == fbResolution) &&
1180 (!colorDepth || colorDepth == fbColorDepth) &&
1181 (!refreshRate || refreshRate == fbRefreshRate) &&
1182 (currentSkin && (!skinName || !strcmp(currentSkin.name, skinName))))
1186 bool wasFullScreen = fullScreenMode;
1187 subclass(Skin) oldSkin = currentSkin;
1190 modeSwitching = true;
1193 desktop.UnloadGraphics(true);
1195 if(inter != interfaceDriver)
1199 interfaceDriver.Terminate();
1201 result = inter.Initialize();
1209 interfaceDriver = inter;
1210 interfaceDriver.SetTimerResolution(timerResolution);
1211 inter.EnsureFullScreen(&fullScreen);
1212 fullScreenMode = fullScreen;
1214 if((!wasFullScreen && !fullScreen) ||
1215 inter.ScreenMode(fullScreen, resolution, colorDepth, refreshRate, &textMode))
1217 if(!fbDriver || (driverName && strcmp(fbDriver, driverName)))
1218 defaultDisplayDriver = driverName;
1220 if(!skinName || !SelectSkin(skinName))
1222 if(!currentSkin || currentSkin.textMode != textMode ||
1223 !SelectSkin(currentSkin.name))
1226 subclass(Skin) skin = null;
1228 for(link = class(Skin).derivatives.first; link; link = link.next)
1231 if(skin.textMode == textMode)
1234 if(!link) skin = null;
1237 #if !defined(__ANDROID__)
1238 SelectSkin(skin.name);
1245 if(currentSkin && desktop.SetupDisplay())
1247 desktop.active = true;
1251 desktop.display.Lock(false);
1252 desktop.display.Position(0,0);
1253 desktop.display.Unlock();
1256 if(desktop.LoadGraphics(false, oldSkin != currentSkin))
1260 desktop.UpdateDisplay();
1263 this.fullScreen = fullScreen;
1269 modeSwitching = false;
1271 LogErrorCode(modeSwitchFailed, driverName ? driverName : defaultDisplayDriver);
1274 LogErrorCode(driverNotSupported, driverName ? driverName : defaultDisplayDriver);
1276 if(!result && fallBack && fbDriver)
1278 if(!SwitchMode(fbFullScreen, fbDriver, fbResolution, fbColorDepth, fbRefreshRate, null, false))
1279 Log($"Error falling back to previous video mode.\n");
1284 bool ProcessFileNotifications()
1286 bool activity = false;
1287 FileMonitor monitor, next;
1288 static int reentrant = 0;
1290 // Reentrant FileNotification is asking for trouble since each monitor is spawning a Modal() MessageBox
1291 if(reentrant) return false;
1292 // printf("[%d] Waiting in ProcessFileNotifications for fileMonitor Mutex %x...\n", (int)GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1293 globalSystem.fileMonitorMutex.Wait();
1295 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1299 next = monitor.next;
1304 if(!monitor.reentrant && !monitor.toBeFreed)
1306 monitor.reentrant = true;
1307 while((notify = monitor.fileNotifies.first))
1309 monitor.fileNotifies.Remove(notify);
1313 if(monitor.directory)
1315 if(!monitor.OnDirNotify(monitor.data, notify.action, notify.fileName, notify.param))
1316 monitor.StopMonitoring();
1320 if(!monitor.OnFileNotify(monitor.data, notify.action, notify.param))
1321 monitor.StopMonitoring();
1324 monitor.reentrant = false;
1330 monitor.reentrant = false;
1333 if(next && next._refCount > 1)
1341 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1343 next = monitor.next;
1344 if(monitor.toBeFreed && !monitor.reentrant)
1345 monitor.FreeMonitor();
1348 // printf("[%d] Releasing in ProcessFileNotifications fileMonitor Mutex %x...\n", (int)GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1349 globalSystem.fileMonitorMutex.Release();
1356 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
1358 XLockDisplay(xGlobalDisplay);
1364 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
1366 XUnlockDisplay(xGlobalDisplay);
1368 lockMutex.Release();
1371 Cursor GetCursor(SystemCursor cursor)
1373 return systemCursors[cursor];
1376 bool GetKeyState(Key key)
1378 return interfaceDriver.GetKeyState(key);
1381 bool GetMouseState(MouseButtons * buttons, int * x, int * y)
1383 return interfaceDriver.GetMouseState(buttons, x, y);
1387 property char * appName
1391 strcpy(appName, value);
1392 if(desktop) desktop.text = appName;
1396 return (char *)(this ? appName : null);
1399 property Semaphore semaphore { get { return globalSystem.eventSemaphore; } };
1400 property bool alwaysEmptyInput{ set { processAll = value; } get { return processAll; } };
1401 property bool fullScreen
1405 SwitchMode(value, defaultDisplayDriver, resolution,
1406 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1408 get { return this ? fullScreen : false; }
1410 property char * driver
1414 SwitchMode( fullScreen, value, resolution, pixelFormat, refreshRate,
1415 currentSkin ? currentSkin.name : null, true);
1417 get { return this ? defaultDisplayDriver : null; }
1419 property Resolution resolution
1423 SwitchMode(fullScreen, defaultDisplayDriver, value, pixelFormat, refreshRate,
1424 currentSkin ? currentSkin.name : null, true);
1426 get { return this ? resolution : 0; }
1428 property PixelFormat pixelFormat
1432 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1433 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1435 get { return this ? pixelFormat : 0; }
1437 property int refreshRate
1441 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1442 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1444 get { return this ? refreshRate : 0; }
1446 property char * skin
1448 set { SelectSkin(value); }
1449 get { return (this && currentSkin) ? currentSkin.name : null; }
1451 property bool textMode
1453 set { textMode = value; } // TODO: Implement switching
1454 get { return this ? textMode : false; }
1456 property Window desktop { get { return this ? desktop : null; } };
1457 property char ** drivers { get { return null; } };
1458 property char ** skins { get { return null; } };
1459 property subclass(Skin) currentSkin { get { return this ? currentSkin : null; } };
1460 property int numDrivers { get { return 0; } };
1461 property int numSkins { get { return 0; } };
1462 property uint timerResolution
1464 set { timerResolution = value; if(interfaceDriver) interfaceDriver.SetTimerResolution(value); }