Changeset b1f0a14 in mainline for uspace/lib/ui/src/ui.c
- Timestamp:
- 2023-01-22T11:05:28Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0161d16
- Parents:
- 5d380b6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/ui.c
r5d380b6 rb1f0a14 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 #include <str.h> 49 49 #include <task.h> 50 #include <types/common.h> 50 51 #include <ui/clickmatic.h> 51 52 #include <ui/ui.h> … … 65 66 * @param ws Place to store window system type (protocol) 66 67 * @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 */ 72 static errno_t ui_ospec_parse(const char *ospec, ui_winsys_t *ws, 73 char **osvc, sysarg_t *ridev_id) 70 74 { 71 75 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; 72 82 73 83 cp = ospec; … … 75 85 ++cp; 76 86 87 /* Window system / protocol */ 77 88 if (*cp == '@') { 78 89 if (str_lcmp(ospec, "disp@", str_length("disp@")) == 0) { … … 88 99 } 89 100 90 if (cp[1] != '\0') 91 *osvc = cp + 1; 92 else 93 *osvc = NULL; 101 ++cp; 94 102 } else { 95 103 *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; 141 error: 142 free(*osvc); 143 *osvc = NULL; 144 return rc; 98 145 } 99 146 … … 114 161 console_gc_t *cgc; 115 162 ui_winsys_t ws; 116 c onst char *osvc;163 char *osvc; 117 164 sysarg_t cols; 118 165 sysarg_t rows; 166 sysarg_t idev_id; 119 167 ui_t *ui; 120 168 121 ui_ospec_parse(ospec, &ws, &osvc); 169 rc = ui_ospec_parse(ospec, &ws, &osvc, &idev_id); 170 if (rc != EOK) 171 return rc; 122 172 123 173 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); 126 176 if (rc != EOK) 127 177 goto disp_fail; … … 133 183 } 134 184 185 free(osvc); 135 186 ui->myoutput = true; 187 ui->idev_id = idev_id; 136 188 *rui = ui; 137 189 return EOK; … … 166 218 } 167 219 220 free(osvc); 221 168 222 ui->cgc = cgc; 169 223 ui->rect.p0.x = 0; … … 180 234 cons_fail: 181 235 if (ws == ui_ws_null) { 236 free(osvc); 182 237 rc = ui_create_disp(NULL, &ui); 183 238 if (rc != EOK) … … 189 244 } 190 245 246 free(osvc); 191 247 return EINVAL; 192 248 }
Note:
See TracChangeset
for help on using the changeset viewer.