[dev] Slock: Logging patch

2010-11-11 Thread Danilo Bargen
Hello all

In case anyone is interested: I've added logging capabilities to
Slock. The patch is attached. It will enable logging of all locks,
unlocks and failed unlock attempts to ~/.slock.log, if compiled with
the ENABLE_LOGGING flag.

--Danilo
diff -up /tmp/slock-0.9/config.mk slock-0.9/config.mk
--- /tmp/slock-0.9/config.mk	2008-07-29 20:22:46.0 +0200
+++ slock-0.9/config.mk	2010-11-11 16:55:19.164582000 +0100
@@ -14,7 +14,7 @@ INCS = -I. -I/usr/include -I${X11INC}
 LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext
 
 # flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H
+CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H -DENABLE_LOGGING
 CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 LDFLAGS = -s ${LIBS}
 
Only in slock-0.9: slock
diff -up /tmp/slock-0.9/slock.c slock-0.9/slock.c
--- /tmp/slock-0.9/slock.c	2008-07-29 20:22:46.0 +0200
+++ slock-0.9/slock.c	2010-11-11 16:42:10.181248668 +0100
@@ -22,6 +22,10 @@
 #include 
 #endif
 
+#ifdef ENABLE_LOGGING
+#include 
+#endif
+
 static void
 die(const char *errstr, ...) {
 	va_list ap;
@@ -123,6 +127,18 @@ main(int argc, char **argv) {
 	len = 0;
 	XSync(dpy, False);
 
+#ifdef ENABLE_LOGGING
+	FILE *logfile;
+	char logfile_path[1024];
+	if (snprintf(logfile_path, sizeof logfile_path, "%s/%s", getenv("HOME"), ".slock.log")
+		>= sizeof logfile_path)
+		die("slock: log file path too long");
+	time_t rawtime;
+	time(&rawtime);
+	logfile = fopen(logfile_path, "a+");
+	fprintf(logfile, "Locked: %s", ctime(&rawtime));
+#endif
+
 	/* main event loop */
 	while(running && !XNextEvent(dpy, &ev)) {
 		if(len == 0 && DPMSCapable(dpy)) {
@@ -150,8 +166,13 @@ main(int argc, char **argv) {
 #else
 running = strcmp(crypt(passwd, pws), pws);
 #endif
-if (running != 0)
+if (running != 0) {
 	XBell(dpy, 100);
+#ifdef ENABLE_LOGGING
+	time(&rawtime);
+	fprintf(logfile, "Failed unlock attempt: %s", ctime(&rawtime));
+#endif
+}
 len = 0;
 break;
 			case XK_Escape:
@@ -174,5 +195,12 @@ main(int argc, char **argv) {
 	XFreePixmap(dpy, pmap);
 	XDestroyWindow(dpy, w);
 	XCloseDisplay(dpy);
+
+#ifdef ENABLE_LOGGING
+	time(&rawtime);
+	fprintf(logfile, "Unlocked: %s", strcat(ctime(&rawtime), "\n"));
+	fclose(logfile);
+#endif
+
 	return 0;
 }
Only in slock-0.9: slock.o


Re: [dev] Recent vain attempts at suckless Web applications

2011-01-20 Thread Danilo Bargen
Hey Kai

On Sun, Jan 9, 2011 at 11:36 PM, Kai Hendry  wrote:
> http://greptweet.com/ -- Uses grep for searching retrieved tweets

That's a pretty awesome idea. Thanks a lot :) But the UI should be
improved, to prevent questions like "what does this webapp do?" or
"how do I get my tweets after the page pulled them from Twitter?".

I especially like fetch-tweets.sh. Would be cool to turn this into a
nice Python script though.

Danilo



Re: [dev] Recent vain attempts at suckless Web applications

2011-01-20 Thread Danilo Bargen
> What's the point of it being in Python? It's several times the size of
> bloated bash! We are trying to make things suck less here, not more.

Reading Python sucks a lot less than reading bloated non-modular Bash
:) But that's a matter of opinion.

Cheers



Re: [dev] wmii put computer to sleep/suspend

2011-01-26 Thread Danilo Bargen
2011/1/20 Kurt H Maier :
> pm-suspend

acpitool also supports suspending.

> -s, --suspend  suspend to memory (sleep state S3), if supported
> -S suspend to disk (sleep state S4), if supported



[dev] dwm battery level alarm system

2011-01-26 Thread Danilo Bargen
Hey list

I need some kind of alarm system in dwm, as my laptop has already
turned off several times due to running out of battery.

I thought of different possibilities. Maybe some kind of popup that is
displayed on every tag. Or letting the blue window title area blink
red. In combination with some warning sound that gets played even if
the volume is turned down.

Does anyone here already have a feasible solution for that problem? If
not, what do you think would be the best approach?

Cheers
Danilo



Re: [dev] dwm battery level alarm system

2011-01-26 Thread Danilo Bargen
Hi

On Wed, Jan 26, 2011 at 11:21 PM, Peter John Hartman
 wrote:
> acpid

Thanks for your answer. acpid is a good idea, as it also works when
dwm hasn't been started. But it only solves the problem of detecting
low battery, not of the way of alarming. In your script, you're
directly suspending your laptop, I would like a warning some time
before that.

On Wed, Jan 26, 2011 at 11:20 PM, Jacob Todd  wrote:
> Check the 'simple monitors' page at dwm.suckless.org for a battery percentage 
> display. It doesn't blink or any silly crap like that, though.

I'm already using a battery notification. I keep forgetting to look at
it... Thanks anyways.

Also thanks Antoni for your idea, looks interesting too. But I think I
just found another solution. As I'm using a Thinkpad laptop, I'll just
start flashing the Thinklight-LED[1]. Should be enough to draw my
attention to it :)

Cheers
Danilo

[1] http://en.wikipedia.org/wiki/ThinkLight



Re: [dev] dwm battery level alarm system

2011-01-26 Thread Danilo Bargen
On Wed, Jan 26, 2011 at 11:51 PM, Jakub Lach  wrote:
> ...in my laptop noisy buzzer kicks
> in before battery is fully depleted,
> are your sure that is not the case
> with yours?

It does sometimes. It certainly did when I ran out of battery while
using Windows, and if i'm not mistaken, it already did using Arch
Linux some times in the past. The last few times it didn't. My volume
settings aren't muted. So I'd have to check what enables or disables
that feature. I'm using a T410.


The ThinkLight LED isn't a standard status-LED, it's a lamp that
illuminates your keyboard. So the following bash script is quite
useful for alarms, as I won't notice a simple message in the
notification bar.

[danilo@t410 ~]$ cat /usr/local/bin/thinklight
#!/bin/bash
if [ -z $1 ]; then
echo 'Argument missing [on|off|blink]'
exit 1
elif [ $1 = 'blink' ]; then
echo 'on' > /proc/acpi/ibm/light && sleep 1
echo 'off' > /proc/acpi/ibm/light && sleep 1
elif [ $1 = 'on' ]; then
echo 'on' > /proc/acpi/ibm/light
elif [ $1 = 'off' ]; then
echo 'off' > /proc/acpi/ibm/light
fi

You need the correct permissions on /proc/acpi/ibm/light for this to
work. I set them in my /etc/rc.local (hope that's the right place, I
didn't test it yet).


Cheers
Danilo



Re: [dev] wmii put computer to sleep/suspend

2011-01-26 Thread Danilo Bargen
A progress bar?

When I suspend my laptop using "acpitool -s", it takes about 2
seconds. No time for a progressbar.

Danilo

On Thu, Jan 27, 2011 at 1:47 AM, Rob  wrote:
> I prefer tux on ice, I get a nice progress bar and the ability to
> cancel hibernation.



Re: [dev] dwm battery level alarm system

2011-01-26 Thread Danilo Bargen
This solution seems to work great (part of my .xinitrc):


while true; do
# Set root title
sh $HOMEDIR/.xsetroot

# Check battery level
BATT=$( acpi -b | sed 's/.*[charging|unknown],
\([0-9]*\)%.*/\1/gi' )
if [ $BATT -le 5 ]; then
# Beep
echo -e "\007" >/dev/tty10 && sleep 0.2
echo -e "\007" >/dev/tty10 && sleep 0.2
echo -e "\007" >/dev/tty10 && sleep 0.2
# Blink
echo 'on' > /proc/acpi/ibm/light && sleep 1
echo 'off' > /proc/acpi/ibm/light
fi

# Update every 30s
sleep 30s
done &


It beeps 3 times and flashes the ThinkLight every 30s, in case the
battery level is below 5%.

--Danilo