+- (id) initWithDomain:(NSString *)_domain module:(NSString *)_module
+{
+ // Key-Value Observing tries to create an Objective-C class named
+ // NSKVONotifying_GlobalDefaults when the configuration page is shown. But if
+ // this is the second XScreenSaver .saver running in the same process, class
+ // creation fails because that class name was already used by the first
+ // .saver, and it refers to the GlobalDefaults from the other .saver.
+
+ // This gives the class a unique name, sidestepping the above issue.
+
+ // It really just needs to be unique for this .saver and this instance.
+ // Using the pointer to the .saver's mach_header and the full path to the
+ // .saver would be preferable, but this should be good enough.
+ char class_name[128];
+ sprintf(class_name, "GlobalDefaults_%s_%p_%u",
+ strrchr(_module.UTF8String, '.') + 1, self, random());
+ Class c = objc_allocateClassPair([GlobalDefaults class], class_name, 0);
+ if (!c)
+ return nil;
+ objc_registerClassPair(c);
+