Changeset 8edec53 in mainline for uspace/srv


Ignore:
Timestamp:
2021-10-25T17:51:10Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
91ece11b
Parents:
805a149
Message:

Support double-click

Needed to open Navigator entries using the mouse.

Location:
uspace/srv/hid
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    r805a149 r8edec53  
    124124static errno_t input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
    125125static errno_t input_ev_button(input_t *, int, int);
     126static errno_t input_ev_dclick(input_t *, int);
    126127
    127128static input_ev_ops_t input_ev_ops = {
     
    131132        .move = input_ev_move,
    132133        .abs_move = input_ev_abs_move,
    133         .button = input_ev_button
     134        .button = input_ev_button,
     135        .dclick = input_ev_dclick
    134136};
    135137
     
    440442}
    441443
     444static errno_t input_ev_dclick(input_t *input, int bnum)
     445{
     446        cons_event_t event;
     447
     448        event.type = CEV_POS;
     449        event.ev.pos.type = POS_DCLICK;
     450        event.ev.pos.btn_num = bnum;
     451        event.ev.pos.hpos = pointer_x / mouse_scale_x;
     452        event.ev.pos.vpos = pointer_y / mouse_scale_y;
     453
     454        console_queue_cons_event(active_console, &event);
     455        return EOK;
     456}
     457
    442458/** Process a character from the client (TTY emulation). */
    443459static void cons_write_char(console_t *cons, char32_t ch)
  • uspace/srv/hid/display/input.c

    r805a149 r8edec53  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4949static errno_t ds_input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
    5050static errno_t ds_input_ev_button(input_t *, int, int);
     51static errno_t ds_input_ev_dclick(input_t *, int);
    5152
    5253static input_ev_ops_t ds_input_ev_ops = {
     
    5657        .move = ds_input_ev_move,
    5758        .abs_move = ds_input_ev_abs_move,
    58         .button = ds_input_ev_button
     59        .button = ds_input_ev_button,
     60        .dclick = ds_input_ev_dclick
    5961};
    6062
     
    131133
    132134        event.type = bpress ? PTD_PRESS : PTD_RELEASE;
     135        event.btn_num = bnum;
     136        event.dmove.x = 0;
     137        event.dmove.y = 0;
     138
     139        ds_display_lock(disp);
     140        rc = ds_display_post_ptd_event(disp, &event);
     141        ds_display_unlock(disp);
     142        return rc;
     143}
     144
     145static errno_t ds_input_ev_dclick(input_t *input, int bnum)
     146{
     147        ds_display_t *disp = (ds_display_t *) input->user;
     148        ptd_event_t event;
     149        errno_t rc;
     150
     151        event.type = PTD_DCLICK;
    133152        event.btn_num = bnum;
    134153        event.dmove.x = 0;
  • uspace/srv/hid/display/seat.c

    r805a149 r8edec53  
    362362        }
    363363
    364         if (event->type == PTD_PRESS || event->type == PTD_RELEASE) {
     364        if (event->type == PTD_PRESS || event->type == PTD_RELEASE ||
     365            event->type == PTD_DCLICK) {
    365366                pevent.pos_id = 0;
    366                 pevent.type = (event->type == PTD_PRESS) ?
    367                     POS_PRESS : POS_RELEASE;
     367                switch (event->type) {
     368                case PTD_PRESS:
     369                        pevent.type = POS_PRESS;
     370                        break;
     371                case PTD_RELEASE:
     372                        pevent.type = POS_RELEASE;
     373                        break;
     374                case PTD_DCLICK:
     375                        pevent.type = POS_DCLICK;
     376                        break;
     377                default:
     378                        assert(false);
     379                }
     380
    368381                pevent.btn_num = event->btn_num;
    369382                pevent.hpos = seat->pntpos.x;
  • uspace/srv/hid/display/types/display/ptd_event.h

    r805a149 r8edec53  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4242        PTD_ABS_MOVE,
    4343        PTD_PRESS,
    44         PTD_RELEASE
     44        PTD_RELEASE,
     45        PTD_DCLICK
    4546} ptd_event_type_t;
    4647
  • uspace/srv/hid/input/input.c

    r805a149 r8edec53  
    11/*
     2 * Copyright (c) 2021 Jiri Svoboda
    23 * Copyright (c) 2006 Josef Cejka
    3  * Copyright (c) 2011 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    311311}
    312312
    313 /** Arbitrate client actiovation */
     313/** Mouse button has been double-clicked. */
     314void mouse_push_event_dclick(mouse_dev_t *mdev, int bnum)
     315{
     316        list_foreach(clients, link, client_t, client) {
     317                if (client->active) {
     318                        async_exch_t *exch = async_exchange_begin(client->sess);
     319                        async_msg_1(exch, INPUT_EVENT_DCLICK, bnum);
     320                        async_exchange_end(exch);
     321                }
     322        }
     323}
     324
     325/** Arbitrate client activation */
    314326static void client_arbitration(void)
    315327{
  • uspace/srv/hid/input/mouse.h

    r805a149 r8edec53  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6666    unsigned int, unsigned int);
    6767extern void mouse_push_event_button(mouse_dev_t *, int, int);
     68extern void mouse_push_event_dclick(mouse_dev_t *, int);
    6869
    6970#endif
  • uspace/srv/hid/input/proto/mousedev.c

    r805a149 r8edec53  
    11/*
     2 * Copyright (c) 2021 Jiri Svoboda
    23 * Copyright (c) 2011 Martin Decky
    34 * All rights reserved.
     
    4344#include <loc.h>
    4445#include <stdlib.h>
     46#include <time.h>
    4547#include "../mouse.h"
    4648#include "../mouse_port.h"
     
    4850#include "../input.h"
    4951
     52enum {
     53        /** Default double-click speed in milliseconds */
     54        dclick_delay_ms = 500
     55};
     56
    5057/** Mousedev softstate */
    5158typedef struct {
    5259        /** Link to generic mouse device */
    5360        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;
    5465} mousedev_t;
    5566
     
    6172
    6273        mousedev->mouse_dev = mdev;
     74        mousedev->press_bnum = -1;
    6375
    6476        return mousedev;
     
    6880{
    6981        free(mousedev);
     82}
     83
     84static 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;
    70106}
    71107
     
    103139                        mouse_push_event_button(mousedev->mouse_dev,
    104140                            ipc_get_arg1(&call), ipc_get_arg2(&call));
     141                        if (ipc_get_arg2(&call) != 0)
     142                                mousedev_press(mousedev, ipc_get_arg1(&call));
    105143                        retval = EOK;
    106144                        break;
Note: See TracChangeset for help on using the changeset viewer.