Changeset 7bf29e5 in mainline for uspace/lib
- Timestamp:
- 2025-01-09T11:29:38Z (7 months ago)
- Children:
- a5c2960e
- Parents:
- bc3d695 (diff), 4e1221c (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. - Location:
- uspace/lib
- Files:
-
- 18 added
- 48 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/abs32le/include/libarch/thread.h
rbc3d695 r7bf29e5 36 36 #define _LIBC_abs32le_THREAD_H_ 37 37 38 #include <align.h> 39 40 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 41 void (*main)(void *), void *arg) 42 { 43 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size, 16); 44 45 sp[-1] = (uintptr_t) arg; 46 sp[-2] = (uintptr_t) main; 47 48 return (uintptr_t) sp; 49 } 50 38 51 #endif 39 52 -
uspace/lib/c/arch/abs32le/src/thread_entry.c
rbc3d695 r7bf29e5 30 30 */ 31 31 32 #include <stdbool.h> 32 33 #include <stddef.h> 33 34 #include "../../../generic/private/thread.h" … … 35 36 void __thread_entry(void) 36 37 { 37 __thread_main(NULL); 38 while (true) 39 ; 38 40 } 39 41 -
uspace/lib/c/arch/amd64/include/libarch/thread.h
rbc3d695 r7bf29e5 36 36 #define _LIBC_amd64_THREAD_H_ 37 37 38 #include <align.h> 39 #include <stddef.h> 40 #include <stdint.h> 41 42 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 43 void (*main)(void *), void *arg) 44 { 45 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size, 16); 46 47 *--sp = (uintptr_t) arg; 48 *--sp = (uintptr_t) main; 49 50 return (uintptr_t) sp; 51 } 52 38 53 #endif 39 54 -
uspace/lib/c/arch/amd64/src/thread_entry.S
rbc3d695 r7bf29e5 35 35 # 36 36 SYMBOL_BEGIN(__thread_entry) 37 # Pop libc thread entry function and argument 38 popq %rax 39 popq %rdi 40 37 41 # 38 42 # Create the first stack frame. … … 42 46 movq %rsp, %rbp 43 47 44 # 45 # RAX contains address of uarg 46 # 47 movq %rax, %rdi 48 call FUNCTION_REF(__thread_main) 48 call *%rax 49 49 SYMBOL_END(__thread_entry) -
uspace/lib/c/arch/arm32/include/libarch/thread.h
rbc3d695 r7bf29e5 37 37 #define _LIBC_arm32_THREAD_H_ 38 38 39 #include <align.h> 40 41 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 42 void (*main)(void *), void *arg) 43 { 44 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size, 16); 45 46 *--sp = (uintptr_t) main; 47 *--sp = (uintptr_t) arg; 48 49 return (uintptr_t) sp; 50 } 51 39 52 #endif 40 53 -
uspace/lib/c/arch/arm32/src/thread_entry.S
rbc3d695 r7bf29e5 35 35 # 36 36 SYMBOL(__thread_entry) 37 # Pop libc entry function and its argument. 38 pop { r0, r4 } 39 37 40 # 38 41 # Create the first stack frame. … … 43 46 sub fp, ip, #4 44 47 45 b __thread_main48 bx r4 -
uspace/lib/c/arch/arm64/include/libarch/thread.h
rbc3d695 r7bf29e5 36 36 #define _LIBC_arm64_THREAD_H_ 37 37 38 #include <align.h> 39 40 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 41 void (*main)(void *), void *arg) 42 { 43 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size, 16); 44 45 *--sp = (uintptr_t) arg; 46 *--sp = (uintptr_t) main; 47 48 return (uintptr_t) sp; 49 } 50 38 51 #endif 39 52 -
uspace/lib/c/arch/arm64/src/thread_entry.S
rbc3d695 r7bf29e5 35 35 # 36 36 SYMBOL(__thread_entry) 37 # 37 # Load entry function and argument from stack. 38 ldp x1, x0, [sp], #16 39 38 40 # Create the first stack frame. 39 #40 41 mov x29, #0 41 42 stp x29, x30, [sp, #-16]! 42 43 mov x29, sp 43 44 44 b __thread_main45 br x1 -
uspace/lib/c/arch/ia32/include/libarch/thread.h
rbc3d695 r7bf29e5 36 36 #define _LIBC_ia32_THREAD_H_ 37 37 38 #include <align.h> 39 #include <stddef.h> 40 #include <stdint.h> 41 42 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 43 void (*main)(void *), void *arg) 44 { 45 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size, 16); 46 47 *--sp = (uintptr_t) arg; 48 *--sp = (uintptr_t) main; 49 50 return (uintptr_t) sp; 51 } 52 38 53 #endif 39 54 -
uspace/lib/c/arch/ia32/src/syscall.S
rbc3d695 r7bf29e5 77 77 pushl %ebp 78 78 mov %esp, %ebp 79 lea ra, %edi80 79 movl 20(%esp), %edx # First argument. 81 80 movl 24(%esp), %ecx # Second argument. … … 83 82 movl 32(%esp), %esi # Fourth argument. 84 83 movl 44(%esp), %eax # Syscall number. 85 sysenter 86 ra: 84 call 1f 87 85 movw %cs, %cx 88 86 addw $8, %cx … … 95 93 popl %ebx 96 94 ret 95 96 /* Trampoline for entering kernel */ 97 1: 98 pop %edi 99 sysenter 97 100 FUNCTION_END(__syscall_fast) -
uspace/lib/c/arch/ia32/src/thread_entry.S
rbc3d695 r7bf29e5 41 41 # Do not set %gs, it contains descriptor that can see TLS 42 42 43 # Pop libc thread main function. 44 popl %eax 45 # Pop argument. 46 popl %ebx 47 43 48 # 44 49 # Create the first stack frame. … … 48 53 mov %esp, %ebp 49 54 50 # 51 # EAX contains address of uarg. 52 # 53 pushl %eax 54 call __thread_main 55 pushl %ebx 56 call *%eax 55 57 56 58 # -
uspace/lib/c/arch/ia64/include/libarch/thread.h
rbc3d695 r7bf29e5 36 36 #define _LIBC_ia64_THREAD_H_ 37 37 38 #include <align.h> 39 40 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 41 void (*main)(void *), void *arg) 42 { 43 uintptr_t *sp = (uintptr_t *) (ALIGN_DOWN((uintptr_t) stack + stack_size / 2, 16)); 44 45 /* Store data under stack pointer */ 46 sp[-1] = (uintptr_t) arg; 47 sp[-2] = (uintptr_t) main; 48 49 return (uintptr_t) sp; 50 } 51 38 52 #endif 39 53 -
uspace/lib/c/arch/ia64/src/thread_entry.S
rbc3d695 r7bf29e5 37 37 alloc loc0 = ar.pfs, 0, 1, 1, 0 38 38 39 #ifndef CONFIG_RTLD 40 # XXX This does not work in a shared library 41 movl gp = __gp 42 #endif 39 add r8 = -8, sp ;; 40 # Entry function argument 41 ld8 out0 = [r8], -8 ;; 43 42 44 # 45 # r8 contains address of uarg structure. 46 # 43 # Entry function descriptor 44 ld8 r8 = [r8] ;; 45 # Entry function address 46 ld8 r9 = [r8], 8 ;; 47 # Entry function global pointer 48 ld8 gp = [r8] ;; 47 49 48 mov out0 = r8;;49 # XXX br.call.sptk.many b0 = FUNCTION_REF(__thread_main) 50 br.call.sptk.many b0 = __thread_main50 mov b1 = r9 ;; 51 52 br.call.sptk.many b0 = b1 ;; 51 53 52 54 # -
uspace/lib/c/arch/mips32/include/libarch/thread.h
rbc3d695 r7bf29e5 37 37 #define _LIBC_mips32_THREAD_H_ 38 38 39 #include <align.h> 40 41 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 42 void (*main)(void *), void *arg) 43 { 44 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size, 16); 45 46 sp[-1] = (uintptr_t) arg; 47 sp[-2] = (uintptr_t) main; 48 49 return (uintptr_t) sp; 50 } 51 39 52 #endif 40 53 -
uspace/lib/c/arch/mips32/src/thread_entry.S
rbc3d695 r7bf29e5 40 40 # 41 41 SYMBOL(__thread_entry) 42 .ent __thread_entry 43 .frame $sp, ABI_STACK_FRAME, $ra 44 .cpload $t9 42 # All registers should be zero, including $fp and $ra. 43 # Instead of setting up a stack frame here, we leave it for __thread_main. 45 44 46 # 47 # v0 contains address of uarg.48 # 49 add $a0, $v0, 045 # Function argument. 46 lw $a0, -4($sp) 47 # Function pointer. 48 lw $t0, -8($sp) 50 49 51 # Allocate the stack frame. 52 addiu $sp, -ABI_STACK_FRAME 53 54 # Allow PIC code 55 .cprestore 16 56 57 jal __thread_main 50 j $t0 58 51 nop 59 60 #61 # Not reached.62 #63 addiu $sp, ABI_STACK_FRAME64 .end __thread_entry -
uspace/lib/c/arch/ppc32/include/libarch/thread.h
rbc3d695 r7bf29e5 36 36 #define _LIBC_ppc32_THREAD_H_ 37 37 38 #include <align.h> 39 40 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 41 void (*main)(void *), void *arg) 42 { 43 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size - sizeof(void *), 16); 44 45 sp[0] = 0; 46 sp[-1] = (uintptr_t) arg; 47 sp[-2] = (uintptr_t) main; 48 49 return (uintptr_t) sp; 50 } 51 38 52 #endif 39 53 -
uspace/lib/c/arch/ppc32/src/thread_entry.S
rbc3d695 r7bf29e5 35 35 # 36 36 SYMBOL(__thread_entry) 37 # 38 # Create the first stack frame. 39 # 40 li %r4, 0 41 stw %r4, 0(%r1) 42 stwu %r1, -16(%r1) 37 # Load function and argument. 38 lwz %r3, -4(%r1) 39 lwz %r4, -8(%r1) 43 40 44 b __thread_main 41 # Clear LR 42 li %r0, 0 43 mtlr %r0 45 44 45 mtctr %r4 46 bctr -
uspace/lib/c/arch/riscv64/include/libarch/thread.h
rbc3d695 r7bf29e5 36 36 #define _LIBC_riscv64_THREAD_H_ 37 37 38 #include <align.h> 39 40 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 41 void (*main)(void *), void *arg) 42 { 43 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size, 16); 44 45 sp[-1] = (uintptr_t) arg; 46 sp[-2] = (uintptr_t) main; 47 48 return (uintptr_t) sp; 49 } 50 38 51 #endif 39 52 -
uspace/lib/c/arch/riscv64/src/thread_entry.c
rbc3d695 r7bf29e5 35 35 void __thread_entry(void) 36 36 { 37 __thread_main((void *) 0); 37 // TODO 38 while (true) 39 ; 38 40 } 39 41 -
uspace/lib/c/arch/sparc64/include/libarch/thread.h
rbc3d695 r7bf29e5 35 35 #define _LIBC_sparc64_THREAD_H_ 36 36 37 #include <assert.h> 38 #include <align.h> 39 #include <libarch/stack.h> 40 41 static inline uintptr_t arch_thread_prepare(void *stack, size_t stack_size, 42 void (*main)(void *), void *arg) 43 { 44 /* We must leave space above the stack pointer for initial register spill area. */ 45 uintptr_t *sp = (uintptr_t *) ALIGN_DOWN((uintptr_t) stack + stack_size - STACK_WINDOW_SAVE_AREA_SIZE - STACK_ARG_SAVE_AREA_SIZE, 16); 46 47 sp[-1] = (uintptr_t) arg; 48 sp[-2] = (uintptr_t) main; 49 50 return ((uintptr_t) sp) - STACK_BIAS; 51 } 52 37 53 #endif 38 54 -
uspace/lib/c/arch/sparc64/src/thread_entry.S
rbc3d695 r7bf29e5 35 35 # 36 36 SYMBOL(__thread_entry) 37 add %sp, 0x7ff, %g1 38 37 39 # 38 40 # Create the first stack frame. … … 43 45 44 46 # 45 # Propagate the input arguments to the new window.47 # Load libc entry point address and argument from stack 46 48 # 49 ldn [%g1 - 8], %o0 50 ldn [%g1 - 16], %g1 47 51 48 call __thread_main ! %o0 contains address of uarg 49 mov %i0, %o0 52 jmpl %g1, %r0 53 # Wipe link register 54 xor %o7, %o7, %o7 50 55 51 56 ! not reached -
uspace/lib/c/generic/malloc.c
rbc3d695 r7bf29e5 38 38 #include <stdbool.h> 39 39 #include <stddef.h> 40 #include <stdio.h> 40 41 #include <as.h> 41 42 #include <align.h> … … 725 726 * 726 727 */ 727 static void *malloc_internal( const size_t size, constsize_t align)728 static void *malloc_internal(size_t size, size_t align) 728 729 { 729 730 malloc_assert(first_heap_area != NULL); 730 731 732 if (size == 0) 733 size = 1; 734 731 735 if (align == 0) 732 return NULL;736 align = BASE_ALIGN; 733 737 734 738 size_t falign = lcm(align, BASE_ALIGN); … … 821 825 * 822 826 */ 823 void *realloc(void *const addr, constsize_t size)827 void *realloc(void *const addr, size_t size) 824 828 { 825 829 if (size == 0) { 826 f ree(addr);827 return NULL;830 fprintf(stderr, "realloc() called with size 0\n"); 831 size = 1; 828 832 } 829 833 … … 930 934 } 931 935 936 /** Reallocate memory for an array 937 * 938 * Same as realloc(ptr, nelem * elsize), except the multiplication is checked 939 * for numerical overflow. Borrowed from POSIX 2024. 940 * 941 * @param ptr 942 * @param nelem 943 * @param elsize 944 * 945 * @return Reallocated memory or NULL. 946 */ 947 void *reallocarray(void *ptr, size_t nelem, size_t elsize) 948 { 949 if (nelem > SIZE_MAX / elsize) 950 return NULL; 951 952 return realloc(ptr, nelem * elsize); 953 } 954 932 955 /** Free a memory block 933 956 * -
uspace/lib/c/generic/private/fibril.h
rbc3d695 r7bf29e5 33 33 #include <context.h> 34 34 #include <tls.h> 35 #include <abi/proc/uarg.h>36 35 #include <fibril.h> 37 36 #include <ipc/common.h> … … 50 49 context_t ctx; 51 50 52 uspace_arg_t uarg;53 51 link_t link; 54 52 void *stack; -
uspace/lib/c/generic/private/thread.h
rbc3d695 r7bf29e5 37 37 38 38 #include <time.h> 39 #include <abi/proc/uarg.h>40 39 #include <libarch/thread.h> 41 40 #include <abi/proc/thread.h> 42 41 43 42 extern void __thread_entry(void); 44 extern void __thread_main(uspace_arg_t *);45 43 46 extern errno_t thread_create(void (*)(void *), void *, const char *, 47 thread_id_t *); 44 extern errno_t thread_create(errno_t (*)(void *), void *, const char *); 48 45 extern void thread_exit(int) __attribute__((noreturn)); 49 extern void thread_detach(thread_id_t);50 46 extern thread_id_t thread_get_id(void); 51 47 extern void thread_usleep(usec_t); -
uspace/lib/c/generic/thread/fibril.c
rbc3d695 r7bf29e5 781 781 } 782 782 783 static void_runner_fn(void *arg)783 static errno_t _runner_fn(void *arg) 784 784 { 785 785 _helper_fibril_fn(arg); 786 return EOK; 786 787 } 787 788 … … 808 809 809 810 for (int i = 0; i < n; i++) { 810 thread_id_t tid; 811 rc = thread_create(_runner_fn, NULL, "fibril runner", &tid); 811 rc = thread_create(_runner_fn, NULL, "fibril runner"); 812 812 if (rc != EOK) 813 813 return i; 814 thread_detach(tid);815 814 } 816 815 -
uspace/lib/c/generic/thread/thread.c
rbc3d695 r7bf29e5 37 37 #include <stdlib.h> 38 38 #include <libarch/faddr.h> 39 #include <abi/proc/uarg.h>40 39 #include <fibril.h> 41 40 #include <stack.h> … … 54 53 * and exit when thread returns back. 55 54 * 56 * @param uarg Pointer to userspace argument structure.55 * @param arg Fibril pointer. 57 56 * 58 57 */ 59 void __thread_main(uspace_arg_t *uarg)58 static void __thread_main(void *arg) 60 59 { 60 fibril_t *fibril = arg; 61 61 62 assert(!__tcb_is_set()); 62 63 fibril_t *fibril = uarg->uspace_thread_arg;64 63 assert(fibril); 65 64 66 65 __tcb_set(fibril->tcb); 67 66 68 uarg->uspace_thread_function(fibril->arg);67 fibril->func(fibril->arg); 69 68 /* 70 69 * XXX: we cannot free the userspace stack while running on it … … 90 89 * @return Zero on success or a code from @ref errno.h on failure. 91 90 */ 92 errno_t thread_create(void (*function)(void *), void *arg, const char *name, 93 thread_id_t *tid) 91 errno_t thread_create(errno_t (*func)(void *), void *arg, const char *name) 94 92 { 95 uspace_arg_t *uarg = calloc(1, sizeof(uspace_arg_t));96 if (! uarg)93 fibril_t *fibril = fibril_alloc(); 94 if (!fibril) 97 95 return ENOMEM; 98 96 99 fibril_t *fibril = fibril_alloc(); 100 if (!fibril) { 101 free(uarg); 102 return ENOMEM; 103 } 97 fibril->func = func; 98 fibril->arg = arg; 104 99 105 100 size_t stack_size = stack_size_get(); … … 109 104 if (stack == AS_MAP_FAILED) { 110 105 fibril_teardown(fibril); 111 free(uarg);112 106 return ENOMEM; 113 107 } 114 108 115 fibril->arg = arg; 116 uarg->uspace_entry = (void *) FADDR(__thread_entry); 117 uarg->uspace_stack = stack; 118 uarg->uspace_stack_size = stack_size; 119 uarg->uspace_thread_function = function; 120 uarg->uspace_thread_arg = fibril; 121 uarg->uspace_uarg = uarg; 109 uintptr_t sp = arch_thread_prepare(stack, stack_size, __thread_main, 110 fibril); 122 111 123 errno_t rc = (errno_t) __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg, 124 (sysarg_t) name, (sysarg_t) str_size(name), (sysarg_t) tid); 112 errno_t rc = (errno_t) __SYSCALL4(SYS_THREAD_CREATE, 113 (sysarg_t) FADDR(__thread_entry), sp, 114 (sysarg_t) name, (sysarg_t) str_size(name)); 125 115 126 116 if (rc != EOK) { … … 130 120 */ 131 121 as_area_destroy(stack); 132 free(uarg);133 122 } 134 123 … … 148 137 while (true) 149 138 ; 150 }151 152 /** Detach thread.153 *154 * Currently not implemented.155 *156 * @param thread TID.157 */158 void thread_detach(thread_id_t thread)159 {160 139 } 161 140 -
uspace/lib/c/include/align.h
rbc3d695 r7bf29e5 41 41 * @param a Size of alignment, must be power of 2. 42 42 */ 43 #define ALIGN_DOWN(s, a) ((s) & ~(( a) - 1))43 #define ALIGN_DOWN(s, a) ((s) & ~((typeof(s))(a) - 1)) 44 44 45 45 /** Align to the nearest higher address which is a power of two. … … 48 48 * @param a Size of alignment, must be power of 2. 49 49 */ 50 #define ALIGN_UP(s, a) (( long)((s) + ((a) - 1)) & ~((long) (a) - 1))50 #define ALIGN_UP(s, a) ((((s) + ((a) - 1)) & ~((typeof(s))(a) - 1))) 51 51 52 52 /** Round up to the nearest higher boundary. -
uspace/lib/c/meson.build
rbc3d695 r7bf29e5 59 59 60 60 src += files( 61 'common/adt/bitmap.c', 61 62 'common/adt/checksum.c', 62 63 'common/adt/circ_buf.c', -
uspace/lib/c/test/double_to_str.c
rbc3d695 r7bf29e5 176 176 PCUT_ASSERT_INT_EQUALS(-3, dec); 177 177 PCUT_ASSERT_STR_EQUALS("1100", buf); 178 179 d = extract_ieee_double(768.0); 180 ret = double_to_fixed_str(d, -1, 3, buf, size, &dec); 181 PCUT_ASSERT_INT_EQUALS(4, ret); 182 PCUT_ASSERT_INT_EQUALS(-3, dec); 183 PCUT_ASSERT_STR_EQUALS("768", buf); 178 184 } 179 185 -
uspace/lib/clui/src/tinput.c
rbc3d695 r7bf29e5 113 113 static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad) 114 114 { 115 char32_t *dbuf = malloc((INPUT_MAX_SIZE + 1) * sizeof(char32_t)); 116 if (!dbuf) 117 return; 118 115 char32_t stash; 119 116 size_t sa; 120 117 size_t sb; 121 118 tinput_sel_get_bounds(ti, &sa, &sb); 119 assert(sa <= sb); 122 120 123 121 tinput_console_set_lpos(ti, ti->text_coord + start); 124 122 console_set_style(ti->console, STYLE_NORMAL); 125 123 126 size_t p = start; 127 if (p < sa) { 128 memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(char32_t)); 129 dbuf[sa - p] = '\0'; 130 printf("%ls", dbuf); 131 p = sa; 132 } 133 134 if (p < sb) { 124 sa = max(start, sa); 125 sb = max(start, sb); 126 127 if (start < sa) { 128 stash = ti->buffer[sa]; 129 ti->buffer[sa] = L'\0'; 130 printf("%ls", &ti->buffer[start]); 131 ti->buffer[sa] = stash; 132 } 133 134 if (sa < sb) { 135 135 console_flush(ti->console); 136 136 console_set_style(ti->console, STYLE_SELECTED); 137 137 138 memcpy(dbuf, ti->buffer + p, 139 (sb - p) * sizeof(char32_t)); 140 dbuf[sb - p] = '\0'; 141 printf("%ls", dbuf); 142 p = sb; 143 } 138 stash = ti->buffer[sb]; 139 ti->buffer[sb] = L'\0'; 140 printf("%ls", &ti->buffer[sa]); 141 ti->buffer[sb] = stash; 142 143 console_flush(ti->console); 144 console_set_style(ti->console, STYLE_NORMAL); 145 } 146 147 if (sb < ti->nc) { 148 ti->buffer[ti->nc] = L'\0'; 149 printf("%ls", &ti->buffer[sb]); 150 } 151 152 for (; pad > 0; pad--) 153 putuchar(' '); 144 154 145 155 console_flush(ti->console); 146 console_set_style(ti->console, STYLE_NORMAL);147 148 if (p < ti->nc) {149 memcpy(dbuf, ti->buffer + p,150 (ti->nc - p) * sizeof(char32_t));151 dbuf[ti->nc - p] = '\0';152 printf("%ls", dbuf);153 }154 155 for (p = 0; p < pad; p++)156 putuchar(' ');157 158 console_flush(ti->console);159 160 free(dbuf);161 156 } 162 157 … … 218 213 tinput_display_prompt(ti); 219 214 220 /* The screen might have scrolled after pri ting the prompt */215 /* The screen might have scrolled after printing the prompt */ 221 216 tinput_update_origin_coord(ti, ti->prompt_coord + str_width(ti->prompt)); 222 217 … … 237 232 return; 238 233 239 unsigned new_width = LIN_TO_COL(ti, ti->text_coord) + ti->nc + 1; 240 if (new_width % ti->con_cols == 0) { 241 /* Advancing to new line. */ 242 sysarg_t new_height = (new_width / ti->con_cols) + 1; 243 if (new_height >= ti->con_rows) { 244 /* Disallow text longer than 1 page for now. */ 245 return; 246 } 247 } 234 /* Disallow text longer than 1 page for now. */ 235 unsigned prompt_len = ti->text_coord - ti->prompt_coord; 236 if (prompt_len + ti->nc + 1 >= ti->con_cols * ti->con_rows) 237 return; 248 238 249 239 size_t i; … … 881 871 } 882 872 873 static errno_t tinput_resize(tinput_t *ti) 874 { 875 assert(ti->prompt_coord % ti->con_cols == 0); 876 877 errno_t rc = console_get_size(ti->console, &ti->con_cols, &ti->con_rows); 878 if (rc != EOK) 879 return rc; 880 881 sysarg_t col, row; 882 rc = console_get_pos(ti->console, &col, &row); 883 if (rc != EOK) 884 return rc; 885 886 assert(ti->prompt_coord <= ti->text_coord); 887 unsigned prompt_len = ti->text_coord - ti->prompt_coord; 888 889 size_t new_caret_coord = row * ti->con_cols + col; 890 891 if (prompt_len <= new_caret_coord && ti->pos <= new_caret_coord - prompt_len) { 892 ti->text_coord = new_caret_coord - ti->pos; 893 ti->prompt_coord = ti->text_coord - prompt_len; 894 895 unsigned prompt_col = ti->prompt_coord % ti->con_cols; 896 if (prompt_col != 0) { 897 /* 898 * Prompt doesn't seem to start at column 0, which means 899 * the console didn't reflow the line like we expected it to. 900 * Change offsets a bit to recover. 901 */ 902 fprintf(stderr, "Unexpected prompt position after resize.\n"); 903 ti->prompt_coord -= prompt_col; 904 ti->text_coord -= prompt_col; 905 906 console_cursor_visibility(ti->console, false); 907 tinput_display_prompt(ti); 908 tinput_display_tail(ti, 0, prompt_col); 909 tinput_position_caret(ti); 910 console_cursor_visibility(ti->console, true); 911 } 912 913 assert(ti->prompt_coord % ti->con_cols == 0); 914 } else { 915 /* 916 * Overflown screen. 917 * We will just trim the buffer and rewrite everything. 918 */ 919 console_clear(ti->console); 920 921 ti->nc = min(ti->nc, ti->con_cols * ti->con_rows - prompt_len - 1); 922 ti->pos = min(ti->pos, ti->nc); 923 ti->sel_start = min(ti->sel_start, ti->nc); 924 925 ti->prompt_coord = 0; 926 ti->text_coord = prompt_len; 927 928 console_cursor_visibility(ti->console, false); 929 tinput_display_prompt(ti); 930 tinput_display_tail(ti, 0, 0); 931 tinput_position_caret(ti); 932 console_cursor_visibility(ti->console, true); 933 } 934 935 assert(ti->nc + ti->text_coord < ti->con_cols * ti->con_rows); 936 937 return EOK; 938 } 939 883 940 /** Read in one line of input with initial text provided. 884 941 * … … 927 984 tinput_pos(ti, &ev.ev.pos); 928 985 break; 986 case CEV_RESIZE: 987 tinput_resize(ti); 988 break; 929 989 } 930 990 } -
uspace/lib/console/include/io/cons_event.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define _LIBCONSOLE_IO_CONS_EVENT_H_ 37 37 38 #include <adt/list.h>39 38 #include <io/kbd_event.h> 40 39 #include <io/pos_event.h> … … 44 43 CEV_KEY, 45 44 /** Position event */ 46 CEV_POS 45 CEV_POS, 46 /** Resize event */ 47 CEV_RESIZE, 47 48 } cons_event_type_t; 48 49 49 50 /** Console event structure. */ 50 51 typedef struct { 51 /** List handle */52 link_t link;53 54 52 /** Event type */ 55 53 cons_event_type_t type; -
uspace/lib/console/src/con_srv.c
rbc3d695 r7bf29e5 53 53 ipc_set_arg4(icall, event->ev.key.mods); 54 54 ipc_set_arg5(icall, event->ev.key.c); 55 break;55 return EOK; 56 56 case CEV_POS: 57 57 ipc_set_arg2(icall, (event->ev.pos.pos_id << 16) | (event->ev.pos.type & 0xffff)); … … 59 59 ipc_set_arg4(icall, event->ev.pos.hpos); 60 60 ipc_set_arg5(icall, event->ev.pos.vpos); 61 break; 62 default: 63 return EIO; 64 } 65 66 return EOK; 61 return EOK; 62 case CEV_RESIZE: 63 ipc_set_arg2(icall, 0); 64 ipc_set_arg3(icall, 0); 65 ipc_set_arg4(icall, 0); 66 ipc_set_arg5(icall, 0); 67 return EOK; 68 } 69 70 return EIO; 67 71 } 68 72 … … 462 466 } 463 467 464 if (!received )468 if (!received || srv->srvs->aborted) 465 469 break; 466 470 -
uspace/lib/console/src/console.c
rbc3d695 r7bf29e5 193 193 event->ev.key.mods = ipc_get_arg4(call); 194 194 event->ev.key.c = ipc_get_arg5(call); 195 break;195 return EOK; 196 196 case CEV_POS: 197 197 event->ev.pos.pos_id = ipc_get_arg2(call) >> 16; … … 200 200 event->ev.pos.hpos = ipc_get_arg4(call); 201 201 event->ev.pos.vpos = ipc_get_arg5(call); 202 break;203 default:204 return E IO;205 } 206 207 return E OK;202 return EOK; 203 case CEV_RESIZE: 204 return EOK; 205 } 206 207 return EIO; 208 208 } 209 209 -
uspace/lib/display/include/display.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 extern errno_t display_open(const char *, display_t **); 49 49 extern void display_close(display_t *); 50 extern void display_lock(display_t *); 51 extern void display_unlock(display_t *); 50 52 extern errno_t display_get_info(display_t *, display_info_t *); 51 53 -
uspace/lib/display/include/types/display/wndparams.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 /** Popup window (capture events, no focus) */ 43 43 wndf_popup = 0x1, 44 /** Window does not receive focus */ 45 wndf_nofocus = 0x2, 44 46 /** Topmost window */ 45 wndf_topmost = 0x 2,47 wndf_topmost = 0x4, 46 48 /** Set specific initial window position */ 47 wndf_setpos = 0x 4,49 wndf_setpos = 0x8, 48 50 /** Window is minimized */ 49 wndf_minimized = 0x 8,51 wndf_minimized = 0x10, 50 52 /** Window is maximized */ 51 wndf_maximized = 0x 10,53 wndf_maximized = 0x20, 52 54 /** Special system window */ 53 wndf_system = 0x 20,55 wndf_system = 0x40, 54 56 /** Maximized windows should avoid this window */ 55 wndf_avoid = 0x 4057 wndf_avoid = 0x80 56 58 } display_wnd_flags_t; 57 59 -
uspace/lib/display/src/display.c
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 138 138 } 139 139 140 /* 141 * Lock display. 142 * 143 * While display is locked, display event handlers will not be called. 144 * 145 * @param display Display 146 */ 147 void display_lock(display_t *display) 148 { 149 fibril_mutex_lock(&display->lock); 150 } 151 152 /* 153 * Unlock display. 154 * 155 * @param display Display 156 */ 157 void display_unlock(display_t *display) 158 { 159 fibril_mutex_unlock(&display->lock); 160 } 161 140 162 /** Initialize window parameters structure. 141 163 * … … 700 722 display_wnd_ev_t event; 701 723 724 display_lock(display); 725 702 726 while (true) { 703 fibril_mutex_lock(&display->lock);704 705 727 if (display->sess != NULL) 706 728 rc = display_get_event(display, &window, &event); 707 729 else 708 730 rc = ENOENT; 709 710 fibril_mutex_unlock(&display->lock);711 731 712 732 if (rc != EOK) … … 752 772 } 753 773 774 display_unlock(display); 754 775 async_answer_0(icall, EOK); 755 776 } -
uspace/lib/input/include/io/kbd_event.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #define _LIBINPUT_IO_KBD_EVENT_H_ 37 37 38 #include <adt/list.h>39 38 #include <inttypes.h> 40 39 #include <io/keycode.h> … … 48 47 /** Console event structure. */ 49 48 typedef struct { 50 /** List handle */51 link_t link;52 53 49 /** Keyboard device ID */ 54 50 sysarg_t kbd_id; -
uspace/lib/meson.build
rbc3d695 r7bf29e5 90 90 'scsi', 91 91 'sif', 92 'system', 92 93 'tbarcfg', 94 'termui', 93 95 'trackmod', 94 96 'untar', … … 120 122 121 123 'ui', 124 'vt', 122 125 ] 123 126 -
uspace/lib/output/include/io/concaps.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 typedef enum { 39 39 CONSOLE_CAP_NONE = 0, 40 CONSOLE_CAP_STYLE = 1, 41 CONSOLE_CAP_INDEXED = 2, 42 CONSOLE_CAP_RGB = 4 40 CONSOLE_CAP_CURSORCTL = 1, 41 CONSOLE_CAP_STYLE = 2, 42 CONSOLE_CAP_INDEXED = 4, 43 CONSOLE_CAP_RGB = 8 43 44 } console_caps_t; 44 45 -
uspace/lib/system/include/system_srv.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 20 11 Martin Decky2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup output29 /** @addtogroup libsystem 30 30 * @{ 31 31 */ 32 /** @file System control protocol server stub 33 */ 32 34 33 #ifndef OUTPUT_PROTO_VT100_H_34 #define OUTPUT_PROTO_VT100_H_35 #ifndef _LIBSYSTEM_SYSTEM_SRV_H_ 36 #define _LIBSYSTEM_SYSTEM_SRV_H_ 35 37 36 #include <io/charfield.h> 38 #include <async.h> 39 #include <errno.h> 37 40 38 typedef void (*vt100_putuchar_t)(char32_t ch); 39 typedef void (*vt100_control_puts_t)(const char *str); 40 typedef void (*vt100_flush_t)(void); 41 typedef struct system_ops system_ops_t; 41 42 43 /** System server structure (per client session) */ 42 44 typedef struct { 43 sysarg_t cols; 44 sysarg_t rows; 45 async_sess_t *client_sess; 46 system_ops_t *ops; 47 void *arg; 48 } system_srv_t; 45 49 46 sysarg_t cur_col; 47 sysarg_t cur_row;48 char_attrs_t cur_attrs;50 struct system_ops { 51 errno_t (*shutdown)(void *); 52 }; 49 53 50 vt100_putuchar_t putuchar; 51 vt100_control_puts_t control_puts; 52 vt100_flush_t flush; 53 } vt100_state_t; 54 55 extern vt100_state_t *vt100_state_create(sysarg_t, sysarg_t, vt100_putuchar_t, 56 vt100_control_puts_t, vt100_flush_t); 57 extern void vt100_state_destroy(vt100_state_t *); 58 59 extern errno_t vt100_yield(vt100_state_t *); 60 extern errno_t vt100_claim(vt100_state_t *); 61 extern void vt100_get_dimensions(vt100_state_t *, sysarg_t *, sysarg_t *); 62 63 extern void vt100_goto(vt100_state_t *, sysarg_t, sysarg_t); 64 extern void vt100_set_attr(vt100_state_t *, char_attrs_t); 65 extern void vt100_cursor_visibility(vt100_state_t *, bool); 66 extern void vt100_putuchar(vt100_state_t *, char32_t); 67 extern void vt100_flush(vt100_state_t *); 54 extern void system_conn(ipc_call_t *, system_srv_t *); 55 extern void system_srv_initialize(system_srv_t *); 56 extern void system_srv_shutdown_complete(system_srv_t *); 57 extern void system_srv_shutdown_failed(system_srv_t *); 68 58 69 59 #endif -
uspace/lib/ui/include/types/ui/msgdialog.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 45 45 typedef struct ui_msg_dialog ui_msg_dialog_t; 46 46 47 enum { 48 /** Maximum number of buttons in message dialog. */ 49 ui_msg_dialog_maxbtn = 2 50 }; 51 52 /** Which choices the user can select from. */ 53 typedef enum { 54 /** OK (the default) */ 55 umdc_ok, 56 /** OK, Cancel */ 57 umdc_ok_cancel 58 } ui_msg_dialog_choice_t; 59 47 60 /** Message dialog parameters */ 48 61 typedef struct { … … 51 64 /** Message text */ 52 65 const char *text; 66 /** The choice that the user is given */ 67 ui_msg_dialog_choice_t choice; 53 68 } ui_msg_dialog_params_t; 54 69 -
uspace/lib/ui/include/types/ui/testctl.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #ifndef _UI_TYPES_TESTCTL_H 37 37 #define _UI_TYPES_TESTCTL_H 38 39 #include <errno.h> 40 #include <io/kbd_event.h> 41 #include <io/pos_event.h> 42 #include <stdbool.h> 43 #include <types/ui/event.h> 38 44 39 45 struct ui_test_ctl; -
uspace/lib/ui/include/types/ui/window.h
rbc3d695 r7bf29e5 58 58 /** Place window to the bottom-right corner of the screen */ 59 59 ui_wnd_place_bottom_right, 60 /** Place window to the center of the screen */ 61 ui_wnd_place_center, 60 62 /** Place window accross the entire screen */ 61 63 ui_wnd_place_full_screen, … … 68 70 /** Popup window */ 69 71 ui_wndf_popup = 0x1, 72 /** Window does not receive focus */ 73 ui_wndf_nofocus = 0x2, 70 74 /** Topmost window */ 71 ui_wndf_topmost = 0x 2,75 ui_wndf_topmost = 0x4, 72 76 /** Special system window */ 73 ui_wndf_system = 0x 4,77 ui_wndf_system = 0x8, 74 78 /** Maximized windows should avoid this window */ 75 ui_wndf_avoid = 0x 879 ui_wndf_avoid = 0x10 76 80 } ui_wnd_flags_t; 77 81 … … 80 84 /** Window rectangle */ 81 85 gfx_rect_t rect; 86 /** Minimum size to which window can be resized */ 87 gfx_coord2_t min_size; 82 88 /** Window caption */ 83 89 const char *caption; -
uspace/lib/ui/private/msgdialog.h
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 #define _UI_PRIVATE_MSGDIALOG_H 39 39 40 #include <types/ui/msgdialog.h> 41 #include <ui/pbutton.h> 42 #include <ui/window.h> 43 40 44 /** Actual structure of message dialog. 41 45 * … … 45 49 /** Dialog window */ 46 50 struct ui_window *window; 47 /** OK button*/48 struct ui_pbutton *b ok;51 /** Buttons */ 52 struct ui_pbutton *btn[ui_msg_dialog_maxbtn]; 49 53 /** Message dialog callbacks */ 50 54 struct ui_msg_dialog_cb *cb; -
uspace/lib/ui/src/filedialog.c
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 396 396 * 397 397 * @param window Window 398 * @param arg Argument (ui_ prompt_dialog_t *)398 * @param arg Argument (ui_file_dialog_t *) 399 399 * @param event Keyboard event 400 400 */ … … 427 427 } 428 428 } 429 430 429 } 431 430 -
uspace/lib/ui/src/msgdialog.c
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 47 47 48 48 static void ui_msg_dialog_wnd_close(ui_window_t *, void *); 49 static void ui_msg_dialog_wnd_kbd(ui_window_t *, void *, kbd_event_t *); 49 50 50 51 ui_window_cb_t ui_msg_dialog_wnd_cb = { 51 .close = ui_msg_dialog_wnd_close 52 .close = ui_msg_dialog_wnd_close, 53 .kbd = ui_msg_dialog_wnd_kbd 52 54 }; 53 55 … … 56 58 ui_pbutton_cb_t ui_msg_dialog_btn_cb = { 57 59 .clicked = ui_msg_dialog_btn_clicked 60 }; 61 62 static const char *ui_msg_dialog_captions[][ui_msg_dialog_maxbtn + 1] = { 63 [umdc_ok] = { "OK", NULL }, 64 [umdc_ok_cancel] = { "OK", "Cancel", NULL } 58 65 }; 59 66 … … 86 93 ui_fixed_t *fixed = NULL; 87 94 ui_label_t *label = NULL; 88 ui_pbutton_t *bok = NULL; 95 ui_pbutton_t *btn[ui_msg_dialog_maxbtn]; 96 const char **cp; 97 unsigned i, nb; 89 98 gfx_rect_t rect; 99 gfx_coord_t bw, bpad, btnsw, bp0x; 90 100 ui_resource_t *ui_res; 101 102 for (i = 0; i < ui_msg_dialog_maxbtn; i++) 103 btn[i] = NULL; 91 104 92 105 dialog = calloc(1, sizeof(ui_msg_dialog_t)); … … 103 116 wparams.rect.p0.x = 0; 104 117 wparams.rect.p0.y = 0; 105 wparams.rect.p1.x = 40;118 wparams.rect.p1.x = 60; 106 119 wparams.rect.p1.y = 7; 107 120 } else { 108 121 wparams.rect.p0.x = 0; 109 122 wparams.rect.p0.y = 0; 110 wparams.rect.p1.x = 200;123 wparams.rect.p1.x = 400; 111 124 wparams.rect.p1.y = 110; 112 125 } … … 132 145 rect.p0.x = 3; 133 146 rect.p0.y = 2; 134 rect.p1.x = 17;147 rect.p1.x = 57; 135 148 rect.p1.y = 3; 136 149 } else { 137 150 rect.p0.x = 10; 138 151 rect.p0.y = 35; 139 rect.p1.x = 190;152 rect.p1.x = 390; 140 153 rect.p1.y = 50; 141 154 } … … 150 163 label = NULL; 151 164 152 rc = ui_pbutton_create(ui_res, "OK", &bok); 153 if (rc != EOK) 154 goto error; 155 156 ui_pbutton_set_cb(bok, &ui_msg_dialog_btn_cb, dialog); 157 158 /* FIXME: Auto layout */ 165 i = 0; 166 assert(params->choice == umdc_ok || params->choice == umdc_ok_cancel); 167 cp = ui_msg_dialog_captions[params->choice]; 168 169 while (*cp != NULL) { 170 rc = ui_pbutton_create(ui_res, *cp, &btn[i]); 171 if (rc != EOK) 172 goto error; 173 174 ui_pbutton_set_cb(btn[i], &ui_msg_dialog_btn_cb, dialog); 175 ++cp; 176 ++i; 177 } 178 179 nb = i; 180 159 181 if (ui_is_textmode(ui)) { 160 rect.p0.x = 8; 161 rect.p0.y = 4; 162 rect.p1.x = 12; 163 rect.p1.y = 5; 182 bw = 12; 183 bpad = 2; 164 184 } else { 165 rect.p0.x = 55; 166 rect.p0.y = 60; 167 rect.p1.x = 145; 168 rect.p1.y = 88; 169 } 170 171 ui_pbutton_set_rect(bok, &rect); 172 173 ui_pbutton_set_default(bok, true); 174 175 rc = ui_fixed_add(fixed, ui_pbutton_ctl(bok)); 176 if (rc != EOK) 177 goto error; 178 179 dialog->bok = bok; 180 bok = NULL; 185 bw = 90; 186 bpad = 10; 187 } 188 189 btnsw = (nb - 1) * (bw + bpad) + bw; 190 bp0x = (wparams.rect.p0.x + wparams.rect.p1.x - btnsw) / 2; 191 192 for (i = 0; i < nb; i++) { 193 /* FIXME: Auto layout */ 194 if (ui_is_textmode(ui)) { 195 rect.p0.x = bp0x + i * (bw + bpad); 196 rect.p0.y = 4; 197 rect.p1.x = bp0x + bw + i * (bw + bpad); 198 rect.p1.y = 5; 199 } else { 200 rect.p0.x = bp0x + i * (bw + bpad); 201 rect.p0.y = 60; 202 rect.p1.x = bp0x + bw + i * (bw + bpad); 203 rect.p1.y = 88; 204 } 205 206 ui_pbutton_set_rect(btn[i], &rect); 207 208 rc = ui_fixed_add(fixed, ui_pbutton_ctl(btn[i])); 209 if (rc != EOK) 210 goto error; 211 } 212 213 ui_pbutton_set_default(btn[0], true); 214 215 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 216 dialog->btn[i] = btn[i]; 217 btn[i] = NULL; 218 } 181 219 182 220 ui_window_add(window, ui_fixed_ctl(fixed)); … … 191 229 return EOK; 192 230 error: 193 if (bok != NULL) 194 ui_pbutton_destroy(bok); 231 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 232 if (btn[i] != NULL) 233 ui_pbutton_destroy(btn[i]); 234 } 195 235 if (label != NULL) 196 236 ui_label_destroy(label); … … 243 283 } 244 284 285 /** Message dialog window keyboard event handler. 286 * 287 * @param window Window 288 * @param arg Argument (ui_msg_dialog_t *) 289 * @param event Keyboard event 290 */ 291 static void ui_msg_dialog_wnd_kbd(ui_window_t *window, void *arg, 292 kbd_event_t *event) 293 { 294 ui_msg_dialog_t *dialog = (ui_msg_dialog_t *) arg; 295 ui_evclaim_t claim; 296 297 claim = ui_window_def_kbd(window, event); 298 if (claim == ui_claimed) 299 return; 300 301 if (event->type == KEY_PRESS && 302 (event->mods & (KM_CTRL | KM_SHIFT | KM_ALT)) == 0) { 303 if (event->key == KC_ENTER) { 304 /* OK / default button */ 305 if (dialog->cb != NULL && dialog->cb->button != NULL) { 306 dialog->cb->button(dialog, dialog->arg, 0); 307 return; 308 } 309 } else if (event->key == KC_ESCAPE) { 310 /* Cancel */ 311 if (dialog->cb != NULL && dialog->cb->close != NULL) { 312 dialog->cb->close(dialog, dialog->arg); 313 return; 314 } 315 } 316 } 317 318 } 319 245 320 /** Message dialog button click handler. 246 321 * … … 251 326 { 252 327 ui_msg_dialog_t *dialog = (ui_msg_dialog_t *) arg; 253 254 if (dialog->cb != NULL && dialog->cb->button != NULL) 255 dialog->cb->button(dialog, dialog->arg, 0); 328 unsigned i; 329 330 if (dialog->cb != NULL && dialog->cb->button != NULL) { 331 for (i = 0; i < ui_msg_dialog_maxbtn; i++) { 332 if (dialog->btn[i] == pbutton) 333 dialog->cb->button(dialog, dialog->arg, i); 334 } 335 } 256 336 } 257 337 -
uspace/lib/ui/src/ui.c
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 357 357 358 358 break; 359 case CEV_RESIZE: 360 ui_lock(ui); 361 ui_window_send_resize(awnd); 362 ui_unlock(ui); 363 break; 359 364 } 360 365 } … … 563 568 void ui_lock(ui_t *ui) 564 569 { 570 if (ui->display != NULL) 571 display_lock(ui->display); 565 572 fibril_mutex_lock(&ui->lock); 566 573 } … … 577 584 { 578 585 fibril_mutex_unlock(&ui->lock); 586 if (ui->display != NULL) 587 display_unlock(ui->display); 579 588 } 580 589 -
uspace/lib/ui/src/window.c
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 189 189 switch (params->placement) { 190 190 case ui_wnd_place_default: 191 assert(ui_is_fullscreen(window->ui)); 191 case ui_wnd_place_center: 192 assert(params->placement != ui_wnd_place_default || 193 ui_is_fullscreen(window->ui)); 192 194 /* Center window */ 193 195 gfx_rect_dims(¶ms->rect, &dims); … … 343 345 dparams.rect = params->rect; 344 346 dparams.caption = params->caption; 345 /* Only allow making the window larger */ 346 gfx_rect_dims(¶ms->rect, &dparams.min_size); 347 dparams.min_size = params->min_size; 347 348 348 349 /* … … 358 359 if ((params->flags & ui_wndf_popup) != 0) 359 360 dparams.flags |= wndf_popup; 361 if ((params->flags & ui_wndf_nofocus) != 0) 362 dparams.flags |= wndf_nofocus; 360 363 if ((params->flags & ui_wndf_topmost) != 0) 361 364 dparams.flags |= wndf_topmost; … … 975 978 ui_t *ui = window->ui; 976 979 977 ui_lock(ui);980 fibril_mutex_lock(&ui->lock); 978 981 ui_window_send_close(window); 979 ui_unlock(ui);982 fibril_mutex_unlock(&ui->lock); 980 983 } 981 984 … … 986 989 ui_t *ui = window->ui; 987 990 988 ui_lock(ui);991 fibril_mutex_lock(&ui->lock); 989 992 (void)nfocus; 990 993 … … 995 998 996 999 ui_window_send_focus(window, nfocus); 997 ui_unlock(ui);1000 fibril_mutex_unlock(&ui->lock); 998 1001 } 999 1002 … … 1004 1007 ui_t *ui = window->ui; 1005 1008 1006 ui_lock(ui);1009 fibril_mutex_lock(&ui->lock); 1007 1010 ui_window_send_kbd(window, kbd_event); 1008 ui_unlock(ui);1011 fibril_mutex_unlock(&ui->lock); 1009 1012 } 1010 1013 … … 1020 1023 return; 1021 1024 1022 ui_lock(ui);1025 fibril_mutex_lock(&ui->lock); 1023 1026 1024 1027 claim = ui_wdecor_pos_event(window->wdecor, event); 1025 1028 if (claim == ui_claimed) { 1026 ui_unlock(ui);1029 fibril_mutex_unlock(&ui->lock); 1027 1030 return; 1028 1031 } 1029 1032 1030 1033 ui_window_send_pos(window, event); 1031 ui_unlock(ui);1034 fibril_mutex_unlock(&ui->lock); 1032 1035 } 1033 1036 … … 1045 1048 return; 1046 1049 1047 ui_lock(ui);1050 fibril_mutex_lock(&ui->lock); 1048 1051 (void) ui_window_resize(window, rect); 1049 1052 ui_window_send_resize(window); 1050 ui_unlock(ui);1053 fibril_mutex_unlock(&ui->lock); 1051 1054 } 1052 1055 … … 1057 1060 ui_t *ui = window->ui; 1058 1061 1059 ui_lock(ui);1062 fibril_mutex_lock(&ui->lock); 1060 1063 1061 1064 if (window->wdecor != NULL && nfocus == 0) { … … 1065 1068 1066 1069 ui_window_send_unfocus(window, nfocus); 1067 ui_unlock(ui);1070 fibril_mutex_unlock(&ui->lock); 1068 1071 } 1069 1072 … … 1295 1298 void ui_window_send_minimize(ui_window_t *window) 1296 1299 { 1297 if (window->cb != NULL && window->cb->m aximize != NULL)1300 if (window->cb != NULL && window->cb->minimize != NULL) 1298 1301 window->cb->minimize(window, window->arg); 1299 1302 else -
uspace/lib/ui/test/msgdialog.c
rbc3d695 r7bf29e5 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 92 92 ui_msg_dialog_params_t params; 93 93 ui_msg_dialog_t *dialog = NULL; 94 unsigned i; 94 95 test_cb_resp_t resp; 95 96 … … 100 101 params.caption = "Message"; 101 102 params.text = "Hello"; 103 params.choice = umdc_ok_cancel; 102 104 103 105 rc = ui_msg_dialog_create(ui, ¶ms, &dialog); … … 106 108 107 109 /* Button callback with no callbacks set */ 108 ui_pbutton_clicked(dialog->b ok);110 ui_pbutton_clicked(dialog->btn[0]); 109 111 110 112 /* Button callback with callback not implemented */ 111 113 ui_msg_dialog_set_cb(dialog, &dummy_msg_dialog_cb, NULL); 112 ui_pbutton_clicked(dialog->b ok);114 ui_pbutton_clicked(dialog->btn[0]); 113 115 114 /* Button callback with real callback set */ 115 resp.button = false; 116 resp.bnum = 123; 117 ui_msg_dialog_set_cb(dialog, &test_msg_dialog_cb, &resp); 118 ui_pbutton_clicked(dialog->bok); 119 PCUT_ASSERT_TRUE(resp.button); 120 PCUT_ASSERT_INT_EQUALS(0, resp.bnum); 116 for (i = 0; i < 2; i++) { 117 /* Button callback with real callback set */ 118 resp.button = false; 119 resp.bnum = 123; 120 ui_msg_dialog_set_cb(dialog, &test_msg_dialog_cb, &resp); 121 ui_pbutton_clicked(dialog->btn[i]); 122 PCUT_ASSERT_TRUE(resp.button); 123 PCUT_ASSERT_INT_EQUALS(i, resp.bnum); 124 } 121 125 122 126 ui_msg_dialog_destroy(dialog);
Note:
See TracChangeset
for help on using the changeset viewer.