9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Stuart Morrow <morrow.stuart@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] screenlock
Date: Sun, 18 Jul 2021 20:31:52 +0100	[thread overview]
Message-ID: <CABB-WO9a+dZbJJcRHTGSGFXewS_pXf4tRULZNGOgV6w2VSyvnQ@mail.gmail.com> (raw)
In-Reply-To: <E34DD43A58FEBD4E0BB840C7C06268DA@felloff.net>

> thats wrong because the read wont return you a '\0' terminated string.

Oh, yeah. And I can even come up with a scenario where wctl will emit
without there being a notcurrent.

--- /mnt/git/object/be36c092ac061a04065720e98e5849130487be7f/tree/sys/src/cmd/screenlock.c
+++ sys/src/cmd/screenlock.c
@@ -119,14 +119,19 @@
 void
 top(void*)
 {
-	int fd;
+	int fd, n;
+	char buf[128];

-	if((fd = open("/dev/wctl", OWRITE)) < 0)
+	if((fd = open("/dev/wctl", ORDWR)) < 0)
 		return;

 	for(;;){
-		write(fd, "current", 7);
-		sleep(500);
+		n = read(fd, buf, sizeof buf-1);
+		if(n > 48){
+			buf[n] = '\0';
+			if(strstr(buf+48, "notcurrent"))
+				write(fd, "current", 7);
+		}
 	}
 }

@@ -186,7 +191,7 @@
 		tm = localtime(time(&blank));
 		s = smprint("user %s at %d:%02.2d", getuser(), tm->hour, tm->min);
 		p = subpt(p, Pt(stringwidth(font, "m") * strlen(s) / 2, 0));
-		string(screen, p, screen->display->white, ZP, font, s);
+		stringbg(screen, p, display->white, ZP, font, s, display->black, ZP);
 	}

  reply	other threads:[~2021-07-18 19:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 16:04 Stuart Morrow
2021-07-18 17:45 ` cinap_lenrek
2021-07-18 19:31   ` Stuart Morrow [this message]
2021-07-18 20:23     ` cinap_lenrek

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=CABB-WO9a+dZbJJcRHTGSGFXewS_pXf4tRULZNGOgV6w2VSyvnQ@mail.gmail.com \
    --to=morrow.stuart@gmail.com \
    --cc=9front@9front.org \
    /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).