Changeset aefdccd in mainline for uspace/lib
- Timestamp:
- 2025-10-20T06:14:54Z (2 months ago)
- Parents:
- adbd7e1 (diff), 3e41cc4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2025-10-20 06:14:54)
- git-committer:
- GitHub <noreply@…> (2025-10-20 06:14:54)
- Location:
- uspace/lib
- Files:
-
- 15 added
- 29 edited
-
c/arch/mips32/meson.build (modified) (1 diff)
-
c/arch/mips32/src/atomic.c (added)
-
c/arch/ppc32/meson.build (modified) (1 diff)
-
c/arch/ppc32/src/atomic.c (added)
-
c/generic/capa.c (modified) (4 diffs)
-
c/include/capa.h (modified) (2 diffs)
-
c/include/math.h (modified) (3 diffs)
-
c/test/capa.c (modified) (2 diffs)
-
cpp/include/__bits/adt/bitset.hpp (modified) (2 diffs)
-
cpp/include/__bits/adt/list.hpp (modified) (3 diffs)
-
cpp/include/__bits/adt/list_node.hpp (modified) (2 diffs)
-
cpp/include/__bits/insert_iterator.hpp (modified) (2 diffs)
-
device/src/bd_srv.c (modified) (2 diffs)
-
fmgt/doc/doxygroups.h (added)
-
fmgt/include/fmgt.h (added)
-
fmgt/include/types/fmgt.h (added)
-
fmgt/meson.build (added)
-
fmgt/src/fmgt.c (added)
-
fmgt/test/fmgt.c (added)
-
fmgt/test/main.c (added)
-
math/generic/atan2.c (added)
-
math/generic/floor.c (added)
-
math/generic/log.c (added)
-
math/generic/pow.c (added)
-
math/generic/sqrt.c (added)
-
math/generic/tan.c (added)
-
math/meson.build (modified) (2 diffs)
-
meson.build (modified) (3 diffs)
-
output/include/io/chargrid.h (modified) (2 diffs)
-
output/src/chargrid.c (modified) (2 diffs)
-
posix/include/posix/unistd.h (modified) (2 diffs)
-
posix/src/unistd.c (modified) (2 diffs)
-
ui/include/types/ui/list.h (modified) (3 diffs)
-
ui/include/ui/filelist.h (modified) (1 diff)
-
ui/include/ui/list.h (modified) (2 diffs)
-
ui/include/ui/window.h (modified) (2 diffs)
-
ui/private/window.h (modified) (2 diffs)
-
ui/src/filelist.c (modified) (3 diffs)
-
ui/src/list.c (modified) (2 diffs)
-
ui/src/msgdialog.c (modified) (4 diffs)
-
ui/src/ui.c (modified) (2 diffs)
-
ui/src/window.c (modified) (1 diff)
-
ui/test/filelist.c (modified) (2 diffs)
-
ui/test/list.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/mips32/meson.build
radbd7e1 raefdccd 30 30 31 31 arch_src += files( 32 'src/atomic.c', 32 33 'src/entryjmp.S', 33 34 'src/thread_entry.S', -
uspace/lib/c/arch/ppc32/meson.build
radbd7e1 raefdccd 30 30 31 31 arch_src += files( 32 'src/atomic.c', 32 33 'src/entryjmp.S', 33 34 'src/thread_entry.S', -
uspace/lib/c/generic/capa.c
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 20 15 Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 199 199 } 200 200 201 /** Format capacity as string into a newly allocated buffer. 202 * 203 * @param capa Capacity 204 * @param rstr Place to store pointer to newly allocated string 205 * @return EOK on success or an error code 206 */ 201 207 errno_t capa_format(capa_spec_t *capa, char **rstr) 202 208 { … … 233 239 } 234 240 241 /** Format capacity as string into an existing buffer. 242 * 243 * @param capa Capacity 244 * @param buf Buffer for storing string 245 * @param bufsize Size of buffer in bytes 246 * @return EOK on success or an error code 247 */ 248 errno_t capa_format_buf(capa_spec_t *capa, char *buf, size_t bufsize) 249 { 250 errno_t rc; 251 const char *sunit; 252 uint64_t ipart; 253 uint64_t fpart; 254 uint64_t div; 255 256 sunit = NULL; 257 258 assert(capa->cunit < CU_LIMIT); 259 260 rc = ipow10_u64(capa->dp, &div); 261 if (rc != EOK) 262 return rc; 263 264 ipart = capa->m / div; 265 fpart = capa->m % div; 266 267 sunit = cu_str[capa->cunit]; 268 if (capa->dp > 0) { 269 snprintf(buf, bufsize, "%" PRIu64 ".%0*" PRIu64 " %s", ipart, 270 (int)capa->dp, fpart, sunit); 271 } else { 272 snprintf(buf, bufsize, "%" PRIu64 " %s", ipart, sunit); 273 } 274 275 return EOK; 276 } 277 278 /** Format capacity of n blocks as string into a newly allocated buffer. 279 * 280 * This computes the total capacity of the blocks, simplifies it 281 * and formats it as string. 282 * 283 * @param nblocks Number of blocks 284 * @param block_size Size of each block in bytes 285 * @param rstr Place to store pointer to newly allocated string 286 * @return EOK on success or an error code 287 */ 288 errno_t capa_blocks_format(uint64_t nblocks, size_t block_size, 289 char **rptr) 290 { 291 capa_spec_t capa; 292 293 capa_from_blocks(nblocks, block_size, &capa); 294 capa_simplify(&capa); 295 return capa_format(&capa, rptr); 296 } 297 298 /** Format capacity of n blocks as string into an existing buffer. 299 * 300 * This computes the total capacity of the blocks, simplifies it 301 * and formats it as string. 302 * 303 * This function does not return error. If the buffer is too small, 304 * the string will be truncated. To make sure it is not truncated, 305 * bufsize should be at least CAPA_BLOCKS_BUFSIZE. 306 * 307 * @param nblocks Number of blocks 308 * @param block_size Size of each block in bytes 309 * @param buf Buffer for storing string 310 * @param bufsize Size of buffer in bytes 311 */ 312 void capa_blocks_format_buf(uint64_t nblocks, size_t block_size, 313 char *buf, size_t bufsize) 314 { 315 capa_spec_t capa; 316 errno_t rc; 317 318 capa_from_blocks(nblocks, block_size, &capa); 319 capa_simplify(&capa); 320 321 /* Should not get range error because of nblocks * block_size limits */ 322 rc = capa_format_buf(&capa, buf, bufsize); 323 assert(rc == EOK); 324 (void)rc; 325 } 326 235 327 static errno_t capa_digit_val(char c, int *val) 236 328 { … … 273 365 } 274 366 367 /** Parse string as capacity specification. 368 * 369 * @param str String (e.g. "100 kB") 370 * @param capa Place to store capacity 371 * @return EOK on success or an error code 372 */ 275 373 errno_t capa_parse(const char *str, capa_spec_t *capa) 276 374 { -
uspace/lib/c/include/capa.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 20 15 Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 87 87 } capa_spec_t; 88 88 89 /** Size of buffer large enough for capa_blocks_format_buf */ 90 #define CAPA_BLOCKS_BUFSIZE 16 91 89 92 extern errno_t capa_format(capa_spec_t *, char **); 93 extern errno_t capa_format_buf(capa_spec_t *, char *, size_t); 94 extern errno_t capa_blocks_format(uint64_t, size_t, char **); 95 extern void capa_blocks_format_buf(uint64_t, size_t, char *, size_t); 90 96 extern errno_t capa_parse(const char *, capa_spec_t *); 91 97 extern void capa_simplify(capa_spec_t *); -
uspace/lib/c/include/math.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2018 CZ.NIC, z.s.p.o. 3 4 * All rights reserved. … … 30 31 #define _MATH_H 31 32 33 #include <_bits/decls.h> 32 34 #include <limits.h> 33 35 #include <stddef.h> 34 36 #include <float.h> 37 38 __C_DECLS_BEGIN; 35 39 36 40 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_HELENOS_SOURCE) … … 322 326 #endif 323 327 328 __C_DECLS_END; 329 324 330 #endif /* _MATH_H */ -
uspace/lib/c/test/capa.c
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2019 Matthieu Riolo 3 4 * All rights reserved. … … 285 286 } 286 287 288 PCUT_TEST(capa_blocks_format) 289 { 290 errno_t rc; 291 char *str; 292 293 rc = capa_blocks_format(42, 1, &str); 294 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 295 PCUT_ASSERT_STR_EQUALS("42 B", str); 296 free(str); 297 } 298 299 PCUT_TEST(capa_blocks_format_buf) 300 { 301 char str[CAPA_BLOCKS_BUFSIZE]; 302 303 capa_blocks_format_buf(42, 1, str, sizeof(str)); 304 PCUT_ASSERT_STR_EQUALS("42 B", str); 305 } 306 287 307 PCUT_EXPORT(capa); -
uspace/lib/cpp/include/__bits/adt/bitset.hpp
radbd7e1 raefdccd 42 42 class bitset 43 43 { 44 private: 45 /** 46 * While this might be a bit more wasteful 47 * than using unsigned or unsigned long, 48 * it will make parts of out code easier 49 * to read. 50 */ 51 using data_type = unsigned long long; 52 44 53 public: 45 54 class reference … … 365 374 366 375 private: 367 /**368 * While this might be a bit more wasteful369 * than using unsigned or unsigned long,370 * it will make parts of out code easier371 * to read.372 */373 using data_type = unsigned long long;374 375 376 static constexpr size_t bits_in_data_type_ = sizeof(data_type) * 8; 376 377 static constexpr size_t data_size_ = N / bits_in_data_type_ + 1; -
uspace/lib/cpp/include/__bits/adt/list.hpp
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2019 Jaroslav Jindrak 3 4 * All rights reserved. … … 80 81 } 81 82 83 pointer operator->() const 84 { 85 return ¤t_->value; 86 } 87 82 88 list_const_iterator& operator++() 83 89 { … … 209 215 return current_->value; 210 216 } 217 218 pointer operator->() const 219 { 220 return ¤t_->value; 221 } 211 222 212 223 list_iterator& operator++() -
uspace/lib/cpp/include/__bits/adt/list_node.hpp
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2018 Jaroslav Jindrak 3 4 * All rights reserved. … … 29 30 #ifndef LIBCPP_BITS_ADT_LIST_NODE 30 31 #define LIBCPP_BITS_ADT_LIST_NODE 32 33 #include <utility> 31 34 32 35 namespace std::aux -
uspace/lib/cpp/include/__bits/insert_iterator.hpp
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2018 Jaroslav Jindrak 3 4 * All rights reserved. … … 33 34 { 34 35 struct forward_iterator_tag; 36 struct input_iterator_tag; 35 37 } 36 38 -
uspace/lib/device/src/bd_srv.c
radbd7e1 raefdccd 77 77 rc = srv->srvs->ops->read_blocks(srv, ba, cnt, buf, size); 78 78 if (rc != EOK) { 79 async_answer_0(&rcall, ENOMEM);80 async_answer_0(call, ENOMEM);79 async_answer_0(&rcall, rc); 80 async_answer_0(call, rc); 81 81 free(buf); 82 82 return; … … 121 121 rc = srv->srvs->ops->read_toc(srv, session, buf, size); 122 122 if (rc != EOK) { 123 async_answer_0(&rcall, ENOMEM);124 async_answer_0(call, ENOMEM);123 async_answer_0(&rcall, rc); 124 async_answer_0(call, rc); 125 125 free(buf); 126 126 return; -
uspace/lib/math/meson.build
radbd7e1 raefdccd 1 1 # 2 # Copyright (c) 2025 Jiri Svoboda 2 3 # Copyright (c) 2013 Vojtech Horky 3 4 # All rights reserved. … … 33 34 'generic/__fpclassify.c', 34 35 'generic/__signbit.c', 36 'generic/atan2.c', 35 37 'generic/cos.c', 36 38 'generic/fabs.c', 39 'generic/floor.c', 37 40 'generic/fmod.c', 38 41 'generic/fmodf.c', 39 42 'generic/nearbyint.c', 43 'generic/pow.c', 44 'generic/log.c', 45 'generic/sqrt.c', 40 46 'generic/round.c', 47 'generic/tan.c', 41 48 'generic/trig.c', 42 49 'generic/sin.c', -
uspace/lib/meson.build
radbd7e1 raefdccd 72 72 'fbfont', 73 73 'fdisk', 74 'fmgt', 74 75 'fmtutil', 75 76 'fs', … … 261 262 install_files += [[ 'lib', _shared_lib.full_path(), _libname ]] 262 263 install_deps += [ _shared_lib ] 264 exported_devel_files += [ 'sharedlib', _shared_lib, _libname ] 263 265 endif 264 266 … … 289 291 dependencies: _shared_deps, 290 292 ) 291 exported_devel_files += [ 'sharedlib', _shared_lib, _libname ]292 293 endif 293 294 -
uspace/lib/output/include/io/chargrid.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2011 Martin Decky 3 4 * All rights reserved. … … 81 82 extern sysarg_t chargrid_putuchar(chargrid_t *, char32_t, bool); 82 83 extern sysarg_t chargrid_newline(chargrid_t *); 84 extern sysarg_t chargrid_cr(chargrid_t *); 83 85 extern sysarg_t chargrid_tabstop(chargrid_t *, sysarg_t); 84 86 extern sysarg_t chargrid_backspace(chargrid_t *); -
uspace/lib/output/src/chargrid.c
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2006 Josef Cejka 3 4 * All rights reserved. … … 180 181 } 181 182 183 /** Return cursor to the beginning of the line. 184 * 185 * @param scrbuf Chargrid. 186 * 187 * @return Number of rows which have been affected. In usual 188 * situations this is 1. 189 * 190 */ 191 sysarg_t chargrid_cr(chargrid_t *scrbuf) 192 { 193 assert(scrbuf->col < scrbuf->cols); 194 assert(scrbuf->row < scrbuf->rows); 195 196 scrbuf->col = 0; 197 return 1; 198 } 199 182 200 /** Jump to a new row in chargrid. 183 201 * -
uspace/lib/posix/include/posix/unistd.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2011 Jiri Zarevucky 3 4 * Copyright (c) 2011 Petr Koupy … … 164 165 extern int execv(const char *path, char *const argv[]); 165 166 extern int execvp(const char *file, char *const argv[]); 167 extern int execlp(const char *file, const char *arg, ...); 166 168 167 169 /* Creating a Pipe */ -
uspace/lib/posix/src/unistd.c
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2011 Jiri Zarevucky 3 4 * Copyright (c) 2011 Petr Koupy … … 530 531 /** 531 532 * 533 * @param file 534 * @param argv 535 * @return 536 */ 537 int execlp(const char *file, const char *arg, ...) 538 { 539 // TODO: low priority, just a compile-time dependency of dosbox 540 not_implemented(); 541 return -1; 542 } 543 544 /** 545 * 532 546 * @param fildes 533 547 * @return -
uspace/lib/ui/include/types/ui/list.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 39 39 #include <gfx/color.h> 40 #include <stddef.h> 40 41 41 42 struct ui_list; … … 67 68 } ui_list_cb_t; 68 69 70 /** Saved list position. */ 71 typedef struct { 72 /** Page index */ 73 size_t page_idx; 74 /** Cursor index */ 75 size_t cursor_idx; 76 } ui_list_pos_t; 77 69 78 #endif 70 79 -
uspace/lib/ui/include/ui/filelist.h
radbd7e1 raefdccd 51 51 extern errno_t ui_file_list_read_dir(ui_file_list_t *, const char *); 52 52 extern errno_t ui_file_list_activate(ui_file_list_t *); 53 extern errno_t ui_file_list_refresh(ui_file_list_t *); 53 54 extern void ui_file_list_deactivate(ui_file_list_t *); 54 55 extern errno_t ui_file_list_open(ui_file_list_t *, ui_file_list_entry_t *); -
uspace/lib/ui/include/ui/list.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 71 71 extern ui_list_entry_t *ui_list_prev(ui_list_entry_t *); 72 72 extern bool ui_list_is_active(ui_list_t *); 73 extern void ui_list_save_pos(ui_list_t *, ui_list_pos_t *); 74 extern void ui_list_restore_pos(ui_list_t *, ui_list_pos_t *); 73 75 74 76 #endif -
uspace/lib/ui/include/ui/window.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 56 56 extern void ui_window_add(ui_window_t *, ui_control_t *); 57 57 extern void ui_window_remove(ui_window_t *, ui_control_t *); 58 extern ui_window_t *ui_window_get_active(ui_t *);59 58 extern errno_t ui_window_resize(ui_window_t *, gfx_rect_t *); 60 59 extern ui_t *ui_window_get_ui(ui_window_t *); -
uspace/lib/ui/private/window.h
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 136 136 extern errno_t ui_window_size_change(ui_window_t *, gfx_rect_t *, 137 137 ui_wnd_sc_op_t); 138 extern ui_window_t *ui_window_get_active(ui_t *); 139 extern ui_window_t *ui_window_first(ui_t *); 140 extern ui_window_t *ui_window_next(ui_window_t *); 138 141 139 142 #endif -
uspace/lib/ui/src/filelist.c
radbd7e1 raefdccd 349 349 goto error; 350 350 } 351 352 ui_file_list_clear_entries(flist); 351 353 352 354 if (str_cmp(ndir, "/") != 0) { … … 422 424 } 423 425 426 /** Re-read file list from directory. 427 * 428 * @param flist File list 429 * @return EOK on success or an error code 430 */ 431 errno_t ui_file_list_refresh(ui_file_list_t *flist) 432 { 433 errno_t rc; 434 ui_list_pos_t pos; 435 436 ui_list_save_pos(flist->list, &pos); 437 rc = ui_file_list_read_dir(flist, flist->dir); 438 if (rc != EOK) 439 return rc; 440 ui_list_restore_pos(flist->list, &pos); 441 return EOK; 442 } 443 424 444 /** Sort file list entries. 425 445 * … … 593 613 return ENOMEM; 594 614 595 ui_file_list_clear_entries(flist);596 597 615 rc = ui_file_list_read_dir(flist, dirname); 598 616 if (rc != EOK) { -
uspace/lib/ui/src/list.c
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 1652 1652 } 1653 1653 1654 /** Save list position for later. 1655 * 1656 * The position will be valid even if the list is cleaned and re-populated 1657 * (it just counts position from the top.) 1658 * 1659 * @param list UI list 1660 * @param pos Place to store position 1661 */ 1662 void ui_list_save_pos(ui_list_t *list, ui_list_pos_t *pos) 1663 { 1664 pos->page_idx = list->page_idx; 1665 pos->cursor_idx = list->cursor_idx; 1666 } 1667 1668 /** Restore saved list position. 1669 * 1670 * The position will be valid even if the list is cleaned and re-populated 1671 * (it just counts position from the top.) 1672 * 1673 * @param list UI list 1674 * @param pos Saved list position 1675 */ 1676 void ui_list_restore_pos(ui_list_t *list, ui_list_pos_t *pos) 1677 { 1678 size_t idx, i; 1679 ui_list_entry_t *entry, *next; 1680 1681 idx = 0; 1682 entry = ui_list_first(list); 1683 1684 for (i = 0; i < pos->cursor_idx; i++) { 1685 next = ui_list_next(entry); 1686 if (next != NULL) { 1687 entry = next; 1688 ++idx; 1689 } 1690 } 1691 1692 list->cursor = entry; 1693 list->cursor_idx = idx; 1694 1695 idx = 0; 1696 entry = ui_list_first(list); 1697 1698 for (i = 0; i < pos->page_idx; i++) { 1699 next = ui_list_next(entry); 1700 if (next != NULL) { 1701 entry = next; 1702 ++idx; 1703 } 1704 } 1705 1706 list->page = entry; 1707 list->page_idx = idx; 1708 } 1709 1654 1710 /** @} 1655 1711 */ -
uspace/lib/ui/src/msgdialog.c
radbd7e1 raefdccd 285 285 if (dialog->cb != NULL && dialog->cb->close != NULL) 286 286 dialog->cb->close(dialog, dialog->arg); 287 else 288 ui_msg_dialog_destroy(dialog); 287 289 } 288 290 … … 310 312 dialog->cb->button(dialog, dialog->arg, 0); 311 313 return; 314 } else { 315 ui_msg_dialog_destroy(dialog); 312 316 } 313 317 } else if (event->key == KC_ESCAPE) { … … 316 320 dialog->cb->close(dialog, dialog->arg); 317 321 return; 322 } else { 323 ui_msg_dialog_destroy(dialog); 318 324 } 319 325 } … … 337 343 dialog->cb->button(dialog, dialog->arg, i); 338 344 } 345 } else { 346 ui_msg_dialog_destroy(dialog); 339 347 } 340 348 } -
uspace/lib/ui/src/ui.c
radbd7e1 raefdccd 412 412 errno_t rc; 413 413 gfx_context_t *gc; 414 ui_window_t * awnd;414 ui_window_t *wnd; 415 415 gfx_color_t *color = NULL; 416 416 … … 439 439 gfx_color_delete(color); 440 440 441 /* XXX Should repaint all windows */ 442 awnd = ui_window_get_active(ui); 443 if (awnd == NULL) 444 return EOK; 445 446 rc = ui_wdecor_paint(awnd->wdecor); 447 if (rc != EOK) 448 return rc; 449 450 return ui_window_paint(awnd); 441 /* Repaint all windows */ 442 wnd = ui_window_first(ui); 443 while (wnd != NULL) { 444 rc = ui_wdecor_paint(wnd->wdecor); 445 if (rc != EOK) 446 return rc; 447 448 rc = ui_window_paint(wnd); 449 if (rc != EOK) 450 return rc; 451 452 wnd = ui_window_next(wnd); 453 } 454 455 return EOK; 451 456 } 452 457 -
uspace/lib/ui/src/window.c
radbd7e1 raefdccd 617 617 } 618 618 619 /** Get first (lowermost) window (only valid in fullscreen mode). 620 * 621 * @param ui User interface 622 * @return First window 623 */ 624 ui_window_t *ui_window_first(ui_t *ui) 625 { 626 link_t *link; 627 628 link = list_first(&ui->windows); 629 if (link == NULL) 630 return NULL; 631 632 return list_get_instance(link, ui_window_t, lwindows); 633 } 634 635 /** Get next window (only valid in fullscreen mode). 636 * 637 * @param cur Current window 638 * @return First window 639 */ 640 ui_window_t *ui_window_next(ui_window_t *cur) 641 { 642 link_t *link; 643 644 link = list_next(&cur->lwindows, &cur->ui->windows); 645 if (link == NULL) 646 return NULL; 647 648 return list_get_instance(link, ui_window_t, lwindows); 649 } 650 619 651 /** Get active window (only valid in fullscreen mode). 620 652 * -
uspace/lib/ui/test/filelist.c
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 665 665 } 666 666 667 /** ui_file_list_refresh() */ 668 PCUT_TEST(refresh) 669 { 670 ui_t *ui; 671 ui_window_t *window; 672 ui_wnd_params_t params; 673 ui_file_list_t *flist; 674 ui_file_list_entry_t *entry; 675 char buf[L_tmpnam]; 676 char *fname; 677 char *p; 678 errno_t rc; 679 FILE *f; 680 int rv; 681 682 /* Create name for temporary directory */ 683 p = tmpnam(buf); 684 PCUT_ASSERT_NOT_NULL(p); 685 686 /* Create temporary directory */ 687 rc = vfs_link_path(p, KIND_DIRECTORY, NULL); 688 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 689 690 rv = asprintf(&fname, "%s/%s", p, "a"); 691 PCUT_ASSERT_TRUE(rv >= 0); 692 693 f = fopen(fname, "wb"); 694 PCUT_ASSERT_NOT_NULL(f); 695 696 rv = fprintf(f, "X"); 697 PCUT_ASSERT_TRUE(rv >= 0); 698 699 rv = fclose(f); 700 PCUT_ASSERT_INT_EQUALS(0, rv); 701 702 rc = ui_create_disp(NULL, &ui); 703 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 704 705 ui_wnd_params_init(¶ms); 706 params.caption = "Test"; 707 708 rc = ui_window_create(ui, ¶ms, &window); 709 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 710 711 rc = ui_file_list_create(window, true, &flist); 712 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 713 714 rc = ui_file_list_read_dir(flist, p); 715 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 716 717 PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list)); 718 719 entry = ui_file_list_first(flist); 720 PCUT_ASSERT_NOT_NULL(entry); 721 PCUT_ASSERT_STR_EQUALS("..", entry->name); 722 723 entry = ui_file_list_next(entry); 724 PCUT_ASSERT_NOT_NULL(entry); 725 PCUT_ASSERT_STR_EQUALS("a", entry->name); 726 PCUT_ASSERT_INT_EQUALS(1, entry->size); 727 728 rv = remove(fname); 729 PCUT_ASSERT_INT_EQUALS(0, rv); 730 free(fname); 731 732 rv = asprintf(&fname, "%s/%s", p, "b"); 733 PCUT_ASSERT_TRUE(rv >= 0); 734 735 f = fopen(fname, "wb"); 736 PCUT_ASSERT_NOT_NULL(f); 737 738 rv = fprintf(f, "X"); 739 PCUT_ASSERT_TRUE(rv >= 0); 740 741 rv = fclose(f); 742 PCUT_ASSERT_INT_EQUALS(0, rv); 743 744 rc = ui_file_list_refresh(flist); 745 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 746 747 entry = ui_file_list_first(flist); 748 PCUT_ASSERT_NOT_NULL(entry); 749 PCUT_ASSERT_STR_EQUALS("..", entry->name); 750 751 entry = ui_file_list_next(entry); 752 PCUT_ASSERT_NOT_NULL(entry); 753 PCUT_ASSERT_STR_EQUALS("b", entry->name); 754 PCUT_ASSERT_INT_EQUALS(1, entry->size); 755 756 rv = remove(fname); 757 PCUT_ASSERT_INT_EQUALS(0, rv); 758 free(fname); 759 760 rv = remove(p); 761 PCUT_ASSERT_INT_EQUALS(0, rv); 762 763 ui_file_list_destroy(flist); 764 765 ui_window_destroy(window); 766 ui_destroy(ui); 767 } 768 667 769 /** ui_file_list_list_compare compares two file list entries */ 668 770 PCUT_TEST(list_compare) -
uspace/lib/ui/test/list.c
radbd7e1 raefdccd 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 3064 3064 } 3065 3065 3066 /** ui_list_save_pos() / ui_list_restore_pos() saves/restores position */ 3067 PCUT_TEST(save_pos_restore_pos) 3068 { 3069 ui_t *ui; 3070 ui_window_t *window; 3071 ui_wnd_params_t params; 3072 ui_list_t *list; 3073 ui_list_entry_t *a, *b; 3074 ui_list_entry_attr_t attr; 3075 ui_list_pos_t pos; 3076 test_resp_t resp; 3077 errno_t rc; 3078 3079 rc = ui_create_disp(NULL, &ui); 3080 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3081 3082 ui_wnd_params_init(¶ms); 3083 params.caption = "Test"; 3084 3085 rc = ui_window_create(ui, ¶ms, &window); 3086 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3087 3088 rc = ui_list_create(window, true, &list); 3089 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3090 3091 ui_list_set_cb(list, &test_cb, &resp); 3092 3093 ui_list_entry_attr_init(&attr); 3094 3095 attr.caption = "a"; 3096 attr.arg = (void *)2; 3097 rc = ui_list_entry_append(list, &attr, &a); 3098 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3099 3100 attr.caption = "b"; 3101 attr.arg = (void *)1; 3102 rc = ui_list_entry_append(list, &attr, &b); 3103 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3104 3105 ui_list_set_cursor(list, b); 3106 3107 ui_list_save_pos(list, &pos); 3108 3109 /* Empty and re-build list. */ 3110 3111 ui_list_entry_destroy(a); 3112 ui_list_entry_destroy(b); 3113 3114 ui_list_entry_attr_init(&attr); 3115 3116 attr.caption = "a"; 3117 attr.arg = (void *)2; 3118 rc = ui_list_entry_append(list, &attr, &a); 3119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3120 3121 attr.caption = "b"; 3122 attr.arg = (void *)1; 3123 rc = ui_list_entry_append(list, &attr, &b); 3124 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3125 3126 ui_list_restore_pos(list, &pos); 3127 3128 PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption); 3129 3130 ui_list_destroy(list); 3131 ui_window_destroy(window); 3132 ui_destroy(ui); 3133 } 3134 3066 3135 static void test_list_activate_req(ui_list_t *list, void *arg) 3067 3136 {
Note:
See TracChangeset
for help on using the changeset viewer.
