Changeset 8edec53 in mainline


Ignore:
Timestamp:
2021-10-25T17:51:10Z (3 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
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/nav.c

    r805a149 r8edec53  
    130130        ui_wnd_params_t params;
    131131        gfx_rect_t rect;
     132        gfx_rect_t arect;
     133        gfx_coord_t pw;
    132134        unsigned i;
    133135        errno_t rc;
     
    155157
    156158        ui_window_set_cb(navigator->window, &window_cb, (void *) navigator);
     159        ui_window_get_app_rect(navigator->window, &arect);
    157160
    158161        rc = ui_fixed_create(&navigator->fixed);
     
    176179                return rc;
    177180        }
     181
     182        /* Panel width */
     183        pw = (arect.p1.x - arect.p0.x) / 2;
    178184
    179185        for (i = 0; i < 2; i++) {
     
    183189                        goto error;
    184190
    185                 rect.p0.x = 40 * i;
    186                 rect.p0.y = 1;
    187                 rect.p1.x = 40 * (i + 1);
    188                 rect.p1.y = 24;
     191                rect.p0.x = arect.p0.x + pw * i;
     192                rect.p0.y = arect.p0.y + 1;
     193                rect.p1.x = arect.p0.x + pw * (i + 1);
     194                rect.p1.y = arect.p1.y - 1;
    189195                panel_set_rect(navigator->panel[i], &rect);
    190196
  • uspace/app/nav/panel.c

    r805a149 r8edec53  
    351351                panel_activate_req(panel);
    352352
    353         if (event->type == POS_PRESS) {
    354                 irect.p0.x = panel->rect.p0.x + 1;
    355                 irect.p0.y = panel->rect.p0.y + 1;
    356                 irect.p1.x = panel->rect.p1.x - 1;
    357                 irect.p1.y = panel->rect.p1.y - 1;
    358 
     353        irect.p0.x = panel->rect.p0.x + 1;
     354        irect.p0.y = panel->rect.p0.y + 1;
     355        irect.p1.x = panel->rect.p1.x - 1;
     356        irect.p1.y = panel->rect.p1.y - 1;
     357
     358        if (event->type == POS_PRESS || event->type == POS_DCLICK) {
    359359                /* Did we click on one of the entries? */
    360360                if (gfx_pix_inside_rect(&pos, &irect)) {
     
    365365                        entry = panel_page_nth_entry(panel, n, &entry_idx);
    366366
    367                         /* Move to the entry found */
    368                         panel_cursor_move(panel, entry, entry_idx);
     367                        if (event->type == POS_PRESS) {
     368                                /* Move to the entry found */
     369                                panel_cursor_move(panel, entry, entry_idx);
     370                        } else {
     371                                /* event->type == POS_DCLICK */
     372                                panel_open(panel, entry);
     373                        }
    369374                } else {
    370                         /* It's in the border. Top or bottom half? */
    371                         if (pos.y >= (irect.p0.y + irect.p1.y) / 2)
    372                                 panel_page_down(panel);
    373                         else
    374                                 panel_page_up(panel);
     375                        /* It's in the border. */
     376                        if (event->type == POS_PRESS) {
     377                                /* Top or bottom half? */
     378                                if (pos.y >= (irect.p0.y + irect.p1.y) / 2)
     379                                        panel_page_down(panel);
     380                                else
     381                                        panel_page_up(panel);
     382                        }
    375383                }
    376384        }
  • uspace/app/nav/panel.h

    r805a149 r8edec53  
    8383extern void panel_activate_req(panel_t *);
    8484
    85 
    8685#endif
    8786
  • uspace/app/terminal/terminal.c

    r805a149 r8edec53  
    842842        sysarg_t sy = -term->off.y;
    843843
    844         if (event->type == POS_PRESS || event->type == POS_RELEASE) {
     844        if (event->type == POS_PRESS || event->type == POS_RELEASE ||
     845            event->type == POS_DCLICK) {
    845846                cevent.type = CEV_POS;
    846847                cevent.ev.pos.type = event->type;
  • uspace/lib/c/generic/io/input.c

    r805a149 r8edec53  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    164164}
    165165
     166static void input_ev_dclick(input_t *input, ipc_call_t *call)
     167{
     168        int bnum;
     169        errno_t rc;
     170
     171        bnum = ipc_get_arg1(call);
     172
     173        rc = input->ev_ops->dclick(input, bnum);
     174        async_answer_0(call, rc);
     175}
     176
    166177static void input_cb_conn(ipc_call_t *icall, void *arg)
    167178{
     
    196207                        input_ev_button(input, &call);
    197208                        break;
     209                case INPUT_EVENT_DCLICK:
     210                        input_ev_dclick(input, &call);
     211                        break;
    198212                default:
    199213                        async_answer_0(&call, ENOTSUP);
  • uspace/lib/c/include/io/input.h

    r805a149 r8edec53  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5454        errno_t (*abs_move)(input_t *, unsigned, unsigned, unsigned, unsigned);
    5555        errno_t (*button)(input_t *, int, int);
     56        errno_t (*dclick)(input_t *, int);
    5657} input_ev_ops_t;
    5758
  • uspace/lib/c/include/io/pos_event.h

    r805a149 r8edec53  
    11/*
     2 * Copyright (c) 2021 Jiri Svoboda
    23 * Copyright (c) 2012 Petr Koupy
    3  * Copyright (c) 2013 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    4040
    4141typedef enum {
     42        /** Position update */
    4243        POS_UPDATE,
     44        /** Button press */
    4345        POS_PRESS,
    44         POS_RELEASE
     46        /** Button release */
     47        POS_RELEASE,
     48        /** Double click */
     49        POS_DCLICK
    4550} pos_event_type_t;
    4651
  • uspace/lib/c/include/ipc/input.h

    r805a149 r8edec53  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4848        INPUT_EVENT_MOVE,
    4949        INPUT_EVENT_ABS_MOVE,
    50         INPUT_EVENT_BUTTON
     50        INPUT_EVENT_BUTTON,
     51        INPUT_EVENT_DCLICK
    5152} input_notif_t;
    5253
  • uspace/lib/ui/src/checkbox.c

    r805a149 r8edec53  
    397397                }
    398398                break;
     399        case POS_DCLICK:
     400                break;
    399401        }
    400402
  • uspace/lib/ui/src/menuentry.c

    r805a149 r8edec53  
    497497                }
    498498                break;
     499        case POS_DCLICK:
     500                break;
    499501        }
    500502
  • uspace/lib/ui/src/pbutton.c

    r805a149 r8edec53  
    521521                }
    522522                break;
     523        case POS_DCLICK:
     524                break;
    523525        }
    524526
  • uspace/lib/ui/src/rbutton.c

    r805a149 r8edec53  
    490490                }
    491491                break;
     492        case POS_DCLICK:
     493                break;
    492494        }
    493495
  • uspace/lib/ui/src/slider.c

    r805a149 r8edec53  
    522522                ui_slider_update(slider, &pos);
    523523                break;
     524        case POS_DCLICK:
     525                break;
    524526        }
    525527
  • 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.