Re: [9fans] focus window on plumb

2018-09-03 Thread umbraticus
Even simpler, run the following program in riostart thus:

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


could probably even be an rc script

#include 
#include 
#include 

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



[9fans] focus window on plumb

2018-09-02 Thread umbraticus
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#include 
#include 
#include 

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, )) > 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]);
}
}