9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] focus window on plumb
@ 2018-09-03 19:52 umbraticus
  0 siblings, 0 replies; 2+ messages in thread
From: umbraticus @ 2018-09-03 19:52 UTC (permalink / raw)
  To: 9fans

Even simpler, run the following program in riostart thus:

window 'raiseplumb web & mothra'
window 'raiseplumb edit & sam'
&c...

could probably even be an rc script

#include <u.h>
#include <libc.h>
#include <plumb.h>

void
main(int argc, char **argv)
{
	Plumbmsg *m;
	int port, wctl;

	if(argc != 2)
		sysfatal("usage: %s port", argv[0]);
	if((port = plumbopen(argv[1], OREAD)) < 0)
		sysfatal("couldn't open plumb port %s", argv[1]);
	if((wctl = open("/dev/wctl", OWRITE)) < 0)
		sysfatal("couldn't open /dev/wctl");
	for(;;){
		if((m = plumbrecv(port)) == nil)
			sysfatal("error on plumb port %s", argv[1]);
		plumbfree(m);
		fprint(wctl, "unhide");
		fprint(wctl, "current");
	}
}

umbraticus



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

* [9fans] focus window on plumb
@ 2018-09-02  8:58 umbraticus
  0 siblings, 0 replies; 2+ messages in thread
From: umbraticus @ 2018-09-02  8:58 UTC (permalink / raw)
  To: 9fans

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

Hi 9fans,

I wrote the attached to listen on a plumb port and make
a given window current when it gets a message.  I'm not
sure how much I will like it: it's nice not to have to
hunt for a buried client program after plumbing something;
on the other hand, sometimes I like to plumb a few urls,
images, or pdfs and view later.  Still, I thought I'd
figure out a way to do it.

The first argument is the port to listen on and the second
is a string to match against the label of the window to
raise.  In my riostart I start my main rc window like this:

window 'raiseplumb web mothra! & raiseplumb edit sam & raiseplumb image page & cat todo; label rc; rc'

(After setting page's label I bind /dev/null over it so it
isn't overwritten) The program could be improved but it
seems to work well enough for a quick implementation.

Other solutions I thought of were to prime the windows I
want to raise by posting their wctl in /srv (since /dev/wsys
isn't in the plumber's namespace) then writing plumb rules
to first raise the window by mounting the wctl, then plumb
to the port; or else patch the client programs to raise
themselves when they get a plumb.

Has anyone else wanted/implemented something like this?

umbraticus

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

#include <u.h>
#include <libc.h>
#include <plumb.h>

enum{LEN = 128};

int
match(int n, char *label)
{
	int fd, len;
	char s[LEN];

	snprint(s, LEN, "/dev/wsys/%d/label", n);
	if((fd = open(s, OREAD)) < 0)
		return 0;
	len = strlen(label);
	if(read(fd, s, len) != len || memcmp(s, label, len) != 0){
		close(fd);
		return 0;
	}
	close(fd);
	snprint(s, LEN, "/dev/wsys/%d/wctl", n);
	if((fd = open(s, OWRITE)) < 0)
		return -1;
	fprint(fd, "unhide");
	fprint(fd, "current");
	close(fd);
	return 1;
}

void
findwctl(char *label)
{
	Dir *d;
	int fd, n, i;

	if((fd = open("/dev/wsys", OREAD)) < 0)
		return;
	while((n = dirread(fd, &d)) > 0){
		for(i = 0; i < n; i++)
			if(match(atoi(d[i].name), label)){
				free(d);
				close(fd);
				return;
			}
		free(d);
	}
	close(fd);
}

void
main(int argc, char **argv)
{
	Plumbmsg *m;
	int fd;

	if(argc != 3)
		sysfatal("usage: %s fd label", argv[0]);
	if(strlen(argv[2]) >= LEN)
		sysfatal("label match too long: %s", argv[2]);
	if((fd = plumbopen(argv[1], OREAD)) < 0)
		sysfatal("couldn't open plumb fd %s", argv[1]);
	for(;;){
		if((m = plumbrecv(fd)) == nil)
			sysfatal("error on plumb fd %s", argv[1]);
		plumbfree(m);
		findwctl(argv[2]);
	}
}

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

end of thread, other threads:[~2018-09-03 19:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 19:52 [9fans] focus window on plumb umbraticus
  -- strict thread matches above, loose matches on Subject: below --
2018-09-02  8:58 umbraticus

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