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__)
36 #define SOCKLEN_TYPE int
37 #define WIN32_LEAN_AND_MEAN
38 #define String _String
42 #elif defined(__unix__) || defined(__APPLE__)
45 #define SOCKLEN_TYPE socklen_t
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__)
87 /*static */bool guiApplicationInitialized = false;
88 GuiApplication guiApp;
91 public class GuiApplication : Application
100 subclass(Interface) interfaceDriver;
101 subclass(Skin) currentSkin;
108 bool fullScreenMode; // Needs to start at true for the desktop to resize
111 Resolution resolution;
112 PixelFormat pixelFormat;
115 const char * defaultDisplayDriver;
117 Cursor systemCursors[SystemCursor];
121 OldList customCursors;
124 OldList windowTimers;
127 Window prevWindow; // Used for OnMouseLeave
128 List<Window> overWindows { }; // Used for OnMouseLeave
129 Window windowCaptured;
131 // Mouse based moving & resizing
133 Point windowMovingStart;
134 Point windowMovingBefore;
135 Size windowResizingBefore;
137 bool windowIsResizing;
138 bool resizeX, resizeEndX;
139 bool resizeY, resizeEndY;
141 // Mouse based scrolling
142 Window windowScrolling;
143 Point windowScrollingBefore, windowScrollingStart;
146 Bitmap cursorBackground { };
147 int cursorBackgroundX, cursorBackgroundY;
148 int cursorBackgroundW, cursorBackgroundH;
154 Window acquiredWindow;
155 int acquiredMouseX, acquiredMouseY;
157 Cursor currentCursor;
159 uint errorLevel, lastErrorCode;
167 Window interimWindow;
171 uint timerResolution;
174 Point virtualScreenPos;
182 mainThread = GetCurrentThreadID();
186 strcpy(appName, $"ECERE Application");
191 // customCursors.offset = OFFSET(Cursor, prev);
192 windowTimers.offset = (uint)(uintptr)&((Timer)0).prev;
194 for(c = 0; c<SystemCursor::enumSize; c++)
195 systemCursors[c] = Cursor { systemCursor = c; };
197 globalSystem.eventSemaphore = Semaphore { };
198 globalSystem.fileMonitorMutex = Mutex { };
199 globalSystem.fileMonitors.offset = (uint)(uintptr)&((FileMonitor)0).prev;
210 customCursors.Clear();
212 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
214 XUnlockDisplay(xGlobalDisplay);
217 #if !defined(__ANDROID__)
218 // Because destruction of app won't be from main thread
219 if(guiApplicationInitialized)
225 interfaceDriver.Terminate();
228 // interfaceDrivers.Free(null);
234 for(c = 0; c<SystemCursor::enumSize; c++)
235 delete systemCursors[c];
237 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
241 delete globalSystem.eventSemaphore;
242 delete globalSystem.fileMonitorMutex;
243 delete globalSystem.fileMonitorThread;
245 UnapplySkin(class(Window));
249 Timer timer, nextTimer;
250 for(timer = windowTimers.first; timer; timer = nextTimer)
252 nextTimer = timer.next;
261 Time time = GetTime();
264 for(timer = windowTimers.first; timer; timer = timer.next)
265 timer.dispatched = false;
268 for(timer = windowTimers.first; timer; timer = timer.next)
270 if(!timer.dispatched)
272 if((timer.delay - (Seconds)(time - timer.lastTime)) < Seconds { 0.00001 })
275 timer.lastTime = time;
276 if(timer.DelayExpired(timer.window))
278 timer.dispatched = true;
280 eInstance_DecRef(timer);
290 // --- Mouse-based window movement ---
291 void SetCurrentCursor(Window window, Cursor cursor)
293 currentCursor = cursor;
296 if(fullScreenMode && cursor.bitmap)
297 interfaceDriver.SetMouseCursor(window ? window : desktop, (SystemCursor)-1);
300 interfaceDriver.SetMouseCursor(window ? window : desktop, cursor.systemCursor);
301 cursorBackground.Free();
307 void PreserveAndDrawCursor()
310 if(!acquiredWindow && cursorUpdate && currentCursor && currentCursor->bitmap)
314 Box against = {0,0, desktop.w-1,desktop.h-1};
315 Box box = {0, 0, currentCursor->bitmap->width,currentCursor->bitmap->height};
317 interfaceDriver->GetMousePosition(&mouseX, &mouseY);
319 mouseX -= currentCursor->hotSpotX;
320 mouseY -= currentCursor->hotSpotY;
322 // Preserve Background
323 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
325 cursorBackgroundX = mouseX;
326 cursorBackgroundY = mouseY;
327 cursorBackgroundW = currentCursor->bitmap->width;
328 cursorBackgroundH = currentCursor->bitmap->height;
329 eDisplay_Grab(desktop.display, cursorBackground,
330 mouseX, mouseY, cursorBackgroundW, cursorBackgroundH);
333 eBox_ClipOffset(&box, &against, mouseX, mouseY);
335 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
336 eDisplay_StartUpdate(desktop.display);
338 surface = eDisplay_GetSurface(desktop.display, mouseX, mouseY, &box);
341 eSurface_SetForeground(surface, WHITE);
342 eSurface_Blit(surface, currentCursor->bitmap, 0,0, 0,0,
343 currentCursor->bitmap->width,currentCursor->bitmap->height);
344 eInstance_Delete(surface);
346 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
351 box.bottom += mouseY;
352 eDisplay_Update(desktop.display, &box);
355 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
356 eDisplay_EndUpdate(desktop.display);
361 void RestoreCursorBackground()
364 // Restore Cursor Background
365 if(cursorBackground && desktop.active)
367 Box box = {0, 0, cursorBackgroundW-1,cursorBackgroundH-1};
368 Box against = {0,0, desktop.w-1,desktop.h-1};
371 eBox_ClipOffset(&box, &against, cursorBackgroundX, cursorBackgroundY);
372 if((surface = eDisplay_GetSurface(desktop.display, cursorBackgroundX,cursorBackgroundY, &box)))
374 eSurface_Blit(surface, cursorBackground, 0, 0, 0,0, cursorBackgroundW,cursorBackgroundH);
375 eInstance_Delete(surface);
381 bool IsModeSwitching()
383 return modeSwitching;
386 public bool SetDesktopPosition(int x, int y, int w, int h, bool moveChildren)
389 bool windowResized = desktop.size.w != w || desktop.size.h != h;
390 bool windowMoved = desktop.clientStart.x != x || desktop.clientStart.y != y;
392 if((windowResized || windowMoved) && moveChildren)
395 desktop.Position(x, y, w, h, true, true, true, true, false, false);
397 // Maximized native decorations windows suffer when we drag the dock around, so remaximize them
398 // It's a little jumpy, but oh well.
400 // Made this Windows only as it was causing occasional wrong stacking of windows in X11/Cinnamon
401 // when switching debugged app from full-screen
403 for(child = desktop.children.first; child; child = child.next)
405 if(child.nativeDecorations && child.rootWindow == child && child.state == maximized)
407 #if defined(__WIN32__)
408 child.state = normal;
409 child.state = maximized;
413 child.state = normal;
414 child.state = maximized;
417 child.requireRemaximize = true;
421 /*for(child = desktop.children.first; child; child = child.next)
423 if(!child.systemParent)
428 child.ComputeAnchors(
429 child.ax, child.ay, child.aw, child.ah,
431 child.Position(x, y, w, h, true, true, true, true, false);
433 if(child.state == Maximized)
437 child.ComputeAnchors(,
438 A_LEFT,A_LEFT,A_OFFSET,A_OFFSET,
440 child.Position(, x, y, w, h, false, true, true, true, false);
446 desktop.display.Lock(true);
449 if(!desktop.display.Resize(desktop.size.w, desktop.size.h))
452 desktop.dirty = true;
453 if(!desktop.display.flags.flipping)
454 desktop.Update(null);
456 // When does the desktop have a display in not fullscreen mode?
457 if(!fullScreenMode && !modeSwitching)
458 desktop.UpdateDisplay();
459 desktop.display.Unlock();
463 desktop.SetPosition(x, y, w, h, false, false, false);
467 void SetAppFocus(bool state)
469 // Shouldn't be property here
470 desktop.active = state;
473 bool SelectSkin(const char * skinName)
479 for(link = class(Skin).derivatives.first; link; link = link.next)
482 if(skin.name && !strcmp(skin.name, skinName))
485 if(!link) skin = null;
489 if(skin != currentSkin || !currentSkin)
491 // Try finding a driver to support this mode
492 if(skin.textMode != textMode)
498 bool needReload = false;
500 if(!modeSwitching && currentSkin)
502 modeSwitching = true;
503 desktop.UnloadGraphics(true);
507 UnapplySkin(class(Window));
511 ApplySkin(class(Window), skin.name, null);
515 if(desktop.SetupDisplay())
516 if(desktop.LoadGraphics(false, true))
518 modeSwitching = false;
530 void Initialize(bool switchMode)
533 // if(!initialized && eClass_IsDerived(__ecereModule->app->module.inst.class, guiApplicationClass))
534 if(!guiApplicationInitialized)
536 const char * defaultDriver = null;
537 #if defined(ECERE_VANILLA) || defined(ECERE_ONEDRIVER)
538 char * driver = null;
541 // char * driver = getenv("ECERE_DRIVER");
542 char * driver = null;
543 static char driverStorage[1024];
544 GetEnvironment("ECERE_DRIVER", driverStorage, sizeof(driverStorage));
545 if(driverStorage[0]) driver = driverStorage;
547 guiApplicationInitialized = true;
549 fullScreenMode = true; // Needs to start at true for the desktop to resize
550 // Set this to true earlier so we can override it!
556 /*#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
558 XLockDisplay(xGlobalDisplay);
564 desktop = Window { nativeDecorations = false };
567 desktop.childrenOrder.circ = true;
568 desktop.childrenCycle.circ = true;
569 desktop.background = blue;
570 desktop.rootWindow = desktop;
571 desktop.cursor = GetCursor(arrow);
572 desktop.caption = appName;
573 *&desktop.visible = true;
574 desktop.position = Point { };
575 desktop.mutex = Mutex { };
576 desktop.created = true;
579 #if defined(__WIN32__)
582 defaultDriver = driver;
583 else if((this.isGUIApp & 1) && !textMode)
584 defaultDriver = "GDI";
586 defaultDriver = "Win32Console";
588 #elif defined(__APPLE__)
591 defaultDriver = driver;
593 defaultDriver = "X"; //"CocoaOpenGL";
595 #elif defined(__ANDROID__)
598 defaultDriver = driver;
600 defaultDriver = "OpenGL";
603 if((this.isGUIApp & 1) && !textMode)
605 char * display = getenv("DISPLAY");
607 if(!display || !display[0] || !SwitchMode(false, "X", 0, 0, 0, null, true))
608 defaultDriver = "NCurses";
609 // SwitchMode(true, "NCurses", 0, PixelFormatText, 0, null, true);
613 defaultDriver = driver;
616 defaultDriver = "NCurses";
621 SwitchMode(false, defaultDriver, 0, 0, 0, null, true);
625 #if defined(__WIN32__)
626 SwitchMode(true, "Win32Console", 0, PixelFormatText, 0, null, true);
631 SwitchMode(true, "SVGA", Res640x480, PixelFormat8, 0, null, true);
634 #if defined(__APPLE__)
635 // SwitchMode(true, "X" /*"CocoaOpenGL"*/, 0, 0, 0, null, true);
638 #if defined(__unix__)
639 #if defined(ECERE_MINIGLX)
640 SwitchMode(true, "OpenGL", 0, 0, 0, null, true);
644 /*if(!interfaceDriver)
645 guiApplicationInitialized = false;*/
648 defaultDisplayDriver = defaultDriver;
653 virtual bool Init(void);
654 virtual bool Cycle(bool idle);
655 virtual void Terminate(void);
665 // better solution when designing tab order/activated window etc, why do windows move in the list?
668 for(window = desktop.children.first; window; window = window.next)
670 if(window.autoCreate && !window.created)
685 while(desktop && interfaceDriver)
689 if(terminateX != terminated)
691 terminated = terminateX;
697 //printf("Resetting terminate X to 0\n");
701 for(child = desktop.children.first; child; child = child.next)
702 if(child.created && child.visible)
706 for(window = desktop.children.first; window; window = window.next)
707 if(window.mutex) window.mutex.Wait();
709 for(window = desktop.children.first; window; window = window.next)
710 if(window.mutex) window.mutex.Release();
711 wait = !ProcessInput(true);
713 if(lockMutex.owningThread != GetCurrentThreadID())
714 PrintLn("WARNING: ProcessInput returned unlocked GUI!");
723 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
725 XUnlockDisplay(xGlobalDisplay);
731 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
733 XLockDisplay(xGlobalDisplay);
737 eInstance_DecRef(desktop);
742 #if defined(__ANDROID__)
743 // Because destruction of GuiApp won't be from main thread
750 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
752 XUnlockDisplay(xGlobalDisplay);
760 interfaceDriver.Wait();
766 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__)
768 XLockDisplay(xGlobalDisplay);
772 bool ProcessInput(bool useProcessAll)
778 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
779 ProcessNetworkEvents();
783 result = interfaceDriver.ProcessInput(useProcessAll && processAll);
784 if(!desktop || !interfaceDriver) return;
788 for(child = app.desktop.children.first; child; child = child.next)
789 if(child.created && child.visible)
791 if(!child) return result;
794 result |= UpdateTimers();
795 result |= ProcessFileNotifications();
798 result |= ProcessFileNotifications();
799 result |= UpdateTimers();
800 result |= interfaceDriver.ProcessInput(useProcessAll && processAll);
807 void UpdateDisplay(void)
809 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
810 if(Desktop3DUpdateDisplay()) return;
815 if(fullScreenMode && desktop.display)
817 desktop.mutex.Wait();
820 desktop.display.Lock(true);
822 if(desktop.dirty || cursorUpdate)
824 if(desktop.display.flags.flipping)
825 desktop.Update(null);
826 desktop.UpdateDisplay();
829 if(cursorUpdate || desktop.dirty)
831 PreserveAndDrawCursor();
832 cursorUpdate = false;
833 desktop.dirty = false;
834 RestoreCursorBackground();
837 desktop.display.Unlock();
839 desktop.mutex.Release();
845 for(window = desktop.children.first; window; window = window.next)
847 if(window.mutex) window.mutex.Wait();
848 if(window.visible && window.dirty)
850 // Logf("Updating %s\n", window.name);
851 interfaceDriver.Lock(window);
854 if(window.display.current)
858 window.display.Lock(true);
859 window.UpdateDisplay();
860 window.display.Unlock();
863 window.dirty = false;
864 interfaceDriver.Unlock(window);
866 Log("--------------\n");
870 if(window.mutex) window.mutex.Release();
878 globalSystem.eventSemaphore.Wait();
881 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
882 bool ProcessNetworkEvents()
884 bool gotEvent = false;
885 #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
886 if(network.networkInitialized)
890 struct timeval tv = {0, 0};
895 PauseNetworkEvents();
896 network.mutex.Wait();
899 if(network.connectEvent || network.networkEvent)
900 Log("[P] [NProcess]\n");
902 rs = network.readSet;
903 ws = network.writeSet;
904 es = network.exceptSet;
906 if((network.ns && select(network.ns, &rs, &ws, &es, &tv)) || network.leftOverBytes)
908 network.leftOverBytes = false;
910 // Danger here? Why looping with a next and not unlocking anything?
911 for(socket = network.connectSockets.first; socket; socket = next)
914 if(!socket.processAlone && FD_ISSET(socket.s, &ws))
916 network.mutex.Release();
917 socket.connectThread.Wait();
918 network.mutex.Wait();
921 for(socket = network.sockets.first; socket; socket = next)
924 if(!socket.processAlone)
926 network.mutex.Release();
927 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
928 network.mutex.Wait();
932 for(service = network.services.first; service; service = nextService)
934 nextService = service.next;
935 if(!service.processAlone)
937 if(FD_ISSET(service.s, &rs))
940 Logf("[P] Accepting connection (%x)\n", service.s);
942 service.accepted = false;
944 if(!service.accepted)
948 SOCKLEN_TYPE addrLen = sizeof(a);
949 s = accept(service.s,(SOCKADDR *)&a,&addrLen);
955 Log("[P] Connection accepted\n");
959 for(socket = service.sockets.first; socket; socket = next)
962 if(!socket.processAlone)
964 network.mutex.Release();
965 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
966 network.mutex.Wait();
971 if(network.connectEvent)
977 for(socket = network.connectSockets.first; socket; socket = next)
980 if(socket._connected && socket._connected != -2)
982 network.connectSockets.Remove(socket);
983 delete socket.connectThread;
985 // printf("%s is connected = %d\n", socket._class.name, socket._connected);
986 if(socket._connected == -1)
989 Logf("[P] Processing disconnected connect (%x)\n", socket.s);
992 if(socket.disconnectCode == ResolveFailed)
993 Logf("Error resolving address %s\n", socket.address);
995 if(socket.s == network.ns - 1)
996 Network_DetermineMaxSocket();
998 socket._connected = 0;
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, const char * driverName, Resolution resolution, PixelFormat colorDepth, int refreshRate, const char * skinName, bool fallBack)
1099 bool result = false;
1101 const char * fbDriver;
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 const 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 const char * appName
1390 strcpy(appName, value);
1391 if(desktop) desktop.text = appName;
1395 return (const 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 const 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 const 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 const char ** drivers { get { return null; } };
1457 property const char * const * 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); }