Cache the screen list information, it's a very frequent call

This commit is contained in:
Lubos Dolezel 2022-04-22 16:44:06 +02:00
parent 7edb4834c7
commit 3b8960eb56
No known key found for this signature in database
GPG Key ID: 87619D75096A7E41
2 changed files with 27 additions and 1 deletions

View File

@ -38,6 +38,8 @@
X11Cursor *_blankCursor, *_defaultCursor;
BOOL _cursorGrabbed;
KeySym _lastKeySym;
int _rrEventBase;
NSArray* _lastScreens;
@public
XIM _xim;

View File

@ -130,6 +130,11 @@ static void socketCallback(CFSocketRef s, CFSocketCallBackType type,
_xim = XOpenIM(_display, NULL, NULL, NULL);
}
int errorBase;
if (XRRQueryExtension(_display, &_rrEventBase, &errorBase)) {
XRRSelectInput(_display, DefaultRootWindow(_display), RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask | RROutputChangeNotifyMask | RROutputPropertyNotifyMask);
}
lastFocusedWindow = nil;
lastClickTimeStamp = 0.0;
clickCount = 0;
@ -178,7 +183,20 @@ static void socketCallback(CFSocketRef s, CFSocketCallBackType type,
XkbSetDetectableAutoRepeat(_display, TRUE, &supported);
}
- (void) _invalidateRRCache {
if (_lastScreens) {
[_lastScreens release];
_lastScreens = nil;
}
}
- (NSArray *) screens {
NSArray* last = [_lastScreens retain];
if (last) {
return [last autorelease];
}
int eventBase, errorBase;
if (XRRQueryExtension(_display, &eventBase, &errorBase)) {
@ -234,7 +252,9 @@ static void socketCallback(CFSocketRef s, CFSocketCallBackType type,
XRRFreeScreenResources(screen);
return [NSArray arrayWithArray: retval];
NSArray* array = [NSArray arrayWithArray: retval];
_lastScreens = [array retain];
return array;
} else {
NSRect frame = NSMakeRect(
0, 0, DisplayWidth(_display, DefaultScreen(_display)),
@ -1299,6 +1319,10 @@ static NSDictionary *modeInfoToDictionary(const XRRModeInfo *mi, int depth) {
break;
default:
if (ev->type == _rrEventBase + RRNotify) {
[self _invalidateRRCache];
break;
}
NSLog(@"Unknown X11 event type %i", ev->type);
break;
}