Skip to content

Commit

Permalink
Try to fix the EVENT handline problem (WINDOWS/SDL) github issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
kollokollo committed Oct 28, 2020
1 parent 40e671a commit 53e1332
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 61 deletions.
2 changes: 2 additions & 0 deletions doc/manual/sec/E.sec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
156 changes: 101 additions & 55 deletions src/gkommandos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1596,42 +1619,52 @@ 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;
if(winnr>0 && winnr<MAXWINDOWS) {
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;
if(winnr>0 && winnr<MAXWINDOWS) {
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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"
Expand Down Expand Up @@ -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){\
Expand Down Expand Up @@ -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;i<t.len;i++) g_out(t.pointer[i]); }
if(t.len) {int i; for(i=0;i<t.len;i++) g_out(t.pointer[i]); }
}


Expand Down Expand Up @@ -2117,9 +2170,7 @@ void c_alert(PARAMETER *plist,int e) {
STRING str;
str.pointer=malloc(sizeof(buffer));
char *a=buffer;
*a++='[';
*a++='0'+plist->integer;
*a++=']';
*a++='['; *a++='0'+plist->integer; *a++=']';
*a++='[';
int i;
for(i=0;i<plist[1].integer;i++) *a++=((char *)plist[1].pointer)[i];
Expand Down Expand Up @@ -2147,9 +2198,9 @@ void c_fileselect(PARAMETER *plist,int e) {


int menuaction=-1;
int menuactiontype=0; /* 0= menuaction ist zeilennummer
1= menuaction ist pointer in bytecode
3= menuaction ist reelle adresse void *(function())*/
int menuactiontype=0; /* 0= menuaction is line number
1= menuaction is pointer into bytecode
3= menuaction is real address void *(function()) */


MENUENTRY menuentry[MAXMENUENTRYS];
Expand Down Expand Up @@ -2246,27 +2297,24 @@ void c_menuset(PARAMETER *plist, int e) {
else xberror(62,""); /* MENU wrong */
}
}
void c_menukill(char *n) {
if(menuaction!=-1) menuaction=-1;
}
void c_menukill(char *n) { if(menuaction!=-1) menuaction=-1; }


/************** RSRC-Library *******************************************/
/************ RSRC-Library wrappers ************/


void c_rsrc_load(PARAMETER *plist,int e) {
graphics(); /* Wegen Screendimensionen */
if(rsrc_load(plist->pointer)) 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","");
Expand All @@ -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 */
Loading

0 comments on commit 53e1332

Please sign in to comment.