9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] rio window overlapping order
@ 2001-08-21 11:46 rob pike
  2001-08-22  0:45 ` YAMANASHI Takeshi
  0 siblings, 1 reply; 5+ messages in thread
From: rob pike @ 2001-08-21 11:46 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

try this.  i call it /bin/top.  top -i (inventory) lists them
and produces a list of commands to 'top' any of the
windows.

#!/bin/rc

rfork e
ifs='
'

if(~ $#* 1 && ~ $1 -i) {
	shift
	for(i in /dev/wsys/*){
		x=`{read $i/label}
		if(~ $#* 0) echo top ''''$x'''' '#' $i 
	}
	exit
}

for(i in /dev/wsys/*){
	x=`{read $i/label}
	if(~ $#* 0) echo top $x
	if not if(~ $x $"*){
		echo top > $i/wctl
		echo current > $i/wctl
	}
}


[-- Attachment #2: Type: message/rfc822, Size: 1786 bytes --]

From: YAMANASHI Takeshi <uncover@beat.cc.titech.ac.jp>
To: 9fans@cse.psu.edu
Subject: [9fans] rio window overlapping order
Date: Tue, 21 Aug 2001 15:44:35 +0900
Message-ID: <10489.998376275@beat.cc.titech.ac.jp>

How can I find the order rio arranges its windows?

I often lost a small window overlapped entirely by other
large windows (like acme), and I feel like to write some
task-bar tool for rio to raise the small one.
-- 

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

* Re: [9fans] rio window overlapping order
  2001-08-21 11:46 [9fans] rio window overlapping order rob pike
@ 2001-08-22  0:45 ` YAMANASHI Takeshi
  0 siblings, 0 replies; 5+ messages in thread
From: YAMANASHI Takeshi @ 2001-08-22  0:45 UTC (permalink / raw)
  To: 9fans

> try this.  i call it /bin/top.  top -i (inventory) lists them
> and produces a list of commands to 'top' any of the
> windows.

Both `top' and `winwatch' tells me much about
`wsys' and I really enjoy the way the window
system is implemented on Plan 9.
-- 
YAMANASHI Takeshi


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

* Re: [9fans] rio window overlapping order
  2001-08-21  6:49 Russ Cox
@ 2001-08-21  7:07 ` YAMANASHI Takeshi
  0 siblings, 0 replies; 5+ messages in thread
From: YAMANASHI Takeshi @ 2001-08-21  7:07 UTC (permalink / raw)
  To: 9fans

> this doesn't show the exact order, but it gives
> you a button for each window, which you can click
> to raise that particular window.

Thank you.  I'm enjoying it.

By the way, can you tell me your favourable way?
Do you `Hide' other windows and seek lost one?

After having wrote my previous mail, I hit on the idea
that rio can have the window list on the Button 3 menu
like `sam'.
-- 


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

* re: [9fans] rio window overlapping order
@ 2001-08-21  6:49 Russ Cox
  2001-08-21  7:07 ` YAMANASHI Takeshi
  0 siblings, 1 reply; 5+ messages in thread
From: Russ Cox @ 2001-08-21  6:49 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 212 bytes --]

this doesn't show the exact order, but it gives
you a button for each window, which you can click
to raise that particular window.  after i wrote this
i found it not as useful as i'd expected.  ymmv.

russ

[-- Attachment #2: winwatch.c --]
[-- Type: text/plain, Size: 4866 bytes --]

#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>

typedef struct Win Win;
struct Win {
	int n;
	int dirty;
	char *label;
	Rectangle r;
};

Win *win;
int nwin;
int mwin;
int onwin;
int rows, cols;
Font *font;
Image *lightblue;

enum {
	PAD = 3,
	MARGIN = 5
};

void*
erealloc(void *v, ulong n)
{
	v = realloc(v, n);
	if(v == nil)
		sysfatal("out of memory reallocating %lud", n);
	return v;
}

void*
emalloc(ulong n)
{
	void *v;

	v = malloc(n);
	if(v == nil)
		sysfatal("out of memory allocating %lud", n);
	memset(v, 0, n);
	return v;
}

char*
estrdup(char *s)
{
	int l;
	char *t;

	if (s == nil)
		return nil;
	l = strlen(s)+1;
	t = emalloc(l);
	memcpy(t, s, l);

	return t;
}

void
refreshwin(void)
{
	char label[128];
	int i, fd, lfd, n, nr, nw, m;
	Dir d, pd[10];

	if((fd = open("/dev/wsys", OREAD)) < 0)
		return;

	nw = 0;
/* i'd rather read one at a time but rio won't let me */
	while((nr=dirread(fd, pd, sizeof(pd))) > 0){
		nr /= DIRLEN;
		for(i=0; i<nr; i++){
			d = pd[i];
			n = atoi(d.name);
			sprint(label, "/dev/wsys/%d/label", n);
			if((lfd = open(label, OREAD)) < 0)
				continue;
			m = read(lfd, label, sizeof(label)-1);
			close(lfd);
			if(m < 0)
				continue;
			label[m] = '\0';
			if(nw < nwin && win[nw].n == n && strcmp(win[nw].label, label)==0){
				nw++;
				continue;
			}
	
			if(nw < nwin){
				free(win[nw].label);
				win[nw].label = nil;
			}
			if(nw >= mwin){
				mwin += 8;
				win = erealloc(win, mwin*sizeof(win[0]));
			}
			win[nw].n = n;
			win[nw].label = estrdup(label);
			win[nw].dirty = 1;
			win[nw].r = Rect(0,0,0,0);
			nw++;
		}
	}
	while(nwin > nw)
		free(win[--nwin].label);
	nwin = nw;
	close(fd);
}

void
drawnowin(int i)
{
	Rectangle r;

	r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height);
	r = rectaddpt(rectaddpt(r, Pt(MARGIN+(PAD+Dx(r))*(i/rows),
				MARGIN+(PAD+Dy(r))*(i%rows))), screen->r.min);
	draw(screen, insetrect(r, -1), lightblue, nil, ZP);
}

void
drawwin(int i)
{
	draw(screen, win[i].r, lightblue, nil, ZP);
	_string(screen, addpt(win[i].r.min, Pt(2,0)), display->black, ZP,
		font, win[i].label, nil, strlen(win[i].label), 
		win[i].r, nil, ZP);
	border(screen, win[i].r, 1, display->black, ZP);	
	win[i].dirty = 0;
}

int
geometry(void)
{
	int i, ncols, z;
	Rectangle r;

	z = 0;
	rows = (Dy(screen->r)-2*MARGIN+PAD)/(font->height+PAD);
	if(rows*cols < nwin || rows*cols >= nwin*2){
		ncols = (nwin+rows-1)/rows;
		if(ncols != cols){
			cols = ncols;
			z = 1;
		}
	}

	r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height);
	for(i=0; i<nwin; i++)
		win[i].r = rectaddpt(rectaddpt(r, Pt(MARGIN+(PAD+Dx(r))*(i/rows),
					MARGIN+(PAD+Dy(r))*(i%rows))), screen->r.min);

	return z;
}

void
redraw(Image *screen, int all)
{
	int i;

	all |= geometry();
	if(all)
		draw(screen, screen->r, lightblue, nil, ZP);
	for(i=0; i<nwin; i++)
		if(all || win[i].dirty)
			drawwin(i);
	if(!all)
		for(; i<onwin; i++)
			drawnowin(i);

	onwin = nwin;
}

void
eresized(int new)
{
	if(new && getwindow(display, Refmesg) < 0)
		fprint(2,"can't reattach to window");
	geometry();
	redraw(screen, 1);
}

void
click(Mouse m)
{
	int fd, i, j;	
	char buf[128];

	if(m.buttons == 0 || (m.buttons & ~4))
		return;

	for(i=0; i<nwin; i++)
		if(ptinrect(m.xy, win[i].r))
			break;
	if(i == nwin)
		return;

	do
		m = emouse();
	while(m.buttons == 4);

	if(m.buttons != 0){
		do
			m = emouse();
		while(m.buttons);
		return;
	}

	for(j=0; j<nwin; j++)
		if(ptinrect(m.xy, win[j].r))
			break;
	if(j != i)
		return;

	sprint(buf, "/dev/wsys/%d/wctl", win[i].n);
	if((fd = open(buf, OWRITE)) < 0)
		return;
	write(fd, "top\n", 4);
	write(fd, "current\n", 8);
	close(fd);
}

void
usage(void)
{
	fprint(2, "usage: winwatch [-f font]\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	char *fontname;
	int Etimer;
	Event e;

	fontname = "/lib/font/bit/lucidasans/unicode.8.font";
	ARGBEGIN{
	case 'f':
		fontname = EARGF(usage());
		break;
	}ARGEND

	if(argc)
		usage();

	initdraw(0, 0, "winwatch");
	lightblue = allocimagemix(display, DPalebluegreen, DWhite);
	if(lightblue == nil)
		sysfatal("allocimagemix: %r");
	if((font = openfont(display, fontname)) == nil)
		sysfatal("font '%s' not found", fontname);

	refreshwin();
	redraw(screen, 1);
	einit(Emouse|Ekeyboard);
	Etimer = etimer(0, 5000);

	for(;;){
		switch(eread(Emouse|Ekeyboard|Etimer, &e)){
		case Ekeyboard:
			if(e.kbdc==0x7F || e.kbdc=='q')
				exits(0);
			break;
		case Emouse:
			if(e.mouse.buttons)
				click(e.mouse);
			break;
		default:	/* Etimer */
			refreshwin();
			redraw(screen, 0);
			break;
		}
	}
}

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

* [9fans] rio window overlapping order
@ 2001-08-21  6:44 YAMANASHI Takeshi
  0 siblings, 0 replies; 5+ messages in thread
From: YAMANASHI Takeshi @ 2001-08-21  6:44 UTC (permalink / raw)
  To: 9fans

How can I find the order rio arranges its windows?

I often lost a small window overlapped entirely by other
large windows (like acme), and I feel like to write some
task-bar tool for rio to raise the small one.
-- 


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

end of thread, other threads:[~2001-08-22  0:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-21 11:46 [9fans] rio window overlapping order rob pike
2001-08-22  0:45 ` YAMANASHI Takeshi
  -- strict thread matches above, loose matches on Subject: below --
2001-08-21  6:49 Russ Cox
2001-08-21  7:07 ` YAMANASHI Takeshi
2001-08-21  6:44 YAMANASHI Takeshi

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).