From 53e1332444d7e94cd859718e6713a66c37bdf698 Mon Sep 17 00:00:00 2001 From: Markus Hoffmann Date: Wed, 7 Oct 2020 16:24:31 +0200 Subject: [PATCH] Try to fix the EVENT handline problem (WINDOWS/SDL) github issue #11 --- doc/manual/sec/E.sec | 2 + src/gkommandos.c | 156 ++++++++++++++++++++++++++++--------------- src/window.c | 19 ++++-- 3 files changed, 116 insertions(+), 61 deletions(-) diff --git a/doc/manual/sec/E.sec b/doc/manual/sec/E.sec index e3bfa0c..9e089b0 100644 --- a/doc/manual/sec/E.sec +++ b/doc/manual/sec/E.sec @@ -423,6 +423,8 @@ DESCRIPTION: mask= 2 --- key release event mask= 4 --- mouse button press event mask= 8 --- mouse button release event + mask= 0x10 --- mouse enters window event + mask= 0x20 --- mouse leaves window event mask= 0x40 --- mouse motion event mask= 0x40000 --- window resize events mask=0x200000 --- window focus change events diff --git a/src/gkommandos.c b/src/gkommandos.c index 88de5dc..4fa3cc1 100644 --- a/src/gkommandos.c +++ b/src/gkommandos.c @@ -1233,8 +1233,8 @@ void c_mouseevent(PARAMETER *plist,int e) { /*MOUSEEVENT x,y,k,rx,ry,s */ } void c_motionevent(PARAMETER *plist,int e) { /* x,y,b,rx,ry,s */ -#ifdef WINDOWS_NATIVE graphics(); +#ifdef WINDOWS_NATIVE ResetEvent(motionevent); WaitForSingleObject(motionevent,INFINITE); if(e>0 && plist[0].typ!=PL_LEER) varcastint(plist[0].integer,plist[0].pointer,global_mousex); @@ -1243,7 +1243,6 @@ void c_motionevent(PARAMETER *plist,int e) { /* x,y,b,rx,ry,s */ if(e>5 && plist[5].typ!=PL_LEER) varcastint(plist[5].integer,plist[5].pointer,global_mouses); #elif defined USE_X11 || defined FRAMEBUFFER XEvent event; - graphics(); #ifdef FRAMEBUFFER FB_mouse_events(1); FB_showx_mouse(); @@ -1283,9 +1282,11 @@ void c_motionevent(PARAMETER *plist,int e) { /* x,y,b,rx,ry,s */ #endif } +/* Command: KEYEVENT */ + void c_keyevent(PARAMETER *plist,int e) { + graphics(); /* make sure, window is open, remove Exposure events.*/ #ifdef WINDOWS_NATIVE - graphics(); ResetEvent(keyevent); WaitForSingleObject(keyevent,INFINITE); while(global_eventtype!=KeyChar) { @@ -1297,13 +1298,11 @@ void c_keyevent(PARAMETER *plist,int e) { if(e>3 && plist[3].typ!=PL_LEER) varcastint(plist[3].integer,plist[3].pointer,global_mouses); if(e>4 && plist[4].typ!=PL_LEER) varcastint(plist[4].integer,plist[4].pointer,global_mousex); if(e>5 && plist[5].typ!=PL_LEER) varcastint(plist[5].integer,plist[5].pointer,global_mousey); -#endif -#ifdef FRAMEBUFFER +#elif defined FRAMEBUFFER FB_keyboard_events(1); #endif #if defined USE_X11 || defined FRAMEBUFFER XEvent event; - graphics(); XWindowEvent(window[usewindow].display, window[usewindow].win,KeyPressMask|ExposureMask, &event); while(event.type!=KeyPress && event.type!=TerminateEventLoop) { @@ -1345,7 +1344,6 @@ void c_keyevent(PARAMETER *plist,int e) { SDL_Event event; STRING str; char buf[4]; - graphics(); if(SDL_WaitEvent(&event)==0) return; while(event.type!=SDL_KEYDOWN /* && event.type!=SDL_KEYUP */ ) { handle_event(&window[usewindow],&event); @@ -1367,10 +1365,14 @@ void c_keyevent(PARAMETER *plist,int e) { #endif } + +/* Function EVENT?(mask%) */ + int f_eventf(int mask) { + graphics(); /* Make sure window is open etc..*/ #if defined USE_X11 || defined FRAMEBUFFER + XEvent event; - graphics(); again: if(XCheckWindowEvent(window[usewindow].display, window[usewindow].win,mask|ExposureMask, &event)) { if(event.type==Expose || event.type==GraphicsExpose|| event.type==NoExpose) { @@ -1382,7 +1384,30 @@ int f_eventf(int mask) { return -1; } #elif defined USE_SDL - if(SDL_PollEvent(NULL)) return(-1); + SDL_Event event; + SDL_PumpEvents(); /* store events internally in the event queue */ + /* filter events according to mask. */ + int sdlmask=0; + if(mask&0x1) sdlmask|=SDL_EVENTMASK(SDL_KEYDOWN); + if(mask&0x2) sdlmask|=SDL_EVENTMASK(SDL_KEYUP); + if(mask&0x4) sdlmask|=SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN); + if(mask&0x8) sdlmask|=SDL_EVENTMASK(SDL_MOUSEBUTTONUP); +#ifdef SDL_WINDOWEVENT + if(mask&0x10) sdlmask|=SDL_EVENTMASK(SDL_WINDOWEVENT_ENTER); + if(mask&0x20) sdlmask|=SDL_EVENTMASK(SDL_WINDOWEVENT_LEAVE); +#endif + if(mask&0x40) sdlmask|=SDL_EVENTMASK(SDL_MOUSEMOTION); +#ifdef SDL_WINDOWEVENT + if(mask&0x40000) sdlmask|=SDL_EVENTMASK(SDL_WINDOWEVENT_RESIZED)|SDL_EVENTMASK(SDL_WINDOWEVENT_MOVED); + if(mask&0x200000) sdlmask|=SDL_EVENTMASK(SDL_WINDOWEVENT_FOCUS_GAINED)|SDL_EVENTMASK(SDL_WINDOWEVENT_FOCUS_LOST); +#endif + + if(mask==-1) sdlmask=SDL_ALLEVENTS; + + int a=SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, sdlmask); + if(a<0) { + printf("SDL_Error: %d\n",a); + } else if(a>0) return(-1); #endif return 0; } @@ -1407,9 +1432,9 @@ int f_eventf(int mask) { void c_allevent(PARAMETER *plist,int e) { + graphics(); /* make sure, window is open, remove Exposure events.*/ #ifdef WINDOWS_NATIVE HANDLE evn[3]; - graphics(); evn[0]=keyevent; evn[1]=motionevent; evn[2]=buttonevent; @@ -1428,8 +1453,7 @@ void c_allevent(PARAMETER *plist,int e) { } if(e>7 && plist[7].typ!=PL_LEER) varcastint(plist[7].integer,plist[7].pointer,global_ks); #elif defined USE_X11 || defined FRAMEBUFFER - XEvent event; - graphics(); + XEvent event; #ifdef FRAMEBUFFER FB_mouse_events(1); FB_showx_mouse(); @@ -1539,7 +1563,6 @@ void c_allevent(PARAMETER *plist,int e) { #elif defined USE_SDL SDL_Event event; char buf[4]; - graphics(); if(SDL_WaitEvent(&event)==0) return; #if 0 @@ -1596,6 +1619,10 @@ void c_allevent(PARAMETER *plist,int e) { } #endif } + + +/* Command: TITLEW */ + void c_titlew(PARAMETER *plist,int e) { int winnr=DEFAULTWINDOW; if(plist->typ!=PL_LEER) winnr=plist->integer; @@ -1603,19 +1630,22 @@ void c_titlew(PARAMETER *plist,int e) { graphics(); if(window[winnr].flags&WIN_CREATED) { #ifdef WINDOWS_NATIVE - SetWindowText(window[winnr].win_hwnd,plist[1].pointer); + SetWindowText(window[winnr].win_hwnd,plist[1].pointer); #elif defined USE_X11 - if (!XStringListToTextProperty((char **)&(plist[1].pointer), 1, &window[winnr].win_name)) - printf("Couldn't set Name of Window.\n"); - XSetWMName(window[winnr].display, window[winnr].win, &window[winnr].win_name); + if(!XStringListToTextProperty((char **)&(plist[1].pointer), 1, &window[winnr].win_name)) + printf("X11-Error: Couldn't set name of window.\n"); + XSetWMName(window[winnr].display, window[winnr].win, &window[winnr].win_name); #elif defined USE_SDL - SDL_WM_SetCaption(plist[1].pointer,NULL); + SDL_WM_SetCaption(plist[1].pointer,NULL); #endif - if(window[winnr].title) free(window[winnr].title); - window[winnr].title=strdup(plist[1].pointer); + if(window[winnr].title) free(window[winnr].title); + window[winnr].title=strdup(plist[1].pointer); } else xberror(99,""); /* Window %s does not exist */ } else xberror(98,""); /* Illegal Window number %s (0-16) */ } + +/* Command: INFOW */ + void c_infow(PARAMETER *plist,int e) { /* Set the Icon Name */ int winnr=usewindow; if(plist->typ!=PL_LEER) winnr=plist->integer; @@ -1623,15 +1653,18 @@ void c_infow(PARAMETER *plist,int e) { /* Set the Icon Name */ graphics(); if(window[winnr].flags&WIN_CREATED) { #ifdef USE_X11 - XSetIconName(window[winnr].display, window[winnr].win,plist[1].pointer); + XSetIconName(window[winnr].display, window[winnr].win,plist[1].pointer); #elif defined USE_SDL - SDL_WM_SetCaption(NULL,plist[1].pointer); + SDL_WM_SetCaption(NULL,plist[1].pointer); #endif - if(window[winnr].info) free(window[winnr].info); - window[winnr].info=strdup(plist[1].pointer); + if(window[winnr].info) free(window[winnr].info); + window[winnr].info=strdup(plist[1].pointer); } else xberror(99,""); /* Window %s does not exist */ } else xberror(98,""); /* Illegal Window number %s (0-16) */ } + +/* Command: CLEARW */ + void c_clearw(PARAMETER *plist,int e) { int winnr=usewindow; if(e) winnr=plist->integer; @@ -1667,6 +1700,9 @@ void c_clearw(PARAMETER *plist,int e) { } else xberror(99,""); /* Window %s does not exist */ } else xberror(98,""); /* Illegal Window number %s (0-16) */ } + +/* Command: CLOSEW */ + void c_closew(PARAMETER *plist,int e) { int winnr=usewindow; if(e) winnr=plist->integer; @@ -1677,6 +1713,9 @@ void c_closew(PARAMETER *plist,int e) { } else xberror(99,""); /* Window %s does not exist */ } else xberror(98,""); /* Illegal Window number %s (0-16) */ } + +/* Command: OPENW */ + void c_openw(PARAMETER *plist,int e) { int winnr=DEFAULTWINDOW; if(e) winnr=plist->integer; @@ -1687,6 +1726,8 @@ void c_openw(PARAMETER *plist,int e) { } else xberror(98,""); /* Illegal Window number %s (0-16) */ } +/* Command: SIZEW */ + void c_sizew(PARAMETER *plist,int e) { int winnr=usewindow; if(plist->typ!=PL_LEER) winnr=plist->integer; @@ -1697,6 +1738,9 @@ void c_sizew(PARAMETER *plist,int e) { } else if(winnr==0) xberror(97,"SIZEW"); /* This operation %s is not allowed for root window */ else xberror(98,""); /* Illegal Window number %s (0-16) */ } + +/* Command: MOVEW */ + void c_movew(PARAMETER *plist,int e) { int winnr=usewindow; if(plist->typ!=PL_LEER) winnr=plist->integer; @@ -1708,6 +1752,8 @@ void c_movew(PARAMETER *plist,int e) { else xberror(98,""); /* Illegal Window number %s (0-16) */ } +/* Command: FULLW */ + void c_fullw(PARAMETER *plist,int e) { int winnr=usewindow; if(e) winnr=plist->integer; @@ -1724,13 +1770,15 @@ void c_fullw(PARAMETER *plist,int e) { DefaultScreen(window[winnr].display)),&root,&ox,&oy,&ow,&oh,&ob,&d); do_sizew(&window[winnr],ow,oh); #elif defined USE_SDL -/*Hier haben wir die chance, den fullscreenmodus zu aktivieren...*/ + /* TODO: Here we have the chance to activate the full screen mode in SDL... */ #endif } else xberror(99,""); /* Window %s does not exist */ } else if(winnr==0) xberror(97,"FULLW"); /* This operation %s is not allowed for root window */ else xberror(98,""); /* Illegal Window number %s (0-16) */ } +/* Command: TOPW */ + void c_topw(PARAMETER *plist,int e) { int winnr=usewindow; if(e) winnr=plist->integer; @@ -1744,6 +1792,9 @@ void c_topw(PARAMETER *plist,int e) { } else xberror(99,""); /* Window %s does not exist */ } else xberror(98,""); /* Illegal Window number %s (0-16) */ } + +/* Command: BOTTOMW */ + void c_bottomw(PARAMETER *plist,int e) { int winnr=usewindow; if(e) winnr=plist->integer; @@ -1757,6 +1808,9 @@ void c_bottomw(PARAMETER *plist,int e) { } else xberror(99,""); /* Window %s does not exist */ } else xberror(98,""); /* Illegal Window number %s (0-16) */ } + +/* Command: DEFMOUSE */ + #ifndef USE_GEM #include "bitmaps/biene.bmp" #include "bitmaps/biene_mask.bmp" @@ -1876,9 +1930,7 @@ void c_defmouse(PARAMETER *plist,int e) { /* graphic window print functions. Should probably be unified with the framebuffer terminal routines. Only few VT100 codes are implemented, - no colors, no attibutes.*/ - - + no colors, no attibutes. */ #define LINEFEED() {lin++; col=0; \ if(lin*window[usewindow].chh>=window[usewindow].h){\ @@ -2065,9 +2117,10 @@ static void g_out(char a) { } } } + + static inline void g_outs(STRING t) { - int i; - if(t.len) { for(i=0;iinteger; - *a++=']'; + *a++='['; *a++='0'+plist->integer; *a++=']'; *a++='['; int i; for(i=0;ipointer)) xberror(72,""); /* Fehler bei RSRC_LOAD*/ } -void c_rsrc_free(char *n) { - if(rsrc_free()) xberror(73,""); /* Fehler bei RSRC_FREE*/ -} -void c_objc_add(PARAMETER *plist,int e) { - objc_add((OBJECT *)INT2POINTER(plist->integer),plist[1].integer,plist[2].integer); -} -void c_objc_delete(PARAMETER *plist,int e) { - objc_delete((OBJECT *)INT2POINTER(plist->integer),plist[1].integer); -} + +void c_rsrc_free(char *n) { if(rsrc_free()) xberror(73,""); /* Fehler bei RSRC_FREE*/ } +void c_objc_add(PARAMETER *plist,int e) { objc_add((OBJECT *)INT2POINTER(plist->integer),plist[1].integer,plist[2].integer); } +void c_objc_delete(PARAMETER *plist,int e) { objc_delete((OBJECT *)INT2POINTER(plist->integer),plist[1].integer); } + + +/*** XLOAD and XRUN ***/ + static int do_xload(char *n) { int ret=0; char *name=fileselector("Load X11-Basic program:","./*.bas",""); @@ -2284,10 +2332,8 @@ static int do_xload(char *n) { free(name); return(ret); } -void c_xload(char *n) { - do_xload(n); -} -void c_xrun(char *n) { - if(!do_xload(n)) do_run(); -} + +void c_xload(char *n) { do_xload(n); } +void c_xrun(char *n) { if(!do_xload(n)) do_run(); } + #endif /* NOGRAPHICS */ diff --git a/src/window.c b/src/window.c index a75c34c..988ddd0 100644 --- a/src/window.c +++ b/src/window.c @@ -581,15 +581,22 @@ void handle_window(WINDOWDEF *w) { if(!(w->flags&WIN_CREATED)) return; #ifdef WINDOWS_NATIVE -#endif -#ifdef USE_SDL + /* TODO ... */ +#elif defined USE_SDL SDL_Event event; - while(SDL_PollEvent(&event)) handle_event(w,&event); + SDL_PumpEvents(); /* store events internally in the event queue */ + /* filter for WINDOW events only (all but keyboard, mouse, joystick) */ + int sdlmask=SDL_ALLEVENTS^(SDL_KEYEVENTMASK|SDL_MOUSEMOTIONMASK|SDL_MOUSEEVENTMASK|SDL_JOYEVENTMASK); + int a=SDL_PeepEvents(&event, 1, SDL_GETEVENT, sdlmask); + while(a>0) { + handle_event(w,&event); + a=SDL_PeepEvents(&event, 1, SDL_GETEVENT, sdlmask); + } #elif defined USE_X11 - XEvent event; - while(XCheckWindowEvent(w->display,w->win,ExposureMask, &event)) { + XEvent event; + while(XCheckWindowEvent(w->display,w->win,ExposureMask, &event)) { handle_event(w,&event); - } + } #endif }