9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: umbraticus@prosimetrum.com
To: 9fans@9fans.net
Subject: [9fans] focus window on plumb
Date: Sun,  2 Sep 2018 20:58:57 +1200	[thread overview]
Message-ID: <DE76F45CAC63F71ED9BF8A9EAA42867B@prosimetrum.com> (raw)

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

             reply	other threads:[~2018-09-02  8:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-02  8:58 umbraticus [this message]
2018-09-03 19:52 umbraticus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DE76F45CAC63F71ED9BF8A9EAA42867B@prosimetrum.com \
    --to=umbraticus@prosimetrum.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).