public ILockedFramebuffer Lock(Vector dpi)
 {
     Monitor.Enter(_lock);
     try
     {
         return(new LockedFramebuffer(Address,
                                      new PixelSize((int)_varInfo.xres, (int)_varInfo.yres),
                                      (int)_fixedInfo.line_length, dpi,
                                      _varInfo.bits_per_pixel == 16 ? PixelFormat.Rgb565
             : _varInfo.blue.offset == 16 ? PixelFormat.Rgba8888
             : PixelFormat.Bgra8888,
                                      () =>
         {
             try
             {
                 NativeUnsafeMethods.ioctl(_fb, FbIoCtl.FBIO_WAITFORVSYNC, null);
                 NativeUnsafeMethods.memcpy(_targetAddress, Address, new IntPtr(RowBytes * Size.Height));
             }
             finally
             {
                 Monitor.Exit(_lock);
             }
         }));
     }
     catch
     {
         Monitor.Exit(_lock);
         throw;
     }
 }
예제 #2
0
        public input_event?NextEvent()
        {
            input_event ev;

            if (NativeUnsafeMethods.libevdev_next_event(_dev, 2, out ev) == 0)
            {
                return(ev);
            }
            return(null);
        }
        static int OpenRestricted(IntPtr path, int flags, IntPtr userData)
        {
            var fd = NativeUnsafeMethods.open(Marshal.PtrToStringAnsi(path), flags, 0);

            if (fd == -1)
            {
                return(-Marshal.GetLastWin32Error());
            }

            return(fd);
        }
예제 #4
0
        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));
        }
예제 #5
0
        private unsafe void InputThread(IntPtr ctx)
        {
            var fd = libinput_get_fd(ctx);

            var timeval = stackalloc IntPtr[2];


            foreach (var f in Directory.GetFiles("/dev/input", "event*"))
            {
                libinput_path_add_device(ctx, f);
            }
            while (true)
            {
                IntPtr ev;
                libinput_dispatch(ctx);
                while ((ev = libinput_get_event(ctx)) != IntPtr.Zero)
                {
                    var type = libinput_event_get_type(ev);
                    if (type >= LibInputEventType.LIBINPUT_EVENT_TOUCH_DOWN &&
                        type <= LibInputEventType.LIBINPUT_EVENT_TOUCH_CANCEL)
                    {
                        HandleTouch(ev, type);
                    }

                    if (type >= LibInputEventType.LIBINPUT_EVENT_POINTER_MOTION &&
                        type <= LibInputEventType.LIBINPUT_EVENT_POINTER_AXIS)
                    {
                        HandlePointer(ev, type);
                    }

                    libinput_event_destroy(ev);
                    libinput_dispatch(ctx);
                }

                pollfd pfd = new pollfd {
                    fd = fd, events = 1
                };
                NativeUnsafeMethods.poll(&pfd, new IntPtr(1), 10);
            }
        }
예제 #6
0
        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;
            }
        }
 static void CloseRestricted(int fd, IntPtr userData)
 {
     NativeUnsafeMethods.close(fd);
 }