Created
May 20, 2024 09:02
-
-
Save hym3242/28c83569bf23b351eb015fc22d0333d0 to your computer and use it in GitHub Desktop.
Uses some SkyLight private symbols to print some useful stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//cc SLsymtest.c -g -o SLsymtest -framework Carbon -undefined dynamic_lookup | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <CoreFoundation/CoreFoundation.h> | |
#include <CoreGraphics/CoreGraphics.h> | |
#include <ApplicationServices/ApplicationServices.h> | |
void SLDisplayDefaultVisualBell(); | |
void SLSGetDebugOptions(int* options); | |
void SLSSetDebugOptions(int); | |
void SLSForceWaitCursorActive(int, int); | |
int SLSDefaultConnectionForThread(void); | |
int SLSSetCursorScale(int cid, double scale); | |
int SLSMainConnectionID(void); | |
int SLSConnectionGetPID(int cid, pid_t *outPID); | |
int SLSCreateLoginSession(int *outSession); | |
int SLSReleaseSession(int session); | |
CFArrayRef SLSCopySpaces(int cid, int mask); | |
int SLSGetActiveSpace(int cid); | |
void SLSShowSpaces(int cid, CFArrayRef spaces); | |
void SLSHideSpaces(int cid, CFArrayRef spaces); | |
void SLSManagedDisplaySetCurrentSpace(int cid, CFStringRef display, int space); //does not actually change current space nor any transition, just displays it in front and brings the app of that space to front. New open windows seem to be layered on real current space, but is actually on the switched to space | |
CGDirectDisplayID SLSMainDisplayID(void); | |
int SLSGetWorkspace(int cid, int *outWorkspace); | |
int SLSSpaceSetFrontPSN(int, int, int); | |
void SLPSSetFrontProcess(ProcessSerialNumber); //(must pass a ptr) | |
int SLSSetFrontWindow(int cid, int wid); | |
CFArrayRef SLSCopySessionList(void); | |
CFDictionaryRef SLSCopyCurrentSessionDictionary(void); | |
CFArrayRef SLSSpaceCopyOwners(int cid, int sid); | |
CFArrayRef SLSCopySpacesForWindows(int cid, int mask, CFArrayRef windowIDs); | |
int SLSSetWorkspace(int cid, int workspace); | |
extern void SLDisplayForceToGray(bool forceToGray); | |
int SLSDisplayGetCurrentVBLDeltaInNanoseconds(int dispid); | |
//int _CGXDumpCursorInfo(int arg0); | |
int cid; | |
int ret; | |
CFArrayRef cfarraywithanum(int num){ | |
int tmpint = num; | |
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &tmpint); | |
const void *tmpelements[] = { number }; | |
CFArrayRef array = CFArrayCreate(kCFAllocatorDefault, tmpelements, 1, &kCFTypeArrayCallBacks); | |
return array; | |
} | |
void dumpCFArrayOfNums(char* desc, CFArrayRef array){ | |
CFIndex cnt = CFArrayGetCount(array); | |
printf("---- %s\n",desc); | |
for (CFIndex i = 0; i < cnt; i++){ | |
CFNumberRef number = CFArrayGetValueAtIndex(array, i); | |
int tempint; | |
CFNumberGetValue(number,kCFNumberIntType, &tempint); | |
printf("array[%ld]: %d\n", i, tempint); | |
} | |
printf("----\n"); | |
} | |
int main(){ | |
int debugoptions; | |
CFArrayRef array; | |
CFStringRef curdisplay; | |
cid = SLSMainConnectionID(); | |
// SLDisplayDefaultVisualBell(); //via default mach port to windowserver (after SkyLight bootstraps) | |
SLSGetDebugOptions(&debugoptions); | |
printf("debugoptions: 0x%08X\n", debugoptions); | |
SLSSetDebugOptions(0x8000009c); | |
SLSGetDebugOptions(&debugoptions); | |
printf("debugoptions: 0x%08X\n", debugoptions); | |
// SLSForceWaitCursorActive(cid,0); | |
// _CGXDumpCursorInfo(0); //need global sessioncontrolref | |
pid_t outpid; | |
ret = SLSConnectionGetPID(cid, &outpid); | |
printf("conn pid %d\n",outpid); | |
array = SLSCopySpaces(cid,1<<0|1<<1|1<<2); | |
CFIndex count = CFArrayGetCount(array); | |
for (CFIndex i = 0; i < count; ++i) { | |
CFNumberRef number = (CFNumberRef)CFArrayGetValueAtIndex(array, i); | |
int value; | |
if (CFNumberGetValue(number, kCFNumberIntType, &value)) { | |
printf("spaces[%ld]: %d\n", i, value); | |
} | |
} | |
int tmpint = 270; | |
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &tmpint); | |
const void *tmpelements[] = { number }; | |
CFArrayRef showarray = CFArrayCreate(kCFAllocatorDefault, tmpelements, 1, &kCFTypeArrayCallBacks); | |
SLSHideSpaces(cid,showarray); | |
CGDirectDisplayID dispid = SLSMainDisplayID(); | |
printf("directdispid: %d (0x%08X)\n",dispid,dispid); | |
printf("Current Display VBL Delta in ns: %d\n",SLSDisplayGetCurrentVBLDeltaInNanoseconds(dispid)); | |
int curworkspace; | |
SLSGetWorkspace(cid, &curworkspace); | |
printf("current workspace: %d\n",curworkspace); | |
printf("active space: %d\n",SLSGetActiveSpace(cid)); | |
CGDirectDisplayID mainDisplay = CGMainDisplayID(); | |
CFUUIDRef uuid = CGDisplayCreateUUIDFromDisplayID(mainDisplay); | |
if (uuid != NULL) { | |
CFStringRef uuidString = CFUUIDCreateString(NULL, uuid); | |
printf("main display UUID: %s\n", CFStringGetCStringPtr(uuidString, kCFStringEncodingUTF8)); | |
// SLSManagedDisplaySetCurrentSpace(cid, uuidString, 316); //works... but weirdly | |
// printf("active space after setcurrentspace: %d\n",SLSGetActiveSpace(cid)); | |
} | |
// ret = SLSSpaceSetFrontPSN(cid, 307, 0); //does not work! | |
ret = SLSSetFrontWindow(cid, 71557); | |
CFDictionaryRef sessionlist = SLSCopyCurrentSessionDictionary(); | |
CFNumberRef sessionid_cfnumref = CFDictionaryGetValue(sessionlist, CFSTR("kCGSSessionIDKey")); | |
int tempint; | |
CFNumberGetValue(sessionid_cfnumref, kCFNumberIntType, &tempint); | |
printf("current session id: %d\n",tempint); | |
array = SLSSpaceCopyOwners(cid, 316); | |
CFIndex cnt = CFArrayGetCount(array); | |
for (CFIndex i = 0; i < cnt; i++){ | |
CFNumberRef number = CFArrayGetValueAtIndex(array, i); | |
int tempint; | |
CFNumberGetValue(number,kCFNumberIntType, &tempint); | |
printf("space 1 owners[%ld]: %d", i, tempint); | |
} | |
dumpCFArrayOfNums("the space for window", SLSCopySpacesForWindows(cid, 1<<0|1<<1|1<<2, cfarraywithanum(0x25e5))); //works! | |
SLDisplayForceToGray(0); //works | |
// ProcessSerialNumber psn; | |
// ret = GetProcessForPID((pid_t)71557, &psn); | |
// SLPSSetFrontProcess(psn); //must pass a ptr. now segfaults. | |
// int outsession; | |
// ret = SLSCreateLoginSession(&outsession); //works!!! | |
// printf("login session created: %d\n",outsession); | |
// SLSReleaseSession(outsession); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment