Changeset b1f0a14 in mainline


Ignore:
Timestamp:
2023-01-22T11:05:28Z (15 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0161d16
Parents:
5d380b6
Message:

Pass input device ID via display specification argument

This allows launcher to start applications in the correct seat,
meaning the correct seat's focus will be changed to the newly
created window.

Location:
uspace
Files:
5 edited

Legend:

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

    r5d380b6 rb1f0a14  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * Copyright (c) 2012 Petr Koupy
    44 * All rights reserved.
     
    5959
    6060static void wnd_close(ui_window_t *, void *);
     61static void wnd_pos(ui_window_t *, void *, pos_event_t *);
    6162
    6263static ui_window_cb_t window_cb = {
    63         .close = wnd_close
     64        .close = wnd_close,
     65        .pos = wnd_pos
    6466};
    6567
     
    7072};
    7173
    72 static int app_launchl(const char *, ...);
     74static int app_launchl(launcher_t *, const char *, ...);
    7375
    7476/** Window close button was clicked.
     
    8486}
    8587
     88/** Window received position event.
     89 *
     90 * @param window Window
     91 * @param arg Argument (launcher)
     92 * @param event Position event
     93 */
     94static void wnd_pos(ui_window_t *window, void *arg, pos_event_t *event)
     95{
     96        launcher_t *launcher = (launcher_t *) arg;
     97
     98        /* Remember ID of device that sent the last event */
     99        launcher->ev_pos_id = event->pos_id;
     100
     101        ui_window_def_pos(window, event);
     102}
     103
    86104/** Push button was clicked.
    87105 *
     
    94112
    95113        if (pbutton == launcher->pb1) {
    96                 app_launchl("/app/terminal", "-c", "/app/nav", NULL);
     114                app_launchl(launcher, "/app/terminal", "-c", "/app/nav", NULL);
    97115        } else if (pbutton == launcher->pb2) {
    98                 app_launchl("/app/terminal", "-c", "/app/edit", NULL);
     116                app_launchl(launcher, "/app/terminal", "-c", "/app/edit", NULL);
    99117        } else if (pbutton == launcher->pb3) {
    100                 app_launchl("/app/terminal", NULL);
     118                app_launchl(launcher, "/app/terminal", NULL);
    101119        } else if (pbutton == launcher->pb4) {
    102                 app_launchl("/app/calculator", NULL);
     120                app_launchl(launcher, "/app/calculator", NULL);
    103121        } else if (pbutton == launcher->pb5) {
    104                 app_launchl("/app/uidemo", NULL);
     122                app_launchl(launcher, "/app/uidemo", NULL);
    105123        } else if (pbutton == launcher->pb6) {
    106                 app_launchl("/app/gfxdemo", "ui", NULL);
    107         }
    108 }
    109 
    110 static int app_launchl(const char *app, ...)
     124                app_launchl(launcher, "/app/gfxdemo", "ui", NULL);
     125        }
     126}
     127
     128static int app_launchl(launcher_t *launcher, const char *app, ...)
    111129{
    112130        errno_t rc;
     
    117135        const char **argv;
    118136        const char **argp;
     137        char *dspec;
    119138        int cnt = 0;
    120139        int i;
     140        int rv;
    121141
    122142        va_start(ap, app);
     
    137157        *argp++ = app;
    138158
    139         if (str_cmp(display_spec, UI_DISPLAY_DEFAULT) != 0) {
    140                 *argp++ = "-d";
    141                 *argp++ = display_spec;
    142         }
     159        rv = asprintf(&dspec, "%s?idev=%zu", display_spec,
     160            (size_t)launcher->ev_pos_id);
     161        if (rv < 0) {
     162                printf("Out of memory.\n");
     163                return -1;
     164        }
     165
     166        /* TODO Might be omitted if default display AND only one seat */
     167        *argp++ = "-d";
     168        *argp++ = dspec;
    143169
    144170        va_start(ap, app);
     
    192218        gfx_rect_t rect;
    193219        gfx_coord2_t off;
     220        const char *dspec = UI_DISPLAY_DEFAULT;
     221        char *qmark;
    194222        errno_t rc;
    195223
     
    204232                        }
    205233
    206                         display_spec = argv[i++];
     234                        dspec = argv[i++];
    207235                } else {
    208236                        printf("Invalid option '%s'.\n", argv[i]);
     
    212240        }
    213241
    214         rc = ui_create(display_spec, &ui);
     242        display_spec = str_dup(dspec);
     243        if (display_spec == NULL) {
     244                printf("Out of memory.\n");
     245                return 1;
     246        }
     247
     248        /* Remove additional arguments */
     249        qmark = str_chr(display_spec, '?');
     250        if (qmark != NULL)
     251                *qmark = '\0';
     252
     253        rc = ui_create(dspec, &ui);
    215254        if (rc != EOK) {
    216255                printf("Error creating UI on display %s.\n", display_spec);
  • uspace/app/launcher/launcher.h

    r5d380b6 rb1f0a14  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838
    3939#include <display.h>
     40#include <types/common.h>
    4041#include <ui/fixed.h>
    4142#include <ui/image.h>
     
    5051        ui_window_t *window;
    5152        ui_fixed_t *fixed;
     53
    5254        ui_image_t *image;
    5355        ui_label_t *label;
     56
    5457        ui_pbutton_t *pb1;
    5558        ui_pbutton_t *pb2;
     
    5861        ui_pbutton_t *pb5;
    5962        ui_pbutton_t *pb6;
     63
     64        /** ID of device that sent last position event */
     65        sysarg_t ev_pos_id;
    6066} launcher_t;
    6167
  • uspace/lib/ui/private/ui.h

    r5d380b6 rb1f0a14  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4444#include <io/console.h>
    4545#include <stdbool.h>
     46#include <types/common.h>
    4647
    4748/** Actual structure of user interface.
     
    6869        /** Clickmatic */
    6970        struct ui_clickmatic *clickmatic;
     71        /** Default input device ID used to determine new window's seat */
     72        sysarg_t idev_id;
    7073};
    7174
  • uspace/lib/ui/src/ui.c

    r5d380b6 rb1f0a14  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4848#include <str.h>
    4949#include <task.h>
     50#include <types/common.h>
    5051#include <ui/clickmatic.h>
    5152#include <ui/ui.h>
     
    6566 * @param ws Place to store window system type (protocol)
    6667 * @param osvc Place to store pointer to output service name
    67  */
    68 static void ui_ospec_parse(const char *ospec, ui_winsys_t *ws,
    69     const char **osvc)
     68 * @param ridev_id Place to store input device ID
     69 * @return EOK on success, EINVAL if syntax is invalid, ENOMEM if out of
     70 *         memory
     71 */
     72static errno_t ui_ospec_parse(const char *ospec, ui_winsys_t *ws,
     73    char **osvc, sysarg_t *ridev_id)
    7074{
    7175        const char *cp;
     76        const char *qm;
     77        const char *endptr;
     78        uint64_t idev_id;
     79        errno_t rc;
     80
     81        *ridev_id = 0;
    7282
    7383        cp = ospec;
     
    7585                ++cp;
    7686
     87        /* Window system / protocol */
    7788        if (*cp == '@') {
    7889                if (str_lcmp(ospec, "disp@", str_length("disp@")) == 0) {
     
    8899                }
    89100
    90                 if (cp[1] != '\0')
    91                         *osvc = cp + 1;
    92                 else
    93                         *osvc = NULL;
     101                ++cp;
    94102        } else {
    95103                *ws = ui_ws_display;
    96                 *osvc = ospec;
    97         }
     104        }
     105
     106        /* Output service is the part before question mark */
     107        qm = str_chr(cp, '?');
     108        if (qm != NULL) {
     109                *osvc = str_ndup(cp, qm - cp);
     110        } else {
     111                /* No question mark */
     112                *osvc = str_dup(cp);
     113        }
     114
     115        if (*osvc == NULL)
     116                return ENOMEM;
     117
     118        if (qm != NULL) {
     119                /* The part after the question mark */
     120                cp = qm + 1;
     121
     122                /* Input device ID parameter */
     123                if (str_lcmp(cp, "idev=", str_length("idev=")) == 0) {
     124                        cp += str_length("idev=");
     125
     126                        rc = str_uint64_t(cp, &endptr, 10, false, &idev_id);
     127                        if (rc != EOK)
     128                                goto error;
     129
     130                        *ridev_id = idev_id;
     131                        cp = endptr;
     132                }
     133        }
     134
     135        if (*cp != '\0') {
     136                rc = EINVAL;
     137                goto error;
     138        }
     139
     140        return EOK;
     141error:
     142        free(*osvc);
     143        *osvc = NULL;
     144        return rc;
    98145}
    99146
     
    114161        console_gc_t *cgc;
    115162        ui_winsys_t ws;
    116         const char *osvc;
     163        char *osvc;
    117164        sysarg_t cols;
    118165        sysarg_t rows;
     166        sysarg_t idev_id;
    119167        ui_t *ui;
    120168
    121         ui_ospec_parse(ospec, &ws, &osvc);
     169        rc = ui_ospec_parse(ospec, &ws, &osvc, &idev_id);
     170        if (rc != EOK)
     171                return rc;
    122172
    123173        if (ws == ui_ws_display || ws == ui_ws_any) {
    124                 rc = display_open(osvc != NULL ? osvc : DISPLAY_DEFAULT,
    125                     &display);
     174                rc = display_open((str_cmp(osvc, "") != 0) ? osvc :
     175                    DISPLAY_DEFAULT, &display);
    126176                if (rc != EOK)
    127177                        goto disp_fail;
     
    133183                }
    134184
     185                free(osvc);
    135186                ui->myoutput = true;
     187                ui->idev_id = idev_id;
    136188                *rui = ui;
    137189                return EOK;
     
    166218                }
    167219
     220                free(osvc);
     221
    168222                ui->cgc = cgc;
    169223                ui->rect.p0.x = 0;
     
    180234cons_fail:
    181235        if (ws == ui_ws_null) {
     236                free(osvc);
    182237                rc = ui_create_disp(NULL, &ui);
    183238                if (rc != EOK)
     
    189244        }
    190245
     246        free(osvc);
    191247        return EINVAL;
    192248}
  • uspace/lib/ui/src/window.c

    r5d380b6 rb1f0a14  
    227227        /* Only allow making the window larger */
    228228        gfx_rect_dims(&params->rect, &dparams.min_size);
    229         dparams.idev_id = params->idev_id;
     229
     230        /*
     231         * If idev_id is not specified, use the UI default (probably
     232         * obtained from display specification. This creates the
     233         * main window in the seat specified on the command line.
     234         */
     235        if (params->idev_id != 0)
     236                dparams.idev_id = params->idev_id;
     237        else
     238                dparams.idev_id = ui->idev_id;
    230239
    231240        if ((params->flags & ui_wndf_popup) != 0)
Note: See TracChangeset for help on using the changeset viewer.