diff --git a/hw/darwin/apple/English.lproj/InfoPlist.strings b/hw/darwin/apple/English.lproj/InfoPlist.strings new file mode 100644 index 000000000..88e1f04ac Binary files /dev/null and b/hw/darwin/apple/English.lproj/InfoPlist.strings differ diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/entries b/hw/darwin/apple/English.lproj/main.nib/.svn/entries new file mode 100644 index 000000000..95a15f220 --- /dev/null +++ b/hw/darwin/apple/English.lproj/main.nib/.svn/entries @@ -0,0 +1,65 @@ +8 + +dir +29110 +svn+ssh://src.apple.com/svn/BSD/X11server/trunk/darwin/apple/English.lproj/main.nib +svn+ssh://src.apple.com/svn/BSD + + + +2007-02-03T03:06:20.842932Z +28761 +bbyer + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +e92bca22-270c-0410-9cea-e3f1106b6a1c + +info.nib +file + + + + +2007-02-27T01:00:07.000000Z +456347804c516786b1d1339ce2ef50a2 +2007-02-03T03:06:20.842932Z +28761 +bbyer + +keyedobjects.nib +file + + + + +2007-02-27T01:00:07.000000Z +eb3010372b09768c846df0d996cfdd8d +2007-02-03T03:06:20.842932Z +28761 +bbyer +has-props + +classes.nib +file + + + + +2007-02-27T01:00:07.000000Z +0ae2660c3afabbd5aa02fc34712c96e6 +2007-02-03T03:06:20.842932Z +28761 +bbyer + diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/format b/hw/darwin/apple/English.lproj/main.nib/.svn/format new file mode 100644 index 000000000..45a4fb75d --- /dev/null +++ b/hw/darwin/apple/English.lproj/main.nib/.svn/format @@ -0,0 +1 @@ +8 diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/prop-base/keyedobjects.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/prop-base/keyedobjects.nib.svn-base new file mode 100644 index 000000000..5e9587e65 --- /dev/null +++ b/hw/darwin/apple/English.lproj/main.nib/.svn/prop-base/keyedobjects.nib.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/classes.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/classes.nib.svn-base new file mode 100644 index 000000000..a82159bd5 --- /dev/null +++ b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/classes.nib.svn-base @@ -0,0 +1,318 @@ + + + + + IBClasses + + + CLASS + IBLibraryObjectTemplate + LANGUAGE + ObjC + OUTLETS + + draggedView + NSView + representedObject + NSObject + + SUPERCLASS + NSView + + + CLASS + IBInspector + LANGUAGE + ObjC + OUTLETS + + inspectorView + NSView + + SUPERCLASS + NSObject + + + CLASS + NSDateFormatter + LANGUAGE + ObjC + SUPERCLASS + NSFormatter + + + ACTIONS + + apps_table_cancel + id + apps_table_delete + id + apps_table_done + id + apps_table_duplicate + id + apps_table_new + id + apps_table_show + id + bring_to_front + id + close_window + id + enable_fullscreen_changed + id + minimize_window + id + next_window + id + prefs_changed + id + prefs_show + id + previous_window + id + toggle_fullscreen + id + x11_help + id + zoom_window + id + + CLASS + X11Controller + LANGUAGE + ObjC + OUTLETS + + apps_separator + id + apps_table + id + depth + id + dock_apps_menu + id + dock_menu + id + dock_window_separator + id + enable_auth + id + enable_fullscreen + id + enable_keyequivs + id + enable_tcp + id + fake_buttons + id + prefs_panel + id + sync_keymap + id + toggle_fullscreen_item + id + use_sysbeep + id + window_separator + id + x11_about_item + id + + SUPERCLASS + NSObject + + + CLASS + NSNumberFormatter + LANGUAGE + ObjC + SUPERCLASS + NSFormatter + + + CLASS + NSFormatter + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + ACTIONS + + alignCenter: + id + alignJustified: + id + alignLeft: + id + alignRight: + id + arrangeInFront: + id + centerSelectionInVisibleArea: + id + changeFont: + id + checkSpelling: + id + clear: + id + clearRecentDocuments: + id + complete: + id + copy: + id + copyFont: + id + copyRuler: + id + cut: + id + delete: + id + deminiaturize: + id + fax: + id + hide: + id + hideOtherApplications: + id + loosenKerning: + id + lowerBaseline: + id + makeKeyAndOrderFront: + id + miniaturize: + id + newDocument: + id + openDocument: + id + orderBack: + id + orderFront: + id + orderFrontColorPanel: + id + orderFrontHelpPanel: + id + orderOut: + id + outline: + id + paste: + id + pasteAsPlainText: + id + pasteAsRichText: + id + pasteFont: + id + pasteRuler: + id + pause: + id + performClose: + id + performFindPanelAction: + id + performMiniaturize: + id + performZoom: + id + play: + id + print: + id + printDocument: + id + raiseBaseline: + id + record: + id + redo: + id + resume: + id + revertDocumentToSaved: + id + run: + id + runPageLayout: + id + runToolbarCustomizationPalette: + id + saveAllDocuments: + id + saveDocument: + id + saveDocumentAs: + id + saveDocumentTo: + id + selectAll: + id + selectText: + id + showGuessPanel: + id + showHelp: + id + start: + id + startSpeaking: + id + stop: + id + stopSpeaking: + id + subscript: + id + superscript: + id + terminate: + id + tightenKerning: + id + toggleContinuousSpellChecking: + id + toggleRuler: + id + toggleToolbarShown: + id + turnOffKerning: + id + turnOffLigatures: + id + underline: + id + undo: + id + unhideAllApplications: + id + unscript: + id + useAllLigatures: + id + useStandardKerning: + id + useStandardLigatures: + id + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + IBVersion + 1 + + diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/info.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/info.nib.svn-base new file mode 100644 index 000000000..88bc6260d --- /dev/null +++ b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/info.nib.svn-base @@ -0,0 +1,18 @@ + + + + + IBFramework Version + 588 + IBOpenObjects + + 244 + 29 + 423 + + IBSystem Version + 9A356 + targetFramework + IBCocoaFramework + + diff --git a/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/keyedobjects.nib.svn-base b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/keyedobjects.nib.svn-base new file mode 100644 index 000000000..8b31450ff Binary files /dev/null and b/hw/darwin/apple/English.lproj/main.nib/.svn/text-base/keyedobjects.nib.svn-base differ diff --git a/hw/darwin/apple/English.lproj/main.nib/classes.nib b/hw/darwin/apple/English.lproj/main.nib/classes.nib new file mode 100644 index 000000000..a82159bd5 --- /dev/null +++ b/hw/darwin/apple/English.lproj/main.nib/classes.nib @@ -0,0 +1,318 @@ + + + + + IBClasses + + + CLASS + IBLibraryObjectTemplate + LANGUAGE + ObjC + OUTLETS + + draggedView + NSView + representedObject + NSObject + + SUPERCLASS + NSView + + + CLASS + IBInspector + LANGUAGE + ObjC + OUTLETS + + inspectorView + NSView + + SUPERCLASS + NSObject + + + CLASS + NSDateFormatter + LANGUAGE + ObjC + SUPERCLASS + NSFormatter + + + ACTIONS + + apps_table_cancel + id + apps_table_delete + id + apps_table_done + id + apps_table_duplicate + id + apps_table_new + id + apps_table_show + id + bring_to_front + id + close_window + id + enable_fullscreen_changed + id + minimize_window + id + next_window + id + prefs_changed + id + prefs_show + id + previous_window + id + toggle_fullscreen + id + x11_help + id + zoom_window + id + + CLASS + X11Controller + LANGUAGE + ObjC + OUTLETS + + apps_separator + id + apps_table + id + depth + id + dock_apps_menu + id + dock_menu + id + dock_window_separator + id + enable_auth + id + enable_fullscreen + id + enable_keyequivs + id + enable_tcp + id + fake_buttons + id + prefs_panel + id + sync_keymap + id + toggle_fullscreen_item + id + use_sysbeep + id + window_separator + id + x11_about_item + id + + SUPERCLASS + NSObject + + + CLASS + NSNumberFormatter + LANGUAGE + ObjC + SUPERCLASS + NSFormatter + + + CLASS + NSFormatter + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + ACTIONS + + alignCenter: + id + alignJustified: + id + alignLeft: + id + alignRight: + id + arrangeInFront: + id + centerSelectionInVisibleArea: + id + changeFont: + id + checkSpelling: + id + clear: + id + clearRecentDocuments: + id + complete: + id + copy: + id + copyFont: + id + copyRuler: + id + cut: + id + delete: + id + deminiaturize: + id + fax: + id + hide: + id + hideOtherApplications: + id + loosenKerning: + id + lowerBaseline: + id + makeKeyAndOrderFront: + id + miniaturize: + id + newDocument: + id + openDocument: + id + orderBack: + id + orderFront: + id + orderFrontColorPanel: + id + orderFrontHelpPanel: + id + orderOut: + id + outline: + id + paste: + id + pasteAsPlainText: + id + pasteAsRichText: + id + pasteFont: + id + pasteRuler: + id + pause: + id + performClose: + id + performFindPanelAction: + id + performMiniaturize: + id + performZoom: + id + play: + id + print: + id + printDocument: + id + raiseBaseline: + id + record: + id + redo: + id + resume: + id + revertDocumentToSaved: + id + run: + id + runPageLayout: + id + runToolbarCustomizationPalette: + id + saveAllDocuments: + id + saveDocument: + id + saveDocumentAs: + id + saveDocumentTo: + id + selectAll: + id + selectText: + id + showGuessPanel: + id + showHelp: + id + start: + id + startSpeaking: + id + stop: + id + stopSpeaking: + id + subscript: + id + superscript: + id + terminate: + id + tightenKerning: + id + toggleContinuousSpellChecking: + id + toggleRuler: + id + toggleToolbarShown: + id + turnOffKerning: + id + turnOffLigatures: + id + underline: + id + undo: + id + unhideAllApplications: + id + unscript: + id + useAllLigatures: + id + useStandardKerning: + id + useStandardLigatures: + id + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + IBVersion + 1 + + diff --git a/hw/darwin/apple/English.lproj/main.nib/info.nib b/hw/darwin/apple/English.lproj/main.nib/info.nib new file mode 100644 index 000000000..88bc6260d --- /dev/null +++ b/hw/darwin/apple/English.lproj/main.nib/info.nib @@ -0,0 +1,18 @@ + + + + + IBFramework Version + 588 + IBOpenObjects + + 244 + 29 + 423 + + IBSystem Version + 9A356 + targetFramework + IBCocoaFramework + + diff --git a/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib b/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib new file mode 100644 index 000000000..8b31450ff Binary files /dev/null and b/hw/darwin/apple/English.lproj/main.nib/keyedobjects.nib differ diff --git a/hw/darwin/apple/Info.plist b/hw/darwin/apple/Info.plist new file mode 100644 index 000000000..ae47e9590 --- /dev/null +++ b/hw/darwin/apple/Info.plist @@ -0,0 +1,71 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + x11app + + CFBundleTypeIconFile + X11.icns + CFBundleTypeName + X11 Application + CFBundleTypeOSTypes + + **** + + CFBundleTypeRole + Viewer + LSIsAppleDefaultForType + + + + CFBundleTypeExtensions + + tool + * + + CFBundleTypeName + UNIX Application + CFBundleTypeOSTypes + + **** + + CFBundleTypeRole + Viewer + + + CFBundleExecutable + X11 + CFBundleGetInfoString + X11 + CFBundleIconFile + X11.icns + CFBundleIdentifier + org.x.X11 + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + X11 + CFBundlePackageType + APPL + CFBundleShortVersionString + 2.0 + CFBundleSignature + ???? + CSResourcesFileMapped + + NSHumanReadableCopyright + Copyright © 2003-2007, Apple Inc. +Copyright © 2003, XFree86 Project, Inc. + NSMainNibFile + main + NSPrincipalClass + X11Application + + diff --git a/hw/darwin/apple/X11.icns b/hw/darwin/apple/X11.icns new file mode 100644 index 000000000..4c4717726 Binary files /dev/null and b/hw/darwin/apple/X11.icns differ diff --git a/hw/darwin/apple/X11.xcodeproj/project.pbxproj b/hw/darwin/apple/X11.xcodeproj/project.pbxproj new file mode 100644 index 000000000..7ca75d498 --- /dev/null +++ b/hw/darwin/apple/X11.xcodeproj/project.pbxproj @@ -0,0 +1,329 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 42; + objects = { + +/* Begin PBXBuildFile section */ + 527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */; }; + 527F241A0B5D938C007840A7 /* main.nib in Resources */ = {isa = PBXBuildFile; fileRef = 02345980000FD03B11CA0E72 /* main.nib */; }; + 527F241B0B5D938C007840A7 /* X11.icns in Resources */ = {isa = PBXBuildFile; fileRef = 50459C5F038587C60ECA21EC /* X11.icns */; }; + 527F241D0B5D938C007840A7 /* bundle-main.c in Sources */ = {isa = PBXBuildFile; fileRef = 50EE2AB703849F0B0ECA21EC /* bundle-main.c */; }; + 527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */; }; + 527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570C5748047186C400ACF82F /* SystemConfiguration.framework */; }; + 527F24370B5D9D89007840A7 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 527F24260B5D938C007840A7 /* Info.plist */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; + 1870340FFE93FCAF11CA0CD7 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/main.nib; sourceTree = ""; }; + 50459C5F038587C60ECA21EC /* X11.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = X11.icns; sourceTree = ""; }; + 50EE2AB703849F0B0ECA21EC /* bundle-main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = "bundle-main.c"; sourceTree = ""; }; + 50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = ""; }; + 527F24260B5D938C007840A7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Info.plist; sourceTree = ""; }; + 527F24270B5D938C007840A7 /* X11.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = X11.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 570C5748047186C400ACF82F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 527F241E0B5D938C007840A7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 527F241F0B5D938C007840A7 /* CoreFoundation.framework in Frameworks */, + 527F24200B5D938C007840A7 /* SystemConfiguration.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 195DF8CFFE9D517E11CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + 527F24270B5D938C007840A7 /* X11.app */, + ); + name = Products; + sourceTree = ""; + }; + 20286C29FDCF999611CA2CEA /* X11 */ = { + isa = PBXGroup; + children = ( + 20286C2AFDCF999611CA2CEA /* Sources */, + 20286C2CFDCF999611CA2CEA /* Resources */, + 20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */, + 195DF8CFFE9D517E11CA2CBB /* Products */, + 527F24260B5D938C007840A7 /* Info.plist */, + ); + name = X11; + sourceTree = ""; + }; + 20286C2AFDCF999611CA2CEA /* Sources */ = { + isa = PBXGroup; + children = ( + 50EE2AB703849F0B0ECA21EC /* bundle-main.c */, + ); + name = Sources; + sourceTree = ""; + }; + 20286C2CFDCF999611CA2CEA /* Resources */ = { + isa = PBXGroup; + children = ( + 50459C5F038587C60ECA21EC /* X11.icns */, + 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */, + 02345980000FD03B11CA0E72 /* main.nib */, + ); + name = Resources; + sourceTree = ""; + }; + 20286C32FDCF999611CA2CEA /* External Frameworks and Libraries */ = { + isa = PBXGroup; + children = ( + 50F4F0A7039D6ACA0E82C0CB /* CoreFoundation.framework */, + 570C5748047186C400ACF82F /* SystemConfiguration.framework */, + ); + name = "External Frameworks and Libraries"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 527F24170B5D938C007840A7 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 527F24160B5D938C007840A7 /* X11 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */; + buildPhases = ( + 527F24170B5D938C007840A7 /* Headers */, + 527F24180B5D938C007840A7 /* Resources */, + 527F241C0B5D938C007840A7 /* Sources */, + 527F241E0B5D938C007840A7 /* Frameworks */, + 527F24210B5D938C007840A7 /* Rez */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = X11; + productName = X11; + productReference = 527F24270B5D938C007840A7 /* X11.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 20286C28FDCF999611CA2CEA /* Project object */ = { + isa = PBXProject; + buildConfigurationList = 527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */; + compatibilityVersion = "Xcode 2.4"; + hasScannedForEncodings = 1; + mainGroup = 20286C29FDCF999611CA2CEA /* X11 */; + projectDirPath = ""; + projectRoot = ""; + shouldCheckCompatibility = 1; + targets = ( + 527F24160B5D938C007840A7 /* X11 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 527F24180B5D938C007840A7 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 527F24370B5D9D89007840A7 /* Info.plist in Resources */, + 527F24190B5D938C007840A7 /* InfoPlist.strings in Resources */, + 527F241A0B5D938C007840A7 /* main.nib in Resources */, + 527F241B0B5D938C007840A7 /* X11.icns in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXRezBuildPhase section */ + 527F24210B5D938C007840A7 /* Rez */ = { + isa = PBXRezBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXRezBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 527F241C0B5D938C007840A7 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 527F241D0B5D938C007840A7 /* bundle-main.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 02345980000FD03B11CA0E72 /* main.nib */ = { + isa = PBXVariantGroup; + children = ( + 1870340FFE93FCAF11CA0CD7 /* English */, + ); + name = main.nib; + sourceTree = ""; + }; + 0867D6AAFE840B52C02AAC07 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 0867D6ABFE840B52C02AAC07 /* English */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 527F24090B5D8FFC007840A7 /* Development */ = { + isa = XCBuildConfiguration; + buildSettings = { + DSTROOT = "$(DSTROOT)"; + SKIP_INSTALL = YES; + }; + name = Development; + }; + 527F240A0B5D8FFC007840A7 /* Deployment */ = { + isa = XCBuildConfiguration; + buildSettings = { + DSTROOT = "$(DSTROOT)"; + SKIP_INSTALL = YES; + }; + name = Deployment; + }; + 527F240B0B5D8FFC007840A7 /* Default */ = { + isa = XCBuildConfiguration; + buildSettings = { + DSTROOT = "$(DSTROOT)"; + SKIP_INSTALL = YES; + }; + name = Default; + }; + 527F24230B5D938C007840A7 /* Development */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(NATIVE_ARCH_32_BIT)"; + COPY_PHASE_STRIP = NO; + DSTROOT = "$(DSTROOT)"; + FRAMEWORK_SEARCH_PATHS = ""; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + HEADER_SEARCH_PATHS = /usr/X11/include; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = $DSTROOT/Applications/Utilties; + LIBRARY_SEARCH_PATHS = /usr/X11/lib; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ( + "-lXau", + "-lX11", + ); + OTHER_REZFLAGS = ""; + PRODUCT_NAME = X11; + SECTORDER_FLAGS = ""; + WARNING_CFLAGS = ( + "-Wmost", + "-Wno-four-char-constants", + "-Wno-unknown-pragmas", + ); + WRAPPER_EXTENSION = app; + }; + name = Development; + }; + 527F24240B5D938C007840A7 /* Deployment */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = YES; + DSTROOT = "$(DSTROOT)"; + FRAMEWORK_SEARCH_PATHS = ""; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + HEADER_SEARCH_PATHS = /usr/X11/include; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = $DSTROOT/Applications/Utilties; + LIBRARY_SEARCH_PATHS = /usr/X11/lib; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ( + "-lXau", + "-lX11", + ); + OTHER_REZFLAGS = ""; + PRODUCT_NAME = X11; + SECTORDER_FLAGS = ""; + WARNING_CFLAGS = ( + "-Wmost", + "-Wno-four-char-constants", + "-Wno-unknown-pragmas", + ); + WRAPPER_EXTENSION = app; + }; + name = Deployment; + }; + 527F24250B5D938C007840A7 /* Default */ = { + isa = XCBuildConfiguration; + buildSettings = { + DSTROOT = "$(DSTROOT)"; + FRAMEWORK_SEARCH_PATHS = ""; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + HEADER_SEARCH_PATHS = /usr/X11/include; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = $DSTROOT/Applications/Utilties; + LIBRARY_SEARCH_PATHS = /usr/X11/lib; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ( + "-lXau", + "-lX11", + ); + OTHER_REZFLAGS = ""; + PRODUCT_NAME = X11; + SECTORDER_FLAGS = ""; + WARNING_CFLAGS = ( + "-Wmost", + "-Wno-four-char-constants", + "-Wno-unknown-pragmas", + ); + WRAPPER_EXTENSION = app; + }; + name = Default; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 527F24080B5D8FFC007840A7 /* Build configuration list for PBXProject "X11" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 527F24090B5D8FFC007840A7 /* Development */, + 527F240A0B5D8FFC007840A7 /* Deployment */, + 527F240B0B5D8FFC007840A7 /* Default */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Default; + }; + 527F24220B5D938C007840A7 /* Build configuration list for PBXNativeTarget "X11" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 527F24230B5D938C007840A7 /* Development */, + 527F24240B5D938C007840A7 /* Deployment */, + 527F24250B5D938C007840A7 /* Default */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Default; + }; +/* End XCConfigurationList section */ + }; + rootObject = 20286C28FDCF999611CA2CEA /* Project object */; +} diff --git a/hw/darwin/apple/X11Application.h b/hw/darwin/apple/X11Application.h new file mode 100644 index 000000000..b9d2af8bf --- /dev/null +++ b/hw/darwin/apple/X11Application.h @@ -0,0 +1,104 @@ +/* X11Application.h -- subclass of NSApplication to multiplex events + $Id: X11Application.h,v 1.26 2003/08/08 19:16:13 jharper Exp $ + + Copyright (c) 2002-2007 Apple Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. */ + +#ifndef X11APPLICATION_H +#define X11APPLICATION_H 1 + +#if __OBJC__ + +#import +#import "X11Controller.h" + +@interface X11Application : NSApplication { + X11Controller *_controller; + + unsigned int _x_active :1; +} + +- (void) set_controller:controller; +- (void) set_window_menu:(NSArray *)list; + +- (int) prefs_get_integer:(NSString *)key default:(int)def; +- (const char *) prefs_get_string:(NSString *)key default:(const char *)def; +- (float) prefs_get_float:(NSString *)key default:(float)def; +- (int) prefs_get_boolean:(NSString *)key default:(int)def; +- (NSArray *) prefs_get_array:(NSString *)key; +- (void) prefs_set_integer:(NSString *)key value:(int)value; +- (void) prefs_set_float:(NSString *)key value:(float)value; +- (void) prefs_set_boolean:(NSString *)key value:(int)value; +- (void) prefs_set_array:(NSString *)key value:(NSArray *)value; +- (void) prefs_set_string:(NSString *)key value:(NSString *)value; +- (void) prefs_synchronize; + +- (BOOL) x_active; + +@end + +extern X11Application *X11App; + +#endif /* __OBJC__ */ + +extern void X11ApplicationSetWindowMenu (int nitems, const char **items, + const char *shortcuts); +extern void X11ApplicationSetWindowMenuCheck (int idx); +extern void X11ApplicationSetFrontProcess (void); +extern void X11ApplicationSetCanQuit (int state); +extern void X11ApplicationServerReady (void); +extern void X11ApplicationShowHideMenubar (int state); + +extern void X11ApplicationMain (int argc, const char *argv[], + void (*server_thread) (void *), + void *server_arg); + +extern int X11EnableKeyEquivalents; +extern int quartzHasRoot, quartzEnableRootless; + +#define APP_PREFS "com.apple.x11" + +#define PREFS_APPSMENU "apps_menu" +#define PREFS_FAKEBUTTONS "enable_fake_buttons" +#define PREFS_SYSBEEP "enable_system_beep" +#define PREFS_KEYEQUIVS "enable_key_equivalents" +#define PREFS_KEYMAP_FILE "keymap_file" +#define PREFS_SYNC_KEYMAP "sync_keymap" +#define PREFS_DEPTH "depth" +#define PREFS_NO_AUTH "no_auth" +#define PREFS_NO_TCP "nolisten_tcp" +#define PREFS_DONE_XINIT_CHECK "done_xinit_check" +#define PREFS_NO_QUIT_ALERT "no_quit_alert" +#define PREFS_FAKE_BUTTON2 "fake_button2" +#define PREFS_FAKE_BUTTON3 "fake_button3" +#define PREFS_ROOTLESS "rootless" +#define PREFS_FULLSCREEN_HOTKEYS "fullscreen_hotkeys" +#define PREFS_SWAP_ALT_META "swap_alt_meta" +#define PREFS_XP_OPTIONS "xp_options" +#define PREFS_ENABLE_STEREO "enable_stereo" + +#endif /* X11APPLICATION_H */ diff --git a/hw/darwin/apple/X11Application.m b/hw/darwin/apple/X11Application.m new file mode 100644 index 000000000..5da057469 --- /dev/null +++ b/hw/darwin/apple/X11Application.m @@ -0,0 +1,1138 @@ +/* X11Application.m -- subclass of NSApplication to multiplex events + $Id: X11Application.m,v 1.59 2006/09/06 21:19:32 jharper Exp $ + + Copyright (c) 2002-2007 Apple Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. */ + +#include "../quartz/quartzCommon.h" + +#import "X11Application.h" +#include + +/* ouch! */ +#define BOOL X_BOOL +//# include "Xproto.h" +# include "darwin.h" +# include "../quartz/quartz.h" +# define _APPLEWM_SERVER_ +# include "X11/extensions/applewm.h" +//# include "X.h" +# include "micmap.h" +#undef BOOL + +#include "xf86Version.h" + +#include +#include +#include + +#define DEFAULTS_FILE "/etc/X11/xserver/Xquartz.plist" + +int X11EnableKeyEquivalents = TRUE; +int quartzHasRoot = FALSE, quartzEnableRootless = TRUE; + +extern int darwinFakeButtons; +// extern Bool enable_stereo; +Bool enable_stereo; //<-- this needs to go back to being an extern once glxCGL is fixed + + +X11Application *X11App; + +#define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask \ +| NSAlternateKeyMask | NSCommandKeyMask) + +@implementation X11Application + +typedef struct message_struct message; +struct message_struct { + mach_msg_header_t hdr; + SEL selector; + NSObject *arg; +}; + +static mach_port_t _port; + +static void send_nsevent (NSEventType type, NSEvent *e); + +/* Quartz mode initialization routine. This is often dynamically loaded + but is statically linked into this X server. */ +extern Bool QuartzModeBundleInit(void); + +static void +init_ports (void) +{ + kern_return_t r; + NSPort *p; + + if (_port != MACH_PORT_NULL) + return; + + r = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &_port); + if (r != KERN_SUCCESS) + return; + + p = [NSMachPort portWithMachPort:_port]; + [p setDelegate:NSApp]; + [p scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; +} + +static void +message_kit_thread (SEL selector, NSObject *arg) +{ + message msg; + kern_return_t r; + + msg.hdr.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MAKE_SEND, 0); + msg.hdr.msgh_size = sizeof (msg); + msg.hdr.msgh_remote_port = _port; + msg.hdr.msgh_local_port = MACH_PORT_NULL; + msg.hdr.msgh_reserved = 0; + msg.hdr.msgh_id = 0; + + msg.selector = selector; + msg.arg = [arg retain]; + + r = mach_msg (&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size, + 0, MACH_PORT_NULL, 0, MACH_PORT_NULL); + if (r != KERN_SUCCESS) + fprintf (stderr, "%s: mach_msg failed: %x\n", __FUNCTION__, r); +} + +- (void) handleMachMessage:(void *)_msg +{ + message *msg = _msg; + + [self performSelector:msg->selector withObject:msg->arg]; + [msg->arg release]; +} + +- (void) set_controller:obj +{ + if (_controller == nil) + _controller = [obj retain]; +} + +- (void) dealloc +{ + if (_controller != nil) + [_controller release]; + + if (_port != MACH_PORT_NULL) + mach_port_deallocate (mach_task_self (), _port); + + [super dealloc]; +} + +- (void) orderFrontStandardAboutPanel: (id) sender +{ + NSMutableDictionary *dict; + NSDictionary *infoDict; + NSString *tem; + + dict = [NSMutableDictionary dictionaryWithCapacity:2]; + infoDict = [[NSBundle mainBundle] infoDictionary]; + + [dict setObject: NSLocalizedString (@"The X Window System", @"About panel") + forKey:@"ApplicationName"]; + + tem = [infoDict objectForKey:@"CFBundleShortVersionString"]; + + [dict setObject:[NSString stringWithFormat:@"X11.app %@ - X.org X11R7.1", + tem] forKey:@"ApplicationVersion"]; + + [self orderFrontStandardAboutPanelWithOptions: dict]; +} + +- (void) activateX:(BOOL)state +{ + /* Create a TSM document that supports full Unicode input, and + have it activated while X is active (unless using the old + keymapping files) */ + static TSMDocumentID x11_document; + + if (state) + { + QuartzMessageServerThread (kXDarwinActivate, 0); + + if (!_x_active) + { + if (x11_document == 0 && darwinKeymapFile == NULL) + { + OSType types[1]; + types[0] = kUnicodeDocument; + NewTSMDocument (1, types, &x11_document, 0); + } + + if (x11_document != 0) + ActivateTSMDocument (x11_document); + } + } + else + { + QuartzMessageServerThread (kXDarwinDeactivate, 0); + + if (_x_active) + { + if (x11_document != 0) + DeactivateTSMDocument (x11_document); + } + } + + _x_active = state; +} + +- (void) became_key:(NSWindow *)win +{ + [self activateX:NO]; +} + +- (void) sendEvent:(NSEvent *)e +{ + NSEventType type; + BOOL for_appkit, for_x; + + type = [e type]; + + /* By default pass down the responder chain and to X. */ + for_appkit = YES; + for_x = YES; + + switch (type) + { + case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown: + case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: + if ([e window] != nil) + { + /* Pointer event has a window. Probably something for the kit. */ + + for_x = NO; + + if (_x_active) + [self activateX:NO]; + } + else if ([self modalWindow] == nil) + { + /* Must be an X window. Tell appkit it doesn't have focus. */ + + for_appkit = NO; + + if ([self isActive]) + { + [self deactivate]; + + if (!_x_active && quartzProcs->IsX11Window([e window], + [e windowNumber])) + [self activateX:YES]; + } + } + break; + + case NSKeyDown: case NSKeyUp: + if (_x_active) + { + static int swallow_up; + + /* No kit window is focused, so send it to X. */ + + for_appkit = NO; + + if (type == NSKeyDown) + { + /* Before that though, see if there are any global + shortcuts bound to it. */ + + if (X11EnableKeyEquivalents + && [[self mainMenu] performKeyEquivalent:e]) + { + swallow_up = [e keyCode]; + for_x = NO; + } + else if (!quartzEnableRootless + && ([e modifierFlags] & ALL_KEY_MASKS) + == (NSCommandKeyMask | NSAlternateKeyMask) + && ([e keyCode] == 0 /*a*/ + || [e keyCode] == 53 /*Esc*/)) + { + swallow_up = 0; + for_x = NO; +#ifdef DARWIN_DDX_MISSING + QuartzMessageServerThread (kXDarwinToggleFullscreen, 0); +#endif + } + } + else + { + /* If we saw a key equivalent on the down, don't pass + the up through to X. */ + + if (swallow_up != 0 && [e keyCode] == swallow_up) + { + swallow_up = 0; + for_x = NO; + } + } + } + else + { + for_x = NO; + } + break; + + case NSFlagsChanged: + /* For the l33t X users who remap modifier keys to normal keysyms. */ + if (!_x_active) + for_x = NO; + break; + + case NSAppKitDefined: + switch ([e subtype]) + { + case NSApplicationActivatedEventType: + for_x = NO; + if ([self modalWindow] == nil) + { + for_appkit = NO; + + /* FIXME: hack to avoid having to pass the event to appkit, + which would cause it to raise one of its windows. */ + _appFlags._active = YES; + + [self activateX:YES]; +#ifdef DARWIN_DDX_MISSING + if ([e data2] & 0x10) QuartzMessageServerThread (kXDarwinBringAllToFront, 0); +#endif + } + break; + + case 18: /* ApplicationDidReactivate */ + if (quartzHasRoot) + for_appkit = NO; + break; + + case NSApplicationDeactivatedEventType: + for_x = NO; + [self activateX:NO]; + break; + } + break; + + default: break; /* for gcc */ + } + + if (for_appkit) + { + [super sendEvent:e]; + } + + if (for_x) + { + send_nsevent (type, e); + } +} + +- (void) set_window_menu:(NSArray *)list +{ + [_controller set_window_menu:list]; +} + +- (void) set_window_menu_check:(NSNumber *)n +{ + [_controller set_window_menu_check:n]; +} + +- (void) set_apps_menu:(NSArray *)list +{ + [_controller set_apps_menu:list]; +} + +- (void) set_front_process:unused +{ + [NSApp activateIgnoringOtherApps:YES]; + + if ([self modalWindow] == nil) + [self activateX:YES]; +} + +- (void) set_can_quit:(NSNumber *)state +{ + [_controller set_can_quit:[state boolValue]]; +} + +- (void) server_ready:unused +{ + [_controller server_ready]; +} + +- (void) show_hide_menubar:(NSNumber *)state +{ + if ([state boolValue]) + ShowMenuBar (); + else + HideMenuBar (); +} + + +/* user preferences */ + +/* Note that these functions only work for arrays whose elements + can be toll-free-bridged between NS and CF worlds. */ + +static const void *cfretain (CFAllocatorRef a, const void *b) { + return CFRetain (b); +} +static void cfrelease (CFAllocatorRef a, const void *b) { + CFRelease (b); +} +static CFMutableArrayRef +nsarray_to_cfarray (NSArray *in) +{ + CFMutableArrayRef out; + CFArrayCallBacks cb; + NSObject *ns; + const CFTypeRef *cf; + int i, count; + + memset (&cb, 0, sizeof (cb)); + cb.version = 0; + cb.retain = cfretain; + cb.release = cfrelease; + + count = [in count]; + out = CFArrayCreateMutable (NULL, count, &cb); + + for (i = 0; i < count; i++) + { + ns = [in objectAtIndex:i]; + + if ([ns isKindOfClass:[NSArray class]]) + cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns); + else + cf = CFRetain ((CFTypeRef) ns); + + CFArrayAppendValue (out, cf); + CFRelease (cf); + } + + return out; +} +static NSMutableArray * +cfarray_to_nsarray (CFArrayRef in) +{ + NSMutableArray *out; + const CFTypeRef *cf; + NSObject *ns; + int i, count; + + count = CFArrayGetCount (in); + out = [[NSMutableArray alloc] initWithCapacity:count]; + + for (i = 0; i < count; i++) + { + cf = CFArrayGetValueAtIndex (in, i); + + if (CFGetTypeID (cf) == CFArrayGetTypeID ()) + ns = cfarray_to_nsarray ((CFArrayRef) cf); + else + ns = [(id)cf retain]; + + [out addObject:ns]; + [ns release]; + } + + return out; +} + +- (CFPropertyListRef) prefs_get:(NSString *)key +{ + CFPropertyListRef value; + + value = CFPreferencesCopyAppValue ((CFStringRef) key, CFSTR (APP_PREFS)); + + if (value == NULL) + { + static CFDictionaryRef defaults; + + if (defaults == NULL) + { + CFStringRef error = NULL; + CFDataRef data; + CFURLRef url; + SInt32 error_code; + + url = (CFURLCreateFromFileSystemRepresentation + (NULL, (unsigned char *)DEFAULTS_FILE, strlen (DEFAULTS_FILE), false)); + if (CFURLCreateDataAndPropertiesFromResource (NULL, url, &data, + NULL, NULL, + &error_code)) + { + defaults = (CFPropertyListCreateFromXMLData + (NULL, data, kCFPropertyListMutableContainersAndLeaves, &error)); + if (error != NULL) + CFRelease (error); + CFRelease (data); + } + CFRelease (url); + + if (defaults != NULL) + { + NSMutableArray *apps, *elt; + int count, i; + NSString *name, *nname; + + /* Localize the names in the default apps menu. */ + + apps = [(NSDictionary *)defaults objectForKey:@PREFS_APPSMENU]; + if (apps != nil) + { + count = [apps count]; + for (i = 0; i < count; i++) + { + elt = [apps objectAtIndex:i]; + if (elt != nil && [elt isKindOfClass:[NSArray class]]) + { + name = [elt objectAtIndex:0]; + if (name != nil) + { + nname = NSLocalizedString (name, nil); + if (nname != nil && nname != name) + [elt replaceObjectAtIndex:0 withObject:nname]; + } + } + } + } + } + } + + if (defaults != NULL) + value = CFDictionaryGetValue (defaults, key); + + if (value != NULL) + CFRetain (value); + } + + return value; +} + +- (int) prefs_get_integer:(NSString *)key default:(int)def +{ + CFPropertyListRef value; + int ret; + + value = [self prefs_get:key]; + + if (value != NULL && CFGetTypeID (value) == CFNumberGetTypeID ()) + CFNumberGetValue (value, kCFNumberIntType, &ret); + else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) + ret = CFStringGetIntValue (value); + else + ret = def; + + if (value != NULL) + CFRelease (value); + + return ret; +} + +- (const char *) prefs_get_string:(NSString *)key default:(const char *)def +{ + CFPropertyListRef value; + const char *ret = NULL; + + value = [self prefs_get:key]; + + if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) + { + NSString *s = (NSString *) value; + + ret = [s UTF8String]; + } + + if (value != NULL) + CFRelease (value); + + return ret != NULL ? ret : def; +} + +- (float) prefs_get_float:(NSString *)key default:(float)def +{ + CFPropertyListRef value; + float ret = def; + + value = [self prefs_get:key]; + + if (value != NULL + && CFGetTypeID (value) == CFNumberGetTypeID () + && CFNumberIsFloatType (value)) + { + CFNumberGetValue (value, kCFNumberFloatType, &ret); + } + else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) + { + ret = CFStringGetDoubleValue (value); + } + + if (value != NULL) + CFRelease (value); + + return ret; +} + +- (int) prefs_get_boolean:(NSString *)key default:(int)def +{ + CFPropertyListRef value; + int ret = def; + + value = [self prefs_get:key]; + + if (value != NULL) + { + if (CFGetTypeID (value) == CFNumberGetTypeID ()) + CFNumberGetValue (value, kCFNumberIntType, &ret); + else if (CFGetTypeID (value) == CFBooleanGetTypeID ()) + ret = CFBooleanGetValue (value); + else if (CFGetTypeID (value) == CFStringGetTypeID ()) + { + const char *tem = [(NSString *) value lossyCString]; + if (strcasecmp (tem, "true") == 0 || strcasecmp (tem, "yes") == 0) + ret = YES; + else + ret = NO; + } + + CFRelease (value); + } + + return ret; +} + +- (NSArray *) prefs_get_array:(NSString *)key +{ + NSArray *ret = nil; + CFPropertyListRef value; + + value = [self prefs_get:key]; + + if (value != NULL) + { + if (CFGetTypeID (value) == CFArrayGetTypeID ()) + ret = [cfarray_to_nsarray (value) autorelease]; + + CFRelease (value); + } + + return ret; +} + +- (void) prefs_set_integer:(NSString *)key value:(int)value +{ + CFNumberRef x; + + x = CFNumberCreate (NULL, kCFNumberIntType, &value); + + CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, CFSTR (APP_PREFS), + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + + CFRelease (x); +} + +- (void) prefs_set_float:(NSString *)key value:(float)value +{ + CFNumberRef x; + + x = CFNumberCreate (NULL, kCFNumberFloatType, &value); + + CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, CFSTR (APP_PREFS), + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + + CFRelease (x); +} + +- (void) prefs_set_boolean:(NSString *)key value:(int)value +{ + CFPreferencesSetValue ((CFStringRef) key, + (CFTypeRef) value ? kCFBooleanTrue + : kCFBooleanFalse, CFSTR (APP_PREFS), + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + +} + +- (void) prefs_set_array:(NSString *)key value:(NSArray *)value +{ + CFArrayRef cfarray; + + cfarray = nsarray_to_cfarray (value); + CFPreferencesSetValue ((CFStringRef) key, + (CFTypeRef) cfarray, + CFSTR (APP_PREFS), + kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + CFRelease (cfarray); +} + +- (void) prefs_set_string:(NSString *)key value:(NSString *)value +{ + CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) value, + CFSTR (APP_PREFS), kCFPreferencesCurrentUser, + kCFPreferencesAnyHost); +} + +- (void) prefs_synchronize +{ + CFPreferencesAppSynchronize (kCFPreferencesCurrentApplication); +} + +- (void) read_defaults +{ + const char *tem; + + quartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP + default:quartzUseSysBeep]; + quartzEnableRootless = [self prefs_get_boolean:@PREFS_ROOTLESS + default:quartzEnableRootless]; +#ifdef DARWIN_DDX_MISSING + quartzFullscreenDisableHotkeys = ![self prefs_get_boolean: + @PREFS_FULLSCREEN_HOTKEYS default: + !quartzFullscreenDisableHotkeys]; + quartzXpluginOptions = [self prefs_get_integer:@PREFS_XP_OPTIONS + default:quartzXpluginOptions]; +#endif + + darwinSwapAltMeta = [self prefs_get_boolean:@PREFS_SWAP_ALT_META + default:darwinSwapAltMeta]; + darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS + default:darwinFakeButtons]; + if (darwinFakeButtons) + { + const char *fake2, *fake3; + + fake2 = [self prefs_get_string:@PREFS_FAKE_BUTTON2 default:NULL]; + fake3 = [self prefs_get_string:@PREFS_FAKE_BUTTON3 default:NULL]; + + if (fake2 != NULL) darwinFakeMouse2Mask = DarwinParseModifierList(fake2); + if (fake3 != NULL) darwinFakeMouse3Mask = DarwinParseModifierList(fake3); + + } + + X11EnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS + default:X11EnableKeyEquivalents]; + + darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP + default:darwinSyncKeymap]; + + tem = [self prefs_get_string:@PREFS_KEYMAP_FILE default:NULL]; + if (tem != NULL) + darwinKeymapFile = strdup (tem); + else + darwinKeymapFile = NULL; + + darwinDesiredDepth = [self prefs_get_integer:@PREFS_DEPTH + default:darwinDesiredDepth]; + + enable_stereo = [self prefs_get_boolean:@PREFS_ENABLE_STEREO + default:false]; +} + +/* This will end up at the end of the responder chain. */ +- (void) copy:sender +{ + QuartzMessageServerThread (kXDarwinPasteboardNotify, 1, + AppleWMCopyToPasteboard); +} + +- (BOOL) x_active +{ + return _x_active; +} + +@end + +static NSArray * +array_with_strings_and_numbers (int nitems, const char **items, + const char *numbers) +{ + NSMutableArray *array, *subarray; + NSString *string; + NSString *number; + int i; + + /* (Can't autorelease on the X server thread) */ + + array = [[NSMutableArray alloc] initWithCapacity:nitems]; + + for (i = 0; i < nitems; i++) + { + subarray = [[NSMutableArray alloc] initWithCapacity:2]; + + string = [[NSString alloc] initWithUTF8String:items[i]]; + [subarray addObject:string]; + [string release]; + + if (numbers[i] != 0) + { + number = [[NSString alloc] initWithFormat:@"%d", numbers[i]]; + [subarray addObject:number]; + [number release]; + } + else + [subarray addObject:@""]; + + [array addObject:subarray]; + [subarray release]; + } + + return array; +} + +void +X11ApplicationSetWindowMenu (int nitems, const char **items, + const char *shortcuts) +{ + NSArray *array; + array = array_with_strings_and_numbers (nitems, items, shortcuts); + + /* Send the array of strings over to the appkit thread */ + + message_kit_thread (@selector (set_window_menu:), array); + [array release]; +} + +void +X11ApplicationSetWindowMenuCheck (int idx) +{ + NSNumber *n; + + n = [[NSNumber alloc] initWithInt:idx]; + + message_kit_thread (@selector (set_window_menu_check:), n); + + [n release]; +} + +void +X11ApplicationSetFrontProcess (void) +{ + message_kit_thread (@selector (set_front_process:), nil); +} + +void +X11ApplicationSetCanQuit (int state) +{ + NSNumber *n; + + n = [[NSNumber alloc] initWithBool:state]; + + message_kit_thread (@selector (set_can_quit:), n); + + [n release]; +} + +void +X11ApplicationServerReady (void) +{ + message_kit_thread (@selector (server_ready:), nil); +} + +void +X11ApplicationShowHideMenubar (int state) +{ + NSNumber *n; + + n = [[NSNumber alloc] initWithBool:state]; + + message_kit_thread (@selector (show_hide_menubar:), n); + + [n release]; +} + +static void * +create_thread (void *func, void *arg) +{ + pthread_attr_t attr; + pthread_t tid; + + pthread_attr_init (&attr); + + pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); + pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + + pthread_create (&tid, &attr, func, arg); + + pthread_attr_destroy (&attr); + + return (void *) tid; +} + +static void +check_xinitrc (void) +{ + char *tem, buf[1024]; + NSString *msg; + + if ([X11App prefs_get_boolean:@PREFS_DONE_XINIT_CHECK default:NO]) + return; + + tem = getenv ("HOME"); + if (tem == NULL) + goto done; + + snprintf (buf, sizeof (buf), "%s/.xinitrc", tem); + if (access (buf, F_OK) != 0) + goto done; + + /* FIXME: put localized strings into Resources/English.lproj */ + + msg = NSLocalizedString ( + @"You have an existing ~/.xinitrc file.\n\n\ + Windows displayed by X11 applications may not have titlebars, or may look \ + different to windows displayed by native applications.\n\n\ + Would you like to move aside the existing file and use the standard X11 \ + environment?", @"Startup xinitrc dialog"); + + if (NSRunAlertPanel (nil, msg, NSLocalizedString (@"Yes", @""), + NSLocalizedString (@"No", @""), nil) + == NSAlertDefaultReturn) + { + char buf2[1024]; + int i = -1; + + snprintf (buf2, sizeof (buf2), "%s.old", buf); + + for (i = 1; access (buf2, F_OK) == 0; i++) + snprintf (buf2, sizeof (buf2), "%s.old.%d", buf, i); + + rename (buf, buf2); + } + + done: + [X11App prefs_set_boolean:@PREFS_DONE_XINIT_CHECK value:YES]; + [X11App prefs_synchronize]; +} + +void +X11ApplicationMain (int argc, const char *argv[], + void (*server_thread) (void *), void *server_arg) +{ + NSAutoreleasePool *pool; + +#ifdef DEBUG + while (access ("/tmp/x11-block", F_OK) == 0) + sleep (1); +#endif + + pool = [[NSAutoreleasePool alloc] init]; + + X11App = (X11Application *) [X11Application sharedApplication]; + + init_ports (); + + [NSApp read_defaults]; + + [NSBundle loadNibNamed:@"main" owner:NSApp]; + + [[NSNotificationCenter defaultCenter] addObserver:NSApp + selector:@selector (became_key:) + name:NSWindowDidBecomeKeyNotification object:nil]; + + check_xinitrc (); + + /* + * The xpr Quartz mode is statically linked into this server. + * Initialize all the Quartz functions. + */ + QuartzModeBundleInit(); + + /* Calculate the height of the menubar so we can avoid it. */ + aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) - + NSMaxY([[NSScreen mainScreen] visibleFrame]) - 1; + + if (!create_thread (server_thread, server_arg)) + { + fprintf (stderr, "can't create secondary thread\n"); + exit (1); + } + + [NSApp run]; + + /* not reached */ +} + + +/* event conversion */ + +static inline unsigned short +convert_flags (unsigned int nsflags) +{ + unsigned int xflags; + + if (nsflags == ~0) return 0xffff; + + xflags = 0; + + if (nsflags & NSAlphaShiftKeyMask) xflags |= LockMask; + if (nsflags & NSShiftKeyMask) xflags |= ShiftMask; + if (nsflags & NSControlKeyMask) xflags |= ControlMask; + if (nsflags & NSAlternateKeyMask) xflags |= Mod1Mask; + if (nsflags & NSCommandKeyMask) xflags |= Mod2Mask; + /* FIXME: secondaryfn? */ + + return xflags; +} + +static void +send_nsevent (NSEventType type, NSEvent *e) +{ + static unsigned int button_state = 0; + NSRect screen; + NSPoint location; + NSWindow *window; + int pointer_x, pointer_y; + xEvent xe; + + memset (&xe, 0, sizeof (xe)); + + /* This field should be filled in for every event */ + xe.u.keyButtonPointer.time = GetTimeInMillis(); + + /* convert location to global top-left coordinates */ + location = [e locationInWindow]; + window = [e window]; + screen = [[[NSScreen screens] objectAtIndex:0] frame]; + + if (window != nil) { + NSRect frame = [window frame]; + pointer_x = location.x + frame.origin.x; + pointer_y = (((screen.origin.y + screen.size.height) + - location.y) - frame.origin.y); + } else { + pointer_x = location.x; + pointer_y = (screen.origin.y + screen.size.height) - location.y; + } + + xe.u.keyButtonPointer.rootX = pointer_x; + xe.u.keyButtonPointer.rootY = pointer_y; + + switch (type) { + float count; + + case NSLeftMouseDown: + xe.u.u.type = ButtonPress; + xe.u.u.detail = 1; + goto do_press_event; + + case NSRightMouseDown: + xe.u.u.type = ButtonPress; + xe.u.u.detail = 3; + goto do_press_event; + + case NSOtherMouseDown: + xe.u.u.type = ButtonPress; + xe.u.u.detail = 2; /* FIXME? */ + goto do_press_event; + +do_press_event: + if (!quartzProcs->IsX11Window([e window], [e windowNumber])) { + /* X server doesn't grok this window, drop the event. + + Note: theoretically this isn't necessary, but if I click + on the menubar, we get sent a LeftMouseDown when the + release happens, but no LeftMouseUp is ever seen! */ + + break; + } + goto do_event; + + case NSLeftMouseUp: + xe.u.u.type = ButtonRelease; + xe.u.u.detail = 1; + goto do_release_event; + + case NSRightMouseUp: + xe.u.u.type = ButtonRelease; + xe.u.u.detail = 3; + goto do_release_event; + + case NSOtherMouseUp: + xe.u.u.type = ButtonRelease; + xe.u.u.detail = 2; /* FIXME? */ + goto do_release_event; + +do_release_event: + if ((button_state & (1 << xe.u.u.detail)) == 0) + { + /* X didn't see the button press for this release, so skip it */ + break; + } + goto do_event; + + case NSMouseMoved: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: + xe.u.u.type = MotionNotify; + goto do_event; + + case NSKeyDown: + xe.u.u.type = KeyPress; + xe.u.u.detail = [e keyCode]; + goto do_event; + + case NSKeyUp: + xe.u.u.type = KeyRelease; + xe.u.u.detail = [e keyCode]; + goto do_event; + + case NSScrollWheel: + xe.u.keyButtonPointer.state = convert_flags ([e modifierFlags]); + count = [e deltaY]; + xe.u.u.detail = count > 0.0f ? 4 : 5; + for (count = fabs(count); count > 0.0; count = count - 1.0f) { + xe.u.u.type = ButtonPress; + DarwinEQEnqueue(&xe); + xe.u.u.type = ButtonRelease; + DarwinEQEnqueue(&xe); + } + xe.u.u.type = 0; + break; + + case NSFlagsChanged: + xe.u.u.type = kXDarwinUpdateModifiers; + xe.u.clientMessage.u.l.longs0 = [e modifierFlags]; + DarwinEQEnqueue (&xe); + break; + +do_event: + // xe.u.keyButtonPointer.state = convert_flags ([e modifierFlags]); + DarwinEQEnqueue (&xe); + break; + + default: break; /* for gcc */ + } + + if (xe.u.u.type == ButtonPress) + button_state |= (1 << xe.u.u.detail); + else if (xe.u.u.type == ButtonRelease) + button_state &= ~(1 << xe.u.u.detail); +} diff --git a/hw/darwin/apple/X11Controller.h b/hw/darwin/apple/X11Controller.h new file mode 100644 index 000000000..954d0abb9 --- /dev/null +++ b/hw/darwin/apple/X11Controller.h @@ -0,0 +1,86 @@ +/* X11Controller.h -- connect the IB ui + $Id: X11Controller.h,v 1.21 2003/07/24 17:52:29 jharper Exp $ + + Copyright (c) 2002 Apple Computer, Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. */ + +#ifndef X11CONTROLLER_H +#define X11CONTROLLER_H 1 + +#if __OBJC__ + +#import +#include "../quartz/xpr/x-list.h" + +@interface X11Controller : NSObject +{ + NSPanel *prefs_panel; + + NSButton *fake_buttons; + NSButton *enable_fullscreen; + NSButton *use_sysbeep; + NSButton *enable_keyequivs; + NSButton *sync_keymap; + NSButton *enable_auth; + NSButton *enable_tcp; + NSPopUpButton *depth; + + NSMenuItem *x11_about_item; + NSMenuItem *window_separator; + NSMenuItem *dock_window_separator; + NSMenuItem *apps_separator; + NSMenuItem *toggle_fullscreen_item; + NSMenu *dock_apps_menu; + NSTableView *apps_table; + + NSArray *apps; + NSMutableArray *table_apps; + + NSMenu *dock_menu; + + int checked_window_item; + x_list *pending_apps; + + BOOL finished_launching; + BOOL can_quit; +} + +- (void) set_window_menu:(NSArray *)list; +- (void) set_window_menu_check:(NSNumber *)n; +- (void) set_apps_menu:(NSArray *)list; +- (void) set_can_quit:(BOOL)state; +- (void) server_ready; + +@end + +#endif /* __OBJC__ */ + +extern void X11ControllerMain (int argc, const char *argv[], + void (*server_thread) (void *), + void *server_arg); + +#endif /* X11CONTROLLER_H */ diff --git a/hw/darwin/apple/X11Controller.m b/hw/darwin/apple/X11Controller.m new file mode 100644 index 000000000..3dc965b69 --- /dev/null +++ b/hw/darwin/apple/X11Controller.m @@ -0,0 +1,752 @@ +/* X11Controller.m -- connect the IB ui, also the NSApp delegate + $Id: X11Controller.m,v 1.40 2006/09/06 21:19:32 jharper Exp $ + + Copyright (c) 2002-2007 Apple Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. */ + +#define DEFAULT_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin" + +#include "../quartz/quartzCommon.h" + +#import "X11Controller.h" +#import "X11Application.h" +#import + +/* ouch! */ +#define BOOL X_BOOL +//# include "Xproto.h" +#include "opaque.h" +# include "darwin.h" +# include "../quartz/quartz.h" +# define _APPLEWM_SERVER_ +# include "X11/extensions/applewm.h" +# include "../quartz/applewmExt.h" +//# include "X.h" +#undef BOOL + +#include +#include +#include +#include +#include + +#define TRACE() fprintf (stderr, "%s\n", __FUNCTION__) + +@implementation X11Controller + +- (void) awakeFromNib +{ + X11Application *xapp = NSApp; + NSArray *array; + + /* Point X11Application at ourself. */ + [xapp set_controller:self]; + + array = [xapp prefs_get_array:@PREFS_APPSMENU]; + if (array != nil) + { + int count; + + /* convert from [TITLE1 COMMAND1 TITLE2 COMMAND2 ...] + to [[TITLE1 COMMAND1] [TITLE2 COMMAND2] ...] format. */ + + count = [array count]; + if (count > 0 + && ![[array objectAtIndex:0] isKindOfClass:[NSArray class]]) + { + int i; + NSMutableArray *copy, *sub; + + copy = [NSMutableArray arrayWithCapacity:(count / 2)]; + + for (i = 0; i < count / 2; i++) + { + sub = [[NSMutableArray alloc] initWithCapacity:3]; + [sub addObject:[array objectAtIndex:i*2]]; + [sub addObject:[array objectAtIndex:i*2+1]]; + [sub addObject:@""]; + [copy addObject:sub]; + [sub release]; + } + + array = copy; + } + + [self set_apps_menu:array]; + } +} + +- (void) item_selected:sender +{ + [NSApp activateIgnoringOtherApps:YES]; + + QuartzMessageServerThread (kXDarwinControllerNotify, 2, + AppleWMWindowMenuItem, [sender tag]); +} + +- (void) remove_window_menu +{ + NSMenu *menu; + int first, count, i; + + /* Work backwards so we don't mess up the indices */ + menu = [window_separator menu]; + first = [menu indexOfItem:window_separator] + 1; + count = [menu numberOfItems]; + for (i = count - 1; i >= first; i--) + [menu removeItemAtIndex:i]; + + menu = [dock_window_separator menu]; + count = [menu indexOfItem:dock_window_separator]; + for (i = 0; i < count; i++) + [dock_menu removeItemAtIndex:0]; +} + +- (void) install_window_menu:(NSArray *)list +{ + NSMenu *menu; + NSMenuItem *item; + int first, count, i; + + menu = [window_separator menu]; + first = [menu indexOfItem:window_separator] + 1; + count = [list count]; + for (i = 0; i < count; i++) + { + NSString *name, *shortcut; + + name = [[list objectAtIndex:i] objectAtIndex:0]; + shortcut = [[list objectAtIndex:i] objectAtIndex:1]; + + item = (NSMenuItem *) [menu addItemWithTitle:name action:@selector + (item_selected:) keyEquivalent:shortcut]; + [item setTarget:self]; + [item setTag:i]; + [item setEnabled:YES]; + + item = (NSMenuItem *) [dock_menu insertItemWithTitle:name + action:@selector + (item_selected:) keyEquivalent:shortcut + atIndex:i]; + [item setTarget:self]; + [item setTag:i]; + [item setEnabled:YES]; + } + + if (checked_window_item >= 0 && checked_window_item < count) + { + item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item]; + [item setState:NSOnState]; + item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item]; + [item setState:NSOnState]; + } +} + +- (void) remove_apps_menu +{ + NSMenu *menu; + NSMenuItem *item; + int i; + + if (apps == nil || apps_separator == nil) return; + + menu = [apps_separator menu]; + + if (menu != nil) + { + for (i = [menu numberOfItems] - 1; i >= 0; i--) + { + item = (NSMenuItem *) [menu itemAtIndex:i]; + if ([item tag] != 0) + [menu removeItemAtIndex:i]; + } + } + + if (dock_apps_menu != nil) + { + for (i = [dock_apps_menu numberOfItems] - 1; i >= 0; i--) + { + item = (NSMenuItem *) [dock_apps_menu itemAtIndex:i]; + if ([item tag] != 0) + [dock_apps_menu removeItemAtIndex:i]; + } + } + + [apps release]; + apps = nil; +} + +- (void) prepend_apps_item:(NSArray *)list index:(int)i menu:(NSMenu *)menu +{ + NSString *title, *shortcut = @""; + NSArray *group; + NSMenuItem *item; + + group = [list objectAtIndex:i]; + title = [group objectAtIndex:0]; + if ([group count] >= 3) + shortcut = [group objectAtIndex:2]; + + if ([title length] != 0) + { + item = (NSMenuItem *) [menu insertItemWithTitle:title + action:@selector (app_selected:) + keyEquivalent:shortcut atIndex:0]; + [item setTarget:self]; + [item setEnabled:YES]; + } + else + { + item = (NSMenuItem *) [NSMenuItem separatorItem]; + [menu insertItem:item atIndex:0]; + } + + [item setTag:i+1]; /* can't be zero, so add one */ +} + +- (void) install_apps_menu:(NSArray *)list +{ + NSMenu *menu; + int i, count; + + count = [list count]; + + if (count == 0 || apps_separator == nil) return; + + menu = [apps_separator menu]; + + for (i = count - 1; i >= 0; i--) + { + if (menu != nil) + [self prepend_apps_item:list index:i menu:menu]; + if (dock_apps_menu != nil) + [self prepend_apps_item:list index:i menu:dock_apps_menu]; + } + + apps = [list retain]; +} + +- (void) set_window_menu:(NSArray *)list +{ + [self remove_window_menu]; + [self install_window_menu:list]; + + QuartzMessageServerThread (kXDarwinControllerNotify, 1, + AppleWMWindowMenuNotify); +} + +- (void) set_window_menu_check:(NSNumber *)nn +{ + NSMenu *menu; + NSMenuItem *item; + int first, count; + int n = [nn intValue]; + + menu = [window_separator menu]; + first = [menu indexOfItem:window_separator] + 1; + count = [menu numberOfItems] - first; + + if (checked_window_item >= 0 && checked_window_item < count) + { + item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item]; + [item setState:NSOffState]; + item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item]; + [item setState:NSOffState]; + } + if (n >= 0 && n < count) + { + item = (NSMenuItem *) [menu itemAtIndex:first + n]; + [item setState:NSOnState]; + item = (NSMenuItem *) [dock_menu itemAtIndex:n]; + [item setState:NSOnState]; + } + checked_window_item = n; +} + +- (void) set_apps_menu:(NSArray *)list +{ + [self remove_apps_menu]; + [self install_apps_menu:list]; +} + +- (void) launch_client:(NSString *)filename +{ + const char *command = [filename UTF8String]; + const char *shell; + const char *argv[5]; + int child1, child2 = 0; + int status; + + shell = getenv("SHELL"); + if (shell == NULL) shell = "/bin/bash"; + + argv[0] = shell; + argv[1] = "-l"; + argv[2] = "-c"; + argv[3] = command; + argv[4] = NULL; + + /* Do the fork-twice trick to avoid having to reap zombies */ + + child1 = fork(); + + switch (child1) { + case -1: /* error */ + break; + + case 0: /* child1 */ + child2 = fork(); + + switch (child2) { + int max_files, i; + char buf[1024], *temp; + + case -1: /* error */ + _exit(1); + + case 0: /* child2 */ + /* close all open files except for standard streams */ + max_files = sysconf(_SC_OPEN_MAX); + for (i = 3; i < max_files; i++) close(i); + + /* ensure stdin is on /dev/null */ + close(0); + open("/dev/null", O_RDONLY); + + /* Setup environment */ + temp = getenv("DISPLAY"); + if (temp == NULL || temp[0] == 0) { + snprintf(buf, sizeof(buf), ":%s", display); + setenv("DISPLAY", buf, TRUE); + } + + temp = getenv("PATH"); + if (temp == NULL || temp[0] == 0) + setenv ("PATH", DEFAULT_PATH, TRUE); + else if (strnstr(temp, "/usr/X11/bin", sizeof(temp)) == NULL) { + snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", temp); + setenv("PATH", buf, TRUE); + } + /* cd $HOME */ + temp = getenv("HOME"); + if (temp != NULL && temp[0]!=0) chdir(temp); + + execvp(argv[0], (char **const) argv); + + _exit(2); + + default: /* parent (child1) */ + _exit(0); + } + break; + + default: /* parent */ + waitpid(child1, &status, 0); + } +} + +- (void) app_selected:sender +{ + int tag; + NSString *item; + + tag = [sender tag] - 1; + if (apps == nil || tag < 0 || tag >= [apps count]) + return; + + item = [[apps objectAtIndex:tag] objectAtIndex:1]; + + [self launch_client:item]; +} + +- (IBAction) apps_table_show:sender +{ + NSArray *columns; + + if (table_apps == nil) { + table_apps = [[NSMutableArray alloc] initWithCapacity:1]; + + if (apps != nil)[table_apps addObjectsFromArray:apps]; + } + + columns = [apps_table tableColumns]; + [[columns objectAtIndex:0] setIdentifier:@"0"]; + [[columns objectAtIndex:1] setIdentifier:@"1"]; + [[columns objectAtIndex:2] setIdentifier:@"2"]; + + [apps_table setDataSource:self]; + [apps_table selectRow:0 byExtendingSelection:NO]; + + [[apps_table window] makeKeyAndOrderFront:sender]; +} + +- (IBAction) apps_table_cancel:sender +{ + [[apps_table window] orderOut:sender]; + [apps_table reloadData]; + + [table_apps release]; + table_apps = nil; +} + +- (IBAction) apps_table_done:sender +{ + [apps_table deselectAll:sender]; /* flush edits? */ + + [self remove_apps_menu]; + [self install_apps_menu:table_apps]; + + [NSApp prefs_set_array:@PREFS_APPSMENU value:table_apps]; + [NSApp prefs_synchronize]; + + [[apps_table window] orderOut:sender]; + + [table_apps release]; + table_apps = nil; +} + +- (IBAction) apps_table_new:sender +{ + NSMutableArray *item; + + int row = [apps_table selectedRow], i; + + if (row < 0) row = 0; + else row = row + 1; + + i = row; + if (i > [table_apps count]) + return; /* avoid exceptions */ + + [apps_table deselectAll:sender]; + + item = [[NSMutableArray alloc] initWithCapacity:3]; + [item addObject:@""]; + [item addObject:@""]; + [item addObject:@""]; + + [table_apps insertObject:item atIndex:i]; + [item release]; + + [apps_table reloadData]; + [apps_table selectRow:row byExtendingSelection:NO]; +} + +- (IBAction) apps_table_duplicate:sender +{ + int row = [apps_table selectedRow], i; + NSObject *item; + + if (row < 0) { + [self apps_table_new:sender]; + return; + } + + i = row; + if (i > [table_apps count] - 1) return; /* avoid exceptions */ + + [apps_table deselectAll:sender]; + + item = [[table_apps objectAtIndex:i] mutableCopy]; + [table_apps insertObject:item atIndex:i]; + [item release]; + + [apps_table reloadData]; + [apps_table selectRow:row+1 byExtendingSelection:NO]; +} + +- (IBAction) apps_table_delete:sender +{ + int row = [apps_table selectedRow]; + + if (row >= 0) + { + int i = row; + + if (i > [table_apps count] - 1) return; /* avoid exceptions */ + + [apps_table deselectAll:sender]; + + [table_apps removeObjectAtIndex:i]; + } + + [apps_table reloadData]; + + row = MIN (row, [table_apps count] - 1); + if (row >= 0) + [apps_table selectRow:row byExtendingSelection:NO]; +} + +- (int) numberOfRowsInTableView:(NSTableView *)tableView +{ + if (table_apps == nil) return 0; + + return [table_apps count]; +} + +- (id) tableView:(NSTableView *)tableView +objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row +{ + NSArray *item; + int col; + + if (table_apps == nil) return nil; + + col = [[tableColumn identifier] intValue]; + + item = [table_apps objectAtIndex:row]; + if ([item count] > col) + return [item objectAtIndex:col]; + else + return @""; +} + +- (void) tableView:(NSTableView *)tableView setObjectValue:(id)object + forTableColumn:(NSTableColumn *)tableColumn row:(int)row +{ + NSMutableArray *item; + int col; + + if (table_apps == nil) return; + + col = [[tableColumn identifier] intValue]; + + item = [table_apps objectAtIndex:row]; + [item replaceObjectAtIndex:col withObject:object]; +} + +- (void) hide_window:sender +{ + if ([X11App x_active]) + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMHideWindow); + else + NSBeep (); /* FIXME: something here */ +} + +- (IBAction)bring_to_front:sender +{ + QuartzMessageServerThread(kXDarwinControllerNotify, 1, AppleWMBringAllToFront); +} + +- (IBAction)close_window:sender +{ + if ([X11App x_active]) + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMCloseWindow); + else + [[NSApp keyWindow] performClose:sender]; +} + +- (IBAction)minimize_window:sender +{ + if ([X11App x_active]) + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMMinimizeWindow); + else + [[NSApp keyWindow] performMiniaturize:sender]; +} + +- (IBAction)zoom_window:sender +{ + if ([X11App x_active]) + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMZoomWindow); + else + [[NSApp keyWindow] performZoom:sender]; +} + +- (IBAction) next_window:sender +{ + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMNextWindow); +} + +- (IBAction) previous_window:sender +{ + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMPreviousWindow); +} + +- (IBAction) enable_fullscreen_changed:sender +{ + int value = ![enable_fullscreen intValue]; + +#ifdef DARWIN_DDX_MISSING + QuartzMessageServerThread (kXDarwinSetRootless, 1, value); +#endif + + [NSApp prefs_set_boolean:@PREFS_ROOTLESS value:value]; + [NSApp prefs_synchronize]; +} + +- (IBAction) toggle_fullscreen:sender +{ +#ifdef DARWIN_DDX_MISSING + QuartzMessageServerThread (kXDarwinToggleFullscreen, 0); +#endif +} + +- (void) set_can_quit:(BOOL)state +{ + can_quit = state; +} + +- (IBAction)prefs_changed:sender +{ + darwinFakeButtons = [fake_buttons intValue]; + quartzUseSysBeep = [use_sysbeep intValue]; + X11EnableKeyEquivalents = [enable_keyequivs intValue]; + darwinSyncKeymap = [sync_keymap intValue]; + + /* after adding prefs here, also add to [X11Application read_defaults] + and below */ + + [NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons]; + [NSApp prefs_set_boolean:@PREFS_SYSBEEP value:quartzUseSysBeep]; + [NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:X11EnableKeyEquivalents]; + [NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap]; + [NSApp prefs_set_boolean:@PREFS_NO_AUTH value:![enable_auth intValue]]; + [NSApp prefs_set_boolean:@PREFS_NO_TCP value:![enable_tcp intValue]]; + [NSApp prefs_set_integer:@PREFS_DEPTH value:[depth selectedTag]]; + + [NSApp prefs_synchronize]; +} + +- (IBAction) prefs_show:sender +{ + [fake_buttons setIntValue:darwinFakeButtons]; + [use_sysbeep setIntValue:quartzUseSysBeep]; + [enable_keyequivs setIntValue:X11EnableKeyEquivalents]; + [sync_keymap setIntValue:darwinSyncKeymap]; + [sync_keymap setEnabled:darwinKeymapFile == NULL]; + + [enable_auth setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_AUTH default:NO]]; + [enable_tcp setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_TCP default:NO]]; + [depth selectItemAtIndex:[depth indexOfItemWithTag:[NSApp prefs_get_integer:@PREFS_DEPTH default:-1]]]; + + [enable_fullscreen setIntValue:!quartzEnableRootless]; + + [prefs_panel makeKeyAndOrderFront:sender]; +} + +- (IBAction) quit:sender +{ + QuartzMessageServerThread (kXDarwinQuit, 0); +} + +- (IBAction) x11_help:sender +{ + AHLookupAnchor (CFSTR ("Mac Help"), CFSTR ("mchlp2276")); +} + +- (BOOL) validateMenuItem:(NSMenuItem *)item +{ + NSMenu *menu = [item menu]; + + if (item == toggle_fullscreen_item) + return !quartzEnableRootless; + else if (menu == [window_separator menu] || menu == dock_menu + || (menu == [x11_about_item menu] && [item tag] == 42)) + return (AppleWMSelectedEvents () & AppleWMControllerNotifyMask) != 0; + else + return TRUE; +} + +- (void) applicationDidHide:(NSNotification *)notify +{ + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMHideAll); +} + +- (void) applicationDidUnhide:(NSNotification *)notify +{ + QuartzMessageServerThread (kXDarwinControllerNotify, 1, AppleWMShowAll); +} + +- (NSApplicationTerminateReply) applicationShouldTerminate:sender +{ + NSString *msg; + + if (can_quit || [X11App prefs_get_boolean:@PREFS_NO_QUIT_ALERT default:NO]) + return NSTerminateNow; + + /* Make sure we're frontmost. */ + [NSApp activateIgnoringOtherApps:YES]; + + msg = NSLocalizedString (@"Are you sure you want to quit X11?\n\nIf you quit X11, any X11 applications you are running will stop immediately and you will lose any changes you have not saved.", @"Dialog when quitting"); + + /* FIXME: safe to run the alert in here? Or should we return Later + and then run the alert on a timer? It seems to work here, so.. */ + + return (NSRunAlertPanel (nil, msg, NSLocalizedString (@"Quit", @""), + NSLocalizedString (@"Cancel", @""), nil) + == NSAlertDefaultReturn) ? NSTerminateNow : NSTerminateCancel; +} + +- (void) applicationWillTerminate:(NSNotification *)aNotification +{ + [X11App prefs_synchronize]; + + /* shutdown the X server, it will exit () for us. */ + QuartzMessageServerThread (kXDarwinQuit, 0); + + /* In case it doesn't, exit anyway after a while. */ + while (sleep (10) != 0) ; + exit (1); +} + +- (void) server_ready +{ + x_list *node; + + finished_launching = YES; + + for (node = pending_apps; node != NULL; node = node->next) + { + NSString *filename = node->data; + [self launch_client:filename]; + [filename release]; + } + + x_list_free (pending_apps); + pending_apps = NULL; +} + +- (BOOL) application:(NSApplication *)app openFile:(NSString *)filename +{ + const char *name = [filename UTF8String]; + + if (finished_launching) + [self launch_client:filename]; + else if (name[0] != ':') /* ignore display names */ + pending_apps = x_list_prepend (pending_apps, [filename retain]); + + /* FIXME: report failures. */ + return YES; +} + +@end + +void X11ControllerMain (int argc, const char *argv[], + void (*server_thread) (void *), void *server_arg) +{ + X11ApplicationMain (argc, argv, server_thread, server_arg); +} diff --git a/hw/darwin/apple/Xquartz.man b/hw/darwin/apple/Xquartz.man new file mode 100644 index 000000000..edac30ee9 --- /dev/null +++ b/hw/darwin/apple/Xquartz.man @@ -0,0 +1,158 @@ +.\" $XFree86: xc/programs/Xserver/hw/darwin/XDarwin.man,v 1.4 2002/01/09 18:01:58 torrey Exp $ +.\" +.TH XQUARTZ 1 __vendorversion__ +.SH NAME +Xquartz \- X window system server for Quartz operating system +.SH SYNOPSIS +.B Xquartz +[ options ] ... +.SH DESCRIPTION +.I Xquartz +is the X window server for Mac OS X provided by Apple. +.I Xquartz +runs in parallel with Aqua in rootless mode. In rootless mode, the X +window system and Mac OS X share your display. The root window of the +X11 display is the size of the screen and contains all the other +windows. The X11 root window is not displayed in rootless mode as Mac +OS X handles the desktop background. +.SH OPTIONS +.PP +In addition to the normal server options described in the \fIXserver(1)\fP +manual page, \fIXquartz\fP accepts the following command line switches: +.TP 8 +.B \-fakebuttons +Emulates a 3 button mouse using modifier keys. By default, the Command modifier +is used to emulate button 2 and Option is used for button 3. Thus, clicking the +first mouse button while holding down Command will act like clicking +button 2. Holding down Option will simulate button 3. +.TP 8 +.B \-nofakebuttons +Do not emulate a 3 button mouse. This is the default. +.TP 8 +.B "\-fakemouse2 \fImodifiers\fP" +Change the modifier keys used to emulate the second mouse button. By default, +Command is used to emulate the second button. Any combination of the following +modifier names may be used: Shift, Option, Control, Command, Fn. For example, +.B \-fakemouse2 """Option,Shift"" +will set holding Option, Shift and clicking on button one as equivalent to +clicking the second mouse button. +.TP 8 +.B "\-fakemouse3 \fImodifiers\fP" +Change the modifier keys used to emulate the third mouse button. By default, +Option is used to emulate the third button. Any combination of the following +modifier names may be used: Shift, Option, Control, Command, Fn. For example, +.B \-fakemouse3 """Control,Shift"" +will set holding Control, Shift and clicking on button one as equivalent to +clicking the third mouse button. +.TP 8 +.B "\-swapAltMeta" +Swaps the meaning of the Alt and Meta modifier keys. +.TP 8 +.B "\-keymap \fIfile\fP" +On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap. +The default is to read this keymapping from USA.keymapping. With this option +the keymapping will be read from \fIfile\fP instead. If the file's path is +not specified, it will be searched for in Library/Keyboards/ underneath the +following directories (in order): ~, /, /Network, /System. +.TP 8 +.B \-nokeymap +On startup \fIXquartz\fP translates a Darwin keymapping into an X keymap. +With this option \fIXquartz\fP queries the kernel for the current keymapping +instead of reading it from a file. This will often fail on newer kernels. +.TP 8 +.B "\-depth \fIdepth\fP" +Specifies the color bit depth to use. Currently only 15, and 24 color +bits per pixel are supported. If not specified, defaults to the depth +of the main display. +.SH CUSTOMIZATION +\fIXquartz\fP can also be customized using the defaults(1) command. The available options are: +.TP 8 +.B defaults write com.apple.x11 enable_fake_buttons -boolean true +Equivalent to the \fB-fakebuttons\fP command line option. +.TP 8 +.B defaults write com.apple.x11 fake_button2 \fImodifiers\fP +Equivalent to the \fB-fakemouse2\fP option. +.TP 8 +.B defaults write com.apple.x11 fake_button3 \fImodifiers\fP +Equivalent to the \fB-fakemouse3\fP option. +.TP 8 +.B defaults write com.apple.x11 swap_alt_meta -boolean true +Equivalent to the \fB-swapAltMeta\fP option. +.TP 8 +.B defaults write com.apple.x11 keymap_file \fIfilename\fP +Equivalent to the \fB-keymap\fP option. +.TP 8 +.B defaults write com.apple.x11 no_quit_alert -boolean true +Disables the alert dialog displayed when attempting to quit X11. +.TP 8 +.B defaults write com.apple.x11 no_auth -boolean true +Stops the X server requiring that clients authenticate themselves when +connecting. See Xsecurity(__miscmansuffix__). +.TP 8 +.B defaults write com.apple.x11 nolisten_tcp -boolean true +Prevents the X server accepting remote connections. +.TP 8 +.B defaults write com.apple.x11 xinit_kills_server -boolean false +Stops the X server exiting when the xinitrc script terminates. +.TP 8 +.B defaults write com.apple.x11 fullscreen_hotkeys -boolean false +Allows system hotkeys to be handled while in X11 fullscreen mode. +.TP 8 +.B defaults write com.apple.x11 enable_system_beep -boolean false +Don't use the standard system beep effect for X11 alerts. +.TP 8 +.B defaults write com.apple.x11 enable_key_equivalents -boolean false +Disable menu keyboard equivalents while X11 windows are focused. +.TP 8 +.B defaults write com.apple.x11 depth \fIdepth\fP +Equivalent to the \fB-depth\fP option. +.SH "SEE ALSO" +.PP +X(__miscmansuffix__), XFree86(1), Xserver(1), xdm(1), xinit(1) +.PP +.SH AUTHORS +XFree86 was originally ported to Mac OS X Server by John Carmack. Dave +Zarzycki used this as the basis of his port of XFree86 4.0 to Darwin 1.0. +Torrey T. Lyons improved and integrated this code into the XFree86 +Project's mainline for the 4.0.2 release. +.PP +The following members of the XonX Team contributed to the following +releases (in alphabetical order): +.TP 4 +XFree86 4.1.0: +.br +Rob Braun - Darwin x86 support +.br +Torrey T. Lyons - Project Lead +.br +Andreas Monitzer - Cocoa version of XDarwin front end +.br +Gregory Robert Parker - Original Quartz implementation +.br +Christoph Pfisterer - Dynamic shared X libraries +.br +Toshimitsu Tanaka - Japanese localization +.TP 4 +XFree86 4.2.0: +.br +Rob Braun - Darwin x86 support +.br +Pablo Di Noto - Spanish localization +.br +Paul Edens - Dutch localization +.br +Kyunghwan Kim - Korean localization +.br +Mario Klebsch - Non-US keyboard support +.br +Torrey T. Lyons - Project Lead +.br +Andreas Monitzer - German localization +.br +Patrik Montgomery - Swedish localization +.br +Greg Parker - Rootless support +.br +Toshimitsu Tanaka - Japanese localization +.br +Olivier Verdier - French localization diff --git a/hw/darwin/apple/bundle-main.c b/hw/darwin/apple/bundle-main.c new file mode 100644 index 000000000..12fb1bf54 --- /dev/null +++ b/hw/darwin/apple/bundle-main.c @@ -0,0 +1,911 @@ +/* bundle-main.c -- X server launcher + $Id: bundle-main.c,v 1.17 2003/09/11 00:17:10 jharper Exp $ + + Copyright (c) 2002-2007 Apple Inc. All rights reserved. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT + HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name(s) of the above + copyright holders shall not be used in advertising or otherwise to + promote the sale, use or other dealings in this Software without + prior written authorization. + + Parts of this file are derived from xdm, which has this copyright: + + Copyright 1988, 1998 The Open Group + + Permission to use, copy, modify, distribute, and sell this software + and its documentation for any purpose is hereby granted without fee, + provided that the above copyright notice appear in all copies and + that both that copyright notice and this permission notice appear in + supporting documentation. + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name of The Open Group shall + not be used in advertising or otherwise to promote the sale, use or + other dealings in this Software without prior written authorization + from The Open Group. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#define X_SERVER "/usr/X11/bin/Xquartz" +#define XTERM_PATH "/usr/X11/bin/xterm" +#define WM_PATH "/usr/X11/bin/quartz-wm" +#define DEFAULT_XINITRC "/etc/X11/xinit/xinitrc" +#define DEFAULT_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin" + +/* what xinit does */ +#ifndef SHELL +# define SHELL "sh" +#endif + +#undef FALSE +#define FALSE 0 +#undef TRUE +#define TRUE 1 + +#define MAX_DISPLAYS 64 + +static int server_pid = -1, client_pid = -1; +static int xinit_kills_server = FALSE; +static jmp_buf exit_continuation; +static const char *server_name = NULL; +static Display *server_dpy; + +static char *auth_file; + +typedef struct addr_list_struct addr_list; + +struct addr_list_struct { + addr_list *next; + Xauth auth; +}; + +static addr_list *addresses; + + +/* Utility functions. */ + +/* Return the current host name. Matches what Xlib does. */ +static char * +host_name (void) +{ +#ifdef NEED_UTSNAME + static struct utsname name; + + uname(&name); + + return name.nodename; +#else + static char buf[100]; + + gethostname(buf, sizeof(buf)); + + return buf; +#endif +} + +static int +read_boolean_pref (CFStringRef name, int default_) +{ + int value; + Boolean ok; + + value = CFPreferencesGetAppBooleanValue (name, + CFSTR ("com.apple.x11"), &ok); + return ok ? value : default_; +} + +static inline int +binary_equal (const void *a, const void *b, int length) +{ + return memcmp (a, b, length) == 0; +} + +static inline void * +binary_dup (const void *a, int length) +{ + void *b = malloc (length); + if (b != NULL) + memcpy (b, a, length); + return b; +} + +static inline void +binary_free (void *data, int length) +{ + if (data != NULL) + free (data); +} + + +/* Functions for managing the authentication entries. */ + +/* Returns true if something matching AUTH is in our list of auth items */ +static int +check_auth_item (Xauth *auth) +{ + addr_list *a; + + for (a = addresses; a != NULL; a = a->next) + { + if (a->auth.family == auth->family + && a->auth.address_length == auth->address_length + && binary_equal (a->auth.address, auth->address, auth->address_length) + && a->auth.number_length == auth->number_length + && binary_equal (a->auth.number, auth->number, auth->number_length) + && a->auth.name_length == auth->name_length + && binary_equal (a->auth.name, auth->name, auth->name_length)) + { + return TRUE; + } + } + + return FALSE; +} + +/* Add one item to our list of auth items. */ +static void +add_auth_item (Xauth *auth) +{ + addr_list *a = malloc (sizeof (addr_list)); + + a->auth.family = auth->family; + a->auth.address_length = auth->address_length; + a->auth.address = binary_dup (auth->address, auth->address_length); + a->auth.number_length = auth->number_length; + a->auth.number = binary_dup (auth->number, auth->number_length); + a->auth.name_length = auth->name_length; + a->auth.name = binary_dup (auth->name, auth->name_length); + a->auth.data_length = auth->data_length; + a->auth.data = binary_dup (auth->data, auth->data_length); + + a->next = addresses; + addresses = a; +} + +/* Free all allocated auth items. */ +static void +free_auth_items (void) +{ + addr_list *a; + + while ((a = addresses) != NULL) + { + addresses = a->next; + + binary_free (a->auth.address, a->auth.address_length); + binary_free (a->auth.number, a->auth.number_length); + binary_free (a->auth.name, a->auth.name_length); + binary_free (a->auth.data, a->auth.data_length); + free (a); + } +} + +/* Add the unix domain auth item. */ +static void +define_local (Xauth *auth) +{ + char *host = host_name (); + +#ifdef DEBUG + fprintf (stderr, "x11: hostname is %s\n", host); +#endif + + auth->family = FamilyLocal; + auth->address_length = strlen (host); + auth->address = host; + + add_auth_item (auth); +} + +/* Add the tcp auth item. */ +static void +define_named (Xauth *auth, const char *name) +{ + struct ifaddrs *addrs, *ptr; + + if (getifaddrs (&addrs) != 0) + return; + + for (ptr = addrs; ptr != NULL; ptr = ptr->ifa_next) + { + if (ptr->ifa_addr->sa_family != AF_INET) + continue; + + auth->family = FamilyInternet; + auth->address_length = sizeof (struct in_addr); + auth->address = (char *) &(((struct sockaddr_in *) ptr->ifa_addr)->sin_addr); + +#ifdef DEBUG + fprintf (stderr, "x11: ipaddr is %d.%d.%d.%d\n", + (unsigned char) auth->address[0], + (unsigned char) auth->address[1], + (unsigned char) auth->address[2], + (unsigned char) auth->address[3]); +#endif + + add_auth_item (auth); + } + + freeifaddrs (addrs); +} + +/* Parse the display number from NAME and add it to AUTH. */ +static void +set_auth_number (Xauth *auth, const char *name) +{ + char *colon; + char *dot, *number; + + colon = strrchr(name, ':'); + if (colon != NULL) + { + colon++; + dot = strchr(colon, '.'); + + if (dot != NULL) + auth->number_length = dot - colon; + else + auth->number_length = strlen (colon); + + number = malloc (auth->number_length + 1); + if (number != NULL) + { + strncpy (number, colon, auth->number_length); + number[auth->number_length] = '\0'; + } + else + { + auth->number_length = 0; + } + + auth->number = number; + } +} + +/* Put 128 bits of random data into DATA. If possible, it will be "high + quality" */ +static int +generate_mit_magic_cookie (char data[16]) +{ + int fd, ret, i; + long *ldata = (long *) data; + + fd = open ("/dev/random", O_RDONLY); + if (fd > 0) { + ret = read (fd, data, 16); + close (fd); + if (ret == 16) return TRUE; + } + + /* fall back to the usual crappy rng */ + + srand48 (getpid () ^ time (NULL)); + + for (i = 0; i < 4; i++) + ldata[i] = lrand48 (); + + return TRUE; +} + +/* Create the keys we'll be using for the display named NAME. */ +static int +make_auth_keys (const char *name) +{ + Xauth auth; + char key[16]; + + if (auth_file == NULL) + return FALSE; + + auth.name = "MIT-MAGIC-COOKIE-1"; + auth.name_length = strlen (auth.name); + + if (!generate_mit_magic_cookie (key)) + { + auth_file = NULL; + return FALSE; + } + + auth.data = key; + auth.data_length = 16; + + set_auth_number (&auth, name); + + define_named (&auth, host_name ()); + define_local (&auth); + + free (auth.number); + + return TRUE; +} + +/* If ADD-ENTRIES is true, merge our auth entries into the existing + Xauthority file. If ADD-ENTRIES is false, remove our entries. */ +static int +write_auth_file (int add_entries) +{ + char *home, newname[1024]; + int fd, ret; + FILE *new_fh, *old_fh; + addr_list *addr; + Xauth *auth; + + if (auth_file == NULL) + return FALSE; + + home = getenv ("HOME"); + if (home == NULL) + { + auth_file = NULL; + return FALSE; + } + + snprintf (newname, sizeof (newname), "%s/.XauthorityXXXXXX", home); + mktemp (newname); + + if (XauLockAuth (auth_file, 1, 2, 10) != LOCK_SUCCESS) + { + /* FIXME: do something here? */ + + auth_file = NULL; + return FALSE; + } + + fd = open (newname, O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd >= 0) + { + new_fh = fdopen (fd, "w"); + if (new_fh != NULL) + { + if (add_entries) + { + for (addr = addresses; addr != NULL; addr = addr->next) + { + XauWriteAuth (new_fh, &addr->auth); + } + } + + old_fh = fopen (auth_file, "r"); + if (old_fh != NULL) + { + while ((auth = XauReadAuth (old_fh)) != NULL) + { + if (!check_auth_item (auth)) + XauWriteAuth (new_fh, auth); + XauDisposeAuth (auth); + } + fclose (old_fh); + } + + fclose (new_fh); + unlink (auth_file); + + ret = rename (newname, auth_file); + + if (ret != 0) + auth_file = NULL; + + XauUnlockAuth (auth_file); + return ret == 0; + } + + close (fd); + } + + XauUnlockAuth (auth_file); + auth_file = NULL; + return FALSE; +} + + +/* Subprocess management functions. */ + +static int +start_server (char **xargv) +{ + int child; + + child = fork (); + + switch (child) + { + case -1: /* error */ + perror ("fork"); + return FALSE; + + case 0: /* child */ + execv (X_SERVER, xargv); + perror ("Couldn't exec " X_SERVER); + _exit (1); + + default: /* parent */ + server_pid = child; + return TRUE; + } +} + +static int +wait_for_server (void) +{ + int count = 100; + + while (count-- > 0) + { + int status; + + server_dpy = XOpenDisplay (server_name); + if (server_dpy != NULL) + return TRUE; + + if (waitpid (server_pid, &status, WNOHANG) == server_pid) + return FALSE; + + sleep (1); + } + + return FALSE; +} + +static int +start_client (void) +{ + int child; + + child = fork(); + + switch (child) { + char *temp, buf[1024]; + + case -1: /* error */ + perror("fork"); + return FALSE; + + case 0: /* child */ + /* Setup environment */ + temp = getenv("DISPLAY"); + if (temp != NULL && temp[0] != 0) + setenv("DISPLAY", server_name, TRUE); + + temp = getenv("PATH"); + if (temp == NULL || temp[0] == 0) + setenv ("PATH", DEFAULT_PATH, TRUE); + else if (strnstr(temp, "/usr/X11/bin", sizeof(temp)) == NULL) { + snprintf(buf, sizeof(buf), "%s:/usr/X11/bin", temp); + setenv("PATH", buf, TRUE); + } + + /* First try value of $XINITRC, if set. */ + temp = getenv("XINITRC"); + if (temp != NULL && temp[0] != 0 && access(temp, R_OK) == 0) + execlp (SHELL, SHELL, temp, NULL); + + /* Then look for .xinitrc in user's home directory. */ + temp = getenv("HOME"); + if (temp != NULL && temp[0] != 0) { + chdir(temp); + snprintf (buf, sizeof (buf), "%s/.xinitrc", temp); + if (access(buf, R_OK) == 0) + execlp(SHELL, SHELL, buf, NULL); + } + + /* Then try the default xinitrc in the lib directory. */ + + if (access(DEFAULT_XINITRC, R_OK) == 0) + execlp(SHELL, SHELL, DEFAULT_XINITRC, NULL); + + /* Then fallback to hardcoding an xterm and the window manager. */ + + // system(XTERM_PATH " &"); + execl(WM_PATH, WM_PATH, NULL); + + perror("exec"); + _exit(1); + + default: /* parent */ + client_pid = child; + return TRUE; + } +} + +static void +sigchld_handler (int sig) +{ + int pid, status; + + again: + pid = waitpid (WAIT_ANY, &status, WNOHANG); + + if (pid > 0) + { + if (pid == server_pid) + { + server_pid = -1; + + if (client_pid >= 0) + kill (client_pid, SIGTERM); + } + else if (pid == client_pid) + { + client_pid = -1; + + if (server_pid >= 0 && xinit_kills_server) + kill (server_pid, SIGTERM); + } + goto again; + } + + if (server_pid == -1 && client_pid == -1) + longjmp (exit_continuation, 1); + + signal (SIGCHLD, sigchld_handler); +} + + +/* Server utilities. */ + +static Boolean +display_exists_p (int number) +{ + char buf[64]; + void *conn; + char *fullname = NULL; + int idisplay, iscreen; + char *conn_auth_name, *conn_auth_data; + int conn_auth_namelen, conn_auth_datalen; + + extern void *_X11TransConnectDisplay (); + extern void _XDisconnectDisplay (); + + /* Since connecting to the display waits for a few seconds if the + display doesn't exist, check for trivial non-existence - if the + socket in /tmp exists or not.. (note: if the socket exists, the + server may still not, so we need to try to connect in that case..) */ + + sprintf (buf, "/tmp/.X11-unix/X%d", number); + if (access (buf, F_OK) != 0) + return FALSE; + + /* This is a private function that we shouldn't really be calling, + but it's the best way to see if the server exists (without + needing to hold the necessary authentication to use it) */ + + sprintf (buf, ":%d", number); + conn = _X11TransConnectDisplay (buf, &fullname, &idisplay, &iscreen, + &conn_auth_name, &conn_auth_namelen, + &conn_auth_data, &conn_auth_datalen); + if (conn == NULL) + return FALSE; + + _XDisconnectDisplay (conn); + return TRUE; +} + + +/* Monitoring when the system's ip addresses change. */ + +static Boolean pending_timer; + +static void +timer_callback (CFRunLoopTimerRef timer, void *info) +{ + pending_timer = FALSE; + + /* Update authentication names. Need to write .Xauthority file first + without the existing entries, then again with the new entries.. */ + + write_auth_file (FALSE); + + free_auth_items (); + make_auth_keys (server_name); + + write_auth_file (TRUE); +} + +/* This function is called when the system's ip addresses may have changed. */ +static void +ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info) +{ +#if DEBUG + if (changed_keys != NULL) { + fprintf (stderr, "x11: changed sc keys: "); + CFShow (changed_keys); + } +#endif + + if (auth_file != NULL && !pending_timer) + { + CFRunLoopTimerRef timer; + + timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0, + 0.0, 0, 0, timer_callback, NULL); + CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer, + kCFRunLoopDefaultMode); + CFRelease (timer); + + pending_timer = TRUE; + } +} + +/* This code adapted from "Living in a Dynamic TCP/IP Environment" technote. */ +static Boolean +install_ipaddr_source (void) +{ + CFRunLoopSourceRef source = NULL; + + SCDynamicStoreContext context = {0}; + SCDynamicStoreRef ref; + + ref = SCDynamicStoreCreate (NULL, + CFSTR ("AddIPAddressListChangeCallbackSCF"), + ipaddr_callback, &context); + + if (ref != NULL) + { + const void *keys[4], *patterns[2]; + int i; + + keys[0] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4); + keys[1] = SCDynamicStoreKeyCreateNetworkGlobalEntity (NULL, kSCDynamicStoreDomainState, kSCEntNetIPv6); + keys[2] = SCDynamicStoreKeyCreateComputerName (NULL); + keys[3] = SCDynamicStoreKeyCreateHostNames (NULL); + + patterns[0] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv4); + patterns[1] = SCDynamicStoreKeyCreateNetworkInterfaceEntity (NULL, kSCDynamicStoreDomainState, kSCCompAnyRegex, kSCEntNetIPv6); + + if (keys[0] != NULL && keys[1] != NULL && keys[2] != NULL + && keys[3] != NULL && patterns[0] != NULL && patterns[1] != NULL) + { + CFArrayRef key_array, pattern_array; + + key_array = CFArrayCreate (NULL, keys, 4, &kCFTypeArrayCallBacks); + pattern_array = CFArrayCreate (NULL, patterns, 2, &kCFTypeArrayCallBacks); + + if (key_array != NULL || pattern_array != NULL) + { + SCDynamicStoreSetNotificationKeys (ref, key_array, pattern_array); + source = SCDynamicStoreCreateRunLoopSource (NULL, ref, 0); + } + + if (key_array != NULL) + CFRelease (key_array); + if (pattern_array != NULL) + CFRelease (pattern_array); + } + + + for (i = 0; i < 4; i++) + if (keys[i] != NULL) + CFRelease (keys[i]); + for (i = 0; i < 2; i++) + if (patterns[i] != NULL) + CFRelease (patterns[i]); + + CFRelease (ref); + } + + if (source != NULL) + { + CFRunLoopAddSource (CFRunLoopGetCurrent (), + source, kCFRunLoopDefaultMode); + CFRelease (source); + } + + return source != NULL; +} + + +/* Entrypoint. */ + +void +termination_signal_handler (int unused_sig) +{ + signal (SIGTERM, SIG_DFL); + signal (SIGHUP, SIG_DFL); + signal (SIGINT, SIG_DFL); + signal (SIGQUIT, SIG_DFL); + + longjmp (exit_continuation, 1); +} + +int +main (int argc, char **argv) +{ + char **xargv; + int i, j; + int fd; + + xargv = alloca (sizeof (char *) * (argc + 32)); + + if (!read_boolean_pref (CFSTR ("no_auth"), FALSE)) + auth_file = XauFileName (); + + /* The standard X11 behaviour is for the server to quit when the first + client exits. But it can be useful for debugging (and to mimic our + behaviour in the beta releases) to not do that. */ + + xinit_kills_server = read_boolean_pref (CFSTR ("xinit_kills_server"), TRUE); + + for (i = 1; i < argc; i++) + { + if (argv[i][0] == ':') + server_name = argv[i]; + } + + if (server_name == NULL) + { + static char name[8]; + + /* No display number specified, so search for the first unused. + + There's a big old race condition here if two servers start at + the same time, but that's fairly unlikely. We could create + lockfiles or something, but that's seems more likely to cause + problems than the race condition itself.. */ + + for (i = 0; i < MAX_DISPLAYS; i++) + { + if (!display_exists_p (i)) + break; + } + + if (i == MAX_DISPLAYS) + { + fprintf (stderr, "%s: couldn't allocate a display number", argv[0]); + exit (1); + } + + sprintf (name, ":%d", i); + server_name = name; + } + + if (auth_file != NULL) + { + /* Create new Xauth keys and add them to the .Xauthority file */ + + make_auth_keys (server_name); + write_auth_file (TRUE); + } + + /* Construct our new argv */ + + i = j = 0; + + xargv[i++] = argv[j++]; + + if (auth_file != NULL) + { + xargv[i++] = "-auth"; + xargv[i++] = auth_file; + } + + /* By default, don't listen on tcp sockets if Xauth is disabled. */ + + if (read_boolean_pref (CFSTR ("nolisten_tcp"), auth_file == NULL)) + { + xargv[i++] = "-nolisten"; + xargv[i++] = "tcp"; + } + + while (j < argc) + { + if (argv[j++][0] != ':') + xargv[i++] = argv[j-1]; + } + + xargv[i++] = (char *) server_name; + xargv[i++] = NULL; + + /* Detach from any controlling terminal and connect stdin to /dev/null */ + +#ifdef TIOCNOTTY + fd = open ("/dev/tty", O_RDONLY); + if (fd != -1) + { + ioctl (fd, TIOCNOTTY, 0); + close (fd); + } +#endif + + fd = open ("/dev/null", O_RDWR, 0); + if (fd >= 0) + { + dup2 (fd, 0); + if (fd > 0) + close (fd); + } + + if (!start_server (xargv)) + return 1; + + if (!wait_for_server ()) + { + kill (server_pid, SIGTERM); + return 1; + } + + if (!start_client ()) + { + kill (server_pid, SIGTERM); + return 1; + } + + signal (SIGCHLD, sigchld_handler); + + signal (SIGTERM, termination_signal_handler); + signal (SIGHUP, termination_signal_handler); + signal (SIGINT, termination_signal_handler); + signal (SIGQUIT, termination_signal_handler); + + if (setjmp (exit_continuation) == 0) + { + if (install_ipaddr_source ()) + CFRunLoopRun (); + else + while (1) pause (); + } + + signal (SIGCHLD, SIG_IGN); + + if (client_pid >= 0) kill (client_pid, SIGTERM); + if (server_pid >= 0) kill (server_pid, SIGTERM); + + if (auth_file != NULL) + { + /* Remove our Xauth keys */ + + write_auth_file (FALSE); + } + + free_auth_items (); + + return 0; +}