From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Sun, 2 Sep 2018 20:58:57 +1200 From: umbraticus@prosimetrum.com To: 9fans@9fans.net MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-qyrznveyguhyjygxkdcxmnlupk" Subject: [9fans] focus window on plumb Topicbox-Message-UUID: df55f1b0-ead9-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --upas-qyrznveyguhyjygxkdcxmnlupk Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit 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 --upas-qyrznveyguhyjygxkdcxmnlupk Content-Disposition: attachment; filename=raiseplumb.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit #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, &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]); } } --upas-qyrznveyguhyjygxkdcxmnlupk--