MacWindows.cpp
1 #include "MacWindows.h" 2 #include <stdlib.h> 3 #include <stdio.h> 4 5 #define NO_X11 6 7 #ifndef NO_X11 8 #include <X11/Xlib.h> 9 #endif 10 11 static int verbose = 0; 12 13 __attribute__((constructor)) 14 static void initme(void) { 15 verbose = getenv("STUB_VERBOSE") != NULL; 16 } 17 18 19 #ifndef NO_X11 20 static Display* g_display = nullptr; 21 #endif 22 static void closeDisplay() __attribute__((destructor)); 23 24 namespace Darling 25 { 26 27 namespace Carbon 28 { 29 30 #ifndef NO_X11 31 Display* getDisplay() 32 { 33 if (g_display) 34 return g_display; 35 36 g_display = XOpenDisplay(nullptr); 37 38 if (!g_display) 39 { 40 fprintf(stderr, "Darling Carbon: Cannot open a connection to the X server!\n"); 41 if (!getenv("DISPLAY")) 42 fprintf(stderr, "The application you are trying to run requires an X server and cannot be run only in the console.\n"); 43 abort(); 44 } 45 46 return g_display; 47 } 48 #endif 49 50 void closeDisplay() 51 { 52 #ifndef NO_X11 53 if (g_display) 54 { 55 XCloseDisplay(g_display); 56 g_display = nullptr; 57 } 58 #endif 59 } 60 61 } 62 } 63 64 OSStatus CreateNewWindow(WindowClass cls, WindowAttributes attr, const Rect* rect, WindowRef* newWindow) 65 { 66 #ifndef NO_X11 67 Window win; 68 Display* dpy; 69 int blackColor, whiteColor; 70 71 *newWindow = 0; 72 73 if (rect->right < rect->left || rect->bottom < rect->top) 74 return paramErr; 75 76 dpy = Darling::Carbon::getDisplay(); 77 blackColor = BlackPixel(dpy, DefaultScreen(dpy)); 78 whiteColor = WhitePixel(dpy, DefaultScreen(dpy)); 79 80 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), rect->left, 81 rect->top, rect->right - rect->left, 82 rect->bottom - rect->top, 0, blackColor, whiteColor); 83 84 if (!win) 85 return paramErr; 86 87 *newWindow = win; 88 #endif 89 return noErr; 90 } 91 92 void DisposeWindow(WindowRef wnd) 93 { 94 #ifndef NO_X11 95 if (wnd) 96 XDestroyWindow(Darling::Carbon::getDisplay(), wnd); 97 #endif 98 } 99 100 void ShowWindow(WindowRef wnd) 101 { 102 #ifndef NO_X11 103 if (wnd) 104 XMapWindow(Darling::Carbon::getDisplay(), Window(wnd)); 105 #endif 106 } 107 108 void HideWindow(WindowRef wnd) 109 { 110 #ifndef NO_X11 111 if (wnd) 112 XUnmapWindow(Darling::Carbon::getDisplay(), Window(wnd)); 113 #endif 114 } 115 116 void ShowHide(WindowRef wnd, Boolean showFlag) 117 { 118 if (showFlag) 119 ShowWindow(wnd); 120 else 121 HideWindow(wnd); 122 } 123 124 Boolean IsWindowVisible(WindowRef wnd) 125 { 126 return 0; 127 } 128 129 130 OSStatus SelectWindow(WindowRef a) 131 { 132 return 0; 133 } 134 135 OSStatus SetWindowContentColor(WindowRef a, const RGBColor * b) 136 { 137 return 0; 138 } 139 140 OSStatus SetWindowGroup(WindowRef a, WindowGroupRef b) 141 { 142 return 0; 143 } 144 145 OSStatus SetWindowGroupLevel(WindowGroupRef a, SInt32 b) 146 { 147 return 0; 148 } 149 150 OSStatus SetWindowTitleWithCFString(WindowRef a, CFStringRef b) 151 { 152 return 0; 153 } 154 155 OSStatus TransitionWindowWithOptions(WindowRef a, WindowTransitionEffect b, WindowTransitionAction c, const HIRect * d, Boolean e, TransitionWindowOptions * f) 156 { 157 return 0; 158 } 159 160 OSStatus CreateWindowGroup(WindowGroupAttributes a, WindowGroupRef *b) 161 { 162 return 0; 163 } 164 165 OSStatus GetWindowBounds(WindowRef a, WindowRegionCode b, Rect * c) 166 { 167 return 0; 168 } 169 170 OSStatus GetWindowEventTarget(WindowRef a) 171 { 172 return 0; 173 } 174 175 OSStatus GetWindowGroupLevel(WindowGroupRef a, SInt32 * b) 176 { 177 return 0; 178 } 179 180 WindowGroupRef GetWindowGroupOfClass(WindowClass a) 181 { 182 return (WindowGroupRef)0; 183 } 184 185 CGrafPtr GetWindowPort(WindowRef a) 186 { 187 return (CGrafPtr)0; 188 } 189 190 Rect* GetWindowPortBounds(WindowRef window, Rect * bounds) 191 { 192 return NULL; 193 } 194 195 Boolean IsValidWindowPtr(WindowRef a) 196 { 197 return 0; 198 } 199 200 OSStatus ReleaseWindow(WindowRef a) 201 { 202 return 0; 203 }