rxvtlib_command.c

来自「具有IDE功能的编辑器」· C语言 代码 · 共 2,607 行 · 第 1/5 页

C
2,607 行
字号
}void rxvt_fd_read_watch (int fd, fd_set * reading, fd_set * writing,				fd_set * error, void *data){    rxvtlib *o = (rxvtlib *) data;    if (!rxvt_fd_read (o))	return;    rxvtlib_main_loop (o);    rxvtlib_update_screen (o);}void rxvt_process_x_event (rxvtlib * o){    o->refresh_count = 0;    o->refresh_limit = 1;    if (o->x_events_pending)	rxvtlib_XProcessEvent (o, o->Xdisplay);    if (o->killed) {	close (o->cmd_fd);	kill (o->cmd_pid, SIGTERM);    }#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING    if (scrollbar_isUp ()) {	if (!o->scroll_arrow_delay-- && rxvtlib_scr_page (o, UP, 1)) {	    o->scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY;	    o->refresh_type |= SMOOTH_REFRESH;	}    } else if (scrollbar_isDn ()) {	if (!o->scroll_arrow_delay-- && rxvtlib_scr_page (o, DN, 1)) {	    o->scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY;	    o->refresh_type |= SMOOTH_REFRESH;	}    }#endif}/* cmd_getc() - Return next input character *//* * Return the next input character after first passing any keyboard input * to the command. *//* INTPROTO */unsigned char rxvtlib_cmd_getc (rxvtlib * o){    int ch = -1;    if (o->v_bufstr < o->v_bufptr)	/* output any pending chars */	rxvtlib_tt_write (o, NULL, 0);    while (ch == -1) {	if (o->cmdbuf_ptr < o->cmdbuf_endp)	    ch = (unsigned char) (*o->cmdbuf_ptr++);	else	    rxvt_fd_read (o);    }    if (o->cmdbuf_endp == o->cmdbuf_base + BUFSIZ && o->cmdbuf_ptr < o->cmdbuf_endp) {/* can't read past the end of the buffer */	CRemoveWatch (o->cmd_fd, rxvt_fd_read_watch, 1);    } else {	CAddWatch (o->cmd_fd, rxvt_fd_read_watch, 1, (void *) o);    }    return ch;}/*}}} */#endif/* * the 'essential' information for reporting Mouse Events * pared down from XButtonEvent *//* milliseconds *//* key or button mask *//* detail *//* INTPROTO */void            rxvtlib_mouse_report (rxvtlib *o, const XButtonEvent * ev){    int             button_number, key_state = 0;    int             x, y;    x = ev->x;    y = ev->y;    pixel_position (o, &x, &y);    button_number = ((o->MEvent.button == AnyButton) ? 3 :		     (o->MEvent.button - Button1));    if (o->PrivateModes & PrivMode_MouseX10) {	/*	 * do not report ButtonRelease	 * no state info allowed	 */	key_state = 0;	if (button_number == 3)	    return;    } else {	/* XTerm mouse reporting needs these values:	 *   4 = Shift	 *   8 = Meta	 *  16 = Control	 * plus will add in our own Double-Click reporting	 *  32 = Double Click	 */	key_state = ((o->MEvent.state & ShiftMask) ? 4 : 0)	    + ((o->MEvent.state & o->ModMetaMask) ? 8 : 0)	    + ((o->MEvent.state & ControlMask) ? 16 : 0);#ifdef MOUSE_REPORT_DOUBLECLICK	key_state += ((o->MEvent.clicks > 1) ? 32 : 0);#endif    }#ifdef DEBUG_MOUSEREPORT    fprintf (stderr, "Mouse [");    if (key_state & 16)	fputc ('C', stderr);    if (key_state & 4)	fputc ('S', stderr);    if (key_state & 8)	fputc ('A', stderr);    if (key_state & 32)	fputc ('2', stderr);    fprintf (stderr, "]: <%d>, %d/%d\n", button_number, x + 1, y + 1);#else    rxvtlib_tt_printf (o, "\033[M%c%c%c",	       (32 + button_number + key_state), (32 + x + 1), (32 + y + 1));#endif}/*{{{ process an X event *//* INTPROTO */void rxvtlib_process_x_event (rxvtlib * o, XEvent * ev){    int reportmode;    Window unused_root, unused_child;    int unused_root_x, unused_root_y;    unsigned int unused_mask;    static int bypass_keystate = 0;    static int csrO = 0;	/* Hops - csr offset in thumb/slider      */    /*        to give proper Scroll behaviour */#ifdef DEBUG_X    char *eventnames[] = {	/* mason - this matches my system */	"",	"",	"KeyPress",	"KeyRelease",	"ButtonPress",	"ButtonRelease",	"MotionNotify",	"EnterNotify",	"LeaveNotify",	"FocusIn",	"FocusOut",	"KeymapNotify",	"Expose",	"GraphicsExpose",	"NoExpose",	"VisibilityNotify",	"CreateNotify",	"DestroyNotify",	"UnmapNotify",	"MapNotify",	"MapRequest",	"ReparentNotify",	"ConfigureNotify",	"ConfigureRequest",	"GravityNotify",	"ResizeRequest",	"CirculateNotify",	"CirculateRequest",	"PropertyNotify",	"SelectionClear",	"SelectionRequest",	"SelectionNotify",	"ColormapNotify",	"ClientMessage",	"MappingNotify"    };    fprintf (stderr, "Event type: %-16s, Window: %lx (p:%lx,vt:%lx,sb:%lx)\n",	     eventnames[ev->type], ev->xany.window, o->TermWin.parent[0],	     o->TermWin.vt, o->scrollBar.win);    fflush (stderr);#endif    switch (ev->type) {    case KeyPress:	rxvtlib_lookup_key (o, ev);	break;    case ClientMessage:	if (ev->xclient.format == 32 && ev->xclient.data.l[0] == o->wmDeleteWindow) {#ifndef STANDALONE	    XDestroyWindow (o->Xdisplay, o->TermWin.parent[0]);	    XDestroyWindow (o->Xdisplay, o->TermWin.vt);	    XDestroyWindow (o->Xdisplay, o->scrollBar.win);	    XFlush (o->Xdisplay);#endif	    o->killed = EXIT_SUCCESS | DO_EXIT;	    return;	}	break;    case MappingNotify:	XRefreshKeyboardMapping (&(ev->xmapping));	break;	/*	 * XXX: this is not the _current_ arrangement	 * Here's my conclusion:	 * If the window is completely unobscured, use bitblt's	 * to scroll. Even then, they're only used when doing partial	 * screen scrolling. When partially obscured, we have to fill	 * in the GraphicsExpose parts, which means that after each refresh,	 * we need to wait for the graphics expose or Noexpose events,	 * which ought to make things real slow!	 */    case VisibilityNotify:	switch (ev->xvisibility.state) {	case VisibilityUnobscured:	    o->refresh_type = FAST_REFRESH;	    break;	case VisibilityPartiallyObscured:	    o->refresh_type = SLOW_REFRESH;	    break;	default:	    o->refresh_type = NO_REFRESH;	    break;	}	break;    case FocusIn:	if (!o->TermWin.focus) {	    o->TermWin.focus = 1;	    o->want_refresh = 1;#ifdef USE_XIM	    if (o->Input_Context != NULL)		XSetICFocus (o->Input_Context);#endif	}	break;    case FocusOut:	if (o->TermWin.focus) {	    o->TermWin.focus = 0;	    o->want_refresh = 1;#ifdef USE_XIM	    if (o->Input_Context != NULL)		XUnsetICFocus (o->Input_Context);#endif	}	break;    case ConfigureNotify:	if (ev->xconfigure.window != o->TermWin.parent[0])	    break;#ifdef TRANSPARENT		/* XXX: maybe not needed - leave in for now */	if (o->Options & Opt_transparent)	    rxvtlib_check_our_parents (o);#endif	if (!rxvtlib_RemoveFromCNQueue (o, ev->xconfigure.width, ev->xconfigure.height)) {	    rxvtlib_resize_window (o, ev->xconfigure.width, ev->xconfigure.height);#ifdef USE_XIM	    rxvtlib_IMSetStatusPosition (o);#endif	}#ifdef TRANSPARENT	if (o->Options & Opt_transparent) {	    rxvtlib_scr_clear (o);	    rxvtlib_scr_touch (o);	}#endif	break;    case SelectionClear:	rxvtlib_selection_clear (o);	break;    case SelectionNotify:	rxvtlib_selection_paste (o, ev->xselection.requestor, ev->xselection.property, True);	break;    case SelectionRequest:	rxvtlib_selection_send (o, &(ev->xselectionrequest));	break;    case UnmapNotify:	o->TermWin.mapped = 0;	break;    case MapNotify:	o->TermWin.mapped = 1;	break;#ifdef TRANSPARENT    case PropertyNotify:	{	    /*	     * if user used some Esetroot compatible prog to set the root	     * bg, use the property to determine that. We don't use it's	     * value, yet	     */	    static Atom atom = 0;	    if (!atom)		atom = XInternAtom (o->Xdisplay, "_XROOTPMAP_ID", False);	    if (ev->xproperty.atom != atom)		break;	}	/* FALLTHROUGH */    case ReparentNotify:	if ((o->Options & Opt_transparent)	    && rxvtlib_check_our_parents (o)) {	/* parents change then clear screen */	    rxvtlib_scr_clear (o);	    rxvtlib_scr_touch (o);	}	break;#endif				/* TRANSPARENT */    case GraphicsExpose:    case Expose:	if (ev->xany.window == o->TermWin.vt) {	    rxvtlib_scr_expose (o, ev->xexpose.x, ev->xexpose.y,				ev->xexpose.width, ev->xexpose.height);	} else {	    XEvent unused_xevent;	    while (XCheckTypedWindowEvent (o->Xdisplay, ev->xany.window, Expose, &unused_xevent));	    while (XCheckTypedWindowEvent (o->Xdisplay, ev->xany.window,					   GraphicsExpose, &unused_xevent));	    if (isScrollbarWindow (ev->xany.window)) {		scrollbar_setNone ();		rxvtlib_scrollbar_show (o, 0);	    }	    if (menubar_visible () && isMenuBarWindow (ev->xany.window))		rxvtlib_menubar_expose (o);	    rxvtlib_Gr_expose (o, ev->xany.window);	}	break;    case ButtonPress:	bypass_keystate = (ev->xbutton.state & (o->ModMetaMask | ShiftMask));	reportmode = (bypass_keystate ? 0 : (o->PrivateModes & PrivMode_mouse_report));	if (ev->xany.window == o->TermWin.vt) {	    if (ev->xbutton.subwindow != None)		Gr_ButtonPress (ev->xbutton.x, ev->xbutton.y);	    else {		if (reportmode) {		    /* mouse report from vt window */		    /* save the xbutton state (for ButtonRelease) */		    o->MEvent.state = ev->xbutton.state;#ifdef MOUSE_REPORT_DOUBLECLICK		    if (ev->xbutton.button == o->MEvent.button			&& (ev->xbutton.time - o->MEvent.time < MULTICLICK_TIME)) {			/* same button, within alloted time */			o->MEvent.clicks++;			if (o->MEvent.clicks > 1) {			    /* only report double clicks */			    o->MEvent.clicks = 2;			    rxvtlib_mouse_report (o, &(ev->xbutton));			    /* don't report the release */			    o->MEvent.clicks = 0;			    o->MEvent.button = AnyButton;			}		    } else {			/* different button, or time expired */			o->MEvent.clicks = 1;			o->MEvent.button = ev->xbutton.button;			rxvtlib_mouse_report (o, &(ev->xbutton));		    }#else		    o->MEvent.button = ev->xbutton.button;		    rxvtlib_mouse_report (o, &(ev->xbutton));#endif				/* MOUSE_REPORT_DOUBLECLICK */		} else {		    if (ev->xbutton.button != o->MEvent.button)			o->MEvent.clicks = 0;		    switch (ev->xbutton.button) {		    case Button1:			if (o->MEvent.button == Button1			    && (ev->xbutton.time - o->MEvent.time <				MULTICLICK_TIME)) o->MEvent.clicks++;			else			    o->MEvent.clicks = 1;			rxvtlib_selection_click (o, o->MEvent.clicks, ev->xbutton.x, ev->xbutton.y);			o->MEvent.button = Button1;			break;		    case Button3:			if (o->MEvent.button == Button3			    && (ev->xbutton.time - o->MEvent.time <				MULTICLICK_TIME))				rxvtlib_selection_rotate (o, ev->xbutton.x, ev->xbutton.y);			else			    rxvtlib_selection_extend (o, ev->xbutton.x, ev->xbutton.y, 1);			o->MEvent.button = Button3;			break;		    }		}		o->MEvent.time = ev->xbutton.time;		return;	    }	}	if (isScrollbarWindow (ev->xany.window)) {	    scrollbar_setNone ();	    /*	     * Rxvt-style scrollbar:	     * move up if mouse is above slider	     * move dn if mouse is below slider	     *	     * XTerm-style scrollbar:	     * Move display proportional to pointer location	     * pointer near top -> scroll one line	     * pointer near bot -> scroll full page	     */#ifndef NO_SCROLLBAR_REPORT	    if (reportmode) {		/*		 * Mouse report disabled scrollbar:		 * arrow buttons - send up/down		 * click on scrollbar - send pageup/down		 */		if (scrollbar_upButton (ev->xbutton.y))		    rxvtlib_tt_printf (o, "\033[A");		else if (scrollbar_dnButton (ev->xbutton.y))		    rxvtlib_tt_printf (o, "\033[B");		else		    switch (ev->xbutton.button) {		    case Button2:			rxvtlib_tt_printf (o, "\014");			break;		    case Button1:			rxvtlib_tt_printf (o, "\033[6~");			break;		    case Button3:			rxvtlib_tt_printf (o, "\033[5~");			break;		    }	    } else#endif				/* NO_SCROLLBAR_REPORT */	    {		if (scrollbar_upButton (ev->xbutton.y)) {#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING		    o->scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY;#endif		    if (rxvtlib_scr_page (o, UP, 1))			scrollbar_setUp ();		} else if (scrollbar_dnButton (ev->xbutton.y)) {#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING		    o->scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY;#endif		    if (rxvtlib_scr_page (o, DN, 1))			scrollbar_setDn ();		} else		    switch (ev->xbutton.button) {		    case Button2:#if ! defined(FUNKY_SCROLL_BEHAVIOUR)			/* align to thumb centre */			csrO = (o->scrollBar.bot - o->scrollBar.top) / 2;#elif ! defined(XTERM_SCROLLBAR)			if (scrollbar_above_slider (ev->xbutton.y)			    || scrollbar_below_slider (ev->xbutton.y))#endif				/* FUNKY_SCROLL_BEHAVIOUR */			    rxvtlib_scr_move_to (o, scrollbar_position (ev->xbutton.y) -						 csrO, scrollbar_size ());			scrollbar_setMotion ();			break;		    case Button1:#ifndef FUNKY_SCROLL_BEHAVIOUR			/* ptr offset in thumb */			csrO = ev->xbutton.y - o->scrollBar.top;#endif			/* FALLTHROUGH */		    case Button3:#ifndef XTERM_SCROLLBAR			if (scrollbar_above_slider (ev->xbutton.y))# ifdef RXVT_SCROLL_FULL			    rxvtlib_scr_page (o, UP, o->TermWin.nrow - 1);# else			rxvtlib_scr_page (o, UP, o->TermWin.nrow / 4);# endif			else		    if (scrollbar_below_slider (ev->xbutton.y))# ifdef RXVT_SCROLL_FULL			rxvtlib_scr_page (o, DN, o->TermWin.nrow - 1);# else			rxvtlib_scr_page (o, DN, o->TermWin.nrow / 4);# endif			else			scrollbar_setMotion ();#else				/* XTERM_SCROLLBAR */			rxvtlib_scr_page (o (o, ev->xbutton.button == Button1 ? DN : UP),					  (o->TermWin.nrow *					   scrollbar_position (ev->xbutton.y) / scrollbar_size ())			    );#endif				/* XTERM_SCROLLBAR */			break;		    }	    }	    return;	}	if (isMenuBarWindow (ev->xany.window)) {	    rxvtlib_menubar_control (o, &(ev->xbutton));	    return;	}	break;    case ButtonRelease:	csrO = 0;		/* reset csr Offset */	reportmode = bypass_keystate ? 0 : (o->PrivateModes & PrivMode_mouse_report);	if (scrollbar_isUpDn ()) {	    scrollbar_setNone ();	    rxvtlib_scrollbar_show (o, 0);#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING	    o->refresh_type &= ~SMOOTH_REFRESH;#endif	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?