Exemple #1
0
        private static int OpenRestrictedHandler(IntPtr path, int flags, IntPtr data)
        {
            int fd = Libc.open(path, (OpenFlags)flags);

            Debug.Print("[Input] Opening '{0}' with flags {1}. fd:{2}",
                        Marshal.PtrToStringAnsi(path), (OpenFlags)flags, fd);

            if (fd >= 0)
            {
                Interlocked.Increment(ref DeviceFDCount);
            }

            return(fd);
        }
Exemple #2
0
        private static int SetupDisplay(string gpu, out IntPtr gbm_device, out IntPtr egl_display)
        {
            Debug.Print("[KMS] Attempting to use gpu '{0}'.", gpu);

            gbm_device  = IntPtr.Zero;
            egl_display = IntPtr.Zero;

            int fd = Libc.open(gpu, OpenFlags.ReadWrite | OpenFlags.CloseOnExec);

            if (fd < 0)
            {
                Debug.Print("[KMS] Failed to open gpu");
                return(fd);
            }
            Debug.Print("[KMS] GPU '{0}' opened as fd:{1}", gpu, fd);

            gbm_device = Gbm.CreateDevice(fd);
            if (gbm_device == IntPtr.Zero)
            {
                throw new NotSupportedException("[KMS] Failed to create GBM device");
            }
            Debug.Print("[KMS] GBM {0:x} created successfully; ", gbm_device);

            egl_display = Egl.GetDisplay(gbm_device);
            if (egl_display == IntPtr.Zero)
            {
                throw new NotSupportedException("[KMS] Failed to create EGL display");
            }
            Debug.Print("[KMS] EGL display {0:x} created successfully", egl_display);

            int major, minor;

            if (!Egl.Initialize(egl_display, out major, out minor))
            {
                ErrorCode error = Egl.GetError();
                throw new NotSupportedException("[KMS] Failed to initialize EGL display. Error code: " + error);
            }
            Debug.Print("[KMS] EGL {0}.{1} initialized successfully on display {2:x}", major, minor, egl_display);

            return(fd);
        }
Exemple #3
0
        private LinuxJoystickDetails OpenJoystick(string path)
        {
            LinuxJoystickDetails stick = null;

            int number = GetJoystickNumber(Path.GetFileName(path));

            if (number >= 0)
            {
                int fd = -1;
                try
                {
                    fd = Libc.open(path, OpenFlags.NonBlock);
                    if (fd == -1)
                    {
                        return(null);
                    }

                    unsafe
                    {
                        const int evsize   = Evdev.EventCount / 8;
                        const int axissize = Evdev.AxisCount / 8;
                        const int keysize  = Evdev.KeyCount / 8;
                        byte *    evbit    = stackalloc byte[evsize];
                        byte *    axisbit  = stackalloc byte[axissize];
                        byte *    keybit   = stackalloc byte[keysize];

                        string       name;
                        EvdevInputId id;

                        // Ensure this is a joystick device
                        bool is_valid = true;

                        is_valid &= Evdev.GetBit(fd, 0, evsize, new IntPtr(evbit)) >= 0;
                        is_valid &= Evdev.GetBit(fd, EvdevType.ABS, axissize, new IntPtr(axisbit)) >= 0;
                        is_valid &= Evdev.GetBit(fd, EvdevType.KEY, keysize, new IntPtr(keybit)) >= 0;

                        is_valid &= TestBit(evbit, (int)EvdevType.KEY);
                        is_valid &= TestBit(evbit, (int)EvdevType.ABS);
                        is_valid &= TestBit(axisbit, (int)EvdevAxis.X);
                        is_valid &= TestBit(axisbit, (int)EvdevAxis.Y);

                        is_valid &= Evdev.GetName(fd, out name) >= 0;
                        is_valid &= Evdev.GetId(fd, out id) >= 0;

                        if (is_valid)
                        {
                            stick = new LinuxJoystickDetails
                            {
                                FileDescriptor = fd,
                                PathIndex      = number,
                                State          = new JoystickState(),
                                Name           = name,
                                Guid           = CreateGuid(id, name),
                            };

                            int axes, buttons, hats;
                            QueryCapabilities(stick, axisbit, axissize, keybit, keysize,
                                              out axes, out buttons, out hats);

                            stick.Caps = new JoystickCapabilities(axes, buttons, hats, false);

                            // Poll the joystick once, to initialize its state
                            PollJoystick(stick);
                        }
                    }

                    Debug.Print("Found joystick on path {0}", path);
                }
                catch (Exception e)
                {
                    Debug.Print("Error opening joystick: {0}", e.ToString());
                }
                finally
                {
                    if (stick == null && fd != -1)
                    {
                        // Not a joystick
                        Libc.close(fd);
                    }
                }
            }

            return(stick);
        }