public override void SetSize(int width, int height) { XWindowAttributes attr = new XWindowAttributes(); XGetWindowAttributes(_display, _window, out attr); XResizeWindow(_display, _window, (uint)(width + attr.border_width), (uint)(height + attr.border_width)); }
} // End Sub PerformanceTest public static void TestX11_Simple() { System.IntPtr display = LibX11Functions.XOpenDisplay(System.IntPtr.Zero); int defaultScreen = LibX11Functions.XDefaultScreen(display); System.UIntPtr window = LibX11Functions.XRootWindow(display, defaultScreen); int screen_width = LibX11Functions.DisplayWidth(display, defaultScreen); int screen_height = LibX11Functions.DisplayHeight(display, defaultScreen); XWindowAttributes xa = new XWindowAttributes(); LibX11Functions.XGetWindowAttributes(display, window, ref xa); System.Console.WriteLine(xa.width); System.Console.WriteLine(xa.height); int AllPlanes = ~0; System.UIntPtr AllPlanes2 = new System.UIntPtr((uint)AllPlanes); /* * XImage* img = LibX11Functions.XGetImage2(display, window, 0, 0, (uint) xa.width, (uint)xa.height * , AllPlanes2, LinScreen.ZPixmap); */ // System.IntPtr image = LibX11Functions.XGetImage(display, window, 0, 0, (uint) xa.width, (uint)xa.height // , AllPlanes2, LinScreen.ZPixmap); SafeX11.SlowScreenshot(display, window, 0, 0, (uint)xa.width, (uint)xa.height , AllPlanes2, LinScreen.ZPixmap, true); // XImage img = System.Runtime.InteropServices.Marshal.PtrToStructure<XImage>(image); // System.Console.WriteLine(img.bitmap_bit_order); // System.Console.WriteLine(img.bits_per_pixel); // System.Console.WriteLine(img.width); // System.Console.WriteLine(img.height); // System.Console.WriteLine(img.data); // // // // // // // System.Console.WriteLine(img->bitmap_bit_order); // System.Console.WriteLine(img->width); // System.Console.WriteLine(img->height); // System.Console.WriteLine(img->data); // rtaNetworking.Linux.tt.foo(); // LibX11Functions.XDestroyImage2(img); LibX11Functions.XCloseDisplay(display); }
public void HandleButtonPress(XButtonEvent e, XWindow window, XWindow root, XWindow subwindow) { pointer.Grab(e.window, XEventMask.PointerMotionMask | XEventMask.ButtonReleaseMask); attr = resize_main_win.GetAttributes(); start = e; old_resize_x = resize_win_x; old_resize_y = resize_win_y; }
private IEnumerable <Tuple <IntPtr, object> > _AllWindows(IntPtr display, IntPtr rootWindow, Dictionary <IntPtr, object> gtkwins, int level = 0) { var status = XQueryTree(display, rootWindow, out IntPtr root_return, out IntPtr parent_return, out IntPtr children_return, out int nchildren_return); if (nchildren_return > 0) { try { IntPtr[] children = new IntPtr[nchildren_return]; Marshal.Copy(children_return, children, 0, nchildren_return); for (int nit = children.Length - 1; nit >= 0; nit--) { if (gtkwins.TryGetValue(children[nit], out object gtkwin)) { yield return(new Tuple <IntPtr, object>(children[nit], gtkwin)); } else { var attr = new XWindowAttributes(); XGetWindowAttributes(display, children[nit], ref attr); if (attr.map_state == 2) { if (level < 2) { bool fnd = false; foreach (var form in _AllWindows(display, children[nit], gtkwins, level + 1)) { if (form.Item2 != null) { fnd = true; yield return(form); break; } } if (!fnd && level == 0) { yield return(new Tuple <IntPtr, object>(children[nit], children[nit])); } } } } } } finally { XFree(children_return); } } }
public override Rectangle GetWindowRect(IntPtr xdisp, object gtkwin) { if (gtkwin is IntPtr) { var attr = new XWindowAttributes(); XGetWindowAttributes(xdisp, (IntPtr)gtkwin, ref attr); return(new Rectangle(attr.x, attr.y, attr.width, attr.height)); } else { var gdkwin = gtkwin.GetType().GetPropertyValue(gtkwin, "GdkWindow"); var xy = new object[] { 0, 0 }; var wh = new object[] { 0, 0 }; gdkwin.GetType().Invoke(gdkwin, "GetOrigin", xy); gdkwin.GetType().Invoke(gdkwin, "GetSize", wh); return(new Rectangle((int)xy[0], (int)xy[1], (int)wh[0], (int)wh[1])); } }
/// <summary> /// Returns the size of a window, given its window handle. /// </summary> /// <param name="sizeOnly">If true, the X and Y coordinates are set to 0.</param> public static Rectangle GetClientRect(IntPtr windowHandle, bool sizeOnly = true) { XWindowAttributes xwa = new XWindowAttributes(); string displayStr = Environment.GetEnvironmentVariable("DISPLAY"); if (String.IsNullOrEmpty(displayStr)) { displayStr = ":0"; } //Log.WriteLine("DISPLAY = " + displayStr); IntPtr display = XOpenDisplay(displayStr); XGetWindowAttributes(display, windowHandle, ref xwa); //Log.WriteLine("X = " + xwa.x + ", Y = " + xwa.y); var result = new Rectangle(xwa.x, xwa.y, xwa.width, xwa.height); // We don't want to use the x and y coordinates -- these need to be 0. if (sizeOnly) { result.X = result.Y = 0; } return(result); }
private static unsafe byte[] UnsafeX11ScreenshotWithCursor(bool withCursor) { byte[] result = null; int AllPlanes = ~0; System.UIntPtr AllPlanes2 = new System.UIntPtr((uint)AllPlanes); System.IntPtr display = LibX11Functions.XOpenDisplay(System.IntPtr.Zero); int defaultScreen = LibX11Functions.XDefaultScreen(display); System.UIntPtr window = LibX11Functions.XRootWindow(display, defaultScreen); XWindowAttributes xa = new XWindowAttributes(); LibX11Functions.XGetWindowAttributes(display, window, ref xa); Screen *screen = xa.screen; // struct screen XShmSegmentInfo shminfo = new XShmSegmentInfo(); XImage *ximg = LibXExt.XShmCreateImage(display, LibXExt.DefaultVisualOfScreen(screen) , (uint)LibXExt.DefaultDepthOfScreen(screen), LinScreen.ZPixmap , System.IntPtr.Zero, ref shminfo, (uint)xa.width, (uint)xa.height); shminfo.shmid = LibC.shmget(LibC.IPC_PRIVATE, new System.IntPtr(ximg->bytes_per_line * ximg->height), LibC.IPC_CREAT | 0777); ximg->data = (sbyte *)LibC.shmat(shminfo.shmid, System.IntPtr.Zero, 0); shminfo.shmaddr = (System.IntPtr)ximg->data; shminfo.readOnly = 0; if (shminfo.shmid < 0) { System.Console.WriteLine("Fatal shminfo error!"); } int s1 = LibXExt.XShmAttach(display, ref shminfo); // System.Console.WriteLine("XShmAttach() {0}\n", s1 != 0 ? "success!" : "failure!"); int res = LibXExt.XShmGetImage(display, window, ximg, 0, 0, AllPlanes2); // const char *filename = "/tmp/test.bmp"; // WriteBitmapToFile(filename, (int) ximg->bits_per_pixel, (int)window_attributes.width, (int)window_attributes.height, (const void*) ximg->data); int bytesPerPixel = (ximg->bits_per_pixel + 7) / 8; int stride = 4 * ((ximg->width * bytesPerPixel + 3) / 4); // long size = ximg->height * stride; // byte[] managedArray = new byte[size]; // Marshal.Copy((IntPtr)(ximg->data), managedArray, 0, (int)size); // System.Console.WriteLine(managedArray); if (withCursor) { PaintMousePointer(display, ximg); } // End if (withCursor) using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ximg->width, ximg->height, stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)ximg->data)) { // bmp.Save("/tmp/shtest.bmp"); #if false // ZERO compression at all ! // using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) // { // bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // result = ms.ToArray(); // } // End Using ms #else result = CompressImage(bmp, 25); #endif } // End Using bmp LibX11Functions.XDestroyImage2(ximg); LibXExt.XShmDetach(display, ref shminfo); LibC.shmdt(shminfo.shmaddr); LibX11Functions.XCloseDisplay(display); return(result); } // End Function UnsafeX11ScreenshotWithCursor
// extern Status XGetWindowAttributes(Display* /* display */, Window /* w */, XWindowAttributes* /* window_attributes_return */); public static extern int XGetWindowAttributes(System.IntPtr display, System.UIntPtr window, ref XWindowAttributes windowAttributesReturn);
public extern static int XGetWindowAttributes(IntPtr display, IntPtr window, ref XWindowAttributes attributes);
/// <summary> /// Gets a value indicating whether the window is valid. /// </summary> /// <param name="window">The pointer to the window.</param> /// <returns><see langword="true"/> if the window is valid; otherwise, <see langword="false"/>.</returns> internal static bool IsWindowValid(IntPtr window) { bool validWindow = false; XWindowAttributes attributes = new XWindowAttributes(); XErrorHandler handler = new XErrorHandler(IgnoreBadWindowHandler); originalEventHandler = XSetErrorHandler(handler); using (XServerConnection serverConnection = new XServerConnection()) { validWindow = XGetWindowAttributes(serverConnection.Display, window, out attributes) != 0; } XSetErrorHandler(originalEventHandler); originalEventHandler = null; return validWindow; }
internal extern static int XGetWindowAttributes(IntPtr display, int window, ref XWindowAttributes attributes);
internal static extern int XGetWindowAttributes(PDISPLAY display, WINDOW window, out XWindowAttributes window_attributes_return);
/// <summary> /// Gets a value indicating if the window is viewable. /// </summary> /// <param name="window">A pointer to the window.</param> /// <returns><see langword="true"/> if the window is viewable; otherwise, <see langword="false"/>.</returns> internal static bool IsWindowViewable(IntPtr window) { bool viewableWindow = false; XWindowAttributes attributes = new XWindowAttributes(); using (XServerConnection serverConnection = new XServerConnection()) { XGetWindowAttributes(serverConnection.Display, window, out attributes); } viewableWindow = attributes.map_state == XMapState.IsViewable; return viewableWindow; }
public static extern Status XGetWindowAttributes(IntPtr display, IntPtr window, out XWindowAttributes attributes);
private static extern void XGetWindowAttributes( IntPtr display, IntPtr window, ref XWindowAttributes attributes);
private static extern int XGetWindowAttributes(IntPtr display, IntPtr window, out XWindowAttributes attributes);
internal static extern int XGetWindowAttributes(IntPtr display, int window, ref XWindowAttributes attributes);
public extern static void XGetWindowAttributes(IntPtr display, IntPtr hwnd, ref XWindowAttributes wndAttr);
public static extern int XChangeWindowAttributes(IntPtr x11display, IntPtr x11window, WindowAttributeMask valuemask, ref XWindowAttributes xwa);
extern public static TInt XGetWindowAttributes(IntPtr x11display, IntPtr x11window, [MarshalAs(UnmanagedType.Struct)] ref XWindowAttributes windowAttributes);
public static extern int XGetWindowAttributes(IntPtr display, IntPtr w, out XWindowAttributes window_attributes_return);
public static extern int XGetWindowAttributes(IntPtr display, IntPtr window, ref XWindowAttributes attributes);