⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.c

📁 rxvt经典的linux下的终端.小巧实用
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <X11/Xlib.h>#include <X11/Xatom.h>#include <X11/keysymdef.h>#include "ntdef.h"/* a crude method to avoid losing the selection when   calling EmptyClipboard, which is necessary to do   every time the selection content changes, otherwise   windows apps use a cached copy of the selection */static volatile int destroyClipboardCatcher = 0;static NT_window *NT_CWIN = NULL;voidcatchNextDestroyClipboard(){    destroyClipboardCatcher=1;}typedef struct WinEvent_{    NT_window *window;    UINT message;    UINT wParam;    LONG lParam;} WinEvent;#define W11_QSIZE 100typedef struct WinEventQ_{    int num;    int avail;    int next;    int count;    int dispatch;    proto_W11EventHandler *handler;    WinEvent list[W11_QSIZE];} WinEventQ;static WinEventQ *wineventq = NULL;voidinitQ() {    int i;    WinEventQ *q = (WinEventQ *)allocateMemory(sizeof(WinEventQ));    q->num=W11_QSIZE-1;    q->avail=0;    q->next=0;    q->count=0;    q->dispatch=0;    q->handler=NULL;    for (i=0; i<W11_QSIZE; i++) {	q->list[i].message=0;	q->list[i].window = NULL;    }    wineventq = q;}static intgetQdEvent(WinEventQ *q, XEvent *ev){    WinEvent we;    if (q->count<=0) {	cjh_printf("Queue is empty\n");	return 0;    }    we = q->list[q->next];    WinEventToXEvent(&we,ev);    q->next++;    q->count--;    if (q->next>q->num) q->next=0;	    return 1;}static voidQSendEvent(WinEventQ *q) {    XEvent e;    if (q->handler != NULL) {	if (getQdEvent(q,&e)) (q->handler)(&e);    }}static intQEvent(WinEventQ *q, NT_window *window,UINT message,UINT wParam,LONG lParam){    q->list[q->avail].window=window;    q->list[q->avail].message=message;    q->list[q->avail].wParam=wParam;    q->list[q->avail].lParam=lParam;    q->avail++; q->count++;    if (q->avail>q->num) q->avail=0;    if (q->dispatch) QSendEvent(q);    return 1;}/* Allow application to install an event handler call back.   This will make some actions such as moving the window work   better.   The event handler should look like:   void process_xevent(XEvent *ev) { }   To install it:   W11AddEventHandler(display,process_xevent);   The specific problem is that calling DefWindowProc()   in response to a WM_SYSCOMMAND will cause windows to run its   own event loop waiting for the mouse up event.  The application   therefore cannot rely on it's main event loop to get run for   each event.  Without running multiple threads, or setjmp, there   is little recourse for alerting the application in the   traditional X manner to Expose events while the window is   being moved.*/void W11AddEventHandler(Display *d, proto_W11EventHandler *ev) {    wineventq->handler = ev;}static voiddoTranslateMessage(MSG *m){	if ((m->message == WM_KEYDOWN) && 	    ((m->wParam == VK_BACK) ||	     (m->wParam == VK_ADD) ||	     (m->wParam == VK_SUBTRACT))) return;	if ((m->message == WM_SYSKEYDOWN) && (m->wParam == VK_F10))	{	    m->message = WM_KEYDOWN;	    return;	}	TranslateMessage(m);}static LONGNT_default(HWND hWnd,UINT message,UINT wParam,LONG lParam){    return DefWindowProc(hWnd, message, wParam, lParam);}static voidNT_wakeup(HWND hWnd) {    PostMessage(hWnd,USR_WakeUp,0,0L);}/*****************************************************************\	Function: MainWndProc	Inputs:   Window handle, message, message parameters.	Comments: This is called when messages are sent to the application		  but not to the application's message queue.  If an		  event can be processed, it is done here.  The equivalent		  XEvent is filled out in l_event, which is picked up		  in the X event routines.  Some events are not received		  from Windows, eg Enter/LeaveNotify, so these are made		  up as required.	Caution:  The application does not see HWND, but Window.\*****************************************************************//* queued messages   WM_KEYDOWN   WM_KEYUP   WM_CHAR   WM_MOUSEMOVE   WM_BUTTONxx   WM_TIMER   WM_PAINT   WM_QUIT   */LONG NT_handleMsg(    HWND hWnd,		  /* window handle		     */    UINT message,		  /* type of message		     */    UINT wParam,		  /* additional information	     */    LONG lParam)		  /* additional information	     */{    RECT rect;    WINDOWPOS *posStruct;    unsigned long int st=0L;    NT_window *window;    long mask;    PAINTSTRUCT paintStruct;    /*	if (message == WM_CLOSE) exit(0); */	    window = NT_find_window_from_id(hWnd);    if (window == NULL) return  (NT_default(hWnd, message, wParam, lParam));    mask = window->mask;	    switch (message) {	/* we'll handle these, later */	case WM_KILLFOCUS:	    QEvent(wineventq,window,message,wParam,lParam);	    NT_wakeup(hWnd);	    break;	case WM_SETFOCUS:	case WM_QUIT:	case WM_CLOSE:	case WM_DESTROY:	case WM_SYSCHAR: /* alt-keys go here */	case WM_CHAR:	case WM_LBUTTONDBLCLK:	case WM_MBUTTONDBLCLK:	case WM_RBUTTONDBLCLK:	case USR_MapNotify:	case USR_EnterNotify:	case WM_MOVE:#if defined(WIN9X)	case WM_SIZING:#endif				case WM_SIZE:				    QEvent(wineventq,window,message,wParam,lParam);	    break;	case WM_DESTROYCLIPBOARD:	    if (destroyClipboardCatcher)		destroyClipboardCatcher=0;	    else {		QEvent(wineventq,window,message,wParam,lParam);		NT_wakeup(hWnd);            }	    break;	case WM_PAINT:	    BeginPaint(hWnd,&paintStruct);	    FillRect(paintStruct.hdc, &paintStruct.rcPaint,window->bg);	    QEvent(wineventq,window,message,		   (((paintStruct.rcPaint.right-paintStruct.rcPaint.left)&0xffff) |		    (((paintStruct.rcPaint.bottom-paintStruct.rcPaint.top)&0xffff)<<16)),		   (((paintStruct.rcPaint.left)&0xffff) | (((paintStruct.rcPaint.top)&0xffff)<<16)));	    EndPaint(hWnd,&paintStruct);	    break;	    /* capture the mouse on button down to emulate x */	case WM_LBUTTONDOWN:	case WM_MBUTTONDOWN:	case WM_RBUTTONDOWN:	    SetCapture(hWnd);	    QEvent(wineventq,window,message,wParam,lParam);	    break;	case WM_MBUTTONUP:	case WM_LBUTTONUP:	case WM_RBUTTONUP:	    ReleaseCapture();	    QEvent(wineventq,window,message,wParam,lParam);	    break;	case WM_MOUSEMOVE:	    if ((mask&PointerMotionMask) ||		((mask&Button1MotionMask)&& (wParam&MK_LBUTTON)) ||		((mask&Button2MotionMask)&& (wParam&MK_MBUTTON)) ||		((mask&Button3MotionMask)&& (wParam&MK_RBUTTON)) ||		((mask&ButtonMotionMask)&&((wParam&(MK_LBUTTON|MK_MBUTTON|MK_RBUTTON))))		)		QEvent(wineventq,window,message,wParam,lParam);	    else		return (NT_default(hWnd, message, wParam, lParam));	    break;	case WM_MOUSEWHEEL:	    /* this event only seems to go to the top most window.	       see if child windows accept it. */	    window = NT_find_child(window,ButtonPressMask|Button2MotionMask|Button3MotionMask,				   ButtonPressMask|Button3MotionMask );	    if (window && ((window->mask)&ButtonPressMask)) 		QEvent(wineventq,window,message,wParam,lParam);	    else		return (NT_default(hWnd, message, wParam, lParam));	    break;	case WM_ERASEBKGND:	    /* don't erase the background */	    return 1;	    break;	case WM_SYSCOMMAND:	    wineventq->dispatch++;	    NT_default(hWnd, message, wParam, lParam);	    wineventq->dispatch--;	    break;	case WM_KEYDOWN:	    switch (wParam)	    {		case VK_CANCEL:		case VK_CLEAR:		case VK_PAUSE:		case VK_PRIOR:		case VK_NEXT:		case VK_END:		case VK_HOME:		case VK_LEFT:		case VK_UP:		case VK_RIGHT:		case VK_DOWN:		case VK_SELECT:		case VK_PRINT:		case VK_EXECUTE:		case VK_INSERT:		case VK_DELETE:		case VK_HELP:		case VK_NUMLOCK:		case VK_SCROLL:		case VK_BACK:                case VK_F1:                case VK_F2:                case VK_F3:                case VK_F4:                case VK_F5:                case VK_F6:                case VK_F7:                case VK_F8:                case VK_F9:                case VK_F10:                case VK_F11:	        case VK_F12:	        case VK_ADD:	        case VK_SUBTRACT:		    QEvent(wineventq,window,message,wParam,lParam);		    break;		default:		    return  (NT_default(hWnd, message, wParam, lParam));		    break;						    }	    break;	default:			  /* Passes it on if unproccessed    */	    return (NT_default(hWnd, message, wParam, lParam));    }    return 0L;}/*****************************************************************\	Function: NT_get_state	Inputs: 	Comments: Get the keyboard state\*****************************************************************/static unsigned intNT_get_state(){	unsigned int state = 0;	if (GetKeyState(VK_SHIFT)   & 0x8000) state |= ShiftMask;	if (GetKeyState(VK_CONTROL) & 0x8000)	{		if (!(GetKeyState(VK_MENU) & 0x8000)) 			state |= ControlMask;	}	else if (GetKeyState(VK_MENU)    & 0x8000)		state |= Mod1Mask;	if (GetKeyState(VK_CAPITAL) & 0x0001) state |= LockMask;	if (GetKeyState(VK_NUMLOCK) & 0x0001) state |= Mod5Mask;	if (GetKeyState(VK_SCROLL)  & 0x0001) state |= Mod3Mask;	if (GetKeyState(VK_LBUTTON) & 0x8000) state |= Button1Mask;	if (GetKeyState(VK_MBUTTON) & 0x8000) state |= Button2Mask;	if (GetKeyState(VK_RBUTTON) & 0x8000) state |= Button3Mask;	return state;}intWinEventToXEvent(    WinEvent *we,    XEvent *event){    POINT pt;    RECT rect;    unsigned long int st=0L;    UINT key;    HWND hWnd;    UINT wParam;    LONG lParam;    NT_window *window;	    do {			if (event==NULL) break;	if (we == NULL) break;	window = we->window;	wParam = we->wParam;	lParam = we->lParam;			event->type=-1;	event->xbutton.subwindow = None;	hWnd = window->w;			switch (we->message) {	    case WM_SETFOCUS:		event->type=FocusIn;		event->xfocus.window=(Window)window;		break;	    case WM_KILLFOCUS:		event->type=FocusOut;		event->xfocus.window=(Window)window;		break;					/*	case WM_ERASEBKGND: */	    case WM_PAINT:		event->type=Expose;		event->xexpose.x=LOWORD(lParam); /* right */		event->xexpose.y=HIWORD(lParam); /* top */		event->xexpose.width=LOWORD(wParam);		event->xexpose.height=HIWORD(wParam);		event->xexpose.count=0;		event->xexpose.window=(Window)window;		break;	    case WM_LBUTTONDOWN:	    case WM_LBUTTONDBLCLK:		event->type = ButtonPress;		event->xbutton.x = LOWORD (lParam);		event->xbutton.y = HIWORD (lParam);		if ( wParam & MK_SHIFT )		    event->xbutton.button=Button2;		else		    event->xbutton.button=Button1;		event->xbutton.window = (Window)window;		event->xbutton.time=GetTickCount();		break;	    case WM_LBUTTONUP:		event->type=ButtonRelease;		event->xbutton.x=LOWORD(lParam);		event->xbutton.y=HIWORD (lParam);		if ( wParam & MK_SHIFT )		    event->xbutton.button=Button2;		else		    event->xbutton.button=Button1;		event->xbutton.window=(Window)window;		event->xbutton.time=GetTickCount();		break;	    case WM_MBUTTONDOWN:	    case WM_MBUTTONDBLCLK:		event->type=ButtonPress;		event->xbutton.x=LOWORD(lParam);		event->xbutton.y=HIWORD (lParam);		event->xbutton.button=Button2;		event->xbutton.window=(Window)window;		event->xbutton.time=GetTickCount();		break;	    case WM_MBUTTONUP:		event->type=ButtonRelease;		event->xbutton.x=LOWORD(lParam);		event->xbutton.y=HIWORD (lParam);		event->xbutton.button=Button2;		event->xbutton.window=(Window)window;		event->xbutton.time=GetTickCount();		break;	    case WM_RBUTTONDOWN:	    case WM_RBUTTONDBLCLK:		event->type=ButtonPress;		event->xbutton.x=LOWORD(lParam);		event->xbutton.y=HIWORD (lParam);		event->xbutton.button=Button3;		event->xbutton.window=(Window)window;		event->xbutton.time=GetTickCount();		break;	    case WM_RBUTTONUP:		event->type=ButtonRelease;		event->xbutton.x=LOWORD(lParam);		event->xbutton.y=HIWORD (lParam);		event->xbutton.button=Button3;		event->xbutton.window=(Window)window;		event->xbutton.time=GetTickCount();		break;	    case WM_MOUSEMOVE:		if (hWnd!=(HWND)NT_CWIN)  /* Mouse in different window? */		{		    if (NT_CWIN==NULL) /* No previous window */		    {			event->type = EnterNotify;			event->xcrossing.x = LOWORD(lParam);			event->xcrossing.y = HIWORD(lParam);			event->xcrossing.window = (Window)window;		    }

⌨️ 快捷键说明

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