Changeset 1b92d4b in mainline
- Timestamp:
- 2022-11-01T13:22:48Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fc00f0d
- Parents:
- 913add60
- git-author:
- Jiri Svoboda <jiri@…> (2022-10-31 18:22:34)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-11-01 13:22:48)
- Location:
- uspace/app/taskbar
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/taskbar.c
r913add60 r1b92d4b 53 53 }; 54 54 55 static void taskbar_wm_window_added(void *, sysarg_t);56 static void taskbar_wm_window_removed(void *, sysarg_t);57 58 static wndmgt_cb_t taskbar_wndmgt_cb = {59 .window_added = taskbar_wm_window_added,60 .window_removed = taskbar_wm_window_removed61 };62 63 55 /** Window close button was clicked. 64 56 * … … 96 88 } 97 89 98 if (wndmgt_svc != NULL) {99 rc = wndmgt_open(wndmgt_svc, &taskbar_wndmgt_cb,100 (void *)taskbar, &taskbar->wndmgt);101 if (rc != EOK)102 goto error;103 }104 105 90 rc = ui_create(display_spec, &taskbar->ui); 106 91 if (rc != EOK) { … … 177 162 } 178 163 179 rc = wndlist_create( ui_res, taskbar->fixed, &taskbar->wndlist);164 rc = wndlist_create(taskbar->window, taskbar->fixed, &taskbar->wndlist); 180 165 if (rc != EOK) { 181 166 printf("Error creating window list.\n"); … … 183 168 } 184 169 185 rc = wndlist_ attach_wm(taskbar->wndlist, taskbar->wndmgt);170 rc = wndlist_open_wm(taskbar->wndlist, wndmgt_svc); 186 171 if (rc != EOK) { 187 172 printf("Error attaching window management service.\n"); … … 233 218 if (taskbar->ui != NULL) 234 219 ui_destroy(taskbar->ui); 235 if (taskbar->wndmgt != NULL)236 wndmgt_close(taskbar->wndmgt);237 220 return rc; 238 221 … … 246 229 ui_window_destroy(taskbar->window); 247 230 ui_destroy(taskbar->ui); 248 if (taskbar->wndmgt != NULL)249 wndmgt_close(taskbar->wndmgt);250 231 } 251 232 252 /** Handle WM window added event.253 *254 * @param arg Argument (taskbar_t *)255 * @param wnd_id Window ID256 */257 static void taskbar_wm_window_added(void *arg, sysarg_t wnd_id)258 {259 taskbar_t *taskbar = (taskbar_t *)arg;260 261 printf("wm_window_added: taskbar=%p wnd_id=%zu\n",262 (void *)taskbar, wnd_id);263 }264 265 /** Handle WM window removed event.266 *267 * @param arg Argument (taskbar_t *)268 * @param wnd_id Window ID269 */270 static void taskbar_wm_window_removed(void *arg, sysarg_t wnd_id)271 {272 taskbar_t *taskbar = (taskbar_t *)arg;273 274 printf("wm_window_removed: taskbar=%p wnd_id=%zu\n",275 (void *)taskbar, wnd_id);276 }277 278 233 /** @} 279 234 */ -
uspace/app/taskbar/test/wndlist.c
r913add60 r1b92d4b 46 46 ui_window_t *window = NULL; 47 47 ui_fixed_t *fixed = NULL; 48 ui_resource_t *res;49 48 wndlist_t *wndlist; 50 49 … … 59 58 PCUT_ASSERT_NOT_NULL(window); 60 59 61 res = ui_window_get_res(window);62 PCUT_ASSERT_ERRNO_VAL(EOK, rc);63 64 60 rc = ui_fixed_create(&fixed); 65 61 ui_window_add(window, ui_fixed_ctl(fixed)); 66 62 67 rc = wndlist_create( res, fixed, &wndlist);63 rc = wndlist_create(window, fixed, &wndlist); 68 64 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 69 65 -
uspace/app/taskbar/types/taskbar.h
r913add60 r1b92d4b 57 57 /** Clock */ 58 58 taskbar_clock_t *clock; 59 /** Window management service */60 wndmgt_t *wndmgt;61 59 } taskbar_t; 62 60 -
uspace/app/taskbar/types/wndlist.h
r913add60 r1b92d4b 41 41 #include <ui/pbutton.h> 42 42 #include <ui/fixed.h> 43 #include <ui/ resource.h>43 #include <ui/window.h> 44 44 #include <wndmgt.h> 45 45 … … 50 50 /** Link to wndlist->entries */ 51 51 link_t lentries; 52 /** Window ID */ 53 sysarg_t wnd_id; 52 54 /** Window button */ 53 55 ui_pbutton_t *button; … … 59 61 struct ui_control *control; 60 62 61 /** UI resource*/62 ui_ resource_t *res;63 /** Containing window */ 64 ui_window_t *window; 63 65 64 66 /** Layout to which we add window buttoons */ -
uspace/app/taskbar/wndlist.c
r913add60 r1b92d4b 34 34 35 35 #include <gfx/coord.h> 36 #include <stdbool.h> 36 37 #include <stdio.h> 37 38 #include <stdlib.h> … … 45 46 #include "wndlist.h" 46 47 48 static void wndlist_wm_window_added(void *, sysarg_t); 49 static void wndlist_wm_window_removed(void *, sysarg_t); 50 51 static wndmgt_cb_t wndlist_wndmgt_cb = { 52 .window_added = wndlist_wm_window_added, 53 .window_removed = wndlist_wm_window_removed 54 }; 55 47 56 /** Create task bar window list. 48 57 * 49 * @param res UI resource58 * @param window Containing window 50 59 * @param fixed Fixed layout to which buttons will be added 51 60 * @param wndmgt Window management service … … 53 62 * @return @c EOK on success or an error code 54 63 */ 55 errno_t wndlist_create(ui_ resource_t *res, ui_fixed_t *fixed,64 errno_t wndlist_create(ui_window_t *window, ui_fixed_t *fixed, 56 65 wndlist_t **rwndlist) 57 66 { … … 65 74 } 66 75 67 wndlist-> res = res;76 wndlist->window = window; 68 77 wndlist->fixed = fixed; 69 78 list_initialize(&wndlist->entries); … … 77 86 * 78 87 * @param wndlist Window list 79 * @param rwndlist Place to store pointer to new window list80 * @return @c EOK on success or an error code 81 */ 82 errno_t wndlist_ attach_wm(wndlist_t *wndlist, wndmgt_t *wndmgt)88 * @param wndmgt_svc Window management service name 89 * @return @c EOK on success or an error code 90 */ 91 errno_t wndlist_open_wm(wndlist_t *wndlist, const char *wndmgt_svc) 83 92 { 84 93 errno_t rc; … … 87 96 sysarg_t i; 88 97 89 rc = wndmgt_get_window_list(wndmgt, &wlist); 98 rc = wndmgt_open(wndmgt_svc, &wndlist_wndmgt_cb, (void *)wndlist, 99 &wndlist->wndmgt); 100 if (rc != EOK) 101 goto error; 102 103 rc = wndmgt_get_window_list(wndlist->wndmgt, &wlist); 90 104 if (rc != EOK) 91 105 goto error; 92 106 93 107 for (i = 0; i < wlist->nwindows; i++) { 94 rc = wndmgt_get_window_info(wnd mgt, wlist->windows[i],108 rc = wndmgt_get_window_info(wndlist->wndmgt, wlist->windows[i], 95 109 &winfo); 96 110 if (rc != EOK) 97 111 goto error; 98 112 99 rc = wndlist_append(wndlist, winfo->caption); 113 rc = wndlist_append(wndlist, wlist->windows[i], winfo->caption, 114 false); 100 115 if (rc != EOK) { 101 116 wndmgt_free_window_info(winfo); … … 106 121 } 107 122 108 wndlist->wndmgt = wndmgt;109 123 return EOK; 110 124 error: 111 125 if (wlist != NULL) 112 126 wndmgt_free_window_list(wlist); 127 if (wndlist->wndmgt != NULL) { 128 wndmgt_close(wndlist->wndmgt); 129 wndlist->wndmgt = NULL; 130 } 113 131 return rc; 114 132 } … … 117 135 void wndlist_destroy(wndlist_t *wndlist) 118 136 { 137 wndlist_entry_t *entry; 138 139 /* Close window management service */ 140 if (wndlist->wndmgt) 141 wndmgt_close(wndlist->wndmgt); 142 143 /* Destroy entries */ 144 entry = wndlist_first(wndlist); 145 while (entry != NULL) { 146 (void)wndlist_remove(wndlist, entry, false); 147 entry = wndlist_first(wndlist); 148 } 149 119 150 free(wndlist); 120 151 } … … 123 154 * 124 155 * @param wndlist Window list 156 * @param wnd_id Window ID 125 157 * @param caption Entry caption 126 * @return @c EOK on success or an error code 127 */ 128 errno_t wndlist_append(wndlist_t *wndlist, const char *caption) 158 * @param paint @c true to paint immediately 159 * @return @c EOK on success or an error code 160 */ 161 errno_t wndlist_append(wndlist_t *wndlist, sysarg_t wnd_id, 162 const char *caption, bool paint) 129 163 { 130 164 wndlist_entry_t *entry = NULL; 131 gfx_rect_t rect; 132 size_t nentries; 165 ui_resource_t *res; 133 166 errno_t rc; 134 135 /* Number of existing entries */136 nentries = list_count(&wndlist->entries);137 167 138 168 entry = calloc(1, sizeof(wndlist_entry_t)); … … 142 172 } 143 173 144 rc = ui_pbutton_create(wndlist->res, caption, &entry->button); 145 if (rc != EOK) 146 goto error; 147 148 if (ui_resource_is_textmode(wndlist->res)) { 149 rect.p0.x = 17 * nentries + 9; 150 rect.p0.y = 0; 151 rect.p1.x = 17 * nentries + 25; 152 rect.p1.y = 1; 153 } else { 154 rect.p0.x = 145 * nentries + 90; 155 rect.p0.y = 3; 156 rect.p1.x = 145 * nentries + 230; 157 rect.p1.y = 29; 158 } 159 160 ui_pbutton_set_rect(entry->button, &rect); 161 162 rc = ui_fixed_add(wndlist->fixed, ui_pbutton_ctl(entry->button)); 174 entry->wnd_id = wnd_id; 175 res = ui_window_get_res(wndlist->window); 176 177 rc = ui_pbutton_create(res, caption, &entry->button); 163 178 if (rc != EOK) 164 179 goto error; … … 166 181 entry->wndlist = wndlist; 167 182 list_append(&entry->lentries, &wndlist->entries); 183 184 /* Set the button rectangle */ 185 wndlist_set_entry_rect(wndlist, entry); 186 187 rc = ui_fixed_add(wndlist->fixed, ui_pbutton_ctl(entry->button)); 188 if (rc != EOK) 189 goto error; 190 191 if (paint) { 192 rc = ui_pbutton_paint(entry->button); 193 if (rc != EOK) 194 goto error; 195 } 168 196 169 197 return EOK; … … 177 205 } 178 206 207 /** Remove entry from window list. 208 * 209 * @param wndlist Window list 210 * @param entry Window list entry 211 * @param paint @c true to repaint window list 212 * @return @c EOK on success or an error code 213 */ 214 errno_t wndlist_remove(wndlist_t *wndlist, wndlist_entry_t *entry, 215 bool paint) 216 { 217 wndlist_entry_t *next; 218 assert(entry->wndlist == wndlist); 219 220 next = wndlist_next(entry); 221 222 ui_fixed_remove(wndlist->fixed, ui_pbutton_ctl(entry->button)); 223 ui_pbutton_destroy(entry->button); 224 list_remove(&entry->lentries); 225 free(entry); 226 227 /* Update positions of the remaining entries */ 228 while (next != NULL) { 229 wndlist_set_entry_rect(wndlist, next); 230 next = wndlist_next(next); 231 } 232 233 if (!paint) 234 return EOK; 235 236 return wndlist_repaint(wndlist); 237 } 238 239 /** Compute and set window list entry rectangle. 240 * 241 * Compute rectangle for window list entry and set it. 242 * 243 * @param wndlist Window list 244 * @param entry Window list entry 245 */ 246 void wndlist_set_entry_rect(wndlist_t *wndlist, wndlist_entry_t *entry) 247 { 248 wndlist_entry_t *e; 249 gfx_rect_t rect; 250 ui_resource_t *res; 251 size_t idx; 252 253 /* Determine entry index */ 254 idx = 0; 255 e = wndlist_first(wndlist); 256 while (e != entry) { 257 assert(e != NULL); 258 e = wndlist_next(e); 259 ++idx; 260 } 261 262 res = ui_window_get_res(wndlist->window); 263 264 if (ui_resource_is_textmode(res)) { 265 rect.p0.x = 17 * idx + 9; 266 rect.p0.y = 0; 267 rect.p1.x = 17 * idx + 25; 268 rect.p1.y = 1; 269 } else { 270 rect.p0.x = 145 * idx + 90; 271 rect.p0.y = 3; 272 rect.p1.x = 145 * idx + 230; 273 rect.p1.y = 29; 274 } 275 276 ui_pbutton_set_rect(entry->button, &rect); 277 } 278 279 /** Handle WM window added event. 280 * 281 * @param arg Argument (wndlist_t *) 282 * @param wnd_id Window ID 283 */ 284 static void wndlist_wm_window_added(void *arg, sysarg_t wnd_id) 285 { 286 wndlist_t *wndlist = (wndlist_t *)arg; 287 wndmgt_window_info_t *winfo = NULL; 288 errno_t rc; 289 290 rc = wndmgt_get_window_info(wndlist->wndmgt, wnd_id, &winfo); 291 if (rc != EOK) 292 goto error; 293 294 rc = wndlist_append(wndlist, wnd_id, winfo->caption, true); 295 if (rc != EOK) { 296 wndmgt_free_window_info(winfo); 297 goto error; 298 } 299 300 wndmgt_free_window_info(winfo); 301 return; 302 error: 303 if (winfo != NULL) 304 wndmgt_free_window_info(winfo); 305 } 306 307 /** Handle WM window removed event. 308 * 309 * @param arg Argument (wndlist_t *) 310 * @param wnd_id Window ID 311 */ 312 static void wndlist_wm_window_removed(void *arg, sysarg_t wnd_id) 313 { 314 wndlist_t *wndlist = (wndlist_t *)arg; 315 wndlist_entry_t *entry; 316 317 printf("wm_window_removed: wndlist=%p wnd_id=%zu\n", 318 (void *)wndlist, wnd_id); 319 320 entry = wndlist_entry_by_id(wndlist, wnd_id); 321 if (entry == NULL) 322 return; 323 324 (void) wndlist_remove(wndlist, entry, true); 325 } 326 327 /** Find window list entry by ID. 328 * 329 * @param wndlist Window list 330 * @param wnd_id Window ID 331 * @return Window list entry on success or @c NULL if not found 332 */ 333 wndlist_entry_t *wndlist_entry_by_id(wndlist_t *wndlist, sysarg_t wnd_id) 334 { 335 wndlist_entry_t *entry; 336 337 entry = wndlist_first(wndlist); 338 while (entry != NULL) { 339 if (entry->wnd_id == wnd_id) 340 return entry; 341 342 entry = wndlist_next(entry); 343 } 344 345 return NULL; 346 } 347 348 /** Get first window list entry. 349 * 350 * @param wndlist Window list 351 * @return First entry or @c NULL if the list is empty 352 */ 353 wndlist_entry_t *wndlist_first(wndlist_t *wndlist) 354 { 355 link_t *link; 356 357 link = list_first(&wndlist->entries); 358 if (link == NULL) 359 return NULL; 360 361 return list_get_instance(link, wndlist_entry_t, lentries); 362 } 363 364 /** Get next window list entry. 365 * 366 * @param cur Current entry 367 * @return Next entry or @c NULL if @a cur is the last entry 368 */ 369 wndlist_entry_t *wndlist_next(wndlist_entry_t *cur) 370 { 371 link_t *link; 372 373 link = list_next(&cur->lentries, &cur->wndlist->entries); 374 if (link == NULL) 375 return NULL; 376 377 return list_get_instance(link, wndlist_entry_t, lentries); 378 } 379 380 /** Repaint window list. 381 * 382 * @param wndlist Window list 383 * @return @c EOK on success or an error code 384 */ 385 errno_t wndlist_repaint(wndlist_t *wndlist) 386 { 387 return ui_window_paint(wndlist->window); 388 } 389 179 390 /** @} 180 391 */ -
uspace/app/taskbar/wndlist.h
r913add60 r1b92d4b 38 38 39 39 #include <errno.h> 40 #include <stdbool.h> 40 41 #include <ui/fixed.h> 41 #include <ui/ resource.h>42 #include <ui/window.h> 42 43 #include <wndmgt.h> 43 44 #include "types/wndlist.h" 44 45 45 extern errno_t wndlist_create(ui_ resource_t *, ui_fixed_t *, wndlist_t **);46 extern errno_t wndlist_ attach_wm(wndlist_t *, wndmgt_t*);46 extern errno_t wndlist_create(ui_window_t *, ui_fixed_t *, wndlist_t **); 47 extern errno_t wndlist_open_wm(wndlist_t *, const char *); 47 48 extern void wndlist_destroy(wndlist_t *); 48 extern errno_t wndlist_append(wndlist_t *, const char *); 49 extern errno_t wndlist_append(wndlist_t *, sysarg_t, const char *, bool); 50 extern errno_t wndlist_remove(wndlist_t *, wndlist_entry_t *, bool); 51 extern void wndlist_set_entry_rect(wndlist_t *, wndlist_entry_t *); 52 extern wndlist_entry_t *wndlist_entry_by_id(wndlist_t *, sysarg_t); 53 extern wndlist_entry_t *wndlist_first(wndlist_t *); 54 extern wndlist_entry_t *wndlist_next(wndlist_entry_t *); 55 extern errno_t wndlist_repaint(wndlist_t *); 49 56 50 57 #endif
Note:
See TracChangeset
for help on using the changeset viewer.