9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] focus bug in libdraw program
@ 2021-04-14  6:03 telephil9
  2021-04-22 15:26 ` istvan bak
  0 siblings, 1 reply; 5+ messages in thread
From: telephil9 @ 2021-04-14  6:03 UTC (permalink / raw)
  To: 9front

Hi,

I have noticed a strange behaviour in a libdraw program where mouse events are wrongfully retriggered when the window focus is "stolen" by another window because of an event.
To illustrate this, here is a test case (full code below):
- A window has a clickable area where a right-click plumbs a mail message. This opens a nedmail window so focus is no more on the main window.
- Hide our window through winwatch or the rio menu, you'll see the nedmail window open once again
- Unhide our window, nedmail window for the third time

This 2 last steps highlight the bug where our main window still receives event and the Mouse struct read from the Mousectl chan has coordinates inside our window whereas we're not there anymore.

I'll try to dig into this but I'm not quite sure, at this stage, where the issue might be. Any kind of help/hints would be appreciated.

--phil


#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <keyboard.h>
#include <thread.h>
#include <plumb.h>

enum
{
	Emouse,
	Eresize,
	Ekeyboard
};

Rectangle clickr;

void
redraw(void)
{
	clickr = insetrect(screen->r, 20);
	draw(screen, screen->r, display->white, nil, ZP);
	border(screen, clickr, 1, display->black, ZP);
	flushimage(display, 1);
}
	
void
plumbmsg(void)
{
	int fd;

	fd = plumbopen("send", OWRITE|OCEXEC);
	if(fd<0)
		return;
	plumbsendtext(fd, "test", nil, nil, "/mail/fs/mbox/1");
	close(fd);
}

void
threadmain(int argc, char *argv[])
{
	USED(argc);
	USED(argv);
	Mousectl *mctl;
	Keyboardctl *kctl;
	Mouse m;
	Rune k;
	Alt alts[] = {
		{ nil, &m,  CHANRCV },
		{ nil, nil, CHANRCV },
		{ nil, &k,  CHANRCV },
		{ nil, nil, CHANEND },
	};

	if(initdraw(nil, nil, "test")<0)
		sysfatal("initdraw: %r");
	if((mctl = initmouse(nil, screen))==nil)
		sysfatal("initmouse: %r");
	if((kctl = initkeyboard(nil))==nil)
		sysfatal("initkeyboard: %r");
	alts[Emouse].c = mctl->c;
	alts[Eresize].c = mctl->resizec;
	alts[Ekeyboard].c = kctl->c;
	redraw();
	for(;;){
		switch(alt(alts)){
		case Emouse:
			if(ptinrect(m.xy, clickr)){
				if(m.buttons&4)
					plumbmsg();
			}
			break;
		case Eresize:
			if(getwindow(display, Refnone)<0)
				sysfatal("getwindow: %r");
			redraw();
			break;
		case Ekeyboard:
			if(k=='q' || k==Kdel)
				threadexitsall(nil);
			break;
		}
	}
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-26  9:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14  6:03 [9front] focus bug in libdraw program telephil9
2021-04-22 15:26 ` istvan bak
2021-04-24 11:17   ` cinap_lenrek
2021-04-25 17:25     ` istvan bak
2021-04-26  5:04     ` telephil9

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).