cosmetix
[yterm.git] / src / menus.inc.c
blob7061d8124fd7a49e6015a10df98024289bbc7dab
1 /*
2 * YTerm -- (mostly) GNU/Linux X11 terminal emulator
4 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
5 * Understanding is not required. Only obedience.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 3 of the License ONLY.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 various OSD control menus.
21 included directly from "x11_keypress.inc.c"
25 //==========================================================================
27 // term_menu_history_cb
29 //==========================================================================
30 static yterm_bool term_menu_history_cb (void *varptr, int sx, int sy) {
31 (void)varptr; (void)sx; (void)sy;
32 if (currterm != NULL) {
33 if (currterm->history.enabled == 0) {
34 if (currterm->history.file.fd >= 0) close(currterm->history.file.fd);
35 currterm->history.blocktype = SBLOCK_NONE;
36 currterm->history.file.fd = -1;
37 currterm->history.file.width = TERM_CBUF(currterm)->width;
38 currterm->history.file.lcount = 0;
41 return 0; // don't close
45 //==========================================================================
47 // term_menu_color_mode_global_color_cb
49 //==========================================================================
50 static yterm_bool term_menu_color_mode_global_color_cb (void *varptr, int sx, int sy) {
51 (void)varptr; (void)sx; (void)sy;
52 colorMode = CMODE_NORMAL;
53 return 1; // close menu
57 //==========================================================================
59 // term_menu_color_mode_global_bw_cb
61 //==========================================================================
62 static yterm_bool term_menu_color_mode_global_bw_cb (void *varptr, int sx, int sy) {
63 (void)varptr; (void)sx; (void)sy;
64 colorMode = CMODE_BW;
65 return 1; // close menu
69 //==========================================================================
71 // term_menu_color_mode_global_green_cb
73 //==========================================================================
74 static yterm_bool term_menu_color_mode_global_green_cb (void *varptr, int sx, int sy) {
75 (void)varptr; (void)sx; (void)sy;
76 colorMode = CMODE_GREEN;
77 return 1; // close menu
81 //==========================================================================
83 // term_menu_color_mode_global_cb
85 //==========================================================================
86 static yterm_bool term_menu_color_mode_global_cb (void *varptr, int sx, int sy) {
87 (void)varptr; (void)sx; (void)sy;
89 if (currterm == NULL) return 0;
91 MenuWindow *menu = menu_new_window(3, 3, "Global Color Mode", -4, -4);
92 menu_add_label(menu, "&color", &term_menu_color_mode_global_color_cb);
93 menu_add_label(menu, "&mono", &term_menu_color_mode_global_bw_cb);
94 menu_add_label(menu, "&green", &term_menu_color_mode_global_green_cb);
96 switch (colorMode) {
97 case CMODE_NORMAL: menu->curr_item = 0; break;
98 case CMODE_BW: menu->curr_item = 1; break;
99 case CMODE_GREEN: menu->curr_item = 2; break;
102 menu_set_position(menu, sx, sy);
103 //menu_shift(menu, 2, 2);
105 open_menu(menu);
107 return 0;
111 //==========================================================================
113 // term_menu_color_mode_tab_default_cb
115 //==========================================================================
116 static yterm_bool term_menu_color_mode_tab_default_cb (void *varptr, int sx, int sy) {
117 (void)varptr; (void)sx; (void)sy;
118 if (currterm != NULL) currterm->colorMode = -1;
119 return 1; // close menu
123 //==========================================================================
125 // term_menu_color_mode_tab_color_cb
127 //==========================================================================
128 static yterm_bool term_menu_color_mode_tab_color_cb (void *varptr, int sx, int sy) {
129 (void)varptr; (void)sx; (void)sy;
130 if (currterm != NULL) currterm->colorMode = CMODE_NORMAL;
131 return 1; // close menu
135 //==========================================================================
137 // term_menu_color_mode_tab_bw_cb
139 //==========================================================================
140 static yterm_bool term_menu_color_mode_tab_bw_cb (void *varptr, int sx, int sy) {
141 (void)varptr; (void)sx; (void)sy;
142 if (currterm != NULL) currterm->colorMode = CMODE_BW;
143 return 1; // close menu
147 //==========================================================================
149 // term_menu_color_mode_tab_green_cb
151 //==========================================================================
152 static yterm_bool term_menu_color_mode_tab_green_cb (void *varptr, int sx, int sy) {
153 (void)varptr; (void)sx; (void)sy;
154 if (currterm != NULL) currterm->colorMode = CMODE_GREEN;
155 return 1; // close menu
159 //==========================================================================
161 // term_menu_color_mode_tab_cb
163 //==========================================================================
164 static yterm_bool term_menu_color_mode_tab_cb (void *varptr, int sx, int sy) {
165 (void)varptr; (void)sx; (void)sy;
167 if (currterm == NULL) return 0;
169 MenuWindow *menu = menu_new_window(3, 3, "Tab Color Mode", -4, -4);
170 menu_add_label(menu, "&default", &term_menu_color_mode_tab_default_cb);
171 menu_add_label(menu, "&color", &term_menu_color_mode_tab_color_cb);
172 menu_add_label(menu, "&mono", &term_menu_color_mode_tab_bw_cb);
173 menu_add_label(menu, "&green", &term_menu_color_mode_tab_green_cb);
175 switch (currterm->colorMode) {
176 case -1: menu->curr_item = 0; break;
177 case CMODE_NORMAL: menu->curr_item = 1; break;
178 case CMODE_BW: menu->curr_item = 2; break;
179 case CMODE_GREEN: menu->curr_item = 3; break;
182 menu_set_position(menu, sx, sy);
183 //menu_shift(menu, 2, 2);
185 menu->term = currterm;
187 open_menu(menu);
189 return 0;
193 //==========================================================================
195 // create_global_options_menu
197 //==========================================================================
198 static void create_global_options_menu (int sx, int sy) {
199 MenuWindow *menu = menu_new_window(max2(sx, 0), max2(sy, 0), "Global Options", -2, -2);
200 menu_add_bool(menu, "&history", &opt_history_enabled, NULL);
201 menu_add_bool(menu, "&mouse reports", &opt_mouse_reports, NULL);
202 menu_add_bool(menu, "&esc-esc fix", &opt_esc_twice, NULL);
203 menu_add_label(menu, NULL, NULL);
204 menu_add_submenu(menu, "&color mode", &term_menu_color_mode_global_cb);
206 if (sx <= 0) menu_center(menu);
207 menu_shift(menu, 0, 0);
208 open_menu(menu);
212 //==========================================================================
214 // term_menu_tab_global_submenu_cb
216 //==========================================================================
217 static yterm_bool term_menu_tab_global_submenu_cb (void *varptr, int sx, int sy) {
218 (void)varptr;
219 create_global_options_menu(sx, sy);
220 return 0; // don't close
224 //==========================================================================
226 // term_menu_send_tab_resize_cb
228 //==========================================================================
229 static yterm_bool term_menu_send_tab_resize_cb (void *varptr, int sx, int sy) {
230 (void)varptr; (void)sx; (void)sy;
231 term_send_size_ioctl(currterm);
232 return 1;
236 //==========================================================================
238 // term_menu_tab_submenu_special_cb
240 //==========================================================================
241 static yterm_bool term_menu_tab_submenu_special_cb (void *varptr, int sx, int sy) {
242 (void)varptr; (void)sx; (void)sy;
244 if (currterm == NULL) return 0;
246 MenuWindow *menu = menu_new_window(sx, sy, "Tab Special Events", 0, 0);
247 menu_add_label(menu, "Send &resize event", &term_menu_send_tab_resize_cb);
249 menu->term = currterm;
250 open_menu(menu);
252 return 0;
256 //==========================================================================
258 // hswap_prompt_yes_cb
260 //==========================================================================
261 static yterm_bool hswap_prompt_yes_cb (void *varptr, int sx, int sy) {
262 (void)varptr; (void)sx; (void)sy;
263 opt_debug_perform_hotswap = 1;
264 return 1; // close the menu
268 //==========================================================================
270 // hswap_prompt_no_cb
272 //==========================================================================
273 static yterm_bool hswap_prompt_no_cb (void *varptr, int sx, int sy) {
274 (void)varptr; (void)sx; (void)sy;
275 opt_debug_perform_hotswap = 0;
276 return 1; // close the menu
280 //==========================================================================
282 // term_menu_hotswap_submenu_cb
284 //==========================================================================
285 static yterm_bool term_menu_hotswap_submenu_cb (void *varptr, int sx, int sy) {
286 (void)varptr; (void)sx; (void)sy;
288 MenuWindow *menu = menu_new_window(sx, sy, "Perform hotswap?", 0, 0);
289 menu_add_label(menu, "&No", &hswap_prompt_no_cb);
290 menu_add_label(menu, "&Yes", &hswap_prompt_yes_cb);
292 menu_add_label(menu, NULL, NULL);
293 menu_add_label(menu, "This will restart the emulator, keeping", NULL);
294 menu_add_label(menu, "all opened tabs and programs intact.", NULL);
295 menu_add_label(menu, "It can be used to upgrade the running", NULL);
296 menu_add_label(menu, "instance without losing your session.", NULL);
298 //menu_center(menu);
299 menu_shift(menu, 0, 0);
300 open_menu(menu);
302 return 0; // don't close the menu
306 //==========================================================================
308 // term_menu_reload_config_cb
310 //==========================================================================
311 static yterm_bool term_menu_reload_config_cb (void *varptr, int sx, int sy) {
312 (void)varptr; (void)sx; (void)sy;
314 const MenuWindow *orig = curr_menu;
316 xrm_reloading = 1;
317 xrm_load_options();
318 if (currterm != NULL) {
319 // we may change colors and such
320 force_frame_redraw(1);
321 force_tab_redraw();
324 // if we have some new menus, it means that there were some errors
325 if (curr_menu == orig) {
326 open_menu(menu_new_message_box("Notification", "Config reloaded!"));
329 return 0; // don't close the menu
333 //==========================================================================
335 // create_tab_options_menu
337 //==========================================================================
338 static void create_tab_options_menu (int sx, int sy) {
339 if (currterm != NULL) {
340 //fprintf(stderr, "creating tab options menu...\n");
341 MenuWindow *menu = menu_new_window(max2(sx, 0), max2(sy, 0), "Tab Options", -2, -2);
342 menu_add_bool(menu, "cursor hidd&en", &currterm->wkscr->curhidden, NULL);
343 menu_add_bool(menu, "&history", &currterm->history.enabled, term_menu_history_cb);
344 menu_add_3bool(menu, "&mouse reports", &currterm->mouse_reports, NULL);
345 menu_add_3bool(menu, "&esc-esc fix", &currterm->escesc, NULL);
346 menu_add_bitbool32(menu, "force &UTF-8", &currterm->mode, YTERM_MODE_FORCED_UTF, NULL);
347 menu_add_label(menu, NULL, NULL);
348 menu_add_submenu(menu, "&color mode", &term_menu_color_mode_tab_cb);
349 menu_add_submenu(menu, "&special events", &term_menu_tab_submenu_special_cb);
350 menu_add_label(menu, NULL, NULL);
351 menu_add_submenu(menu, "&GLOBAL OPTIONS", &term_menu_tab_global_submenu_cb);
352 menu_add_label(menu, NULL, NULL);
353 menu_add_label(menu, "&Reload Config", &term_menu_reload_config_cb);
354 menu_add_label(menu, NULL, NULL);
355 menu_add_submenu(menu, "HOTSWAP", &term_menu_hotswap_submenu_cb);
357 menu->term = currterm;
359 if (sx <= 0) menu_center(menu);
360 menu_shift(menu, 0, 0);
361 open_menu(menu);
366 //==========================================================================
368 // qprompt_yes_cb
370 //==========================================================================
371 static yterm_bool qprompt_yes_cb (void *varptr, int sx, int sy) {
372 (void)varptr; (void)sx; (void)sy;
373 quitMessage = 666;
374 return 1; // close the menu
378 //==========================================================================
380 // qprompt_no_cb
382 //==========================================================================
383 static yterm_bool qprompt_no_cb (void *varptr, int sx, int sy) {
384 (void)varptr; (void)sx; (void)sy;
385 quitMessage = 0; // just in case
386 return 1; // close the menu
390 //==========================================================================
392 // show_quit_prompt
394 //==========================================================================
395 static void show_quit_prompt (void) {
396 if (currterm != NULL) {
397 MenuWindow *menu = menu_new_window(0, 0, "Do you really want to quit?", 0, 0);
398 menu_add_label(menu, "&Yes", &qprompt_yes_cb);
399 menu_add_label(menu, "&No", &qprompt_no_cb);
401 menu_center(menu);
402 menu_shift(menu, 0, 0);
403 open_menu(menu);
404 } else {
405 quitMessage = 666;
410 //==========================================================================
412 // x11_menu_keyevent
414 //==========================================================================
415 static void x11_menu_keyevent (XKeyEvent *e, KeySym ksym, uint32_t kmods) {
416 (void)e; (void)ksym; (void)kmods;
418 MenuWindow *menu = curr_menu;
419 if (menu == NULL) return;
421 if (ksym != NoSymbol) {
422 int cidx = 0;
423 MenuItem *it = menu->items;
424 while (it != NULL && it->caption.hotkey != ksym) {
425 cidx += 1; it = it->next;
427 if (it != NULL) {
428 menu->curr_item = cidx;
429 menu_make_cursor_visible(menu);
430 menu->dirty = 1;
431 if (menu_action(menu)) goto close_menu;
432 force_frame_redraw(1);
433 return;
437 if ((e->state&Mod2Mask) == 0) ksym = translate_keypad(ksym);
439 switch (ksym) {
440 case XK_Return:
441 case XK_KP_Enter:
442 case XK_space:
443 if (menu_action(menu)) goto close_menu;
444 force_frame_redraw(1);
445 return;
447 case XK_Escape:
448 close_menu:
449 curr_menu = menu->prev;
450 menu_free_window(menu);
451 menu_mark_all_dirty(curr_menu);
452 force_frame_redraw(1);
453 return;
455 case XK_Up: menu_up(menu); break;
456 case XK_Down: menu_down(menu); break;
457 case XK_Home: menu_home(menu); break;
458 case XK_End: menu_end(menu); break;
459 case XK_Page_Up: menu_page_up(menu); break;
460 case XK_Page_Down: menu_page_down(menu); break;
463 menu = curr_menu;
464 if (menu == NULL) {
465 force_frame_redraw(1);
466 } else {
467 while (menu != NULL && menu->dirty == 0) menu = menu->prev;
468 if (menu != NULL) force_frame_redraw(1);