📄 suntools.c
字号:
/* * Finish initializing the root. */ if (root_background_file != (char *) NULL) root_set_background(root_background_file); cursor = cursor_create((char *)0); (void)win_getcursor(rootfd, cursor); if (root_color != 1 && root_image_type == ROOT_IMAGE_SOLID) (void)cursor_set(cursor, CURSOR_OP, PIX_SRC^PIX_DST, 0); (void)cursor_set(cursor, CURSOR_IMAGE, &hglass_cursor, 0); (void)win_setcursor(rootfd, cursor); cursor_destroy(cursor); /* Set input parameters */ if (set_focus) if (win_set_focus_event(rootfd, &fe_focus, fe_focus_shift)) { (void) _error("win_set_focus_event"); exit(1); } if (set_restore_focus) if (win_set_swallow_event(rootfd, &fe_restore_focus, fe_restore_focus_shift)){ (void) _error("win_set_swallow_event"); exit(1); } if (set_sync_tv) if (win_set_event_timeout(rootfd, &sync_tv)) { (void) _error("win_set_event_timeout"); exit(1); } (void)win_screenget(rootfd, &screen); /* * Open pixwin. */ if ((pixwin = pw_open_monochrome(rootfd)) == 0) { (void) _error("%s not available for window system usage", screen.scr_fbname); exit(1); } /* Set up own color map if have own color */ if (root_color == 1) { char cmsname[CMS_NAMESIZE]; int color, bg, fg;#define ROOT_CMS_SIZE 4 u_char root_red[ROOT_CMS_SIZE], root_green[ROOT_CMS_SIZE], root_blue[ROOT_CMS_SIZE]; /* * -pattern grey or -color got us here but if -i was specified, * pwo_putcolormap will only check for SCR_SWITCHBKGRDFRGRD * if the depth is 1. In this situation, the root background * and default cms have depth 8 and the SCR_SWITCHBKGRDFRGRD * is lost. Taking care of it at this time appears to yield * correct results even for framebuffers with multiple planes. */ bg = (screen.scr_flags & SCR_SWITCHBKGRDFRGRD) ? ROOT_CMS_SIZE - 1 : 0; fg = (screen.scr_flags & SCR_SWITCHBKGRDFRGRD) ? 0 : ROOT_CMS_SIZE - 1; root_red[bg] = screen.scr_background.red; root_green[bg] = screen.scr_background.green; root_blue[bg] = screen.scr_background.blue; for (color = 1; color < ROOT_CMS_SIZE-1; color++) { root_red[color] = single_color.red; root_green[color] = single_color.green; root_blue[color] = single_color.blue; } root_red[fg] = screen.scr_foreground.red; root_green[fg] = screen.scr_foreground.green; root_blue[fg] = screen.scr_foreground.blue; (void)sprintf(cmsname, "rootcolor%ld", getpid()); (void)pw_setcmsname(pixwin, cmsname); (void)pw_putcolormap(pixwin, 0, ROOT_CMS_SIZE, root_red, root_green, root_blue); } /* * Steal a window for the tool slot allocator * & stash its name in the environment */ if ((placeholderfd = win_getnewwindow()) == -1) { (void) _error("no window available for placing open windows"); } else { (void)win_fdtoname(placeholderfd, name); (void)setenv("WMGR_ENV_PLACEHOLDER", name); } /* * Set up tool slot allocator */ (void)wmgr_init_icon_position(rootfd); (void)wmgr_init_tool_position(rootfd); /* * Setup tty parameters for all terminal emulators that will start. */ {int tty_fd; tty_fd = open("/dev/tty", O_RDWR, 0); if (tty_fd < 0) (void)ttysw_saveparms(2); /* Try stderr */ else { (void)ttysw_saveparms(tty_fd); (void) close(tty_fd); } } /* try to make sure there is a selection service */#define SEL_SVC_SEC_WAIT 5#define SEL_CLIENT_NULL (Seln_client) NULL if ((root_seln_handle = seln_create((void (*)())(LINT_CAST(dummy_proc)), (Seln_result (*)())(LINT_CAST(dummy_proc)), (char *)(LINT_CAST(&root_seln_handle)))) == SEL_CLIENT_NULL) { root_start_service(); for (i = 0; i < SEL_SVC_SEC_WAIT && root_seln_handle == SEL_CLIENT_NULL; i++) { usleep(1 << 20); root_seln_handle = seln_create( (void (*)())(LINT_CAST(dummy_proc)), (Seln_result (*)())(LINT_CAST(dummy_proc)), (char *)(LINT_CAST(&root_seln_handle)) ); } if (root_seln_handle == SEL_CLIENT_NULL) (void) _error(NO_PERROR, "cannot find old, or start new, selection service"); } /* * Initialize root menu from menu file * -- must be done before background is displayed * -- must be done late enough so "cleanup" can be done. * (or we could revise/modularize the code) * -- done here because it works...! */ rootmenufile = defaults_get_string("/SunView/Rootmenu_filename", "", (int *)NULL); if (*rootmenufile == '\0' && (rootmenufile = getenv("ROOTMENU")) == NULL) rootmenufile = ROOTMENUFILE; wmgr_rootmenu = NULL; if (GET_MENU(rootmenufile) <= 0) { (void) _error(NO_PERROR, "invalid root menu"); goto CLEANUP; } /* * Draw background. */ root_sigwinchhandler(); /* * Do initial window setup. */ if (!donosetup) root_initialsetup(setupfile); /* * Do window management loop. */ cursor = cursor_create((char *)0); (void)win_getcursor(rootfd, cursor); if (root_color != 1 && root_image_type == ROOT_IMAGE_SOLID) (void)cursor_set(cursor, CURSOR_OP, PIX_SRC^PIX_DST, 0); (void)cursor_set(cursor, CURSOR_IMAGE, &arrow_cursor, 0); (void)win_setcursor(rootfd, cursor); cursor_destroy(cursor); root_winmgr();CLEANUP: /* * Delete temporary files from /tmp for added security */ for (j=0; j<3; j++) { if ((file_exists = stat(tmp_file[j], &tmpb)) == 0) (void)unlink(tmp_file[j]); } if (plane_groups[PIXPG_CURSOR]) { /* Take the cursor down if on a hawk - bugid 1058820 */ Cursor cur; cur = cursor_create((char *)0); (void)win_getcursor(rootfd, cur); (void)cursor_set(cur, CURSOR_OP, PIX_CLR, CURSOR_IMAGE, NULL, 0); (void)win_setcursor(rootfd, cur); cursor_destroy(cur); } /* * Destroy screen sends SIGTERMs to all existing windows and * wouldn''t let any windows install themselves in the window tree. * Calling process of win_screedestroy is spared SIGTERM. */ (void)win_screendestroy(rootfd); (void)close(placeholderfd); /* * Lock screen before clear so don''t clobber frame buffer while * cursor moving. */ (void)pw_lock(pixwin, &screen.scr_rect); /* * Clear available plane groups */#ifdef PRE_IBIS for (i = 1; i < PIX_MAX_PLANE_GROUPS; i++) { if (plane_groups [i]) { int op; /* Write to all plane groups */ pr_set_planes(pixwin->pw_pixrect, i, PIX_ALL_PLANES); op = PIX_CLR; switch (i) { case PIXPG_MONO: case PIXPG_OVERLAY: if (! red_o [0]) red_o [0] = ~red_o [0]; (void) pr_putcolormap (pixwin->pw_pixrect, 0, 2, red_o, green_o, blue_o); break; case PIXPG_OVERLAY_ENABLE: if (! red_oe [0]) red_oe [0] = ~red_oe [0]; (void) pr_putcolormap (pixwin->pw_pixrect, 0, 2, red_oe, green_oe, blue_oe); if (plane_groups [PIXPG_24BIT_COLOR]) op = PIX_SET; break; case PIXPG_24BIT_COLOR: /* Fall through to 8 bit case. */ case PIXPG_8BIT_COLOR: (void) pr_putcolormap (pixwin->pw_pixrect, 0, 256, red, green, blue); break; } /* Clear screen */ (void)pr_rop(pixwin->pw_pixrect, screen.scr_rect.r_left, screen.scr_rect.r_top, screen.scr_rect.r_width, screen.scr_rect.r_height, op, (Pixrect *)0, 0, 0); } }#else /* PRE_IBIS */ for (i = 1; i < PIX_MAX_PLANE_GROUPS; i++) { if (plane_groups[i]) { pr_set_planes(pixwin->pw_pixrect, i, PIX_ALL_PLANES); /* User is not permitted to post cursor colormap */ switch (i) { case PIXPG_CURSOR: pr_rop(pixwin->pw_pixrect, screen.scr_rect.r_left, screen.scr_rect.r_top, screen.scr_rect.r_width, screen.scr_rect.r_height, PIX_CLR, (Pixrect *)0, 0, 0); break; case PIXPG_CURSOR_ENABLE: pr_rop(pixwin->pw_pixrect, screen.scr_rect.r_left, screen.scr_rect.r_top, screen.scr_rect.r_width, screen.scr_rect.r_height, PIX_SET, (Pixrect *)0, 0, 0); break; default: if (pr_ioctl(fb_pixrect, FBIOGCMSIZE, &cmsize) < 0) { /* for frame buffers which have no pr_ioctl implemented */ switch (i) { case PIXPG_MONO: case PIXPG_OVERLAY: case PIXPG_OVERLAY_ENABLE: cmsize = 2; break; default: cmsize = 256; } } (void)pr_putcolormap(pixwin->pw_pixrect, 0, cmsize, red[i], green[i],blue[i]); free(green[i]); free(blue[i]); free(red[i]); (void)pr_rop(pixwin->pw_pixrect, screen.scr_rect.r_left,screen.scr_rect.r_top, screen.scr_rect.r_width, screen.scr_rect.r_height, (i==PIXPG_OVERLAY_ENABLE) ? PIX_SET : PIX_CLR, (Pixrect *)0, 0, 0); } } }#endif /* !PRE_IBIS */ pr_set_plane_group (pixwin->pw_pixrect, original_pg); /* be sure to push the state on "state-full" boards bugid 1046602 */ (void) pr_get(pixwin->pw_pixrect, 0, 0); /* * Unlock screen. */ (void)pw_unlock(pixwin);/* bug 1027565 -- fork to change owner/group/permissions of window system devices */ switch (vfork()) { case -1: /* ERROR */ (void)fprintf(stderr, "sunview: Fork failed.\n"); _exit(1); case 0: /* CHILD */ (void)execl(SV_RELEASE, "sv_release", 0); /* should not return */ (void)fprintf(stderr, "sunview: exec for sv_release failed\n"); _exit(1); default: /* PARENT */ /* do nothing */ break; } /* * Performance: don't wait for the child to finish */ exit(0);Arg_Count_Error: exit(_error(NO_PERROR, "%s arg count error", args));}staticargs_remaining(args) char **args;{ register i; for (i = 0; *(args+i); i++) {} return (i);}staticget_focus_from_args(argv_ptr, event, value, shift) char ***argv_ptr; register short *event; register int *value; register int *shift;{#define SHIFT_MASK(bit) (1 << (bit)) char str[200]; register char *arg; if (args_remaining(*argv_ptr) < 4) { exit(_error(NO_PERROR, "%s arg count error", *argv_ptr)); } (*argv_ptr)++; arg = **argv_ptr; if (strcmp(arg, "LOC_WINENTER") == 0) *event = LOC_WINENTER; else if (strcmp(arg, "MS_LEFT") == 0) *event = MS_LEFT; else if (strcmp(arg, "MS_MIDDLE") == 0) *event = MS_MIDDLE; else if (strcmp(arg, "MS_RIGHT") == 0) *event = MS_RIGHT; else if (sscanf(arg, "BUT%s", str) == 1) *event = atoi(str)+BUT_FIRST; else if (sscanf(arg, "KEY_LEFT%s", str) == 1) *event = atoi(str)+KEY_LEFTFIRST-1; else if (sscanf(arg, "KEY_RIGHT%s", str) == 1) *event = atoi(str)+KEY_RIGHTFIRST-1; else if (sscanf(arg, "KEY_TOP%s", str) == 1) *event = atoi(str)+KEY_TOPFIRST-1; else if (strcmp(arg, "KEY_BOTTOMLEFT") == 0) *event = KEY_BOTTOMLEFT; else if (strcmp(arg, "KEY_BOTTOMRIGHT") == 0) *event = KEY_BOTTOMRIGHT; else *event = atoi(arg); (*argv_ptr)++; arg = **argv_ptr; if (strcmp(arg, "DOWN") == 0 || strcmp(arg, "Down") == 0 || strcmp(arg, "down") == 0) *value = 1; else if (strcmp(arg, "ENTER") == 0 || strcmp(arg, "Enter") == 0 || strcmp(arg, "enter") == 0) *value = 1; else if (strcmp(arg, "UP") == 0 || strcmp(arg, "Up") == 0 || strcmp(arg, "up") == 0) *value = 0; else *value = atoi(arg); (*argv_ptr)++; arg = **argv_ptr; if (strcmp(arg, "SHIFT_LEFT") == 0) *shift = SHIFT_MASK(LEFTSHIFT); else if (strcmp(arg, "SHIFT_RIGHT") == 0) *shift = SHIFT_MASK(RIGHTSHIFT); else if (strcmp(arg, "SHIFT_LEFTCTRL") == 0) *shift = SHIFT_MASK(LEFTCTRL); else if (strcmp(arg, "SHIFT_RIGHTCTRL") == 0) *shift = SHIFT_MASK(RIGHTCTRL); else if (strcmp(arg, "SHIFT_DONT_CARE") == 0) *shift = DONT_CARE_SHIFT; else if (strcmp(arg, "SHIFT_ALL_UP") == 0) *shift = 0; else *shift = atoi(arg);}static voidroot_winmgr(){ struct inputmask im; struct inputevent event; int keyexit = 0; /* * Set up input mask so can do menu stuff */ (void)input_imnull(&im); im.im_flags |= IM_NEGEVENT; im.im_flags |= IM_ASCII; win_setinputcodebit(&im, SELECT_BUT); win_setinputcodebit(&im, MENU_BUT); win_keymap_set_smask(rootfd, ACTION_STOP); win_keymap_set_imask_from_std_bind(&im, ACTION_STOP); win_setinputcodebit(&im, KBD_REQUEST); win_keymap_set_smask(rootfd, KEY_PUT); win_keymap_set_smask(rootfd, KEY_GET); win_keymap_set_smask(rootfd, KEY_FIND); win_keymap_set_smask(rootfd, KEY_DELETE); win_keymap_set_smask(rootfd, KEY_HELP); win_keymap_set_imask_from_std_bind(&im, KEY_HELP); win_keymap_set_imask_from_std_bind(&im, KEY_PUT); win_keymap_set_imask_from_std_bind(&im, KEY_GET); win_keymap_set_imask_from_std_bind(&im, KEY_FIND); win_keymap_set_imask_from_std_bind(&im, KEY_DELETE); (void)win_setinputmask(rootfd, &im, (struct inputmask *) 0, WIN_NULLLINK); /* * Read and invoke menu items */ for (;;) { fd_set ibits; int nfds; int maxfds = GETDTABLESIZE();#ifdef ecd.suntools if (root_SIGTERM) return ;#endif /* * Use select (to see if have input) so will return on SIGWINCH or * SIGCHLD. */ /* ibits = 1 << rootfd; */ FD_ZERO(&ibits); FD_SET(rootfd, &ibits); do { if (root_SIGCHLD) root_sigchldhandler(); if (root_SIGWINCH) root_sigwinchhandler(); } while (root_SIGCHLD || root_SIGWINCH); nfds = select(maxfds, &ibits, (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0); if (nfds == -1) { if (errno == EINTR) /* * Go around again so that signals can be handled. ibits may * be non-zero but should be ignored in this case and they will * be selected again. */ continue; else { abort(); (void) _error("root window select error"); break; } } /* if (ibits & (1 << rootfd)) { */ if (FD_ISSET(rootfd, &ibits)) { /* * Read will not block. */ if (input_readevent(rootfd, &event) < 0) { if (errno != EWOULDBLOCK) { (void) _error("root window event read error"); break; } } } else continue; switch (event_action(&event)) { case CTRL(q): /* Escape for getting out */ if (keyexit) { /* when no mouse around */ return; } continue; case CTRL(d): keyexit = 1; continue; case CTRL(l): case CTRL(r): wmgr_refreshwindow(rootfd); break; case KEY_STOP: if (root_seln_handle != (Seln_client) NULL) { seln_clear_functions(); } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -