Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  yesno.c -- implements the yes/no box
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "dialog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Display termination buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static void print_buttons(WINDOW * dialog, int height, int width, int selected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	int x = width / 2 - 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	int y = height - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	print_button(dialog, " Yes ", y, x, selected == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	print_button(dialog, "  No  ", y, x + 13, selected == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	wmove(dialog, y, x + 1 + 13 * selected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * Display a dialog box with two buttons - Yes and No
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) int dialog_yesno(const char *title, const char *prompt, int height, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	int i, x, y, key = 0, button = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	WINDOW *dialog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) do_resize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (getmaxy(stdscr) < (height + YESNO_HEIGTH_MIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return -ERRDISPLAYTOOSMALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return -ERRDISPLAYTOOSMALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	/* center dialog box on screen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	x = (getmaxx(stdscr) - width) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	y = (getmaxy(stdscr) - height) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	draw_shadow(stdscr, y, x, height, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	dialog = newwin(height, width, y, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	keypad(dialog, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	draw_box(dialog, 0, 0, height, width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		 dlg.dialog.atr, dlg.border.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	wattrset(dialog, dlg.border.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	for (i = 0; i < width - 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		waddch(dialog, ACS_HLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	wattrset(dialog, dlg.dialog.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	waddch(dialog, ACS_RTEE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	print_title(dialog, title, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	wattrset(dialog, dlg.dialog.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	print_autowrap(dialog, prompt, width - 2, 1, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	print_buttons(dialog, height, width, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	while (key != KEY_ESC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		key = wgetch(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		switch (key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		case 'Y':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		case 'y':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		case 'N':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		case 'n':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		case TAB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		case KEY_LEFT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		case KEY_RIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			print_buttons(dialog, height, width, button);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			wrefresh(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		case ' ':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		case '\n':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			return button;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		case KEY_ESC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			key = on_key_esc(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		case KEY_RESIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			on_key_resize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			goto do_resize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	delwin(dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return key;		/* ESC pressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }