Ignore:
File:
1 edited

Legend:

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

    r5d1ff11 r49aaa0e  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * Copyright (c) 2011 Martin Decky
    44 * All rights reserved.
     
    3737#include <stdio.h>
    3838#include <adt/prodcons.h>
     39#include <io/console.h>
    3940#include <io/input.h>
    4041#include <ipc/vfs.h>
     
    8990} console_t;
    9091
     92static loc_srv_t *console_srv;
     93
    9194/** Input server proxy */
    9295static input_t *input;
     
    120123static errno_t input_ev_active(input_t *);
    121124static errno_t input_ev_deactive(input_t *);
    122 static errno_t input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, char32_t);
    123 static errno_t input_ev_move(input_t *, int, int);
    124 static errno_t input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
    125 static errno_t input_ev_button(input_t *, int, int);
     125static errno_t input_ev_key(input_t *, unsigned, kbd_event_type_t, keycode_t,
     126    keymod_t, char32_t);
     127static errno_t input_ev_move(input_t *, unsigned, int, int);
     128static errno_t input_ev_abs_move(input_t *, unsigned, unsigned, unsigned,
     129    unsigned, unsigned);
     130static errno_t input_ev_button(input_t *, unsigned, int, int);
     131static errno_t input_ev_dclick(input_t *, unsigned, int);
    126132
    127133static input_ev_ops_t input_ev_ops = {
     
    131137        .move = input_ev_move,
    132138        .abs_move = input_ev_abs_move,
    133         .button = input_ev_button
     139        .button = input_ev_button,
     140        .dclick = input_ev_dclick
    134141};
    135142
     
    149156static void cons_set_rgb_color(con_srv_t *, pixel_t, pixel_t);
    150157static void cons_set_cursor_visibility(con_srv_t *, bool);
     158static errno_t cons_set_caption(con_srv_t *, const char *);
    151159static errno_t cons_get_event(con_srv_t *, cons_event_t *);
    152160static errno_t cons_map(con_srv_t *, sysarg_t, sysarg_t, charfield_t **);
     
    170178        .set_rgb_color = cons_set_rgb_color,
    171179        .set_cursor_visibility = cons_set_cursor_visibility,
     180        .set_caption = cons_set_caption,
    172181        .get_event = cons_get_event,
    173182        .map = cons_map,
     
    353362}
    354363
    355 static errno_t input_ev_key(input_t *input, kbd_event_type_t type, keycode_t key,
    356     keymod_t mods, char32_t c)
     364static errno_t input_ev_key(input_t *input, unsigned kbd_id,
     365    kbd_event_type_t type, keycode_t key, keymod_t mods, char32_t c)
    357366{
    358367        cons_event_t event;
    359 
     368        bool alt;
     369        bool shift;
     370
     371        alt = (mods & KM_ALT) != 0 && (mods & (KM_CTRL | KM_SHIFT)) == 0;
     372        shift = (mods & KM_SHIFT) != 0 && (mods & (KM_CTRL | KM_ALT)) == 0;
     373
     374        /* Switch console on Alt+Fn or Shift+Fn */
    360375        if ((key >= KC_F1) && (key <= KC_F1 + CONSOLE_COUNT) &&
    361             ((mods & KM_CTRL) == 0)) {
     376            (alt || shift)) {
    362377                cons_switch(key - KC_F1);
    363378        } else {
     
    365380                event.type = CEV_KEY;
    366381
     382                (void)kbd_id;
    367383                event.ev.key.type = type;
    368384                event.ev.key.key = key;
     
    413429}
    414430
    415 static errno_t input_ev_move(input_t *input, int dx, int dy)
    416 {
     431static errno_t input_ev_move(input_t *input, unsigned pos_id, int dx, int dy)
     432{
     433        (void) pos_id;
    417434        pointer_update(pointer_x + dx, pointer_y + dy);
    418435        return EOK;
    419436}
    420437
    421 static errno_t input_ev_abs_move(input_t *input, unsigned x, unsigned y,
    422     unsigned max_x, unsigned max_y)
    423 {
     438static errno_t input_ev_abs_move(input_t *input, unsigned pos_id, unsigned x,
     439    unsigned y, unsigned max_x, unsigned max_y)
     440{
     441        (void)pos_id;
    424442        pointer_update(mouse_scale_x * cols * x / max_x, mouse_scale_y * rows * y / max_y);
    425443        return EOK;
    426444}
    427445
    428 static errno_t input_ev_button(input_t *input, int bnum, int bpress)
     446static errno_t input_ev_button(input_t *input, unsigned pos_id, int bnum,
     447    int bpress)
    429448{
    430449        cons_event_t event;
     450
     451        (void)pos_id;
    431452
    432453        event.type = CEV_POS;
    433454        event.ev.pos.type = bpress ? POS_PRESS : POS_RELEASE;
     455        event.ev.pos.btn_num = bnum;
     456        event.ev.pos.hpos = pointer_x / mouse_scale_x;
     457        event.ev.pos.vpos = pointer_y / mouse_scale_y;
     458
     459        console_queue_cons_event(active_console, &event);
     460        return EOK;
     461}
     462
     463static errno_t input_ev_dclick(input_t *input, unsigned pos_id, int bnum)
     464{
     465        cons_event_t event;
     466
     467        (void)pos_id;
     468
     469        event.type = CEV_POS;
     470        event.ev.pos.type = POS_DCLICK;
    434471        event.ev.pos.btn_num = bnum;
    435472        event.ev.pos.hpos = pointer_x / mouse_scale_x;
     
    653690}
    654691
     692static errno_t cons_set_caption(con_srv_t *srv, const char *caption)
     693{
     694        console_t *cons = srv_to_console(srv);
     695
     696        (void) cons;
     697        (void) caption;
     698        return EOK;
     699}
     700
    655701static errno_t cons_get_event(con_srv_t *srv, cons_event_t *event)
    656702{
     
    865911        /* Register server */
    866912        async_set_fallback_port_handler(client_connection, NULL);
    867         rc = loc_server_register(NAME);
     913        rc = loc_server_register(NAME, &console_srv);
    868914        if (rc != EOK) {
    869915                printf("%s: Unable to register server (%s)\n", NAME,
     
    915961                        snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
    916962
    917                         if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
     963                        if (loc_service_register(console_srv, vc,
     964                            &consoles[i].dsid) != EOK) {
    918965                                printf("%s: Unable to register device %s\n", NAME, vc);
    919966                                return false;
Note: See TracChangeset for help on using the changeset viewer.