// Constructor. internal Screen(Display dpy, int number, IntPtr screen) { // Copy parameters in from the create process. this.dpy = dpy; this.number = number; this.screen = screen; // Create the root window instance for this screen. rootWindow = new Xsharp.RootWindow (dpy, this, Xlib.XRootWindowOfScreen(screen)); // Get the default root visual for this screen. visual = Xlib.XDefaultVisualOfScreen(screen); // Create a "Colormap" object for the default colormap. defaultColormap = new Colormap (dpy, this, Xlib.XDefaultColormapOfScreen(screen)); // Create the GC cache. defaultGCs = new IntPtr [GCCacheSize]; bitmapGCs = new IntPtr [GCCacheSize]; // Initialize the standard colors. InitStandardColors(); // Create the placeholder window for parent-less widgets. placeholder = new PlaceholderWindow(rootWindow); // Create the grab window for managing popup window events. grabWindow = new GrabWindow(rootWindow); }
// Create a new application group for embedding a child application. private unsafe void CreateApplicationGroup() { String displayName; Xauth *auth; Xauth *authReturn; XSecurityAuthorizationAttributes xsa; Xlib.XSecurityAuthorization xs; // Check that we can create application groups. if (!CanEmbed(dpy, true, out displayName)) { return; } try { // Lock down the display while we do this. IntPtr display = dpy.Lock(); // Create the application group identifier. if (Xlib.XagCreateEmbeddedApplicationGroup (display, XVisualID.Zero, Xlib.XDefaultColormapOfScreen(screen.screen), Xlib.XBlackPixelOfScreen(screen.screen), Xlib.XWhitePixelOfScreen(screen.screen), out group) == XStatus.Zero) { return; } // Generate an authentication token for the group. auth = Xlib.XSecurityAllocXauth(); if (auth == null) { return; } auth->name = Marshal.StringToHGlobalAnsi ("MIT-MAGIC-COOKIE-1"); auth->name_length = 18; xsa = new XSecurityAuthorizationAttributes(); xsa.timeout = 300; xsa.trust_level = 0; // XSecurityClientTrusted xsa.group = (XID)group; xsa.event_mask = 0; authReturn = Xlib.XSecurityGenerateAuthorization (display, auth, (uint)(XSecurityAttributeMask.XSecurityTimeout | XSecurityAttributeMask.XSecurityTrustLevel | XSecurityAttributeMask.XSecurityGroup), ref xsa, out xs); if (authReturn == null) { Xlib.XSecurityFreeXauth(auth); return; } // Write the credentials to a temporary X authority file. String authFile = Path.GetTempFileName(); FileStream stream = new FileStream (authFile, FileMode.Create, FileAccess.Write); WriteShort(stream, 65535); // family = FamilyWild WriteShort(stream, 0); // address_length WriteShort(stream, 0); // number_length WriteShort(stream, authReturn->name_length); WriteBytes(stream, authReturn->name, authReturn->name_length); WriteShort(stream, authReturn->data_length); WriteBytes(stream, authReturn->data, authReturn->data_length); stream.Close(); // Free the Xauth structures that we don't need any more. Xlib.XSecurityFreeXauth(auth); Xlib.XSecurityFreeXauth(authReturn); // Record the app group information. redirectDisplay = displayName; authorityFile = authFile; // Create a wrapper around the appgroup to get events. groupWrapper = new AppGroupWidget(dpy, screen, group, this); } catch (MissingMethodException) { return; } catch (DllNotFoundException) { return; } catch (EntryPointNotFoundException) { return; } finally { dpy.Unlock(); } }