3 #if defined(__unix__) || defined(__APPLE__)
4 #define property _property
9 #define Window X11Window
10 #define Cursor X11Cursor
12 #define Display X11Display
14 #define KeyCode X11KeyCode
15 #define Picture X11Picture
17 #include <X11/Xutil.h>
34 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
35 #if defined(__WIN32__)
37 #define WIN32_LEAN_AND_MEAN
39 static WSADATA wsaData;
41 #elif defined(__unix__) || defined(__APPLE__)
48 #include <netinet/in.h>
50 #include <sys/socket.h>
52 #include <sys/types.h>
54 #include <arpa/inet.h>
59 typedef struct hostent HOSTENT;
60 typedef struct sockaddr SOCKADDR;
61 typedef struct sockaddr_in SOCKADDR_IN;
62 typedef struct in_addr IN_ADDR;
63 #define closesocket(s) close(s)
70 #if defined(__APPLE__)
71 import "CocoaInterface"
72 #elif defined(__unix__)
78 GuiApplication guiApp;
81 enum GuiErrorCode : ErrorCode
83 driverNotSupported = ErrorCode { VeryFatal, 1 },
84 windowCreationFailed = ErrorCode { VeryFatal, 2 },
85 graphicsLoadingFailed = ErrorCode { VeryFatal, 3 },
86 modeSwitchFailed = ErrorCode { VeryFatal, 4 }
89 static Array<String> errorMessages
92 $"Graphics driver not supported by any user interface system",
93 $"Window creation failed",
94 $"Window graphics loading failed",
95 $"Driver/Mode switch failed"
98 public class GuiApplication : Application
107 subclass(Interface) interfaceDriver;
108 subclass(Skin) currentSkin;
115 bool fullScreenMode; // Needs to start at true for the desktop to resize
118 Resolution resolution;
119 PixelFormat pixelFormat;
122 char * defaultDisplayDriver;
124 Cursor systemCursors[SystemCursor];
128 OldList customCursors;
131 OldList windowTimers;
134 Window prevWindow; // Used for OnMouseLeave
135 Window windowCaptured;
137 // Mouse based moving & resizing
139 Point windowMovingStart;
140 Point windowMovingBefore;
141 Size windowResizingBefore;
143 bool windowIsResizing;
144 bool resizeX, resizeEndX;
145 bool resizeY, resizeEndY;
147 // Mouse based scrolling
148 Window windowScrolling;
149 Point windowScrollingBefore, windowScrollingStart;
152 Bitmap cursorBackground { };
153 int cursorBackgroundX, cursorBackgroundY;
154 int cursorBackgroundW, cursorBackgroundH;
160 Window acquiredWindow;
161 int acquiredMouseX, acquiredMouseY;
163 Cursor currentCursor;
165 uint errorLevel, lastErrorCode;
173 Window interimWindow;
177 uint timerResolution;
180 Point virtualScreenPos;
188 mainThread = GetCurrentThreadID();
192 strcpy(appName, $"ECERE Application");
197 // customCursors.offset = OFFSET(Cursor, prev);
198 windowTimers.offset = (uint)&((Timer)0).prev;
200 for(c = 0; c<SystemCursor::enumSize; c++)
201 systemCursors[c] = Cursor { systemCursor = c; };
203 globalSystem.eventSemaphore = Semaphore { };
204 globalSystem.fileMonitorMutex = Mutex { };
205 globalSystem.fileMonitors.offset = (uint)&((FileMonitor)0).prev;
216 customCursors.Clear();
218 #if defined(__unix__)
220 XUnlockDisplay(xGlobalDisplay);
227 interfaceDriver.Terminate();
230 // interfaceDrivers.Free(null);
236 for(c = 0; c<SystemCursor::enumSize; c++)
237 delete systemCursors[c];
239 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
243 delete globalSystem.eventSemaphore;
244 delete globalSystem.fileMonitorMutex;
245 delete globalSystem.fileMonitorThread;
247 UnapplySkin(class(Window));
253 Time time = GetTime();
256 for(timer = windowTimers.first; timer; timer = timer.next)
257 timer.dispatched = false;
260 for(timer = windowTimers.first; timer; timer = timer.next)
262 if(!timer.dispatched)
264 if((timer.delay - (Seconds)(time - timer.lastTime)) < Seconds { 0.00001 })
267 timer.lastTime = time;
268 if(timer.DelayExpired(timer.window))
270 timer.dispatched = true;
272 eInstance_DecRef(timer);
282 // --- Mouse-based window movement ---
283 void SetCurrentCursor(Cursor cursor)
285 currentCursor = cursor;
288 if(fullScreenMode && cursor.bitmap)
289 interfaceDriver.SetMouseCursor((SystemCursor)-1);
292 interfaceDriver.SetMouseCursor(cursor.systemCursor);
293 cursorBackground.Free();
299 void PreserveAndDrawCursor()
302 if(!acquiredWindow && cursorUpdate && currentCursor && currentCursor->bitmap)
306 Box against = {0,0, desktop.w-1,desktop.h-1};
307 Box box = {0, 0, currentCursor->bitmap->width,currentCursor->bitmap->height};
309 interfaceDriver->GetMousePosition(&mouseX, &mouseY);
311 mouseX -= currentCursor->hotSpotX;
312 mouseY -= currentCursor->hotSpotY;
314 // Preserve Background
315 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
317 cursorBackgroundX = mouseX;
318 cursorBackgroundY = mouseY;
319 cursorBackgroundW = currentCursor->bitmap->width;
320 cursorBackgroundH = currentCursor->bitmap->height;
321 eDisplay_Grab(desktop.display, cursorBackground,
322 mouseX, mouseY, cursorBackgroundW, cursorBackgroundH);
325 eBox_ClipOffset(&box, &against, mouseX, mouseY);
327 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
328 eDisplay_StartUpdate(desktop.display);
330 surface = eDisplay_GetSurface(desktop.display, mouseX, mouseY, &box);
333 eSurface_SetForeground(surface, WHITE);
334 eSurface_Blit(surface, currentCursor->bitmap, 0,0, 0,0,
335 currentCursor->bitmap->width,currentCursor->bitmap->height);
336 eInstance_Delete(surface);
338 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
343 box.bottom += mouseY;
344 eDisplay_Update(desktop.display, &box);
347 if(!(eDisplay_GetFlags(desktop.display) & DISPLAY_FLIPPING))
348 eDisplay_EndUpdate(desktop.display);
353 void RestoreCursorBackground()
356 // Restore Cursor Background
357 if(cursorBackground && desktop.active)
359 Box box = {0, 0, cursorBackgroundW-1,cursorBackgroundH-1};
360 Box against = {0,0, desktop.w-1,desktop.h-1};
363 eBox_ClipOffset(&box, &against, cursorBackgroundX, cursorBackgroundY);
364 if((surface = eDisplay_GetSurface(desktop.display, cursorBackgroundX,cursorBackgroundY, &box)))
366 eSurface_Blit(surface, cursorBackground, 0, 0, 0,0, cursorBackgroundW,cursorBackgroundH);
367 eInstance_Delete(surface);
373 bool IsModeSwitching()
375 return modeSwitching;
378 public bool SetDesktopPosition(int x, int y, int w, int h, bool moveChildren)
381 bool windowResized = desktop.size.w != w || desktop.size.h != h;
382 bool windowMoved = desktop.clientStart.x != x || desktop.clientStart.y != y;
384 if((windowResized || windowMoved) && moveChildren)
387 desktop.Position(x, y, w, h, true, true, true, true, false, false);
389 // Maximized native decorations windows suffer when we drag the dock around, so remaximize them
390 // It's a little jumpy, but oh well.
391 for(child = desktop.children.first; child; child = child.next)
393 if(child.nativeDecorations && child.rootWindow == child && child.state == maximized)
395 child.state = normal;
396 child.state = maximized;
399 /*for(child = desktop.children.first; child; child = child.next)
401 if(!child.systemParent)
406 child.ComputeAnchors(
407 child.ax, child.ay, child.aw, child.ah,
409 child.Position(x, y, w, h, true, true, true, true, false);
411 if(child.state == Maximized)
415 child.ComputeAnchors(,
416 A_LEFT,A_LEFT,A_OFFSET,A_OFFSET,
418 child.Position(, x, y, w, h, false, true, true, true, false);
424 desktop.display.Lock(true);
427 if(!desktop.display.Resize(desktop.size.w, desktop.size.h))
430 desktop.dirty = true;
431 if(!desktop.display.flags.flipping)
432 desktop.Update(null);
434 // When does the desktop have a display in not fullscreen mode?
435 if(!fullScreenMode && !modeSwitching)
436 desktop.UpdateDisplay();
437 desktop.display.Unlock();
441 desktop.SetPosition(x, y, w, h, false, false, false);
445 void SetAppFocus(bool state)
447 // Shouldn't be property here
448 desktop.active = state;
451 bool SelectSkin(char * skinName)
457 for(link = class(Skin).derivatives.first; link; link = link.next)
460 if(skin.name && !strcmp(skin.name, skinName))
463 if(!link) skin = null;
467 if(skin != currentSkin || !currentSkin)
469 // Try finding a driver to support this mode
470 if(skin.textMode != textMode)
476 bool needReload = false;
478 if(!modeSwitching && currentSkin)
480 modeSwitching = true;
481 desktop.UnloadGraphics(true);
485 UnapplySkin(class(Window));
489 ApplySkin(class(Window), skin.name, null);
493 if(desktop.SetupDisplay())
494 if(desktop.LoadGraphics(false, true))
496 modeSwitching = false;
508 void Initialize(bool switchMode)
510 static bool initialized = false;
513 // if(!initialized && eClass_IsDerived(__ecereModule->app->module.inst.class, guiApplicationClass))
516 char * defaultDriver = null;
517 #if defined(ECERE_VANILLA)
518 char * driver = null;
521 // char * driver = getenv("ECERE_DRIVER");
522 char * driver = null;
523 static char driverStorage[1024];
524 GetEnvironment("ECERE_DRIVER", driverStorage, sizeof(driverStorage));
525 if(driverStorage[0]) driver = driverStorage;
529 fullScreenMode = true; // Needs to start at true for the desktop to resize
530 // Set this to true earlier so we can override it!
536 #if defined(__unix__)
538 XLockDisplay(xGlobalDisplay);
544 desktop = Window { };
547 desktop.childrenOrder.circ = true;
548 desktop.childrenCycle.circ = true;
549 desktop.background = blue;
550 desktop.rootWindow = desktop;
551 desktop.cursor = GetCursor(arrow);
552 desktop.caption = new char[strlen(appName) + 1];
553 strcpy(desktop.caption, appName);
554 *&desktop.visible = true;
555 desktop.position = Point { };
556 desktop.mutex = Mutex { };
557 desktop.created = true;
560 #if defined(__WIN32__)
563 defaultDriver = driver;
564 else if(this.isGUIApp && !textMode)
565 defaultDriver = "GDI";
567 defaultDriver = "Win32Console";
569 #elif defined(__APPLE__)
572 defaultDriver = driver;
574 defaultDriver = "CocoaOpenGL";
578 if(this.isGUIApp && !textMode)
580 char * display = getenv("DISPLAY");
582 if(!display || !display[0] || !SwitchMode(false, "X", 0, 0, 0, null, true))
583 defaultDriver = "NCurses";
584 // SwitchMode(true, "NCurses", 0, PixelFormatText, 0, null, true);
588 defaultDriver = driver;
591 defaultDriver = "NCurses";
596 SwitchMode(false, defaultDriver, 0, 0, 0, null, true);
600 #if defined(__WIN32__)
601 SwitchMode(true, "Win32Console", 0, PixelFormatText, 0, null, true);
606 SwitchMode(true, "SVGA", Res640x480, PixelFormat8, 0, null, true);
609 #if defined(__APPLE__)
610 SwitchMode(true, "CocoaOpenGL", 0, 0, 0, null, true);
613 #if defined(__unix__)
614 #if defined(ECERE_MINIGLX)
615 SwitchMode(true, "OpenGL", 0, 0, 0, null, true);
623 defaultDisplayDriver = defaultDriver;
628 virtual bool Init(void);
629 virtual bool Cycle(bool idle);
630 virtual void Terminate(void);
640 // better solution when designing tab order/activated window etc, why do windows move in the list?
643 for(window = desktop.children.first; window; window = window.next)
645 if(window.autoCreate && !window.created)
659 while(desktop && interfaceDriver)
663 if(terminateX != terminated)
665 terminated = terminateX;
671 //printf("Resetting terminate X to 0\n");
675 for(child = desktop.children.first; child; child = child.next)
676 if(child.created && child.visible)
680 for(window = desktop.children.first; window; window = window.next)
681 if(window.mutex) window.mutex.Wait();
683 for(window = desktop.children.first; window; window = window.next)
684 if(window.mutex) window.mutex.Release();
685 wait = !ProcessInput(true);
687 if(lockMutex.owningThread != GetCurrentThreadID())
688 PrintLn("WARNING: ProcessInput returned unlocked GUI!");
697 #if defined(__unix__)
699 XUnlockDisplay(xGlobalDisplay);
705 #if defined(__unix__)
707 XLockDisplay(xGlobalDisplay);
711 eInstance_DecRef(desktop);
719 #if defined(__unix__)
721 XUnlockDisplay(xGlobalDisplay);
729 interfaceDriver.Wait();
735 #if defined(__unix__)
737 XLockDisplay(xGlobalDisplay);
741 bool ProcessInput(bool useProcessAll)
747 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
748 ProcessNetworkEvents();
752 result = interfaceDriver.ProcessInput(useProcessAll && processAll);
753 if(!desktop || !interfaceDriver) return;
757 for(child = app.desktop.children.first; child; child = child.next)
758 if(child.created && child.visible)
760 if(!child) return result;
763 result |= UpdateTimers();
764 result |= ProcessFileNotifications();
767 result |= ProcessFileNotifications();
768 result |= UpdateTimers();
769 result |= interfaceDriver.ProcessInput(useProcessAll && processAll);
776 void UpdateDisplay(void)
778 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
779 if(Desktop3DUpdateDisplay()) return;
784 if(fullScreenMode && desktop.display)
786 desktop.mutex.Wait();
789 desktop.display.Lock(true);
791 if(desktop.dirty || cursorUpdate)
793 if(desktop.display.flags.flipping)
794 desktop.Update(null);
795 desktop.UpdateDisplay();
798 if(cursorUpdate || desktop.dirty)
800 PreserveAndDrawCursor();
801 cursorUpdate = false;
802 desktop.dirty = false;
803 RestoreCursorBackground();
806 desktop.display.Unlock();
808 desktop.mutex.Release();
814 for(window = desktop.children.first; window; window = window.next)
816 if(window.mutex) window.mutex.Wait();
817 if(window.visible && window.dirty)
819 // Logf("Updating %s\n", window.name);
820 interfaceDriver.Lock(window);
823 if(window.display.current)
827 window.display.Lock(true);
828 window.UpdateDisplay();
829 window.display.Unlock();
832 window.dirty = false;
833 interfaceDriver.Unlock(window);
835 Log("--------------\n");
839 if(window.mutex) window.mutex.Release();
847 globalSystem.eventSemaphore.Wait();
850 #if !defined(ECERE_VANILLA) && !defined(ECERE_NONET)
851 bool ProcessNetworkEvents()
853 bool gotEvent = false;
854 #if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
855 if(network.networkInitialized)
859 struct timeval tv = {0, 0};
864 PauseNetworkEvents();
865 network.mutex.Wait();
868 if(network.connectEvent || network.networkEvent)
869 Log("[P] [NProcess]\n");
871 rs = network.readSet;
872 ws = network.writeSet;
873 es = network.exceptSet;
875 if((network.ns && select(network.ns, &rs, &ws, &es, &tv)) || network.leftOverBytes)
877 network.leftOverBytes = false;
879 // Danger here? Why looping with a next and not unlocking anything?
880 for(socket = network.connectSockets.first; socket; socket = next)
883 if(!socket.processAlone && FD_ISSET(socket.s, &ws))
885 network.mutex.Release();
886 socket.connectThread.Wait();
887 network.mutex.Wait();
890 for(socket = network.sockets.first; socket; socket = next)
893 if(!socket.processAlone)
895 network.mutex.Release();
896 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
897 network.mutex.Wait();
901 for(service = network.services.first; service; service = nextService)
903 nextService = service.next;
904 if(!service.processAlone)
906 if(FD_ISSET(service.s, &rs))
909 Logf("[P] Accepting connection (%x)\n", service.s);
911 service.accepted = false;
913 if(!service.accepted)
917 int addrLen = sizeof(a);
918 s = accept(service.s,(SOCKADDR *)&a,&addrLen);
924 Log("[P] Connection accepted\n");
928 for(socket = service.sockets.first; socket; socket = next)
931 if(!socket.processAlone)
933 network.mutex.Release();
934 gotEvent |= socket.ProcessSocket(&rs, &ws, &es);
935 network.mutex.Wait();
940 if(network.connectEvent)
946 for(socket = network.connectSockets.first; socket; socket = next)
949 if(socket._connected && socket._connected != -2)
951 network.connectSockets.Remove(socket);
952 delete socket.connectThread;
954 // printf("%s is connected = %d\n", socket._class.name, socket._connected);
955 if(socket._connected == -1)
958 Logf("[P] Processing disconnected connect (%x)\n", socket.s);
961 if(socket.disconnectCode == ResolveFailed)
962 Logf("Error resolving address %s\n", socket.address);
964 if(socket.s == network.ns - 1)
965 Network_DetermineMaxSocket();
970 else if(socket._connected == 1)
973 Log("[P] Processing connected connect\n");
975 FD_CLR(socket.s, &network.writeSet);
976 FD_SET(socket.s, &network.readSet);
977 FD_SET(socket.s, &network.exceptSet);
978 network.mutex.Release();
980 // printf("Calling OnConnect on %s\n", socket._class.name);
982 network.mutex.Wait();
983 network.sockets.Add(socket);
991 network.connectEvent = false;
993 if(network.networkEvent)
995 network.networkEvent = false;
996 network.selectSemaphore.Release();
1001 for(semPtr = network.mtSemaphores.first; semPtr; semPtr = semPtr.next)
1003 ((Semaphore)semPtr.data).Release();
1007 network.mutex.Release();
1008 ResumeNetworkEvents();
1014 void WaitNetworkEvent()
1016 if(network.networkInitialized)
1018 if(GetCurrentThreadID() == network.mainThreadID)
1024 Semaphore semaphore { };
1025 OldLink semPtr { data = semaphore };
1026 network.mutex.Wait();
1027 network.mtSemaphores.Add(semPtr);
1028 network.mutex.Release();
1030 ResumeNetworkEvents();
1032 PauseNetworkEvents();
1033 network.mutex.Wait();
1034 network.mtSemaphores.Delete(semPtr);
1035 network.mutex.Release();
1041 void PauseNetworkEvents()
1043 if(network.networkInitialized)
1045 network.processMutex.Wait();
1049 void ResumeNetworkEvents()
1051 if(network.networkInitialized)
1053 network.processMutex.Release();
1058 void SignalEvent(void)
1060 globalSystem.eventSemaphore.Release();
1063 // TODO: Might want to make this private with simpler public version?
1064 bool SwitchMode(bool fullScreen, char * driverName, Resolution resolution, PixelFormat colorDepth, int refreshRate, char * skinName, bool fallBack)
1066 bool result = false;
1069 bool fbFullScreen = 0;
1070 Resolution fbResolution = 0;
1071 PixelFormat fbColorDepth = 0;
1072 int fbRefreshRate = 0;
1073 subclass(Interface) inter;
1074 subclass(Skin) skin = null;
1080 for(link = class(Skin).derivatives.first; link; link = link.next)
1083 if(skin.name && !strcmp(skin.name, skinName))
1086 if(!link) skin = null;
1091 fbDriver = defaultDisplayDriver;
1092 inter = interfaceDriver;
1095 interfaceDriver.GetCurrentMode(&fbFullScreen, &fbResolution, &fbColorDepth, &fbRefreshRate);
1097 if(!driverName && !interfaceDriver)
1098 driverName = defaultDisplayDriver;
1100 if(driverName || (skin && skin.textMode != textMode))
1102 for(link = class(Interface).derivatives.first; link; link = link.next)
1104 bool foundDriver = false;
1106 char ** graphicsDrivers;
1109 graphicsDrivers = inter.GraphicsDrivers(&numDrivers);
1111 for(c=0; c<numDrivers; c++)
1112 if(!driverName || !strcmp(driverName, graphicsDrivers[c]))
1114 if(!skin || skin.textMode == IsDriverTextMode(graphicsDrivers[c]))
1116 driverName = graphicsDrivers[c];
1131 #if defined(__WIN32__)
1132 #if !defined(ECERE_VANILLA)
1133 if(!strcmp(driverName, "Win32Console")) inter = (subclass(Interface))class(Win32ConsoleInterface); else
1135 inter = (subclass(Interface))class(Win32Interface);
1137 if(!strcmp(driverName, "X")) inter = (subclass(Interface))class(XInterface);
1138 else inter = (subclass(Interface))class(NCursesInterface);
1143 if(interfaceDriver && (!driverName || (fbDriver && !strcmp(fbDriver, driverName))) &&
1144 fullScreen == fbFullScreen &&
1145 (!resolution || resolution == fbResolution) &&
1146 (!colorDepth || colorDepth == fbColorDepth) &&
1147 (!refreshRate || refreshRate == fbRefreshRate) &&
1148 (currentSkin && (!skinName || !strcmp(currentSkin.name, skinName))))
1152 bool wasFullScreen = fullScreenMode;
1153 subclass(Skin) oldSkin = currentSkin;
1156 modeSwitching = true;
1159 desktop.UnloadGraphics(true);
1161 if(inter != interfaceDriver)
1165 interfaceDriver.Terminate();
1167 result = inter.Initialize();
1175 interfaceDriver = inter;
1176 interfaceDriver.SetTimerResolution(timerResolution);
1177 inter.EnsureFullScreen(&fullScreen);
1178 fullScreenMode = fullScreen;
1180 if((!wasFullScreen && !fullScreen) ||
1181 inter.ScreenMode(fullScreen, resolution, colorDepth, refreshRate, &textMode))
1183 if(!fbDriver || (driverName && strcmp(fbDriver, driverName)))
1184 defaultDisplayDriver = driverName;
1186 if(!skinName || !SelectSkin(skinName))
1188 if(!currentSkin || currentSkin.textMode != textMode ||
1189 !SelectSkin(currentSkin.name))
1192 subclass(Skin) skin = null;
1194 for(link = class(Skin).derivatives.first; link; link = link.next)
1197 if(skin.textMode == textMode)
1200 if(!link) skin = null;
1203 SelectSkin(skin.name);
1207 if(currentSkin && desktop.SetupDisplay())
1209 desktop.active = true;
1213 desktop.display.Lock(false);
1214 desktop.display.Position(0,0);
1215 desktop.display.Unlock();
1218 if(desktop.LoadGraphics(false, oldSkin != currentSkin))
1222 desktop.UpdateDisplay();
1225 this.fullScreen = fullScreen;
1231 modeSwitching = false;
1233 LogErrorCode(modeSwitchFailed, driverName ? driverName : defaultDisplayDriver);
1236 LogErrorCode(driverNotSupported, driverName ? driverName : defaultDisplayDriver);
1238 if(!result && fallBack && fbDriver)
1240 if(!SwitchMode(fbFullScreen, fbDriver, fbResolution, fbColorDepth, fbRefreshRate, null, false))
1241 Log($"Error falling back to previous video mode.\n");
1246 bool ProcessFileNotifications()
1248 bool activity = false;
1249 FileMonitor monitor, next;
1250 static int reentrant = 0;
1252 // printf("[%d] Waiting in ProcessFileNotifications for fileMonitor Mutex %x...\n", GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1253 globalSystem.fileMonitorMutex.Wait();
1255 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1259 next = monitor.next;
1262 if(!monitor.reentrant && !monitor.toBeFreed)
1264 monitor.reentrant = true;
1265 while((notify = monitor.fileNotifies.first))
1267 monitor.fileNotifies.Remove(notify);
1271 if(monitor.directory)
1273 if(!monitor.OnDirNotify(monitor.data, notify.action, notify.fileName, notify.param))
1274 monitor.StopMonitoring();
1278 if(!monitor.OnFileNotify(monitor.data, notify.action, notify.param))
1279 monitor.StopMonitoring();
1282 monitor.reentrant = false;
1288 monitor.reentrant = false;
1295 for(monitor = globalSystem.fileMonitors.first; monitor; monitor = next)
1297 next = monitor.next;
1298 if(monitor.toBeFreed && !monitor.reentrant)
1299 monitor.FreeMonitor();
1302 // printf("[%d] Releasing in ProcessFileNotifications fileMonitor Mutex %x...\n", GetCurrentThreadID(), globalSystem.fileMonitorMutex);
1303 globalSystem.fileMonitorMutex.Release();
1310 #if defined(__unix__)
1312 XLockDisplay(xGlobalDisplay);
1318 #if defined(__unix__)
1320 XUnlockDisplay(xGlobalDisplay);
1322 lockMutex.Release();
1325 Cursor GetCursor(SystemCursor cursor)
1327 return systemCursors[cursor];
1330 bool GetKeyState(Key key)
1332 return interfaceDriver.GetKeyState(key);
1335 bool GetMouseState(MouseButtons * buttons, int * x, int * y)
1337 return interfaceDriver.GetMouseState(buttons, x, y);
1341 property char * appName
1345 strcpy(appName, value);
1346 if(desktop) desktop.text = appName;
1350 return (char *)(this ? appName : null);
1353 property Semaphore semaphore { get { return globalSystem.eventSemaphore; } };
1354 property bool alwaysEmptyInput{ set { processAll = value; } get { return processAll; } };
1355 property bool fullScreen
1359 SwitchMode(value, defaultDisplayDriver, resolution,
1360 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1362 get { return this ? fullScreen : false; }
1364 property char * driver
1368 SwitchMode( fullScreen, value, resolution, pixelFormat, refreshRate,
1369 currentSkin ? currentSkin.name : null, true);
1371 get { return this ? defaultDisplayDriver : null; }
1373 property Resolution resolution
1377 SwitchMode(fullScreen, defaultDisplayDriver, value, pixelFormat, refreshRate,
1378 currentSkin ? currentSkin.name : null, true);
1380 get { return this ? resolution : 0; }
1382 property PixelFormat pixelFormat
1386 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1387 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1389 get { return this ? pixelFormat : 0; }
1391 property int refreshRate
1395 SwitchMode(fullScreen, defaultDisplayDriver, resolution,
1396 pixelFormat, refreshRate, currentSkin ? currentSkin.name : null, true);
1398 get { return this ? refreshRate : 0; }
1400 property char * skin
1402 set { SelectSkin(value); }
1403 get { return (this && currentSkin) ? currentSkin.name : null; }
1405 property bool textMode
1407 set { textMode = value; } // TODO: Implement switching
1408 get { return this ? textMode : false; }
1410 property Window desktop { get { return this ? desktop : null; } };
1411 property char ** drivers { get { return null; } };
1412 property char ** skins { get { return null; } };
1413 property subclass(Skin) currentSkin { get { return this ? currentSkin : null; } };
1414 property int numDrivers { get { return 0; } };
1415 property int numSkins { get { return 0; } };
1416 property uint timerResolution
1418 set { timerResolution = value; if(interfaceDriver) interfaceDriver.SetTimerResolution(value); }