public void Dispose() { VSync(); NativeUnsafeMethods.memcpy(_address, Address, new IntPtr(RowBytes * Size.Height)); Marshal.FreeHGlobal(Address); Address = IntPtr.Zero; }
private void ReleaseUnmanagedResources() { if (_mappedAddress != IntPtr.Zero) { NativeUnsafeMethods.munmap(_mappedAddress, _mappedLength); _mappedAddress = IntPtr.Zero; } if (_fd == 0) return; }
public input_event?NextEvent() { input_event ev; if (NativeUnsafeMethods.libevdev_next_event(_dev, 2, out ev) == 0) { return(ev); } return(null); }
private static List <EvDevDevice> OpenMouseDevices() { var rv = new List <EvDevDevice>(); foreach (var dev in Directory.GetFiles("/dev/input", "event*").Select(Open)) { if (!dev.IsMouse) { NativeUnsafeMethods.close(dev.Fd); } else { rv.Add(dev); } } return(rv); }
public static EvDevDevice Open(string device) { var fd = NativeUnsafeMethods.open(device, 2048, 0); if (fd <= 0) { throw new Exception($"Unable to open {device} code {Marshal.GetLastWin32Error()}"); } IntPtr dev; var rc = NativeUnsafeMethods.libevdev_new_from_fd(fd, out dev); if (rc < 0) { NativeUnsafeMethods.close(fd); throw new Exception($"Unable to initialize evdev for {device} code {Marshal.GetLastWin32Error()}"); } return(new EvDevDevice(fd, dev)); }
/// <summary> /// Create a Linux frame buffer device output /// </summary> /// <param name="fileName">The frame buffer device name. /// Defaults to the value in environment variable FRAMEBUFFER or /dev/fb0 when FRAMEBUFFER is not set</param> /// <param name="format">The required pixel format for the frame buffer. /// A null value will leave the frame buffer in the current pixel format. /// Otherwise sets the frame buffer to the required format</param> public FbdevOutput(string fileName, PixelFormat?format) { fileName ??= Environment.GetEnvironmentVariable("FRAMEBUFFER") ?? "/dev/fb0"; _fd = NativeUnsafeMethods.open(fileName, 2, 0); if (_fd <= 0) { throw new Exception("Error: " + Marshal.GetLastWin32Error()); } try { Init(format); } catch { Dispose(); throw; } }
public LinuxFramebuffer(string fileName = null, Vector?dpi = null) { _dpi = dpi ?? new Vector(96, 96); fileName = fileName ?? Environment.GetEnvironmentVariable("FRAMEBUFFER") ?? "/dev/fb0"; _fd = NativeUnsafeMethods.open(fileName, 2, 0); if (_fd <= 0) { throw new Exception("Error: " + Marshal.GetLastWin32Error()); } try { Init(); } catch { Dispose(); throw; } }
public EvDevDevice(int fd, IntPtr dev) { Fd = fd; _dev = dev; Name = Marshal.PtrToStringAnsi(NativeUnsafeMethods.libevdev_get_name(_dev)); foreach (EvType type in Enum.GetValues(typeof(EvType))) { if (NativeUnsafeMethods.libevdev_has_event_type(dev, type) != 0) { EventTypes.Add(type); } } var ptr = NativeUnsafeMethods.libevdev_get_abs_info(dev, (int)AbsAxis.ABS_X); if (ptr != null) { AbsX = *ptr; } ptr = NativeUnsafeMethods.libevdev_get_abs_info(dev, (int)AbsAxis.ABS_Y); if (ptr != null) { AbsY = *ptr; } }
void Init() { fixed(void *pnfo = &_varInfo) { if (-1 == NativeUnsafeMethods.ioctl(_fd, FbIoCtl.FBIOGET_VSCREENINFO, pnfo)) { throw new Exception("FBIOGET_VSCREENINFO error: " + Marshal.GetLastWin32Error()); } SetBpp(); _varInfo.yoffset = 100; if (-1 == NativeUnsafeMethods.ioctl(_fd, FbIoCtl.FBIOPUT_VSCREENINFO, pnfo)) { _varInfo.transp = new fb_bitfield(); } if (-1 == NativeUnsafeMethods.ioctl(_fd, FbIoCtl.FBIOPUT_VSCREENINFO, pnfo)) { throw new Exception("FBIOPUT_VSCREENINFO error: " + Marshal.GetLastWin32Error()); } if (-1 == NativeUnsafeMethods.ioctl(_fd, FbIoCtl.FBIOGET_VSCREENINFO, pnfo)) { throw new Exception("FBIOGET_VSCREENINFO error: " + Marshal.GetLastWin32Error()); } if (_varInfo.bits_per_pixel != 32) { throw new Exception("Unable to set 32-bit display mode"); } } fixed(void *pnfo = &_fixedInfo) if (-1 == NativeUnsafeMethods.ioctl(_fd, FbIoCtl.FBIOGET_FSCREENINFO, pnfo)) { throw new Exception("FBIOGET_FSCREENINFO error: " + Marshal.GetLastWin32Error()); } _mappedLength = new IntPtr(_fixedInfo.line_length * _varInfo.yres); _mappedAddress = NativeUnsafeMethods.mmap(IntPtr.Zero, _mappedLength, 3, 1, _fd, IntPtr.Zero); if (_mappedAddress == new IntPtr(-1)) { throw new Exception($"Unable to mmap {_mappedLength} bytes, error {Marshal.GetLastWin32Error()}"); fixed(fb_fix_screeninfo *pnfo = &_fixedInfo) { int idlen; for (idlen = 0; idlen < 16 && pnfo->id[idlen] != 0; idlen++) { ; } Id = Encoding.ASCII.GetString(pnfo->id, idlen); } } void SetBpp() { _varInfo.bits_per_pixel = 32; _varInfo.grayscale = 0; _varInfo.red = _varInfo.blue = _varInfo.green = _varInfo.transp = new fb_bitfield { length = 8 }; _varInfo.green.offset = 8; _varInfo.blue.offset = 16; _varInfo.transp.offset = 24; }
void VSync() { NativeUnsafeMethods.ioctl(_fb, FbIoCtl.FBIO_WAITFORVSYNC, null); }