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)
686 while(desktop && interfaceDriver)
690 if(terminateX != terminated)
692 terminated = terminateX;
698 //printf("Resetting terminate X to 0\n");
702 for(child = desktop.children.first; child; child = child.next)
703 if(child.created && child.visible)
707 for(window = desktop.children.first; window; window = window.next)
708 if(window.mutex) window.mutex.Wait();
710 for(window = desktop.children.first; window; window = window.next)
711 if(window.mutex) window.mutex.Release();
712 wait = !ProcessInput(true);
714 if(lockMutex.owningThread != GetCurrentThreadID())
715 PrintLn("WARNING: ProcessInput returned unlocked GUI!");
724 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
726 XUnlockDisplay(xGlobalDisplay);
732 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
734 XLockDisplay(xGlobalDisplay);
738 eInstance_DecRef(desktop);
743 #if defined(__ANDROID__)
744 // Because destruction of GuiApp won't be from main thread
751 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
753 XUnlockDisplay(xGlobalDisplay);
761 interfaceDriver.Wait();
767 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
769 XLockDisplay(xGlobalDisplay);
773 bool ProcessInput(bool useProcessAll)
779 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
780 ProcessNetworkEvents();
784 result = interfaceDriver.ProcessInput(useProcessAll && processAll);
785 if(!desktop || !interfaceDriver) return;
789 for(child = app.desktop.children.first; child; child = child.next)
790 if(child.created && child.visible)
792 if(!child) return result;
795 result |= UpdateTimers();
796 result |= ProcessFileNotifications();
799 result |= ProcessFileNotifications();
800 result |= UpdateTimers();
801 result |= interfaceDriver.ProcessInput(useProcessAll && processAll);
808 void UpdateDisplay(void)
810 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
811 if(Desktop3DUpdateDisplay()) return;
816 if(fullScreenMode && desktop.display)
818 desktop.mutex.Wait();
821 desktop.display.Lock(true);
823 if(desktop.dirty || cursorUpdate)
825 if(desktop.display.flags.flipping)
826 desktop.Update(null);
827 desktop.UpdateDisplay();
830 if(cursorUpdate || desktop.dirty)
832 PreserveAndDrawCursor();
833 cursorUpdate = false;
834 desktop.dirty = false;
835 RestoreCursorBackground();
838 desktop.display.Unlock();
840 desktop.mutex.Release();
846 for(window = desktop.children.first; window; window = window.next)
848 if(window.mutex) window.mutex.Wait();
849 if(window.visible && window.dirty)
851 // Logf("Updating %s\n", window.name);
852 interfaceDriver.Lock(window);
855 if(window.display.current)
859 window.display.Lock(true);
860 window.UpdateDisplay();
861 window.display.Unlock();
864 window.dirty = false;
865 interfaceDriver.Unlock(window);
867 Log("--------------\n");
871 if(window.mutex) window.mutex.Release();
879 globalSystem.eventSemaphore.Wait();
882 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
883 bool ProcessNetworkEvents()
885 bool gotEvent = false;
886 #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
887 if(network.networkInitialized)
891 struct timeval tv = {0, 0};
896 PauseNetworkEvents();
897 network.mutex.Wait();
900 if(network.connectEvent || network.networkEvent)
901 Log("[P] [NProcess]\n");
903 rs = network.readSet;
904 ws = network.writeSet;
905 es = network.exceptSet;
907 if((network.ns && select(network.ns, &rs, &ws, &es, &tv)) || network.leftOverBytes)
909 network.leftOverBytes = false;
911 // Danger here? Why looping with a next and not unlocking anything?
912 for(socket = network.connectSockets.first; socket; socket = next)
915 if(!socket.processAlone && FD_ISSET(socket.s, &ws))
917 network.mutex.Release();
918 socket.connectThread.Wait();
919 network.mutex.Wait();
922 for(socket = network.sockets.first; socket; socket = next)
925 if(!socket.processAlone)
927 network.mutex.Release();
928 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
929 network.mutex.Wait();
933 for(service = network.services.first; service; service = nextService)
935 nextService = service.next;
936 if(!service.processAlone)
938 if(FD_ISSET(service.s, &rs))
941 Logf("[P] Accepting connection (%x)\n", service.s);
943 service.accepted = false;
945 if(!service.accepted)
949 int addrLen = sizeof(a);
950 s = accept(service.s,(SOCKADDR *)&a,&addrLen);
956 Log("[P] Connection accepted\n");
960 for(socket = service.sockets.first; socket; socket = next)
963 if(!socket.processAlone)
965 network.mutex.Release();
966 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
967 network.mutex.Wait();
972 if(network.connectEvent)
978 for(socket = network.connectSockets.first; socket; socket = next)
981 if(socket._connected && socket._connected != -2)
983 network.connectSockets.Remove(socket);
984 delete socket.connectThread;
986 // printf("%s is connected = %d\n", socket._class.name, socket._connected);
987 if(socket._connected == -1)
990 Logf("[P] Processing disconnected connect (%x)\n", socket.s);
993 if(socket.disconnectCode == ResolveFailed)
994 Logf("Error resolving address %s\n", socket.address);
996 if(socket.s == network.ns - 1)
997 Network_DetermineMaxSocket();
1002 else if(socket._connected == 1)
1004 #ifdef DEBUG_SOCKETS
1005 Log("[P] Processing connected connect\n");
1007 FD_CLR(socket.s, &network.writeSet);
1008 FD_SET(socket.s, &network.readSet);
1009 FD_SET(socket.s, &network.exceptSet);
1010 network.mutex.Release();
1012 // printf("Calling OnConnect on %s\n", socket._class.name);
1014 network.mutex.Wait();
1015 if(socket._connected)
1016 network.sockets.Add(socket);
1024 network.connectEvent = false;
1026 if(network.networkEvent)
1028 network.networkEvent = false;
1029 network.selectSemaphore.Release();
1034 for(semPtr = network.mtSemaphores.first; semPtr; semPtr = semPtr.next)
1036 ((Semaphore)semPtr.data).Release();
1040 network.mutex.Release();
1041 ResumeNetworkEvents();
1047 void WaitNetworkEvent()
1049 if(network.networkInitialized)
1051 if(GetCurrentThreadID() == network.mainThreadID)
1057 Semaphore semaphore { };
1058 OldLink semPtr { data = semaphore };
1059 network.mutex.Wait();
1060 network.mtSemaphores.Add(semPtr);
1061 network.mutex.Release();
1063 ResumeNetworkEvents();
1065 PauseNetworkEvents();
1066 network.mutex.Wait();
1067 network.mtSemaphores.Delete(semPtr);
1068 network.mutex.Release();
1074 void PauseNetworkEvents()
1076 if(network.networkInitialized)
1078 network.processMutex.Wait();
1082 void ResumeNetworkEvents()
1084 if(network.networkInitialized)
1086 network.processMutex.Release();
1091 void SignalEvent(void)
1093 globalSystem.eventSemaphore.Release();
1096 // TODO: Might want to make this private with simpler public version?
1097 bool SwitchMode(bool fullScreen, char * driverName, Resolution resolution, PixelFormat colorDepth, int refreshRate, char * skinName, bool fallBack)
1099 bool result = false;
1102 bool fbFullScreen = 0;
1103 Resolution fbResolution = 0;
1104 PixelFormat fbColorDepth = 0;
1105 int fbRefreshRate = 0;
1106 subclass(Interface) inter;
1107 subclass(Skin) skin = null;
1113 for(link = class(Skin).derivatives.first; link; link = link.next)
1116 if(skin.name && !strcmp(skin.name, skinName))
1119 if(!link) skin = null;
1124 fbDriver = defaultDisplayDriver;
1125 inter = interfaceDriver;
1128 interfaceDriver.GetCurrentMode(&fbFullScreen, &fbResolution, &fbColorDepth, &fbRefreshRate);
1130 if(!driverName && !interfaceDriver)
1131 driverName = defaultDisplayDriver;
1133 if(driverName || (skin && skin.textMode != textMode))
1135 for(link = class(Interface).derivatives.first; link; link = link.next)
1137 bool foundDriver = false;
1139 char ** graphicsDrivers;
1142 graphicsDrivers = inter.GraphicsDrivers(&numDrivers);
1144 for(c=0; c<numDrivers; c++)
1145 if(!driverName || !strcmp(driverName, graphicsDrivers[c]))
1147 if(!skin || skin.textMode == IsDriverTextMode(graphicsDrivers[c]))
1149 driverName = graphicsDrivers[c];
1164 #if defined(__WIN32__)
1165 #if !defined(ECERE_VANILLA)
1166 if(!strcmp(driverName, "Win32Console")) inter = (subclass(Interface))class(Win32ConsoleInterface); else
1168 inter = (subclass(Interface))class(Win32Interface);
1170 if(!strcmp(driverName, "X")) inter = (subclass(Interface))class(XInterface);
1171 else inter = (subclass(Interface))class(NCursesInterface);
1176 if(interfaceDriver && (!driverName || (fbDriver && !strcmp(fbDriver, driverName))) &&
1177 fullScreen == fbFullScreen &&
1178 (!resolution || resolution == fbResolution) &&
1179 (!colorDepth || colorDepth == fbColorDepth) &&
1180 (!refreshRate || refreshRate == fbRefreshRate) &&
1181 (currentSkin && (!skinName || !strcmp(currentSkin.name, skinName))))
1185 bool wasFullScreen = fullScreenMode;
1186 subclass(Skin) oldSkin = currentSkin;
1189 modeSwitching = true;
1192 desktop.UnloadGraphics(true);
1194 if(inter != interfaceDriver)
1198 interfaceDriver.Terminate();
1200 result = inter.Initialize();
1208 interfaceDriver = inter;
1209 interfaceDriver.SetTimerResolution(timerResolution);
1210 inter.EnsureFullScreen(&fullScreen);
1211 fullScreenMode = fullScreen;
1213 if((!wasFullScreen && !fullScreen) ||
1214 inter.ScreenMode(fullScreen, resolution, colorDepth, refreshRate, &textMode))
1216 if(!fbDriver || (driverName && strcmp(fbDriver, driverName)))
1217 defaultDisplayDriver = driverName;
1219 if(!skinName || !SelectSkin(skinName))
1221 if(!currentSkin || currentSkin.textMode != textMode ||
1222 !SelectSkin(currentSkin.name))
1225 subclass(Skin) skin = null;
1227 for(link = class(Skin).derivatives.first; link; link = link.next)
1230 if(skin.textMode == textMode)
1233 if(!link) skin = null;
1236 #if !defined(__ANDROID__)
1237 SelectSkin(skin.name);
1244 if(currentSkin && desktop.SetupDisplay())
1246 desktop.active = true;
1250 desktop.display.Lock(false);
1251 desktop.display.Position(0,0);
1252 desktop.display.Unlock();
1255 if(desktop.LoadGraphics(false, oldSkin != currentSkin))
1259 desktop.UpdateDisplay();
1262 this.fullScreen = fullScreen;
1268 modeSwitching = false;
1270 LogErrorCode(modeSwitchFailed, driverName ? driverName : defaultDisplayDriver);
1273 LogErrorCode(driverNotSupported, driverName ? driverName : defaultDisplayDriver);
1275 if(!result && fallBack && fbDriver)
1277 if(!SwitchMode(fbFullScreen, fbDriver, fbResolution, fbColorDepth, fbRefreshRate, null, false))
1278 Log($"Error falling back to previous video mode.\n");
1283 bool ProcessFileNotifications()
1285 bool activity = false;
1286 FileMonitor monitor, next;
1287 static int reentrant = 0;
1289 // Reentrant FileNotification is asking for trouble since each monitor is spawning a Modal() MessageBox
1290 if(reentrant) return false;
1291 // printf("[%d] Waiting in ProcessFileNotifications for fileMonitor Mutex %x...\n", (int)GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1292 globalSystem.fileMonitorMutex.Wait();
1294 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1298 next = monitor.next;
1303 if(!monitor.reentrant && !monitor.toBeFreed)
1305 monitor.reentrant = true;
1306 while((notify = monitor.fileNotifies.first))
1308 monitor.fileNotifies.Remove(notify);
1312 if(monitor.directory)
1314 if(!monitor.OnDirNotify(monitor.data, notify.action, notify.fileName, notify.param))
1315 monitor.StopMonitoring();
1319 if(!monitor.OnFileNotify(monitor.data, notify.action, notify.param))
1320 monitor.StopMonitoring();
1323 monitor.reentrant = false;
1329 monitor.reentrant = false;
1332 if(next && next._refCount > 1)
1340 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1342 next = monitor.next;
1343 if(monitor.toBeFreed && !monitor.reentrant)
1344 monitor.FreeMonitor();
1347 // printf("[%d] Releasing in ProcessFileNotifications fileMonitor Mutex %x...\n", (int)GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1348 globalSystem.fileMonitorMutex.Release();
1355 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
1357 XLockDisplay(xGlobalDisplay);
1363 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
1365 XUnlockDisplay(xGlobalDisplay);
1367 lockMutex.Release();
1370 Cursor GetCursor(SystemCursor cursor)
1372 return systemCursors[cursor];
1375 bool GetKeyState(Key key)
1377 return interfaceDriver.GetKeyState(key);
1380 bool GetMouseState(MouseButtons * buttons, int * x, int * y)
1382 return interfaceDriver.GetMouseState(buttons, x, y);
1386 property char * appName
1390 strcpy(appName, value);
1391 if(desktop) desktop.text = appName;
1395 return (char *)(this ? appName : null);
1398 property Semaphore semaphore { get { return globalSystem.eventSemaphore; } };
1399 property bool alwaysEmptyInput{ set { processAll = value; } get { return processAll; } };
1400 property bool fullScreen
1404 SwitchMode(value, defaultDisplayDriver, resolution,
1405 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1407 get { return this ? fullScreen : false; }
1409 property char * driver
1413 SwitchMode( fullScreen, value, resolution, pixelFormat, refreshRate,
1414 currentSkin ? currentSkin.name : null, true);
1416 get { return this ? defaultDisplayDriver : null; }
1418 property Resolution resolution
1422 SwitchMode(fullScreen, defaultDisplayDriver, value, pixelFormat, refreshRate,
1423 currentSkin ? currentSkin.name : null, true);
1425 get { return this ? resolution : 0; }
1427 property PixelFormat pixelFormat
1431 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1432 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1434 get { return this ? pixelFormat : 0; }
1436 property int refreshRate
1440 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1441 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1443 get { return this ? refreshRate : 0; }
1445 property char * skin
1447 set { SelectSkin(value); }
1448 get { return (this && currentSkin) ? currentSkin.name : null; }
1450 property bool textMode
1452 set { textMode = value; } // TODO: Implement switching
1453 get { return this ? textMode : false; }
1455 property Window desktop { get { return this ? desktop : null; } };
1456 property char ** drivers { get { return null; } };
1457 property char ** skins { get { return null; } };
1458 property subclass(Skin) currentSkin { get { return this ? currentSkin : null; } };
1459 property int numDrivers { get { return 0; } };
1460 property int numSkins { get { return 0; } };
1461 property uint timerResolution
1463 set { timerResolution = value; if(interfaceDriver) interfaceDriver.SetTimerResolution(value); }