Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/proto/mousedev.c

    r8edec53 rfafb8e5  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
    32 * Copyright (c) 2011 Martin Decky
    43 * All rights reserved.
     
    4443#include <loc.h>
    4544#include <stdlib.h>
    46 #include <time.h>
    4745#include "../mouse.h"
    4846#include "../mouse_port.h"
     
    5048#include "../input.h"
    5149
    52 enum {
    53         /** Default double-click speed in milliseconds */
    54         dclick_delay_ms = 500
    55 };
    56 
    5750/** Mousedev softstate */
    5851typedef struct {
    5952        /** Link to generic mouse device */
    6053        mouse_dev_t *mouse_dev;
    61         /** Button number of last button pressed (or -1 if none) */
    62         int press_bnum;
    63         /** Time at which button was last pressed */
    64         struct timespec press_time;
    6554} mousedev_t;
    6655
     
    7261
    7362        mousedev->mouse_dev = mdev;
    74         mousedev->press_bnum = -1;
    7563
    7664        return mousedev;
     
    8068{
    8169        free(mousedev);
    82 }
    83 
    84 static void mousedev_press(mousedev_t *mousedev, int bnum)
    85 {
    86         struct timespec now;
    87         nsec_t ms_delay;
    88 
    89         getuptime(&now);
    90 
    91         /* Same button was pressed previously */
    92         if (mousedev->press_bnum == bnum) {
    93                 /* Compute milliseconds since previous press */
    94                 ms_delay = ts_sub_diff(&now, &mousedev->press_time) / 1000000;
    95 
    96                 if (ms_delay <= dclick_delay_ms) {
    97                         mouse_push_event_dclick(mousedev->mouse_dev, bnum);
    98                         mousedev->press_bnum = -1;
    99                         return;
    100                 }
    101         }
    102 
    103         /* Record which button was last pressed and at what time */
    104         mousedev->press_bnum = bnum;
    105         mousedev->press_time = now;
    10670}
    10771
     
    139103                        mouse_push_event_button(mousedev->mouse_dev,
    140104                            ipc_get_arg1(&call), ipc_get_arg2(&call));
    141                         if (ipc_get_arg2(&call) != 0)
    142                                 mousedev_press(mousedev, ipc_get_arg1(&call));
    143105                        retval = EOK;
    144106                        break;
Note: See TracChangeset for help on using the changeset viewer.