/// <summary> /// <para>Close the X display connection if it is currently active.</para> /// </summary> public void Close() { lock (this) { if (dpy != IntPtr.Zero) { lock (typeof(Display)) { // Disassociate window handles from all windows. for (int scr = 0; scr < screens.Length; ++scr) { screens[scr].RootWindow.Disassociate(); } // Disassociate the fonts from this display. IDictionaryEnumerator e = fonts.GetEnumerator(); while (e.MoveNext()) { ((Font)(e.Value)).Disassociate(this); } fonts.Clear(); // Close the connection to the X server. Xlib.XCloseDisplay(dpy); dpy = IntPtr.Zero; } } } }
// Release an Xlib GC value from a GC object that was disposed. internal void ReleaseGC(IntPtr gc, bool isBitmapGC) { if (!isBitmapGC) { if (numDefaultGCs < GCCacheSize) { defaultGCs[numDefaultGCs++] = gc; } else { Xlib.XFreeGC(dpy.dpy, gc); } } else { if (numBitmapGCs < GCCacheSize) { bitmapGCs[numBitmapGCs++] = gc; } else { Xlib.XFreeGC(dpy.dpy, gc); } } }
public bool SetText(String[] value) { // Bail out early if we don't have any strings. if (value == null || value.Length == 0) { return(SetText("")); } // Convert the strings into an array of pointers. IntPtr[] strings = new IntPtr [value.Length]; int posn; String str; for (posn = 0; posn < value.Length; ++posn) { str = value[posn]; if (str == null) { str = String.Empty; } strings[posn] = Marshal.StringToHGlobalAnsi(str); } // Convert the string list into a text property. bool result = (Xlib.XStringListToTextProperty (strings, value.Length, ref this) != XStatus.Zero); // Free the strings, which we no longer require. for (posn = 0; posn < value.Length; ++posn) { Marshal.FreeHGlobal(strings[posn]); } return(result); }
/// <summary> /// <para>Process a color theme change for this widget.</para> /// </summary> public override void ThemeChange() { // Pass the theme change on to all of the child widgets. base.ThemeChange(); // Change the background pixel to match the new theme // settings, and then force a repaint on the widget. try { IntPtr display = dpy.Lock(); XWindow window = GetWidgetHandle(); StandardColor sc = background.Index; if (sc != StandardColor.Inherit && sc != StandardColor.Pixmap && sc != StandardColor.RGB) { Xlib.XSetWindowBackground (display, window, ToPixel(background)); } if (mapped && AncestorsMapped) { Xlib.XClearArea(display, window, 0, 0, (uint)0, (uint)0, XBool.True); } } finally { dpy.Unlock(); } }
/// <summary> /// <para>Subtract another region from this one.</para> /// </summary> /// /// <param name="r"> /// <para>The other region to subtract from this one. If /// <paramref name="r"/> is <see langword="null"/> or disposed, /// the method does nothing.</para> /// </param> /// /// <remarks> /// <para>If this region has been disposed, then it will be re-created /// with its initial contents set to empty.</para> /// </remarks> public void Subtract(Region r) { lock (typeof(Region)) { if (region == IntPtr.Zero) { region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } else if (r == null || r.region == IntPtr.Zero) { // Nothing to do here: subtracting an empty region. } else if (r == this) { // Subtract the region from itself: result is empty. Xlib.XDestroyRegion(region); region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } else { Xlib.XSubtractRegion(region, r.region, region); } } }
/// <summary> /// <para>Xor another region with this one.</para> /// </summary> /// /// <param name="r"> /// <para>The other region to xor with this one. If /// <paramref name="r"/> is <see langword="null"/> or disposed, /// then it will be treated as the empty region.</para> /// </param> /// /// <remarks> /// <para>If this region has been disposed, then it will be treated /// as empty prior to the xor operation.</para> /// </remarks> public void Xor(Region r) { lock (typeof(Region)) { if (region == IntPtr.Zero) { region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } if (r == null || r.region == IntPtr.Zero) { // Xor of an empty and a non-empty region gives // the non-empty region as the result. } else if (r == this) { // Xor the region with itself: result is empty. Xlib.XDestroyRegion(region); region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } else { Xlib.XXorRegion(region, r.region, region); } } }
/// <summary> /// <para>Subtract an explicitly-specified rectangle from /// this region.</para> /// </summary> /// /// <param name="x"> /// <para>The X co-ordinate of the top-left corner of the rectangle.</para> /// </param> /// /// <param name="y"> /// <para>The Y co-ordinate of the top-left corner of the rectangle.</para> /// </param> /// /// <param name="width"> /// <para>The width of the rectangle.</para> /// </param> /// /// <param name="height"> /// <para>The height of the rectangle.</para> /// </param> /// /// <exception cref="T:Xsharp.XException"> /// <para>Raised if the rectangle co-ordinates are out of range.</para> /// </exception> /// /// <remarks> /// <para>If this region has been disposed, then it will be re-created /// with its initial contents set to empty.</para> /// </remarks> public void Subtract(int x, int y, int width, int height) { lock (typeof(Region)) { if (region == IntPtr.Zero) { region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } else { XRectangle xrect = new XRectangle(x, y, width, height); IntPtr reg = Xlib.XCreateRegion(); if (reg == IntPtr.Zero) { Display.OutOfMemory(); } Xlib.XUnionRectWithRegion(ref xrect, reg, reg); Xlib.XSubtractRegion(region, reg, region); Xlib.XDestroyRegion(reg); } } }
/// <summary> /// <para>Intersect another region with this one.</para> /// </summary> /// /// <param name="r"> /// <para>The other region to intersect with this one. If /// <paramref name="r"/> is <see langword="null"/> or disposed, /// the method operates as an intersection with the empty region.</para> /// </param> /// /// <remarks> /// <para>If this region has been disposed, then it will be re-created /// with its initial contents set to empty.</para> /// </remarks> public void Intersect(Region r) { lock (typeof(Region)) { if (region == IntPtr.Zero) { region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } else if (r == null || r.region == IntPtr.Zero) { Xlib.XDestroyRegion(region); region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } else if (r != this) { Xlib.XIntersectRegion(r.region, region, region); } } }
/// <summary> /// <para>Intersect a rectangle with this region.</para> /// </summary> /// /// <param name="rect"> /// <para>The rectangle to intersect with this region.</para> /// </param> /// /// <exception cref="T:Xsharp.XException"> /// <para>Raised if the rectangle co-ordinates are out of range.</para> /// </exception> /// /// <remarks> /// <para>If this region has been disposed, then it will be re-created /// with its initial contents set to empty.</para> /// </remarks> public void Intersect(Rectangle rect) { lock (typeof(Region)) { if (region == IntPtr.Zero) { region = Xlib.XCreateRegion(); if (region == IntPtr.Zero) { Display.OutOfMemory(); } } else { IntPtr reg = Xlib.XCreateRegion(); if (reg == IntPtr.Zero) { Display.OutOfMemory(); } XRectangle xrect = new XRectangle (rect.x, rect.y, rect.width, rect.height); Xlib.XUnionRectWithRegion(ref xrect, reg, reg); Xlib.XIntersectRegion(reg, region, region); Xlib.XDestroyRegion(reg); } } }
// 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); }
protected internal override void Send(System.Windows.Forms.Keys key) { var vk = (uint)key; Xlib.XTestFakeKeyEvent(XConn.Handle, vk, true, 0); Xlib.XTestFakeKeyEvent(XConn.Handle, vk, false, 0); }
/// <summary> /// <para>Get the list of rectangles that defines this region.</para> /// </summary> /// /// <returns> /// <para>An array of <see cref="T:Xsharp.Rectangle"/> instances /// corresponding to the rectangles that make up the region. /// Returns a zero-length array if the region is empty.</para> /// </returns> public Rectangle[] GetRectangles() { lock (typeof(Region)) { if (region == IntPtr.Zero) { return(new Rectangle [0]); } else { Rectangle[] rects; XRectangle xrect; int size, index; size = Xlib.XSharpGetRegionSize(region); rects = new Rectangle [size]; for (index = 0; index < size; ++index) { Xlib.XSharpGetRegionRect(region, index, out xrect); rects[index].x = xrect.x; rects[index].y = xrect.y; rects[index].width = xrect.width; rects[index].height = xrect.height; } return(rects); } } }
// End a double buffer drawing operation. internal void End(Graphics graphics) { try { IntPtr display = dpy.Lock(); if (handle != XDrawable.Zero) { if (usesXdbe) { Xlib.XdbeSwapInfo info = new Xlib.XdbeSwapInfo(); info.swap_window = widget.GetWidgetHandle(); info.swap_action = Xlib.XdbeSwapAction.Background; Xlib.XdbeSwapBuffers(display, ref info, 1); } else { using (Graphics g = new Graphics(widget)) { Xlib.XCopyArea (display, handle, widget.GetGCHandle(), g.gc, 0, 0, (uint)width, (uint)height, 0, 0); } } } } finally { dpy.Unlock(); } }
// Convert an image frame into an XImage. public static IntPtr FrameToXImage(Screen screen, Frame frame) { int[] fpalette; XPixel[] palette; int index, color; Colormap colormap = screen.DefaultColormap; // Create a palette to use to render the image. fpalette = frame.Palette; if (fpalette != null) { // Convert the palette within the image frame itself. palette = new XPixel [256]; for (index = 0; index < 256 && index < fpalette.Length; ++index) { color = fpalette[index]; palette[index] = colormap.RGBToPixel (new Color((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF)); } } else { // We have an RGB image: use a standard palette. palette = colormap.GetStandardPalette(); } // Convert the frame into an XImage and return it. return(Xlib.XSharpCreateImageFromDIB (screen.screen, frame.Width, frame.Height, frame.Stride, (int)(frame.PixelFormat), frame.Data, 0, palette)); }
/// <summary> /// <para>Destroy this drawable if it is currently active.</para> /// </summary> public override void Destroy() { try { IntPtr display = dpy.Lock(); if (handle != XDrawable.Zero) { if (widget.HasWidgetHandle()) { if (usesXdbe) { Xlib.XdbeDeallocateBackBufferName(display, handle); } else { Xlib.XFreePixmap(display, (XPixmap)handle); } } else { // the widget was destroyed } handle = XDrawable.Zero; } } finally { dpy.Unlock(); } }
// Start a double buffer drawing operation. internal void Start(Graphics graphics) { // Re-create the pixmap object if the widget size has changed. if (!usesXdbe) { if (widget.width != width || widget.height != height) { try { IntPtr display = dpy.Lock(); if (handle != XDrawable.Zero) { Xlib.XFreePixmap(display, (XPixmap)handle); } handle = (XDrawable) Xlib.XCreatePixmap (display, (XDrawable) Xlib.XRootWindowOfScreen(screen.screen), (uint)(widget.Width), (uint)(widget.Height), (uint)Xlib.XDefaultDepthOfScreen (screen.screen)); } finally { dpy.Unlock(); } } } // Copy the width and height values from the widget. width = widget.Width; height = widget.Height; }
// Grab control of the mouse and keyboard to manage popups. private void Grab() { try { IntPtr display = dpy.Lock(); XWindow handle = GetWidgetHandle(); Xlib.XGrabKeyboard (display, handle, XBool.False, 1 /* GrabModeAsync */, 1 /* GrabModeAsync */, dpy.knownEventTime); Xlib.XGrabPointer (display, handle, XBool.False, (uint)(EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask), 1 /* GrabModeAsync */, 1 /* GrabModeAsync */, XWindow.Zero, dpy.GetCursor(CursorType.XC_left_ptr), dpy.knownEventTime); Xlib.XFlush(display); } finally { dpy.Unlock(); } }
public void Dispose() { if (_handle != IntPtr.Zero && _handle != _defaultDisp) { Xlib.XCloseDisplay(_handle); } }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Bitmap"/> instance /// that represents an off-screen bitmap. The bitmap is created /// on the default screen of the primary display.</para> /// </summary> /// /// <param name="width"> /// <para>The width of the new bitmap.</para> /// </param> /// /// <param name="height"> /// <para>The height of the new bitmap.</para> /// </param> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="width"/> or <paramref name="height"/> /// values are out of range.</para> /// </exception> public Bitmap(int width, int height) : base(Xsharp.Application.Primary.Display, Xsharp.Application.Primary.Display.DefaultScreenOfDisplay, DrawableKind.Bitmap) { if (width < 1 || width > 32767 || height < 1 || height > 32767) { throw new XException(S._("X_InvalidBitmapSize")); } try { IntPtr display = dpy.Lock(); SetPixmapHandle(Xlib.XCreatePixmap (display, (XDrawable) Xlib.XRootWindowOfScreen(screen.screen), (uint)width, (uint)height, (uint)1)); this.width = width; this.height = height; } finally { dpy.Unlock(); } }
// Internal constructor that wraps a bitmap XID. internal Bitmap(Display dpy, Screen screen, XPixmap pixmap) : base(dpy, screen, DrawableKind.Bitmap) { SetPixmapHandle(pixmap); try { // Get the geometry of the pixmap from the X server. IntPtr display = dpy.Lock(); XWindow root_return; Xlib.Xint x_return, y_return; Xlib.Xuint width_return, height_return; Xlib.Xuint border_width_return, depth_return; Xlib.XGetGeometry (display, handle, out root_return, out x_return, out y_return, out width_return, out height_return, out border_width_return, out depth_return); this.width = (int)width_return; this.height = (int)height_return; } finally { dpy.Unlock(); } }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Bitmap"/> instance /// that represents an off-screen bitmap. The bitmap is created /// on the specified <paramref name="screen"/>, using the /// supplied bitmap data.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen upon which to create the new bitmap.</para> /// </param> /// /// <param name="width"> /// <para>The width of the new bitmap.</para> /// </param> /// /// <param name="height"> /// <para>The height of the new bitmap.</para> /// </param> /// /// <param name="bits"> /// <para>The bits that make up the data.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>Raised if <paramref name="bits"/> is <see langword="null"/>. /// </para> /// </exception> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="width"/> or <paramref name="height"/> /// values are out of range, or <paramref name="bits"/> is invalid /// in some way.</para> /// </exception> public Bitmap(Screen screen, int width, int height, byte[] bits) : base(GetDisplay(screen), screen, DrawableKind.Bitmap) { if (width < 1 || width > 32767 || height < 1 || height > 32767) { throw new XException(S._("X_InvalidBitmapSize")); } if (bits == null) { throw new ArgumentNullException("bits"); } if (((((width + 15) & ~15) * height) / 8) > bits.Length) { throw new XException(S._("X_InvalidBitmapBits")); } try { IntPtr display = dpy.Lock(); XDrawable drawable = (XDrawable) Xlib.XRootWindowOfScreen(screen.screen); SetPixmapHandle(Xlib.XCreateBitmapFromData (display, drawable, bits, (uint)width, (uint)height)); this.width = width; this.height = height; } finally { dpy.Unlock(); } }
/// <summary> /// <para>Determine if two regions are equal.</para> /// </summary> /// /// <param name="obj"> /// <para>The region object to compare against.</para> /// </param> /// /// <returns> /// <para>Returns <see langword="true"/> if the two regions are equal; /// <see langword="false"/> otherwise. For the purposes of this /// method, disposed regions are considered the same as empty /// regions.</para> /// </returns> public override bool Equals(Object obj) { lock (typeof(Region)) { Region other = (obj as Region); if (other != null) { if (this == other) { return(true); } else if (IsEmpty()) { return(other.IsEmpty()); } else if (other.IsEmpty()) { return(false); } else { return(Xlib.XEqualRegion (region, other.region) != 0); } } else { return(false); } } }
/// <summary> /// In the X Window system, windows can have sub windows. This function crawls a /// specific function, and then recurses on all child windows. It is called to /// select all initial windows. It make some time (~0.5s) /// </summary> /// <param name="Display"></param> /// <param name="RootWindow"></param> void RecurseTree(IntPtr Display, int RootWindow) { int RootWindowRet, ParentWindow, NChildren; IntPtr ChildrenPtr; int[] Children; if (!Windows.Contains(RootWindow)) { Windows.Add(RootWindow); } // Request all children of the given window, along with the parent Xlib.XQueryTree(Display, RootWindow, out RootWindowRet, out ParentWindow, out ChildrenPtr, out NChildren); if (NChildren != 0) { // Fill the array with zeroes to prevent NullReferenceException from glue layer Children = new int[NChildren]; Marshal.Copy(ChildrenPtr, Children, 0, NChildren); Xlib.XSelectInput(Display, RootWindow, SelectMask); // Subwindows shouldn't be forgotten, especially since everything is a subwindow of RootWindow for (int i = 0; i < NChildren; i++) { if (Children[i] != 0) { Xlib.XSelectInput(Display, Children[i], SelectMask); RecurseTree(Display, Children[i]); } } } }
// Load builtin bitmaps for a particular display. public BuiltinBitmaps(Display display) { IntPtr dpy = display.dpy; XDrawable drawable = display.DefaultRootWindow.handle; RadioBottom = Xlib.XCreateBitmapFromData (dpy, drawable, radio_b_bits, (uint)12, (uint)12); RadioBottomEnhanced = Xlib.XCreateBitmapFromData (dpy, drawable, radio_B_bits, (uint)12, (uint)12); RadioTop = Xlib.XCreateBitmapFromData (dpy, drawable, radio_t_bits, (uint)12, (uint)12); RadioTopEnhanced = Xlib.XCreateBitmapFromData (dpy, drawable, radio_T_bits, (uint)12, (uint)12); RadioBackground = Xlib.XCreateBitmapFromData (dpy, drawable, radio_w_bits, (uint)12, (uint)12); RadioForeground = Xlib.XCreateBitmapFromData (dpy, drawable, radio_f_bits, (uint)12, (uint)12); Close = Xlib.XCreateBitmapFromData (dpy, drawable, close_button_bits, (uint)9, (uint)9); Minimize = Xlib.XCreateBitmapFromData (dpy, drawable, minimize_button_bits, (uint)9, (uint)9); Maximize = Xlib.XCreateBitmapFromData (dpy, drawable, maximize_button_bits, (uint)9, (uint)9); Restore = Xlib.XCreateBitmapFromData (dpy, drawable, restore_button_bits, (uint)9, (uint)9); Help = Xlib.XCreateBitmapFromData (dpy, drawable, help_button_bits, (uint)9, (uint)9); }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Bitmap"/> instance /// that represents an off-screen bitmap. The bitmap is created /// on the default screen of the primary display, using the /// supplied bitmap data.</para> /// </summary> /// /// <param name="width"> /// <para>The width of the new bitmap.</para> /// </param> /// /// <param name="height"> /// <para>The height of the new bitmap.</para> /// </param> /// /// <param name="bits"> /// <para>The bits that make up the data.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>Raised if <paramref name="bits"/> is <see langword="null"/>. /// </para> /// </exception> /// /// <exception cref="T:Xsharp.XException"> /// <para>The <paramref name="width"/> or <paramref name="height"/> /// values are out of range, or <paramref name="bits"/> is invalid /// in some way.</para> /// </exception> public Bitmap(int width, int height, byte[] bits) : base(Xsharp.Application.Primary.Display, Xsharp.Application.Primary.Display.DefaultScreenOfDisplay, DrawableKind.Bitmap) { if (width < 1 || width > 32767 || height < 1 || height > 32767) { throw new XException(S._("X_InvalidBitmapSize")); } if (bits == null) { throw new ArgumentNullException("bits"); } int unit = (width <= 8 ? 7 : 15); if (((((width + unit) & ~unit) * height) / 8) > bits.Length) { throw new XException(S._("X_InvalidBitmapBits")); } try { IntPtr display = dpy.Lock(); XDrawable drawable = (XDrawable) Xlib.XRootWindowOfScreen(screen.screen); SetPixmapHandle(Xlib.XCreateBitmapFromData (display, drawable, bits, (uint)width, (uint)height)); this.width = width; this.height = height; } finally { dpy.Unlock(); } }
// Constructor. Called from the "Screen" class. internal RootWindow(Display dpy, Screen screen, XWindow handle) : base(dpy, screen, DrawableKind.Widget, null) { // Set this window's handle and add it to the handle map. this.handle = (XDrawable)handle; if (dpy.handleMap == null) { dpy.handleMap = new HandleMap(); } dpy.handleMap[handle] = this; // Adjust the root window object to match the screen state. width = (int)(Xlib.XWidthOfScreen(screen.screen)); height = (int)(Xlib.XHeightOfScreen(screen.screen)); mapped = true; autoMapChildren = false; // Get the current state of the RESOURCE_MANAGER property. // We extract color theme information from it. resourceManager = Xlib.XInternAtom (dpy.dpy, "RESOURCE_MANAGER", XBool.False); IntPtr resptr = Xlib.XSharpGetResources(dpy.dpy, handle); if (resptr != IntPtr.Zero) { resources = Marshal.PtrToStringAnsi(resptr); Xlib.XSharpFreeResources(resptr); } // Select for property notifications so that we can // track changes to the RESOURCE_MANAGER property. SelectInput(EventMask.PropertyChangeMask); }
protected internal override void Send(string Sequence) { foreach (var C in Sequence) { CachedKey Key = LookupKeycode(C); // If it is an upper case character, hold the shift key... if (char.IsUpper(C) || Key.Shift) { Xlib.XTestFakeKeyEvent(XConn.Handle, (uint)XKeys.LeftShift, true, 0); } // Make sure the key is up before we press it again. // If X thinks this key is still down, nothing will happen if we press it. // Likewise, if X thinks that the key is up, this will do no harm. Xlib.XTestFakeKeyEvent(XConn.Handle, Key.Sym, false, 0); // Fake a key event. Note that some programs filter this kind of event. Xlib.XTestFakeKeyEvent(XConn.Handle, Key.Sym, true, 0); Xlib.XTestFakeKeyEvent(XConn.Handle, Key.Sym, false, 0); // ...and release it later on if (char.IsUpper(C) || Key.Shift) { Xlib.XTestFakeKeyEvent(XConn.Handle, (uint)XKeys.LeftShift, false, 0); } } }
private void FishEvent() { var Event = new XEvent(); Xlib.XNextEvent(Display, ref Event); if (OnEvent != null) { OnEvent(Event); } if (Event.type == XEventName.CreateNotify) { int Window = Event.CreateWindowEvent.window; Success = true; Windows.Add(Window); SurpressErrors = true; if (Success) { RecurseTree(Display, Window); } SurpressErrors = false; } else if (Event.type == XEventName.DestroyNotify) { Windows.Remove(Event.DestroyWindowEvent.window); } }
// https://stackoverflow.com/questions/42449050/cant-get-a-window-handle private static Window?FindChildWindows(IntPtr display, Window window, string title) { Window rootWindow = 0; Window parentWindow = 0; string windowName = ""; try { Xlib.XFetchName(display, window, ref windowName); } catch { return(null); } if (windowName == title) { return(window); } List <Window> childWindows = new List <Window>(); Xlib.XQueryTree(display, window, ref rootWindow, ref parentWindow, out childWindows); foreach (Window childWindow in childWindows) { if (FindChildWindows(display, childWindow, title) is Window foundWindow) { return(foundWindow); } } return(null); }
public RCode ThreadCleanUp() { Marshal.FreeHGlobal(ev); Xlib.XDestroyWindow(display, mainWindow); Xlib.XCloseDisplay(display); return(RCode.OK); }
extern public static Xlib.Xint IceRegisterForProtocolReply (String protocolName, String vendor, String release, Xlib.Xint versionCount, ref IcePaVersionRec versionRecs, Xlib.Xint authCount, ref String[] authNames, ref IcePaAuthProc authProcs, IceHostBasedAuthProc hostBasedAuthProc, IceProtocolSetupProc protocolSetupProc, IceProtocolActivateProc protocolActivateProc, IceIOErrorProc ioErrorProc);
extern public static void IceFreeListenObjs (Xlib.Xint count, IntPtr listenObjs);
extern public static String IceComposeNetworkIdList (Xlib.Xint count, IntPtr listenObjs);
extern public static XStatus IceListenForWellKnownConnections (String port, ref Xlib.Xint countRet, ref IntPtr listenObjsRet, Xlib.Xint errorLength, byte[] errorStringRet);
extern public static IceConn *IceOpenConnection (String networkIdsList, IntPtr context, XBool mustAuthenticate, Xlib.Xint majorOpcodeCheck, Xlib.Xint errorLength, byte[] errorStringRet);
extern public static XStatus IceProtocolShutdown (IceConn *iceConn, Xlib.Xint majorOpcode);
extern public static void _IceErrorBadLength (IceConn *iceConn, Xlib.Xint majorOpcode, Xlib.Xint offendingMinor, Xlib.Xint severity);
extern public static void _IceWrite (IceConn *iceConn, Xlib.Xulong nbytes, byte[] ptr);
extern public static IntPtr IceAllocScratch (IceConn *iceConn, Xlib.Xulong size);
extern public static void _IceErrorBadValue (IceConn *iceConn, Xlib.Xint majorOpcode, Xlib.Xint offendingMinor, Xlib.Xint offset, Xlib.Xint length, IntPtr value);
extern public static Xlib.Xint IceRegisterForProtocolSetup (String protocolName, String vendor, String release, Xlib.Xint versionCount, ref IcePoVersionRec versionRecs, Xlib.Xint authCount, String[] authNames, ref IcePoAuthProcIncapsulator authProcs, IceIOErrorProc ioErrorProc);
extern public static Xlib.Xint _IcePaMagicCookie1Proc (IntPtr iceConn, IntPtr authStatePtr, XBool swap, Xlib.Xint authDataLen, IntPtr authData, ref Xlib.Xint replyDataLenRet, ref IntPtr replyDataRet, ref IntPtr errorStringRet);
extern public static Xlib.Xint IceProtocolSetup (IceConn *iceConn, Xlib.Xint myOpcode, IntPtr clientData, XBool mustAuthenticate, out Xlib.Xint majorVersionRet, out Xlib.Xint minorVersionRet, out IntPtr vendorRet, out IntPtr releaseRet, Xlib.Xint errorLength, byte[] errorStringRet);
extern public static XStatus _IceRead (IceConn *iceConn, Xlib.Xulong nbytes, byte[] ptr);
extern public static void _IceReadSkip (IceConn *iceConn, Xlib.Xulong nbytes);
extern public static IceConn *IceAcceptConnection (IntPtr listenObj, ref Xlib.Xint statusRet);
// Callback from "libICE" to process a message. private void ProcessMessage (IntPtr iceConn, IntPtr clientData, Xlib.Xint opcode, Xlib.Xulong length, XBool swap, ref IceReplyWaitInfo replyWait, ref XBool replyReadyRet) { bool haveReply; if(messageTransaction) { throw new XInvalidOperationException("Attempt to process message in the middle of sending another one"); // I always wondered, what will happen if we throw exception from callback? :) } this.messageTransaction = true; this.messageLength = (int)length; // Process the message. try { replyWait = replyWait; haveReply = true; replyReadyRet = ProcessMessage((int)opcode, replyWait.reply) ? XBool.True:XBool.False; // We omit `swap' here, can one need it? Even theoretrically?.. } catch (NullReferenceException) { haveReply = false; replyReadyRet = ProcessMessage((int)opcode) ? XBool.True:XBool.False; } this.messageTransaction = false; }