Beispiel #1
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (input_context != IntPtr.Zero)
                {
                    Debug.Print("[Input] Destroying libinput context");
                    LibInput.Suspend(input_context);
                    Interlocked.Increment(ref exit);

                    LibInput.DestroyContext(input_context);
                    input_context = IntPtr.Zero;
                }

                if (udev != IntPtr.Zero)
                {
                    Debug.Print("[Input] Destroying udev context");
                    Udev.Destroy(udev);
                    udev = IntPtr.Zero;
                }

                input_interface = null;
            }
            else
            {
                Debug.Print("[Input] {0} leaked. Did you forget to call Dispose()?", GetType().FullName);
            }
        }
Beispiel #2
0
        private void ProcessEvents(IntPtr input_context)
        {
            // Process all events in the event queue
            while (true)
            {
                // Data available
                int ret = LibInput.Dispatch(input_context);
                if (ret != 0)
                {
                    Debug.Print("[Input] LibInput.Dispatch({0:x}) failed. Error: {1}",
                                input_context, ret);
                    break;
                }

                IntPtr pevent = LibInput.GetEvent(input_context);
                if (pevent == IntPtr.Zero)
                {
                    break;
                }

                IntPtr         device = LibInput.GetDevice(pevent);
                InputEventType type   = LibInput.GetEventType(pevent);

                lock (Sync)
                {
                    switch (type)
                    {
                    case InputEventType.DeviceAdded:
                        HandleDeviceAdded(input_context, device);
                        break;

                    case InputEventType.DeviceRemoved:
                        HandleDeviceRemoved(input_context, device);
                        break;

                    case InputEventType.KeyboardKey:
                        HandleKeyboard(GetKeyboard(device), LibInput.GetKeyboardEvent(pevent));
                        break;

                    case InputEventType.PointerAxis:
                        HandlePointerAxis(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;

                    case InputEventType.PointerButton:
                        HandlePointerButton(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;

                    case InputEventType.PointerMotion:
                        HandlePointerMotion(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;

                    case InputEventType.PointerMotionAbsolute:
                        HandlePointerMotionAbsolute(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;
                    }
                }

                LibInput.DestroyEvent(pevent);
            }
        }
        private void Setup()
        {
            // Todo: add static path fallback when udev is not installed.
            udev = Udev.New();
            if (udev == IntPtr.Zero)
            {
                Debug.Print("[Input] Udev.New() failed.");
                Interlocked.Increment(ref exit);
                return;
            }

            Debug.Print("[Input] Udev.New() = {0:x}", udev);

            input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev);
            if (input_context == IntPtr.Zero)
            {
                Debug.Print("[Input] LibInput.CreateContext({0:x}) failed.", udev);
                Interlocked.Increment(ref exit);
                return;
            }

            Debug.Print("[Input] LibInput.CreateContext({0:x}) = {1:x}", udev, input_context);

            var seat_id         = "seat0";
            var seat_assignment = LibInput.AssignSeat(input_context, seat_id);

            if (seat_assignment == -1)
            {
                Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1} failed.", input_context, seat_id);
                Interlocked.Increment(ref exit);
                return;
            }

            Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1}", input_context, seat_id);

            fd = LibInput.GetFD(input_context);
            if (fd < 0)
            {
                Debug.Print("[Input] LibInput.GetFD({0:x}) failed.", input_context);
                Interlocked.Increment(ref exit);
                return;
            }

            Debug.Print("[Input] LibInput.GetFD({0:x}) = {1}.", input_context, fd);

            ProcessEvents(input_context);
            LibInput.Resume(input_context);
            Debug.Print("[Input] LibInput.Resume({0:x})", input_context);

            if (Interlocked.Read(ref DeviceFDCount) <= 0)
            {
                Debug.Print("[Error] Failed to open any input devices.");
                Debug.Print("[Error] Ensure that you have access to '/dev/input/event*'.");
                Interlocked.Increment(ref exit);
            }
        }
Beispiel #4
0
        private void HandleDeviceRemoved(IntPtr context, IntPtr device)
        {
            if (LibInput.DeviceHasCapability(device, DeviceCapability.Keyboard))
            {
                int id = GetId(device);
                Keyboards.TryRemove(id);
                KeyboardCandidates.TryRemove(id);
            }

            if (LibInput.DeviceHasCapability(device, DeviceCapability.Mouse))
            {
                int id = GetId(device);
                Mice.TryRemove(id);
                MouseCandidates.TryRemove(id);
            }
        }
Beispiel #5
0
        private void HandleDeviceAdded(IntPtr context, IntPtr device)
        {
            if (LibInput.DeviceHasCapability(device, DeviceCapability.Keyboard))
            {
                KeyboardDevice keyboard = new KeyboardDevice(device, Keyboards.Count);
                KeyboardCandidates.Add(keyboard.Id, keyboard);
                Debug.Print("[Input] Added keyboard device {0} '{1}' on '{2}' ('{3}')",
                            keyboard.Id, keyboard.Name, keyboard.LogicalSeatName, keyboard.PhysicalSeatName);
            }

            if (LibInput.DeviceHasCapability(device, DeviceCapability.Mouse))
            {
                MouseDevice mouse = new MouseDevice(device, Mice.Count);
                MouseCandidates.Add(mouse.Id, mouse);
                Debug.Print("[Input] Added mouse device {0} '{1}' on '{2}' ('{3}')",
                            mouse.Id, mouse.Name, mouse.LogicalSeatName, mouse.PhysicalSeatName);
            }

            if (LibInput.DeviceHasCapability(device, DeviceCapability.Touch))
            {
                Debug.Print("[Input] Todo: touch device.");
            }
        }
Beispiel #6
0
 private static int GetId(IntPtr device)
 {
     return(LibInput.DeviceGetData(device).ToInt32());
 }