this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CF & F both building + other fixes

+9 -1603
+6
.gitmodules
··· 190 190 [submodule "src/external/configd"] 191 191 path = src/external/configd 192 192 url = ../darling-configd.git 193 + [submodule "src/external/coregraphics"] 194 + path = src/external/coregraphics 195 + url = ../darling-coregraphics.git 196 + [submodule "src/external/IONetworkingFamily"] 197 + path = src/external/IONetworkingFamily 198 + url = ../darling-IONetworkingFamily.git
+3 -2
src/CMakeLists.txt
··· 110 110 add_subdirectory(external/icu/icuSources) 111 111 add_subdirectory(external/corefoundation) 112 112 add_subdirectory(external/openssl/src) 113 - #add_subdirectory(external/foundation) 113 + #add_subdirectory(external/configd/SystemConfiguration.fproj) 114 + add_subdirectory(external/foundation) 114 115 add_subdirectory(external/curl) 115 116 add_subdirectory(external/liblzma) 116 - #add_subdirectory(external/cfnetwork) 117 + #add_subdirectory(external/cfnetwork/src) 117 118 add_subdirectory(external/pcre) 118 119 add_subdirectory(external/sqlite) 119 120 add_subdirectory(external/openpam)
-37
src/CoreGraphics/CGBase.h
··· 1 - #ifndef CGBASE_H_ 2 - #define CGBASE_H_ 3 - #include <limits.h> 4 - 5 - #ifndef CGFLOAT_DEFINED 6 - # ifdef __x86_64__ 7 - # define CGFLOAT_IS_DOUBLE 1 8 - # define CGFLOAT_MIN DBL_MIN 9 - # define CGFLOAT_MAX DBL_MAX 10 - # ifdef DARLING_BUILD 11 - # define CGFLOAT_EPSILON DBL_EPSILON 12 - # endif 13 - typedef double CGFloat; 14 - # else 15 - # define CGFLOAT_IS_DOUBLE 0 16 - # define CGFLOAT_MIN FLT_MIN 17 - # define CGFLOAT_MAX FLT_MAX 18 - # ifdef DARLING_BUILD 19 - # define CGFLOAT_EPSILON FLT_EPSILON 20 - # endif 21 - typedef float CGFloat; 22 - # endif 23 - #endif 24 - 25 - #ifndef BEGIN_EXTERN_C 26 - # ifdef __cplusplus 27 - # define BEGIN_EXTERN_C extern "C" { 28 - # define END_EXTERN_C } 29 - # else 30 - # define BEGIN_EXTERN_C 31 - # define END_EXTERN_C 32 - # endif 33 - #endif 34 - 35 - 36 - #endif 37 -
-100
src/CoreGraphics/CGContext.cpp
··· 1 - #include "CGContext.h" 2 - #include <CoreFoundation/CFRuntime.h> 3 - #include <CoreFoundation/CFDictionary.h> 4 - #include <CoreFoundation/CFString.h> 5 - #include <QPainter> 6 - 7 - static CFTypeID _kCGContextTypeID; 8 - __attribute__((constructor)) void CGContextInitialize(); 9 - 10 - struct __CGContext 11 - { 12 - CFRuntimeBase _parent; 13 - QPainter* painter; 14 - }; 15 - 16 - CGContextRef CGContextForPaintDevice(QPaintDevice* paintDevice) 17 - { 18 - CGContextRef context = (CGContextRef)_CFRuntimeCreateInstance (nullptr, _kCGContextTypeID, 19 - sizeof(struct __CGContext) - sizeof(CFRuntimeBase), nullptr); 20 - 21 - // TODO: mutual reference counting? 22 - context->painter = new QPainter(paintDevice); 23 - 24 - return context; 25 - } 26 - 27 - QPainter* CGContextGetPainter(CGContextRef ref) 28 - { 29 - return ref->painter; 30 - } 31 - 32 - CGContextRef CGContextRetain(CGContextRef c) 33 - { 34 - if (c) 35 - CFRetain(c); 36 - return c; 37 - } 38 - 39 - void CGContextRelease(CGContextRef c) 40 - { 41 - if (c) 42 - CFRelease(c); 43 - } 44 - 45 - static CFHashCode CGContextHash (CFTypeRef cf) 46 - { 47 - return CFHash (cf); 48 - } 49 - 50 - static CFStringRef CGContextCopyFormattingDesc (CFTypeRef cf, CFDictionaryRef formatOptions) 51 - { 52 - return CFSTR("CGContext"); 53 - } 54 - 55 - static Boolean CGContextEqual (CFTypeRef cf1, CFTypeRef cf2) 56 - { 57 - return cf1 == cf2; 58 - } 59 - 60 - static void CGContextDealloc(CFTypeRef cf) 61 - { 62 - CGContextRef ref = CGContextRef(cf); 63 - delete ref->painter; 64 - } 65 - 66 - void CGContextInitialize() 67 - { 68 - static const CFRuntimeClass CGContextClass = 69 - { 70 - 0, 71 - "CGContext", 72 - NULL, 73 - NULL, 74 - CGContextDealloc, 75 - NULL, 76 - CGContextHash, 77 - CGContextCopyFormattingDesc, 78 - NULL 79 - }; 80 - _kCGContextTypeID = _CFRuntimeRegisterClass (&CGContextClass); 81 - } 82 - 83 - CFTypeID CGContextGetTypeID(void) 84 - { 85 - return _kCGContextTypeID; 86 - } 87 - 88 - void CGContextSaveGState(CGContextRef c) 89 - { 90 - c->painter->save(); 91 - } 92 - 93 - void CGContextRestoreGState(CGContextRef c) 94 - { 95 - c->painter->restore(); 96 - } 97 - 98 - void CGContextFlush(CGContextRef c) 99 - { 100 - }
-21
src/CoreGraphics/CGContext.h
··· 1 - #ifndef CGCONTEXT_H_ 2 - #define CGCONTEXT_H_ 3 - #include "CGGeometry.h" 4 - #include <CoreFoundation/CFBase.h> 5 - 6 - BEGIN_EXTERN_C 7 - 8 - struct __CGContext; 9 - typedef struct __CGContext *CGContextRef; 10 - 11 - CGContextRef CGContextRetain(CGContextRef c); 12 - void CGContextRelease(CGContextRef c); 13 - CFTypeID CGContextGetTypeID(void); 14 - 15 - void CGContextSaveGState(CGContextRef c); 16 - void CGContextRestoreGState(CGContextRef c); 17 - void CGContextFlush(CGContextRef c); 18 - 19 - END_EXTERN_C 20 - 21 - #endif
-117
src/CoreGraphics/CGDirectDisplay.h
··· 1 - /* 2 - This file is part of Darling. 3 - 4 - Copyright (C) 2013 Lubos Dolezel 5 - 6 - Darling is free software: you can redistribute it and/or modify 7 - it under the terms of the GNU General Public License as published by 8 - the Free Software Foundation, either version 3 of the License, or 9 - (at your option) any later version. 10 - 11 - Darling is distributed in the hope that it will be useful, 12 - but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - GNU General Public License for more details. 15 - 16 - You should have received a copy of the GNU General Public License 17 - along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 - */ 19 - 20 - #ifndef CGDIRECTDISPLAY_H 21 - #define CGDIRECTDISPLAY_H 22 - #include <stdint.h> 23 - #include <Foundation/NSString.h> 24 - #include <CoreFoundation/CFDictionary.h> 25 - #include <CoreFoundation/CFArray.h> 26 - #include <CoreGraphics/CGGeometry.h> 27 - #include "CGError.h" 28 - 29 - extern "C" 30 - { 31 - 32 - typedef uint32_t CGCaptureOptions; 33 - typedef uint32_t CGDirectDisplayID; 34 - typedef CFDictionaryRef CGDisplayModeRef; 35 - typedef float CGGammaValue; 36 - 37 - CGDirectDisplayID CGMainDisplayID(); 38 - 39 - // couple of missing functions (locating the displays) 40 - CGError CGGetActiveDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut); 41 - CGError CGGetOnlineDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut); 42 - size_t CGDisplayPixelsWide(CGDirectDisplayID id); 43 - size_t CGDisplayPixelsHigh(CGDirectDisplayID id); 44 - 45 - // old mode APIs 46 - extern CFStringRef kCGDisplayWidth; 47 - extern CFStringRef kCGDisplayHeight; 48 - extern CFStringRef kCGDisplayMode; 49 - extern CFStringRef kCGDisplayBitsPerPixel; 50 - extern CFStringRef kCGDisplayBitsPerSample; 51 - extern CFStringRef kCGDisplaySamplesPerPixel; 52 - extern CFStringRef kCGDisplayRefreshRate; 53 - extern CFStringRef kCGDisplayModeUsableForDesktopGUI; 54 - extern CFStringRef kCGDisplayIOFlags; 55 - extern CFStringRef kCGDisplayBytesPerRow; 56 - 57 - CFDictionaryRef CGDisplayCurrentMode(CGDirectDisplayID id); 58 - CGError CGDisplaySwitchToMode(CGDirectDisplayID id, CFDictionaryRef mode); 59 - 60 - // new mode APIs 61 - CFArrayRef CGDisplayCopyAllDisplayModes(CGDirectDisplayID id); 62 - CGDisplayModeRef CGDisplayCopyDisplayMode(CGDirectDisplayID id); 63 - CGDisplayModeRef CGDisplayModeRetain(CGDisplayModeRef mode); 64 - void CGDisplayModeRelease(CGDisplayModeRef mode); 65 - CFStringRef CGDisplayModeCopyPixelEncoding(CGDisplayModeRef mode); 66 - size_t CGDisplayModeGetHeight(CGDisplayModeRef mode); 67 - double CGDisplayModeGetRefreshRate(CGDisplayModeRef mode); 68 - CFTypeID CGDisplayModeGetTypeID(); // typeid of CGDisplayModeRef 69 - size_t CGDisplayModeGetWidth(CGDisplayModeRef mode); 70 - bool CGDisplayModeIsUsableForDesktopGUI(CGDisplayModeRef mode); 71 - 72 - bool CGDisplayIsActive(CGDirectDisplayID id); 73 - bool CGDisplayIsAlwaysInMirrorSet(CGDirectDisplayID id); 74 - bool CGDisplayIsAsleep(CGDirectDisplayID id); 75 - bool CGDisplayIsBuiltin(CGDirectDisplayID id); 76 - bool CGDisplayIsCaptured(CGDirectDisplayID id); 77 - bool CGDisplayIsInHWMirrorSet(CGDirectDisplayID id); 78 - bool CGDisplayIsInMirrorSet(CGDirectDisplayID id); 79 - bool CGDisplayIsMain(CGDirectDisplayID id); 80 - bool CGDisplayIsOnline(CGDirectDisplayID id); 81 - bool CGDisplayIsStereo(CGDirectDisplayID id); 82 - CGDirectDisplayID CGDisplayMirrorsDisplay(CGDirectDisplayID id); 83 - uint32_t CGDisplayModelNumber(CGDirectDisplayID); 84 - CGDirectDisplayID CGDisplayPrimaryDisplay(CGDirectDisplayID id); 85 - double CGDisplayRotation(CGDirectDisplayID id); 86 - CGSize CGDisplayScreenSize(CGDirectDisplayID id); 87 - uint32_t CGDisplaySerialNumber(CGDirectDisplayID id); 88 - CGError CGDisplaySetDisplayMode(CGDirectDisplayID id, CGDisplayModeRef mode, CFDictionaryRef unused); 89 - uint32_t CGDisplayUnitNumber(CGDirectDisplayID id); 90 - bool CGDisplayUsesOpenGLAcceleration(CGDirectDisplayID id); 91 - uint32_t CGDisplayVendorNumber(CGDirectDisplayID id); 92 - 93 - CGError CGCaptureAllDisplays(); 94 - CGError CGCaptureAllDisplaysWithOptions(CGCaptureOptions opts); 95 - bool CGDisplayIsCaptured(CGDirectDisplayID id); 96 - CGError CGDisplayRelease(CGDirectDisplayID id); 97 - CGError CGReleaseAllDisplays(); 98 - 99 - CGError CGDisplayHideCursor(CGDirectDisplayID id); 100 - CGError CGDisplayShowCursor(CGDirectDisplayID id); 101 - 102 - CGError CGDisplayMoveCursorToPoint(CGDirectDisplayID id, CGPoint pt); 103 - void CGGetLastMouseDelta(int32_t* x, int32_t* y); 104 - 105 - // gamma 106 - CGError CGSetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue redMin, CGGammaValue redMax, CGGammaValue redGamma, 107 - CGGammaValue greenMin, CGGammaValue greenMax, CGGammaValue greenGamma, CGGammaValue blueMin, CGGammaValue blueMax, CGGammaValue blueGamma); 108 - CGError CGGetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue* redMin, CGGammaValue* redMax, CGGammaValue* redGamma, 109 - CGGammaValue* greenMin, CGGammaValue* greenMax, CGGammaValue* greenGamma, CGGammaValue* blueMin, CGGammaValue* blueMax, CGGammaValue* blueGamma); 110 - 111 - uint32_t CGDisplayGammaTableCapacity(CGDirectDisplayID id); 112 - CGError CGSetDisplayTransferByTable(CGDirectDisplayID id, uint32_t tableSize, const CGGammaValue* redTable, const CGGammaValue* greenTable, const CGGammaValue* blueTable); 113 - CGError CGGetDisplayTransferByTable(CGDirectDisplayID id, uint32_t capacity, CGGammaValue* redTable, CGGammaValue* greenTable, CGGammaValue* blueTable, uint32_t* sampleCount); 114 - 115 - } 116 - 117 - #endif
-593
src/CoreGraphics/CGDirectDisplay.mm
··· 1 - /* 2 - This file is part of Darling. 3 - 4 - Copyright (C) 2013 Lubos Dolezel 5 - 6 - Darling is free software: you can redistribute it and/or modify 7 - it under the terms of the GNU General Public License as published by 8 - the Free Software Foundation, either version 3 of the License, or 9 - (at your option) any later version. 10 - 11 - Darling is distributed in the hope that it will be useful, 12 - but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - GNU General Public License for more details. 15 - 16 - You should have received a copy of the GNU General Public License 17 - along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 - */ 19 - 20 - #include <iostream> 21 - #include "CGDirectDisplay.h" 22 - #include <CoreFoundation/CFString.h> 23 - #include <CoreFoundation/CFNumber.h> 24 - #include <X11/Xlib.h> 25 - #include <X11/extensions/Xrandr.h> 26 - #include <cstdlib> 27 - #include <cmath> 28 - 29 - static Display* g_display = nullptr; 30 - static Display* getDisplay(); 31 - static void closeDisplay() __attribute__((destructor)); 32 - 33 - static int g_lastMouseX = -1, g_lastMouseY = -1; 34 - 35 - CFStringRef kCGDisplayWidth = CFSTR("Width"); 36 - CFStringRef kCGDisplayHeight = CFSTR("Height"); 37 - CFStringRef kCGDisplayMode = CFSTR("Mode"); 38 - CFStringRef kCGDisplayBitsPerPixel = CFSTR("BitsPerPixel"); 39 - CFStringRef kCGDisplayBitsPerSample = CFSTR("BitsPerSample"); 40 - CFStringRef kCGDisplaySamplesPerPixel = CFSTR("SamplesPerPixel"); 41 - CFStringRef kCGDisplayRefreshRate = CFSTR("RefreshRate"); 42 - CFStringRef kCGDisplayModeUsableForDesktopGUI = CFSTR("UsableForDesktopGUI"); 43 - CFStringRef kCGDisplayIOFlags = CFSTR("IOFlags"); 44 - CFStringRef kCGDisplayBytesPerRow = CFSTR("kCGDisplayBytesPerRow"); 45 - static CFStringRef kCGDarlingResolutionIndex = CFSTR("kCGDarlingResolutionIndex"); 46 - 47 - Display* getDisplay() 48 - { 49 - if (g_display) 50 - return g_display; 51 - 52 - g_display = XOpenDisplay(nullptr); 53 - 54 - // Returning a CG error would be better than this 55 - if (!g_display) 56 - { 57 - std::cerr << "Darling CG: Cannot open a connection to the X server!\n"; 58 - if (!getenv("DISPLAY")) 59 - std::cerr << "The application you are trying to run requires an X server and cannot be run only in the console.\n"; 60 - abort(); 61 - } 62 - 63 - int evbase, errbase; 64 - if (!XRRQueryExtension(g_display, &evbase, &errbase)) 65 - { 66 - std::cerr << "Darling CG: XRandR not available\n"; 67 - abort(); 68 - } 69 - 70 - return g_display; 71 - } 72 - 73 - void closeDisplay() 74 - { 75 - if (g_display) 76 - { 77 - XCloseDisplay(g_display); 78 - g_display = nullptr; 79 - } 80 - } 81 - 82 - bool checkRandRVersion(int minMaj, int minMin) 83 - { 84 - static int maj = 0, min = 0; 85 - if (!maj && !min) 86 - XRRQueryVersion(getDisplay(), &maj, &min); 87 - if (minMaj < maj) 88 - return false; 89 - if (minMin < min) 90 - return false; 91 - return true; 92 - } 93 - 94 - CGError CGCaptureAllDisplays() 95 - { 96 - return kCGErrorSuccess; 97 - } 98 - 99 - CGError CGCaptureAllDisplaysWithOptions(CGCaptureOptions opts) 100 - { 101 - return kCGErrorSuccess; 102 - } 103 - 104 - bool CGDisplayIsCaptured(CGDirectDisplayID id) 105 - { 106 - return true; 107 - } 108 - 109 - CGError CGDisplayRelease(CGDirectDisplayID id) 110 - { 111 - return kCGErrorSuccess; 112 - } 113 - 114 - CGError CGReleaseAllDisplays() 115 - { 116 - return kCGErrorSuccess; 117 - } 118 - 119 - CGError CGDisplayMoveCursorToPoint(CGDirectDisplayID id, CGPoint pt) 120 - { 121 - Display* dpy = getDisplay(); 122 - Window root_window; 123 - root_window = XRootWindow(dpy, 0); 124 - 125 - XSelectInput(dpy, root_window, KeyReleaseMask); 126 - XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, pt.x, pt.y); 127 - 128 - g_lastMouseX = pt.x; 129 - g_lastMouseY = pt.y; 130 - 131 - XFlush(dpy); 132 - return kCGErrorSuccess; 133 - } 134 - 135 - void CGGetLastMouseDelta(int32_t* x, int32_t* y) 136 - { 137 - Display* dpy = getDisplay(); 138 - Window root_window; 139 - Window window_returned; 140 - int root_x, root_y; 141 - int win_x, win_y; 142 - unsigned int mask_return; 143 - 144 - root_window = XRootWindow(dpy, 0); 145 - XQueryPointer(dpy, root_window, &window_returned, 146 - &window_returned, &root_x, &root_y, &win_x, &win_y, 147 - &mask_return); 148 - 149 - if (g_lastMouseX == -1) 150 - *x = 0; 151 - else 152 - *x = root_x - g_lastMouseX; 153 - 154 - if (g_lastMouseY == -1) 155 - *y = 0; 156 - else 157 - *y = root_y - g_lastMouseY; 158 - 159 - g_lastMouseX = root_x; 160 - g_lastMouseY = root_y; 161 - } 162 - 163 - CGError CGGetActiveDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut) 164 - { 165 - Display* dpy = getDisplay(); 166 - int count = XScreenCount(dpy); 167 - 168 - for (int i = 0; i < count && i < max; i++) 169 - list[i] = i; 170 - 171 - *countOut = std::min<uint32_t>(count, max); 172 - return kCGErrorSuccess; 173 - } 174 - 175 - CGError CGGetOnlineDisplayList(uint32_t max, CGDirectDisplayID* list, uint32_t* countOut) 176 - { 177 - return CGGetActiveDisplayList(max, list, countOut); 178 - } 179 - 180 - size_t CGDisplayPixelsWide(CGDirectDisplayID id) 181 - { 182 - Screen* screen = XScreenOfDisplay(getDisplay(), id); 183 - if (!screen) 184 - return 0; 185 - else 186 - return XWidthOfScreen(screen); 187 - } 188 - 189 - size_t CGDisplayPixelsHigh(CGDirectDisplayID id) 190 - { 191 - Screen* screen = XScreenOfDisplay(getDisplay(), id); 192 - if (!screen) 193 - return 0; 194 - else 195 - return XHeightOfScreen(screen); 196 - } 197 - 198 - static void CFDictAddInt(CFMutableDictionaryRef dict, CFStringRef key, int number) 199 - { 200 - CFNumberRef num; 201 - num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &number); 202 - CFDictionaryAddValue(dict, key, num); 203 - CFRelease(num); 204 - } 205 - 206 - CFArrayRef CGDisplayCopyAllDisplayModes(CGDirectDisplayID id) 207 - { 208 - CFMutableArrayRef rv; 209 - Display* dpy = getDisplay(); 210 - XRRScreenConfiguration* rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id)); 211 - XRRScreenSize *rrsizes; 212 - int nSizes; 213 - 214 - rrsizes = XRRConfigSizes(rrc, &nSizes); 215 - 216 - if (nSizes <= 0) 217 - { 218 - XRRFreeScreenConfigInfo(rrc); 219 - return nullptr; 220 - } 221 - 222 - rv = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); 223 - for (int i = 0; i < nSizes; i++) 224 - { 225 - CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, 226 - &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 227 - short* rates; 228 - int nRates; 229 - 230 - CFDictAddInt(dict, kCGDisplayWidth, rrsizes[i].width); 231 - CFDictAddInt(dict, kCGDisplayHeight, rrsizes[i].height); 232 - CFDictAddInt(dict, kCGDisplayBitsPerPixel, 24); 233 - CFDictAddInt(dict, kCGDisplayIOFlags, 0); 234 - CFDictAddInt(dict, kCGDarlingResolutionIndex, i); 235 - 236 - CFDictionaryAddValue(dict, kCGDisplayModeUsableForDesktopGUI, 237 - (rrsizes[i].width > 800 && rrsizes[i].height > 600) ? kCFBooleanTrue : kCFBooleanFalse); 238 - 239 - rates = XRRConfigRates (rrc, i, &nRates); 240 - for (int j = 0; j < nRates; j++) 241 - { 242 - CFMutableDictionaryRef dictR = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, (CFDictionaryRef) dict); 243 - CFDictAddInt(dictR, kCGDisplayRefreshRate, rates[j]); 244 - CFDictAddInt(dictR, kCGDisplayMode, (i << 16) | rates[j]); 245 - 246 - CFArrayAppendValue(rv, dictR); 247 - CFRelease(dictR); 248 - } 249 - 250 - CFRelease(dict); 251 - } 252 - 253 - XRRFreeScreenConfigInfo(rrc); 254 - return (CFArrayRef) rv; 255 - } 256 - 257 - CGError CGDisplaySwitchToMode(CGDirectDisplayID id, CFDictionaryRef mode) 258 - { 259 - XRRScreenConfiguration* rrc; 260 - Display* dpy = getDisplay(); 261 - CFNumberRef sizeIndex, refreshRate; 262 - int sizeIndexN, refreshRateN; 263 - Status status; 264 - 265 - sizeIndex = (CFNumberRef) CFDictionaryGetValue(mode, kCGDarlingResolutionIndex); 266 - if (!sizeIndex) 267 - return kCGErrorIllegalArgument; 268 - 269 - refreshRate = (CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayRefreshRate); 270 - if (!refreshRate) 271 - return kCGErrorIllegalArgument; 272 - 273 - CFNumberGetValue(sizeIndex, kCFNumberIntType, &sizeIndexN); 274 - CFNumberGetValue(refreshRate, kCFNumberIntType, &refreshRateN); 275 - 276 - rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id)); 277 - // TODO: remove fixed RR_Rotate_0 278 - status = XRRSetScreenConfigAndRate(dpy, rrc, RootWindow(dpy, id), sizeIndexN, RR_Rotate_0, refreshRateN, CurrentTime); 279 - 280 - return (status != Success) ? kCGErrorFailure : kCGErrorSuccess; 281 - } 282 - 283 - CFDictionaryRef CGDisplayCurrentMode(CGDirectDisplayID id) 284 - { 285 - Display* dpy = getDisplay(); 286 - XRRScreenConfiguration* rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id)); 287 - XRRScreenSize *rrsizes; 288 - int nSizes; 289 - SizeID curSize; 290 - Rotation curRotation; 291 - 292 - rrsizes = XRRConfigSizes(rrc, &nSizes); 293 - 294 - if (nSizes <= 0) 295 - { 296 - XRRFreeScreenConfigInfo(rrc); 297 - return nullptr; 298 - } 299 - 300 - curSize = XRRConfigCurrentConfiguration(rrc, &curRotation); 301 - 302 - CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, 303 - &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 304 - 305 - CFDictAddInt(dict, kCGDisplayWidth, rrsizes[curSize].width); 306 - CFDictAddInt(dict, kCGDisplayHeight, rrsizes[curSize].height); 307 - CFDictAddInt(dict, kCGDisplayBitsPerPixel, 24); 308 - CFDictAddInt(dict, kCGDisplayIOFlags, 0); 309 - CFDictAddInt(dict, kCGDarlingResolutionIndex, curSize); 310 - 311 - CFDictionaryAddValue(dict, kCGDisplayModeUsableForDesktopGUI, 312 - (rrsizes[curSize].width > 800 && rrsizes[curSize].height > 600) ? kCFBooleanTrue : kCFBooleanFalse); 313 - 314 - short rate = XRRConfigCurrentRate(rrc); 315 - CFDictAddInt(dict, kCGDisplayRefreshRate, rate); 316 - CFDictAddInt(dict, kCGDisplayMode, (curSize << 16) | rate); 317 - 318 - XRRFreeScreenConfigInfo(rrc); 319 - 320 - return (CFDictionaryRef) dict; 321 - } 322 - 323 - CGDisplayModeRef CGDisplayCopyDisplayMode(CGDirectDisplayID id) 324 - { 325 - return CGDisplayCurrentMode(id); 326 - } 327 - 328 - CGDisplayModeRef CGDisplayModeRetain(CGDisplayModeRef mode) 329 - { 330 - return (CGDisplayModeRef) CFRetain(mode); 331 - } 332 - 333 - void CGDisplayModeRelease(CGDisplayModeRef mode) 334 - { 335 - CFRelease(mode); 336 - } 337 - 338 - CFStringRef CGDisplayModeCopyPixelEncoding(CGDisplayModeRef mode) 339 - { 340 - return nullptr; 341 - } 342 - 343 - static size_t CGDisplayModeGetInt(CGDisplayModeRef mode, CFStringRef key) 344 - { 345 - int n; 346 - CFNumberRef height = (CFNumberRef) CFDictionaryGetValue(mode, key); 347 - if (!height) 348 - return 0; 349 - 350 - CFNumberGetValue(height, kCFNumberIntType, &n); 351 - return n; 352 - } 353 - 354 - size_t CGDisplayModeGetHeight(CGDisplayModeRef mode) 355 - { 356 - return CGDisplayModeGetInt(mode, kCGDisplayHeight); 357 - } 358 - 359 - double CGDisplayModeGetRefreshRate(CGDisplayModeRef mode) 360 - { 361 - return CGDisplayModeGetInt(mode, kCGDisplayRefreshRate); 362 - } 363 - 364 - CFTypeID CGDisplayModeGetTypeID() 365 - { 366 - return CFDictionaryGetTypeID(); 367 - } 368 - 369 - size_t CGDisplayModeGetWidth(CGDisplayModeRef mode) 370 - { 371 - return CGDisplayModeGetInt(mode, kCGDisplayWidth); 372 - } 373 - 374 - bool CGDisplayModeIsUsableForDesktopGUI(CGDisplayModeRef mode) 375 - { 376 - CFBooleanRef _bool = (CFBooleanRef) CFDictionaryGetValue(mode, kCGDisplayModeUsableForDesktopGUI); 377 - return !!CFBooleanGetValue(_bool); 378 - } 379 - 380 - bool CGDisplayIsActive(CGDirectDisplayID id) 381 - { 382 - return true; 383 - } 384 - 385 - bool CGDisplayIsAlwaysInMirrorSet(CGDirectDisplayID id) 386 - { 387 - return false; 388 - } 389 - 390 - bool CGDisplayIsAsleep(CGDirectDisplayID id) 391 - { 392 - return false; 393 - } 394 - 395 - bool CGDisplayIsBuiltin(CGDirectDisplayID id) 396 - { 397 - return false; 398 - } 399 - 400 - bool CGDisplayIsInHWMirrorSet(CGDirectDisplayID id) 401 - { 402 - return false; 403 - } 404 - 405 - bool CGDisplayIsInMirrorSet(CGDirectDisplayID id) 406 - { 407 - return false; 408 - } 409 - 410 - bool CGDisplayIsMain(CGDirectDisplayID id) 411 - { 412 - return true; 413 - } 414 - 415 - bool CGDisplayIsOnline(CGDirectDisplayID id) 416 - { 417 - return true; 418 - } 419 - 420 - bool CGDisplayIsStereo(CGDirectDisplayID id) 421 - { 422 - return false; 423 - } 424 - 425 - CGDirectDisplayID CGDisplayMirrorsDisplay(CGDirectDisplayID id) 426 - { 427 - return id; 428 - } 429 - 430 - uint32_t CGDisplayModelNumber(CGDirectDisplayID) 431 - { 432 - return 0; 433 - } 434 - 435 - CGDirectDisplayID CGDisplayPrimaryDisplay(CGDirectDisplayID id) 436 - { 437 - return id; 438 - } 439 - 440 - double CGDisplayRotation(CGDirectDisplayID id) 441 - { 442 - Display* dpy = getDisplay(); 443 - XRRScreenConfiguration* rrc = XRRGetScreenInfo(dpy, RootWindow(dpy, id)); 444 - Rotation rot; 445 - 446 - XRRConfigCurrentConfiguration(rrc, &rot); 447 - XRRFreeScreenConfigInfo(rrc); 448 - 449 - switch (rot) 450 - { 451 - case RR_Rotate_0: 452 - return 0.0; 453 - case RR_Rotate_90: 454 - return 90.0; 455 - case RR_Rotate_180: 456 - return 180.0; 457 - case RR_Rotate_270: 458 - return 270.0; 459 - default: 460 - return 0.0; 461 - } 462 - } 463 - 464 - CGSize CGDisplayScreenSize(CGDirectDisplayID id) 465 - { 466 - Display* dpy = getDisplay(); 467 - XRRScreenResources* rrc = XRRGetScreenResources(dpy, RootWindow(dpy, id)); 468 - CGSize size; 469 - 470 - // No idea if this is even nearly correct, idea taken from Qt 471 - for (int i = 0; i < rrc->noutput; i++) 472 - { 473 - XRROutputInfo *output = XRRGetOutputInfo(dpy, rrc, rrc->outputs[i]); 474 - if (output->crtc) 475 - size = CGSizeMake(output->mm_width, output->mm_height); 476 - XRRFreeOutputInfo(output); 477 - } 478 - 479 - XRRFreeScreenResources(rrc); 480 - return size; 481 - } 482 - 483 - uint32_t CGDisplaySerialNumber(CGDirectDisplayID id) 484 - { 485 - return 0; 486 - } 487 - 488 - CGError CGDisplaySetDisplayMode(CGDirectDisplayID id, CGDisplayModeRef mode, CFDictionaryRef) 489 - { 490 - return CGDisplaySwitchToMode(id, mode); 491 - } 492 - 493 - uint32_t CGDisplayUnitNumber(CGDirectDisplayID id) 494 - { 495 - return 0; 496 - } 497 - 498 - bool CGDisplayUsesOpenGLAcceleration(CGDirectDisplayID id) 499 - { 500 - return true; 501 - } 502 - 503 - uint32_t CGDisplayVendorNumber(CGDirectDisplayID id) 504 - { 505 - return 0; 506 - } 507 - 508 - CGError CGSetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue redMin, CGGammaValue redMax, CGGammaValue redGamma, 509 - CGGammaValue greenMin, CGGammaValue greenMax, CGGammaValue greenGamma, CGGammaValue blueMin, CGGammaValue blueMax, CGGammaValue blueGamma) 510 - { 511 - if (!checkRandRVersion(1, 2)) 512 - return kCGErrorNotImplemented; 513 - 514 - int SAMPLES = CGDisplayGammaTableCapacity(id); 515 - CGGammaValue r[SAMPLES], g[SAMPLES], b[SAMPLES]; 516 - 517 - auto CalculateSample = [](float index, float min, float max, float value) -> float 518 - { 519 - return min + ((max-min) * powf(index, value)); 520 - }; 521 - 522 - for (int i = 0; i < SAMPLES; i++) 523 - { 524 - float index = 1.0f/SAMPLES * i; 525 - r[i] = CalculateSample(index, redMin, redMax, redGamma); 526 - g[i] = CalculateSample(index, greenMin, greenMax, greenGamma); 527 - b[i] = CalculateSample(index, blueMin, blueMax, blueGamma); 528 - } 529 - 530 - return CGSetDisplayTransferByTable(id, SAMPLES, r, g, b); 531 - } 532 - 533 - CGError CGGetDisplayTransferByFormula(CGDirectDisplayID id, CGGammaValue* redMin, CGGammaValue* redMax, CGGammaValue* redGamma, 534 - CGGammaValue* greenMin, CGGammaValue* greenMax, CGGammaValue* greenGamma, CGGammaValue* blueMin, CGGammaValue* blueMax, CGGammaValue* blueGamma) 535 - { 536 - if (!checkRandRVersion(1, 2)) 537 - return kCGErrorNotImplemented; 538 - 539 - return kCGErrorNotImplemented; 540 - } 541 - 542 - uint32_t CGDisplayGammaTableCapacity(CGDirectDisplayID id) 543 - { 544 - if (!checkRandRVersion(1, 2)) 545 - return kCGErrorNotImplemented; 546 - 547 - Display* dpy = getDisplay(); 548 - XRRScreenResources* rrc = XRRGetScreenResources(dpy, RootWindow(dpy, id)); 549 - int rv; 550 - 551 - rv = XRRGetCrtcGammaSize(dpy, rrc->crtcs[0]); 552 - 553 - XRRFreeScreenResources(rrc); 554 - return rv; 555 - } 556 - 557 - CGError CGSetDisplayTransferByTable(CGDirectDisplayID id, uint32_t tableSize, const CGGammaValue* redTable, const CGGammaValue* greenTable, const CGGammaValue* blueTable) 558 - { 559 - if (!checkRandRVersion(1, 2)) 560 - return kCGErrorNotImplemented; 561 - 562 - XRRCrtcGamma* gamma; 563 - Display* dpy = getDisplay(); 564 - XRRScreenResources* rrc; 565 - 566 - gamma = XRRAllocGamma(tableSize); 567 - if (!gamma) 568 - return kCGErrorCannotComplete; 569 - 570 - rrc = XRRGetScreenResources(dpy, RootWindow(dpy, id)); 571 - 572 - for (uint32_t i = 0; i < tableSize; i++) 573 - { 574 - gamma->red[i] = short(redTable[i]*65535.0f); 575 - gamma->green[i] = short(greenTable[i]*65535.0f); 576 - gamma->blue[i] = short(blueTable[i]*65535.0f); 577 - } 578 - 579 - for (int i = 0; i < rrc->ncrtc; i++) 580 - XRRSetCrtcGamma(dpy, rrc->crtcs[i], gamma); 581 - 582 - XRRFreeScreenResources(rrc); 583 - XRRFreeGamma(gamma); 584 - return kCGErrorNotImplemented; 585 - } 586 - 587 - CGError CGGetDisplayTransferByTable(CGDirectDisplayID id, uint32_t capacity, CGGammaValue* redTable, CGGammaValue* greenTable, CGGammaValue* blueTable, uint32_t* sampleCount) 588 - { 589 - if (!checkRandRVersion(1, 2)) 590 - return kCGErrorNotImplemented; 591 - return kCGErrorNotImplemented; 592 - } 593 -
-22
src/CoreGraphics/CGError.h
··· 1 - #ifndef CGERROR_H 2 - #define CGERROR_H 3 - #include <stdint.h> 4 - 5 - typedef int32_t CGError; 6 - 7 - enum : CGError 8 - { 9 - kCGErrorSuccess = 0, 10 - kCGErrorFailure = 1000, 11 - kCGErrorIllegalArgument, 12 - kCGErrorInvalidConnection, 13 - kCGErrorInvalidContext, 14 - kCGErrorCannotComplete, 15 - kCGErrorNotImplemented, 16 - kCGErrorRangeCheck, 17 - kCGErrorTypeCheck, 18 - kCGErrorInvalidOperation = 1010, 19 - kCGErrorNoneAvailable 20 - }; 21 - 22 - #endif
-13
src/CoreGraphics/CGEventRef.h
··· 1 - #ifndef CGEVENTREF_H_ 2 - #define CGEVENTREF_H_ 3 - 4 - #ifdef DARLING_BUILD 5 - # include <QEvent> 6 - typedef QEvent *CGEventRef; 7 - #else 8 - struct __CGEvent; 9 - typedef struct __CGEvent *CGEventRef; 10 - #endif 11 - 12 - #endif 13 -
-404
src/CoreGraphics/CGGeometry.cpp
··· 1 - #include "CGGeometry.h" 2 - #include <limits> 3 - #include <cmath> 4 - #include <cstring> 5 - #include <algorithm> 6 - #include <CoreFoundation/CFNumber.h> 7 - #include <CoreFoundation/CFString.h> 8 - #include <QRect> 9 - 10 - const CGRect CGRectInfinite = { CGPoint { -CGFLOAT_MAX / 2, -CGFLOAT_MAX / 2 }, CGSize { CGFLOAT_MAX, CGFLOAT_MAX } }; 11 - const CGPoint CGPointZero = { 0, 0 }; 12 - const CGSize CGSizeZero = { 0, 0 }; 13 - const CGRect CGRectZero = { CGPointZero, CGSizeZero }; 14 - const CGRect CGRectNull = { { std::numeric_limits<CGFloat>::infinity(), std::numeric_limits<CGFloat>::infinity() }, CGSizeZero }; 15 - 16 - inline CGFloat cgabs(CGFloat a) { return a > 0 ? a : -a; } 17 - 18 - CGPoint CGPointMake(CGFloat x, CGFloat y) 19 - { 20 - return CGPoint { x, y }; 21 - } 22 - 23 - CGSize CGSizeMake(CGFloat width, CGFloat height) 24 - { 25 - return CGSize { width, height }; 26 - } 27 - 28 - CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) 29 - { 30 - return CGRect { CGPoint { x, y }, CGSize { width, height } }; 31 - } 32 - 33 - CGVector CGVectorMake(CGFloat dx, CGFloat dy) 34 - { 35 - return CGVector { dx, dy }; 36 - } 37 - 38 - bool CGSizeEqualToSize(CGSize size1, CGSize size2) 39 - { 40 - return cgabs(size1.width - size2.width) < CGFLOAT_EPSILON 41 - && cgabs(size1.height - size2.height) < CGFLOAT_EPSILON; 42 - } 43 - 44 - bool CGPointEqualToPoint(CGPoint point1, CGPoint point2) 45 - { 46 - return cgabs(point1.x - point2.x) < CGFLOAT_EPSILON 47 - && cgabs(point1.y - point2.y) < CGFLOAT_EPSILON; 48 - } 49 - 50 - bool CGRectEqualToRect(CGRect rect1, CGRect rect2) 51 - { 52 - return CGSizeEqualToSize(rect1.size, rect2.size) 53 - && CGPointEqualToPoint(rect1.origin, rect2.origin); 54 - } 55 - 56 - CGFloat CGRectGetHeight(CGRect rect) 57 - { 58 - return cgabs(rect.size.height); 59 - } 60 - 61 - CGFloat CGRectGetWidth(CGRect rect) 62 - { 63 - return cgabs(rect.size.width); 64 - } 65 - 66 - CGFloat CGRectGetMaxX(CGRect rect) 67 - { 68 - return (rect.size.width > 0) ? (rect.origin.x + rect.size.width) : (rect.origin.x); 69 - } 70 - 71 - CGFloat CGRectGetMaxY(CGRect rect) 72 - { 73 - return (rect.size.height > 0) ? (rect.origin.y + rect.size.height) : (rect.origin.y); 74 - } 75 - 76 - CGFloat CGRectGetMidY(CGRect rect) 77 - { 78 - return rect.origin.y + rect.size.height/2; 79 - } 80 - 81 - CGFloat CGRectGetMidX(CGRect rect) 82 - { 83 - return rect.origin.x + rect.size.width/2; 84 - } 85 - 86 - CGFloat CGRectGetMinX(CGRect rect) 87 - { 88 - return (rect.size.width > 0) ? (rect.origin.x) : (rect.origin.x + rect.size.width); 89 - } 90 - 91 - CGFloat CGRectGetMinY(CGRect rect) 92 - { 93 - return (rect.size.height > 0) ? (rect.origin.y) : (rect.origin.y + rect.size.height); 94 - } 95 - 96 - bool CGRectIsNull(CGRect rect) 97 - { 98 - return rect.origin.x == std::numeric_limits<CGFloat>::infinity() 99 - && rect.origin.y == std::numeric_limits<CGFloat>::infinity(); 100 - } 101 - 102 - bool CGRectIsInfinite(CGRect rect) 103 - { 104 - return rect.origin.x == CGRectInfinite.origin.x 105 - && rect.origin.y == CGRectInfinite.origin.y 106 - && rect.size.width == CGRectInfinite.size.width 107 - && rect.size.height == CGRectInfinite.size.height; 108 - } 109 - 110 - bool CGRectIsEmpty(CGRect rect) 111 - { 112 - return rect.size.height == 0 && rect.size.width == 0; 113 - } 114 - 115 - bool CGRectContainsPoint(CGRect rect, CGPoint point) 116 - { 117 - return point.x >= rect.origin.x && point.x < rect.origin.x+rect.size.width 118 - && point.y >= rect.origin.y && point.y < rect.origin.y+rect.size.height; 119 - } 120 - 121 - bool CGRectContainsRect(CGRect rect1, CGRect rect2) 122 - { 123 - return CGRectContainsPoint(rect1, rect2.origin) 124 - && CGRectContainsPoint(rect1, CGPoint { rect2.origin.x+rect2.size.width, rect2.origin.y+rect2.size.height }); 125 - } 126 - 127 - CGRect CGRectStandardize(CGRect rect) 128 - { 129 - if (rect.size.width < 0) 130 - { 131 - rect.origin.x += rect.size.width; 132 - rect.size.width = -rect.size.width; 133 - } 134 - 135 - if (rect.size.height < 0) 136 - { 137 - rect.origin.y += rect.size.height; 138 - rect.size.height = -rect.size.height; 139 - } 140 - 141 - return rect; 142 - } 143 - 144 - CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy) 145 - { 146 - return CGRect { CGPoint { rect.origin.x+dx, rect.origin.y+dy }, rect.size }; 147 - } 148 - 149 - CGRect CGRectIntegral(CGRect rect) 150 - { 151 - return CGRect { 152 - CGPoint { std::floor(rect.origin.x), std::floor(rect.origin.y) }, 153 - CGSize { std::ceil(rect.size.width), std::ceil(rect.size.height) } 154 - }; 155 - } 156 - 157 - CGRect CGRectIntersection(CGRect r1, CGRect r2) 158 - { 159 - r1 = CGRectStandardize(r1); 160 - r2 = CGRectStandardize(r2); 161 - 162 - CGFloat x0 = std::max(r1.origin.x, r2.origin.x); 163 - CGFloat x1 = std::min(r1.origin.x + r1.size.width, r2.origin.x + r2.size.width); 164 - 165 - if (x0 <= x1) 166 - { 167 - CGFloat y0 = std::max(r1.origin.y, r2.origin.y); 168 - CGFloat y1 = std::min(r1.origin.y + r1.size.height, r2.origin.y + r2.size.height); 169 - 170 - if (y0 <= y1) 171 - { 172 - return CGRect { 173 - CGPoint { x0, y0 }, 174 - CGSize { x1 - x0, y1 - y0 } 175 - }; 176 - } 177 - } 178 - 179 - return CGRectNull; 180 - } 181 - 182 - CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy) 183 - { 184 - if (cgabs(dx)*2 > rect.size.width || cgabs(dy)*2 > rect.size.height) 185 - return CGRectNull; 186 - 187 - rect.origin.x -= dx; 188 - rect.origin.y -= dy; 189 - rect.size.width -= dx*2; 190 - rect.size.height -= dy*2; 191 - 192 - return rect; 193 - } 194 - 195 - CGRect CGRectUnion(CGRect r1, CGRect r2) 196 - { 197 - if (CGRectIsNull(r1)) 198 - return r2; 199 - if (CGRectIsNull(r2)) 200 - return r1; 201 - 202 - r1 = CGRectStandardize(r1); 203 - r2 = CGRectStandardize(r2); 204 - 205 - CGFloat x0 = std::min(r1.origin.x, r2.origin.x); 206 - CGFloat x1 = std::max(r1.origin.x + r1.size.width, r2.origin.x + r2.size.width); 207 - CGFloat y0 = std::min(r1.origin.y, r2.origin.y); 208 - CGFloat y1 = std::max(r1.origin.y + r1.size.height, r2.origin.y + r2.size.height); 209 - 210 - return CGRect { 211 - CGPoint { x0, y0 }, 212 - CGSize { x1 - x0, y1 - y0 } 213 - }; 214 - } 215 - 216 - void CGRectDivide(CGRect rect, CGRect* slice, CGRect* remainder, CGFloat amount, CGRectEdge edge) 217 - { 218 - rect = CGRectStandardize(rect); 219 - 220 - if (((edge == CGRectMinXEdge || edge == CGRectMaxXEdge) && amount > rect.size.width) 221 - || ((edge == CGRectMinYEdge || edge == CGRectMaxYEdge) && amount > rect.size.height)) 222 - { 223 - memcpy(slice, &rect, sizeof(CGRect)); 224 - memcpy(remainder, &CGRectZero, sizeof(CGRect)); 225 - return; 226 - } 227 - 228 - switch (edge) 229 - { 230 - case CGRectMinXEdge: 231 - slice->origin.x = rect.origin.x; 232 - slice->origin.y = rect.origin.y; 233 - slice->size.width = amount; 234 - slice->size.height = rect.size.height; 235 - 236 - remainder->origin.x = rect.origin.x + amount; 237 - remainder->origin.y = rect.origin.y; 238 - remainder->size.width = rect.size.width - amount; 239 - remainder->size.height = rect.size.height; 240 - 241 - break; 242 - case CGRectMinYEdge: 243 - slice->origin.x = rect.origin.x; 244 - slice->origin.y = rect.origin.y; 245 - slice->size.width = rect.size.width; 246 - slice->size.height = amount; 247 - 248 - remainder->origin.x = rect.origin.x; 249 - remainder->origin.y = rect.origin.y + amount; 250 - remainder->size.width = rect.size.width; 251 - remainder->size.height = rect.size.height - amount; 252 - 253 - break; 254 - case CGRectMaxXEdge: 255 - slice->origin.x = rect.origin.x + rect.size.width - amount; 256 - slice->origin.y = rect.origin.y; 257 - slice->size.width = amount; 258 - slice->size.height = rect.size.height; 259 - 260 - remainder->origin.x = rect.origin.x; 261 - remainder->origin.y = rect.origin.y; 262 - remainder->size.width = rect.size.width - amount; 263 - remainder->size.height = rect.size.height; 264 - 265 - break; 266 - case CGRectMaxYEdge: 267 - slice->origin.x = rect.origin.x; 268 - slice->origin.y = rect.origin.y + rect.size.height - amount; 269 - slice->size.width = rect.size.width; 270 - slice->size.height = amount; 271 - 272 - remainder->origin.x = rect.origin.x; 273 - remainder->origin.y = rect.origin.y; 274 - remainder->size.width = rect.size.width; 275 - remainder->size.height = rect.size.height - amount; 276 - 277 - break; 278 - } 279 - } 280 - 281 - CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point) 282 - { 283 - CFNumberRef values[2]; 284 - static const CFStringRef keys[] = { CFSTR("X"), CFSTR("Y") }; 285 - CFDictionaryRef dict; 286 - 287 - values[0] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &point.x); 288 - values[1] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &point.y); 289 - 290 - dict = CFDictionaryCreate(nullptr, (const void**) keys, (const void**) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 291 - 292 - CFRelease(values[0]); 293 - CFRelease(values[1]); 294 - 295 - return dict; 296 - } 297 - 298 - CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size) 299 - { 300 - CFNumberRef values[2]; 301 - static const CFStringRef keys[] = { CFSTR("Width"), CFSTR("Height") }; 302 - CFDictionaryRef dict; 303 - 304 - values[0] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &size.width); 305 - values[1] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &size.height); 306 - 307 - dict = CFDictionaryCreate(nullptr, (const void**) keys, (const void**) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 308 - 309 - CFRelease(values[0]); 310 - CFRelease(values[1]); 311 - 312 - return dict; 313 - } 314 - 315 - CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect rect) 316 - { 317 - CFNumberRef values[4]; 318 - static const CFStringRef keys[] = { CFSTR("X"), CFSTR("Y"), CFSTR("Width"), CFSTR("Height") }; 319 - CFDictionaryRef dict; 320 - 321 - values[0] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.origin.x); 322 - values[1] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.origin.y); 323 - values[2] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.size.width); 324 - values[3] = CFNumberCreate(nullptr, kCFNumberCGFloatType, &rect.size.height); 325 - 326 - dict = CFDictionaryCreate(nullptr, (const void**) keys, (const void**) values, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 327 - 328 - CFRelease(values[0]); 329 - CFRelease(values[1]); 330 - CFRelease(values[2]); 331 - CFRelease(values[3]); 332 - 333 - return dict; 334 - } 335 - 336 - bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point) 337 - { 338 - CFNumberRef x, y; 339 - 340 - if (!point) 341 - return false; 342 - 343 - x = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("X")); 344 - y = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Y")); 345 - 346 - if (!x || !y) 347 - return false; 348 - 349 - if (CFGetTypeID(x) != CFNumberGetTypeID() || CFGetTypeID(y) != CFNumberGetTypeID()) 350 - return false; 351 - 352 - return CFNumberGetValue(x, kCFNumberCGFloatType, &point->x) 353 - && CFNumberGetValue(y, kCFNumberCGFloatType, &point->y); 354 - } 355 - 356 - bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size) 357 - { 358 - CFNumberRef w, h; 359 - 360 - if (!size) 361 - return false; 362 - 363 - w = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Width")); 364 - h = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Height")); 365 - 366 - if (!w || !h) 367 - return false; 368 - 369 - if (CFGetTypeID(w) != CFNumberGetTypeID() || CFGetTypeID(h) != CFNumberGetTypeID()) 370 - return false; 371 - 372 - return CFNumberGetValue(w, kCFNumberCGFloatType, &size->width) 373 - && CFNumberGetValue(h, kCFNumberCGFloatType, &size->height); 374 - } 375 - 376 - bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect *rect) 377 - { 378 - CFNumberRef x, y, w, h; 379 - 380 - if (!rect) 381 - return false; 382 - 383 - x = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("X")); 384 - y = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Y")); 385 - w = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Width")); 386 - h = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR("Height")); 387 - 388 - if (!x || !y || !w || !h) 389 - return false; 390 - 391 - if (CFGetTypeID(x) != CFNumberGetTypeID() || CFGetTypeID(y) != CFNumberGetTypeID() 392 - || CFGetTypeID(w) != CFNumberGetTypeID() || CFGetTypeID(h) != CFNumberGetTypeID()) 393 - { 394 - return false; 395 - } 396 - 397 - return CFNumberGetValue(x, kCFNumberCGFloatType, &rect->origin.x) 398 - && CFNumberGetValue(y, kCFNumberCGFloatType, &rect->origin.y) 399 - && CFNumberGetValue(w, kCFNumberCGFloatType, &rect->size.width) 400 - && CFNumberGetValue(h, kCFNumberCGFloatType, &rect->size.height); 401 - } 402 - 403 - 404 -
-98
src/CoreGraphics/CGGeometry.h
··· 1 - #ifndef CGGEOMETRY_H_ 2 - #define CGGEOMETRY_H_ 3 - #include "CGBase.h" 4 - #include <float.h> 5 - #include <stdbool.h> 6 - #include <CoreFoundation/CFDictionary.h> 7 - 8 - BEGIN_EXTERN_C 9 - 10 - struct CGPoint 11 - { 12 - CGFloat x; 13 - CGFloat y; 14 - }; 15 - typedef struct CGPoint CGPoint; 16 - //typedef struct CGPoint NSPoint; 17 - 18 - struct CGSize 19 - { 20 - CGFloat width; 21 - CGFloat height; 22 - }; 23 - typedef struct CGSize CGSize; 24 - //typedef struct CGSize NSSize; 25 - 26 - struct CGVector 27 - { 28 - CGFloat dx; 29 - CGFloat dy; 30 - }; 31 - typedef struct CGVector CGVector; 32 - 33 - struct CGRect 34 - { 35 - CGPoint origin; 36 - CGSize size; 37 - }; 38 - typedef struct CGRect CGRect; 39 - //typedef struct CGRect NSRect; 40 - 41 - enum CGRectEdge 42 - { 43 - CGRectMinXEdge, 44 - CGRectMinYEdge, 45 - CGRectMaxXEdge, 46 - CGRectMaxYEdge 47 - }; 48 - typedef enum CGRectEdge CGRectEdge; 49 - 50 - extern const CGRect CGRectInfinite; 51 - extern const CGPoint CGPointZero; 52 - extern const CGRect CGRectZero; 53 - extern const CGSize CGSizeZero; 54 - extern const CGRect CGRectNull; 55 - 56 - CGPoint CGPointMake(CGFloat x, CGFloat y); 57 - CGSize CGSizeMake(CGFloat width, CGFloat height); 58 - CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height); 59 - CGVector CGVectorMake(CGFloat dx, CGFloat dy); 60 - 61 - bool CGSizeEqualToSize(CGSize size1, CGSize size2); 62 - bool CGPointEqualToPoint(CGPoint point1, CGPoint point2); 63 - bool CGRectEqualToRect(CGRect rect1, CGRect rect2); 64 - 65 - CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point); 66 - CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size); 67 - CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect rect); 68 - 69 - bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point); 70 - bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size); 71 - bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect *rect); 72 - 73 - CGFloat CGRectGetHeight(CGRect rect); 74 - CGFloat CGRectGetWidth(CGRect rect); 75 - CGFloat CGRectGetMaxX(CGRect rect); 76 - CGFloat CGRectGetMaxY(CGRect rect); 77 - CGFloat CGRectGetMinX(CGRect rect); 78 - CGFloat CGRectGetMinY(CGRect rect); 79 - CGFloat CGRectGetMidX(CGRect rect); 80 - CGFloat CGRectGetMidY(CGRect rect); 81 - bool CGRectIsNull(CGRect rect); 82 - bool CGRectIsInfinite(CGRect rect); 83 - bool CGRectContainsPoint(CGRect rect, CGPoint point); 84 - bool CGRectContainsRect(CGRect rect1, CGRect rect2); 85 - 86 - CGRect CGRectStandardize(CGRect rect); 87 - CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy); 88 - CGRect CGRectIntegral(CGRect rect); 89 - CGRect CGRectIntersection(CGRect r1, CGRect r2); 90 - CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy); 91 - CGRect CGRectUnion(CGRect r1, CGRect r2); 92 - void CGRectDivide(CGRect rect, CGRect* slice, CGRect* remainder, CGFloat amount, CGRectEdge edge); 93 - 94 - 95 - END_EXTERN_C 96 - 97 - #endif 98 -
-126
src/CoreGraphics/CGLayer.cpp
··· 1 - #include "CGLayer.h" 2 - #include <QPicture> 3 - #include <QPainter> 4 - #include <CoreFoundation/CFRuntime.h> 5 - #include <CoreFoundation/CFDictionary.h> 6 - #include <CoreFoundation/CFString.h> 7 - 8 - static CFTypeID _kCGLayerTypeID; 9 - __attribute__((constructor)) void CGLayerInitialize(); 10 - 11 - // in CGContext.cpp 12 - CGContextRef CGContextForPaintDevice(QPaintDevice* paintDevice); 13 - QPainter* CGContextGetPainter(CGContextRef ref); 14 - 15 - struct __CGLayer 16 - { 17 - CFRuntimeBase _parent; 18 - QPicture* picture; 19 - CGContextRef context; 20 - }; 21 - 22 - void CGContextDrawLayerAtPoint(CGContextRef context, CGPoint point, CGLayerRef layer) 23 - { 24 - QPainter* painter = CGContextGetPainter(context); 25 - painter->drawPicture(QPointF(point.x, point.y), *layer->picture); 26 - } 27 - 28 - void CGContextDrawLayerInRect(CGContextRef context, CGRect rect, CGLayerRef layer) 29 - { 30 - QPainter* painter = CGContextGetPainter(context); 31 - QTransform tf = painter->worldTransform(); 32 - qreal sx, sy; 33 - CGSize origSize = CGLayerGetSize(layer); 34 - 35 - sx = CGRectGetWidth(rect) / origSize.width; 36 - sy = CGRectGetHeight(rect) / origSize.height; 37 - 38 - painter->scale(sx, sy); 39 - 40 - painter->drawPicture(QPointF(rect.origin.x / sx, rect.origin.y / sy), *layer->picture); 41 - 42 - painter->setWorldTransform(tf); 43 - } 44 - 45 - CGLayerRef CGLayerCreateWithContext(CGContextRef context, CGSize size, CFDictionaryRef auxiliaryInfo) 46 - { 47 - CGLayerRef layer = (CGLayerRef)_CFRuntimeCreateInstance (nullptr, _kCGLayerTypeID, 48 - sizeof(struct __CGLayer) - sizeof(CFRuntimeBase), nullptr); 49 - 50 - layer->picture = new QPicture; 51 - layer->picture->setBoundingRect(QRect(0, 0, size.width, size.height)); 52 - layer->context = CGContextForPaintDevice(layer->picture); 53 - 54 - // TODO: copy over settings from "context" 55 - 56 - return layer; 57 - } 58 - 59 - CGContextRef CGLayerGetContext(CGLayerRef layer) 60 - { 61 - return layer->context; 62 - } 63 - 64 - CGSize CGLayerGetSize(CGLayerRef layer) 65 - { 66 - QRect rect = layer->picture->boundingRect(); 67 - return CGSize { CGFloat(rect.width()), CGFloat(rect.height()) }; 68 - } 69 - 70 - static CFHashCode CGLayerHash (CFTypeRef cf) 71 - { 72 - return CFHash (cf); 73 - } 74 - 75 - static CFStringRef CGLayerCopyFormattingDesc (CFTypeRef cf, CFDictionaryRef formatOptions) 76 - { 77 - return CFSTR("CGLayer"); 78 - } 79 - 80 - static Boolean CGLayerEqual (CFTypeRef cf1, CFTypeRef cf2) 81 - { 82 - return cf1 == cf2; 83 - } 84 - 85 - static void CGLayerDealloc(CFTypeRef cf) 86 - { 87 - CGLayerRef ref = CGLayerRef(cf); 88 - CFRelease(ref->context); 89 - delete ref->picture; 90 - } 91 - 92 - void CGLayerInitialize() 93 - { 94 - static const CFRuntimeClass CGLayerClass = 95 - { 96 - 0, 97 - "CGLayer", 98 - NULL, 99 - NULL, 100 - CGLayerDealloc, 101 - NULL, 102 - CGLayerHash, 103 - CGLayerCopyFormattingDesc, 104 - NULL 105 - }; 106 - _kCGLayerTypeID = _CFRuntimeRegisterClass (&CGLayerClass); 107 - } 108 - 109 - CFTypeID CGLayerGetTypeID(void) 110 - { 111 - return _kCGLayerTypeID; 112 - } 113 - 114 - 115 - void CGLayerRelease(CGLayerRef layer) 116 - { 117 - if (layer) 118 - CFRelease(layer); 119 - } 120 - 121 - CGLayerRef CGLayerRetain(CGLayerRef layer) 122 - { 123 - if (layer) 124 - CFRetain(layer); 125 - return layer; 126 - }
-23
src/CoreGraphics/CGLayer.h
··· 1 - #ifndef CGLAYER_H_ 2 - #define CGLAYER_H_ 3 - #include <CoreFoundation/CFDictionary.h> 4 - #include "CGContext.h" 5 - #include "CGGeometry.h" 6 - 7 - BEGIN_EXTERN_C 8 - 9 - struct __CGLayer; 10 - typedef __CGLayer *CGLayerRef; 11 - 12 - void CGContextDrawLayerAtPoint(CGContextRef context, CGPoint point, CGLayerRef layer); 13 - void CGContextDrawLayerInRect(CGContextRef context, CGRect rect, CGLayerRef layer); 14 - CGLayerRef CGLayerCreateWithContext(CGContextRef context, CGSize size, CFDictionaryRef auxiliaryInfo); 15 - CGContextRef CGLayerGetContext(CGLayerRef layer); 16 - CGSize CGLayerGetSize(CGLayerRef layer); 17 - CFTypeID CGLayerGetTypeID(void); 18 - void CGLayerRelease(CGLayerRef layer); 19 - CGLayerRef CGLayerRetain(CGLayerRef layer); 20 - 21 - END_EXTERN_C 22 - 23 - #endif
-47
src/CoreGraphics/CMakeLists.txt
··· 1 - project(CoreGraphics) 2 - 3 - cmake_minimum_required(VERSION 2.4.0) 4 - if(COMMAND cmake_policy) 5 - cmake_policy(SET CMP0003 NEW) 6 - endif(COMMAND cmake_policy) 7 - 8 - set(QT_USE_QTDECLARATIVE TRUE) 9 - find_package(Qt4 REQUIRED) 10 - 11 - add_definitions(${QT_DEFINITIONS}) 12 - include_directories(${QT_INCLUDE_DIR}) 13 - include(${QT_USE_FILE}) 14 - 15 - #if (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang") 16 - # message(FATAL_ERROR "Clang is the only supported compiler.") 17 - #endif (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang") 18 - 19 - #configure_file(config.h.in config.h) 20 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 21 - #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks") 22 - 23 - add_definitions(-D__STDC_LIMIT_MACROS) 24 - add_definitions(-DDARLING_BUILD) 25 - 26 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 27 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) 28 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../util) 29 - 30 - set(CoreGraphics_SRCS 31 - CGDirectDisplay.mm 32 - CGGeometry.cpp 33 - CGLayer.cpp 34 - CGContext.cpp 35 - ) 36 - 37 - SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/darling") 38 - #SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags") 39 - SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 40 - SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 41 - 42 - add_library(CoreGraphics SHARED ${CoreGraphics_SRCS}) 43 - target_link_libraries(CoreGraphics -lopal -lgnustep-corebase -lX11 -lXrandr 44 - -lgnustep-corebase ${QT_LIBRARIES}) 45 - 46 - install(TARGETS CoreGraphics DESTINATION "${CMAKE_INSTALL_LIBDIR}/darling") 47 -