Re: [dev] [st] RFC halt function

2013-04-26 Thread Patrick Haller
On 2013-04-26 23:11, hiro wrote:
 just mod your shell to always copy all stdout of commands into a temp
 file, then open the file with less after one of these stupidly long
 commands.

Or run them via 'at'
Or run 'script' when you login

And sed out all the terminal carp later on.



Re: [dev] [st] RFC halt function

2013-04-25 Thread Patrick Haller
On 2013-04-25 20:05, Christoph Lohmann wrote:
 while  trying to copy some stuff from iotop I came to the idea of having
 some ??halt?? function in st. This is like the ??halt?? in 9term, where  ev???
 erything  will  stand still but the terminal is working on the output in
 the background.

Why not let tmux or screen handle that? Does st really need an
(xon/xoff)++ feature?



Re: [dev] ii IPv6 support

2013-04-11 Thread Patrick Haller
On 2013-04-11 20:53, Nico Golde wrote:
 http://tools.suckless.org/ii/patches/ii-ipv6.diff

Aw fsck. Can we put the patches in the git repo? Either as plain files
in patches/, or create a branch based on the commit they diff'd at?



Re: [dev] ii IPv6 support

2013-04-11 Thread Patrick Haller
On 2013-04-11 21:17, Carlos Torres wrote:
 it was there just a little hidden
 http://git.suckless.org/sites/tree/tools.suckless.org/ii/patches/ii-ipv6.diff

i mean in the ii repo - http://git.suckless.org/ii



Re: [dev] Call for pkgsrc users

2013-04-10 Thread Patrick Haller
On 2013-04-10 13:13, William Giokas wrote:
 There are extremely strong technical arguments for using systemd as a
 simple, easy to use and easy to configure initialization system.

systemd trades simplicity for boot-speed and stack integration.

There are always trade-offs. It's just this seems like a bad trade from
a suckless point of view which calls for orthogonality and composability,
not integrated software superstructures.

Anyway, pancake's contributing to voidlinux so I'll try void. Any other
good rolling release distros?



Re: [dev] Makefile/markdown based static site generator

2013-02-21 Thread Patrick Haller
On 2013-02-21 10:19, sta...@cs.tu-berlin.de wrote:
 of course:
   sed -n '/^\s*!--/{

We know it's the first comment, so
sed -n '/!--/{ ... }'

works as well. Convention can cut as fast as code. 



Re: [dev] Makefile/markdown based static site generator

2013-02-20 Thread Patrick Haller
On 2013-02-21 14:19, Kai Hendry wrote:
 If you are a Makefile demi-god, you could please help me support input
 files blighted with spaces. For example running the Makefile on my
 blog, it chokes and stops with
 https://github.com/kaihendry/natalian/blob/master/archives/tag/fair%20use.mdwn

http://www.cmcrossroads.com/article/gnu-make-meets-file-names-spaces-them

OR

Fix the naming convention. Don't support arbitrary idiocy; let it die.



Re: [dev] [surf] make error

2012-01-04 Thread Patrick Haller
On 2012-01-04 21:28, Hannes Blut wrote:
 When making surf on my setup i get

do what the error says, add it to your libs in your config.mk, like:

LIBS = -L/usr/lib -lc -lX11 -ljavascriptcoregtk-1.0 ${GTKLIB} -lgthread-2.0



Re: [dev] wmii falling out of favor

2012-01-02 Thread Patrick Haller
On 2012-01-02 12:26, hiro wrote:
 I don't understand how this is related to your quote?

Suraj re-evaluated his toolset. I think the re-evaluation part is a good
idea, however it seems you could spend too much time doing it.

 You always execute ls when you cd to a different folder?

in interactive shells, yes.

I examined my interactive shell history and found that I had too many cd
then ls, amongst other things.

However, it's not as easy to do the same analysis with my X11 interactions.

Do people do this? How? Just guessing at my usage, I would think that
sync'ing cut buffers, selections, vim last yank, and screen/tmux buffers
would be a win. No clue without data, though



Re: [dev] wmii falling out of favor

2012-01-01 Thread Patrick Haller
On 2012-01-01 21:13, Suraj N. Kurapati wrote:
 So I considered the trade-offs between SLOC minimalism, project and
 community activity, and my productivity in DWM vs. WMII and finally
 decided to switch back to WMII (which I used since six years prior).

How often do people re-evaluate their toolsets?

With my shell, I can examine shell history and do stuff like:
cd() {
dir=$1
test -f $1  dir=`dirname $1`
builtin cd $dir  ls | sed 10q | fmt -w $COLUMNS
}

With X11, do we screencast a day's work and watch it in fast-forward?

Every three months I look at
https://wiki.archlinux.org/index.php/Lightweight_Software

and occasionally find stuff (like zathura).



Re: [dev] network usage graphs

2011-12-23 Thread Patrick Haller
On 2011-12-23 23:16, hiro wrote:
 Only so nobody falls in the same pits: gnuplot sucks, bourne shell
 sucks (better use awk for tabular calculations)

post the scripts?

also, check out http://www.colorcombos.com/



Re: [dev] network usage graphs

2011-12-22 Thread Patrick Haller
On 2011-12-22 13:58, hiro wrote:
 What tools do you know that are able to render such graphics and
 update once per second or so?

push the burden of making pretty crap on the client; drop the data to
json and let the clients use a javascript library like highcharts.



Re: [dev] Shameless patch request

2011-12-07 Thread Patrick Haller
On 2011-12-07 11:04, Justin Pogue wrote:
 At work, I typically have a terminal doing something like while true;
 do ls -l /var/cores  sleep 10  clear; done

Jobs need two scriptable pathways to your brain: 1) an immediate
attention interrupt, and 2) a handle when not busy interrupt.

statusbar, sms texts, xosd, email, use whatever fits your personal
preferences to create those pathways.



Re: [dev] dmenu's lsx binary naming conflicts with lrzsz!

2011-11-27 Thread Patrick Haller
On 2011-11-27 15:32, Roger wrote:
 locate stest |grep ^stest$

08:53:31 Err 130 /Volumes/Users/phaller
 locate ls | grep ^ls$
08:53:34 Err 1 /Volumes/Users/phaller
 locate ls | grep ^/bin/ls$
/bin/ls
08:53:43 /Volumes/Users/phaller



Re: [dev] [dwm] [PATCH] spawn_cwd - spawn from current client's cwd

2011-11-25 Thread Patrick Haller
On 2011-11-25 22:42, Julian Dammann wrote:
  It's all about spatial locality.
 Ever tried :!your_terminal  in vim? Maybe that's good enough for you if 
 bound to some key.

autocmd BufEnter * cd %:p:h
for when you use multiple buffers in vim.



Re: [dev] semicolons

2011-11-18 Thread Patrick Haller
On 2011-11-18 11:40, pancake wrote:

 $ cat dwm.c | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l

use cpp to deal with the includes, defines, comments.

__sloc()
{
grep -v '^#include.*' $1 | cpp - | grep -v '^#' | grep -v '^$'
}

sloc()
{
__sloc $1 | wc -l
__sloc $1 | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l
__sloc $1 | sed -e 's,(,ROFL\n,g' |grep ROFL |wc -l
}

worrying about stuff like the next seems tree/forest-y

if (error)
return printf(boot-head = missed?), -1;

btw, anyone recommend a suckless AST tool for C?


Patrick



Re: [dev] semicolons

2011-11-18 Thread Patrick Haller
On 2011-11-18 13:24, pancake wrote:
 should we support code written by bitches?

KR v1, page 59:

for (i = 0, j = strlen(s)-1; i  j; i++, j--) {

SLoC count? Bitch count? ;)



Re: [dev] [dwm] 2000 SLOC

2011-10-31 Thread Patrick Haller
On 2011-10-31 10:49, pancake wrote:
 I dont understand the point of documentation.

Neither do I, so let's triage:

Deviation from Convention
served by README

Commentary on the Code
served by IRC, mailing list

What is this? How do I?
bless some wiki/forum someplace as *the* place for users


Patrick



Re: [dev] Please recommend a suckless rss reader

2011-10-29 Thread Patrick Haller
On 2011-10-29 23:22, Yue Wu wrote:
 I'm looking for a cli newsreader, suckless, less dependencies. Thanks!

cron + curl + xmlstarlet + md5 = lighter than rss2email.py


Patrick



Re: [dev] Please recommend a suckless rss reader

2011-10-29 Thread Patrick Haller
On 2011-10-29 19:22, Christoph Lohmann wrote:
 I'm looking for a cli newsreader, suckless, less dependencies. Thanks!
 cron + curl + xmlstarlet + md5 = lighter than rss2email.py
 Would you mind sharing your script for that?

Not exactly posix, so it's got 1/2 of running code, rough concensus ;)

rss() splits an rss feed, drops each article to disk with a filename =
the md5sum of the article, then prints all the new articles since last
cron run that match a basic grep.

things it could do better:
be POSIX
use ETAG / HEAD check
not use perl for the filter

filter has been a ridiculously useful script, being a hash of  common
encoding transforms. It could be a sed scripts or in C; anyone seen
or written something like it?


Patrick


wcat() {
which curl  /dev/null 21  curl -s $1;
if [[ $? != 0 ]]; then
which wget  /dev/null 21  wget -q -O - $1;
fi;
return $?
}

rss_disk() {
split='#'
xmlstarlet sel -t -m //*[local-name()='description'] -v '.' -n -o 
$split -n | while read line; do
[[ $line != $split ]]  {
article=${article} ${line}
continue
}
d=$( md5sum  $article | sed -e 's/ .*//' )
[[ ! -e $d ]]  { echo $article  $d ; }
article=
done
}

# lgab = https://github.com/patrickhaller/linux-gnu-admin-bash
rss() {
dir=$1
url=$2
pattern=$3
cd $dir
wcat $url | rss_disk 
lgab_kill_after 30
find $dir -type f -cmin -9 -print | while read f; do
tmp=${f}.html
filter htmldecode  $f  $tmp
grep -qEi $pattern $tmp  lynx -dump $tmp
/bin/rm $tmp
done
find $dir -type f -ctime +7 -delete
}


# filter
#!/usr/bin/perl
use MIME::Base64;
use CGI ':standard';
use HTML::Entities;
my $action = shift;

my %block = (
email  = '/($s)/i and print $1 . \n',
url= '/href\s*=\s*(?:\'|\)($s)(?:\'|\)/i and print $1 . \n',
base64 = 'if (/^[a-zA-Z0-9\+\/]{78,}/) { print 
MIME::Base64::decode_base64($_) } else { print }',
urlencode = 'print CGI::escape($_)',
htmlencode = 'print HTML::Entities::encode_entities($_)',
htmldecode = 'print HTML::Entities::decode_entities($_)',
crlf   = q{ s/\r//g; print },
);

my %re = (
email  = qr/ ? \S+ \@ \S+ ? /x,
url= qr/ [^\\']+ /x,
);
my $s = $re{$action};

map { eval($block{$action}) } ;





Re: [dev] Linux sucks!

2011-10-28 Thread Patrick Haller
On 2011-10-29 01:44, Connor Lane Smith wrote:
 This thread is demented... *very* irritating.

Trolls have to perform some socially useful function or else we'd all
have learned by now.


Patrick
* yeah, I know it's only October. ;)



Re: [dev] Focusing on windows by name

2011-10-26 Thread Patrick Haller
On 2011-10-26 11:48, Manolo Martínez wrote:

 In openbox I have a key bound to the following:wmctrl -xa mutt ||
 urxvt -name mutt -e mutt

xlsclients | grep -q mutt || urxvt -e mutt



Re: [dev] Simple made Easy (Rich Hickey at StrangeLoop)

2011-10-21 Thread Patrick Haller
On 2011-10-22 00:08, Connor Lane Smith wrote:
On 21/10/2011, Pierre Chapuis catw...@archlinux.us wrote:
  http://www.infoq.com/presentations/Simple-Made-Easy
 Thanks, I enjoyed watching this.

Let's all write parsers.

Hickey kicks unix because although pipes = composability, output and
input = free-form text. We combined data exchange with user interface,
and user interface usually won that fight.

Say data exchange won; would it help us to rewrite our programs to
output JSON and our shells to pretty-print* JSON?


Patrick

[*] The cynic points out that people would then spend time customizing
their pretty-printers.



Re: [dev] Suckless way of checking Nagios?

2011-10-16 Thread Patrick Haller
On 2011-10-16 20:12, Sime Ramov wrote:
 Hello. I need to keep track of one remote Nagios instance output, which
 excludes cnagios[1].

While nagios output can be made lite [1], watching system stats all
day does suck.

Is permanently allocating visual space really your best interrupt vector
(and not an sms)? If so, I'd do something stoopid like parse the output
of [1] and for every warning, put up a picture of kitty cat, and for
every critical, put up an angry tiger.

It sounds like w3m and a sed script would work just GRRReat!


Patrick

[1] 
http://ligers_kick_ass/cgi-bin/nagios3/status.cgi?host=alltype=detailservicestatustypes=20



Re: [dev] Make dmenu sensitive to user aliases (Hello world)

2011-10-02 Thread Patrick Haller
On 2011-10-02 22:52, Ethan Grammatikidis wrote:
 On Sat, 01 Oct 2011 21:55:56 +0300
 Kiriakos at Kindstudios ka...@kindstudios.gr wrote:

  Hi there,
 
  I'm using many aliases in my terminal sessions and want to be able to use
  them with dmenu
  (which I use as the default menu in all of my xmonad installations) aswell.
 
  Is that possible? I haven't gotten a real chance to look at the code yet
  (just downloaded it).
  I'm a total noob when it comes to actually modifying C sources so I
  thought that I should
  fire off a request in the offchance somebody has already done that or can
  point in the right
  direction.

 I'm using scripts where I once used aliases, mostly because it's far
 more convenient to write or alter a script than to update an alias or
 function in all my open terminals.

??? something like?

update_config() { [ `mtime $cfg` -gt `mtime $history` ]  . $cfg ; }
export PS1='`update_config` '


Patrick



Re: [dev] [surf] download patch updated

2011-09-28 Thread Patrick Haller
On 2011-09-28 14:51, Nick wrote:
 Quoth Troels Henriksen:
  Nick suckless-...@njw.me.uk writes:
  Huh?  I have not had trouble using wget for this.
 Can anyone else confirm / deny this?

Not for those sites, however I did see enough fails to add the same to
https://github.com/patrickhaller/surf-ph


Patrick



Re: [dev] New utility

2011-09-24 Thread Patrick Haller
On 2011-09-25 03:19, Christoph Lohmann wrote:
 ocaml;wu (ocaml; won't use)

use the bringer_obsolete.bash [1] from the package?

why ocaml;wu? because it's outside the C/sh stack, or ?


Patrick

[1] send 
https://github.com/cfuehrmann/bringer/raw/master/bringer_obsolete.bash \r
expect bash;wu



Re: [dev] ideas on suckless file manager

2011-06-08 Thread Patrick Haller
On Wed, Jun 08, 2011 at 08:01:10AM +0200, Petr Sabata wrote:
 On Wed, Jun 08, 2011 at 12:57:40PM +0800, Patrick Haller wrote:
 
  define $EDITOR then ^x^e

 I guess this is just something bash-specific?

yeah, edit the current command using $EDITOR

file manager
= file selection + file (pre)viewing
= ls/awk/$EDITOR + i_give_my_files_retarded_names
= fix your naming convention


Patrick



Re: [dev] ideas on suckless file manager

2011-06-07 Thread Patrick Haller
On Tue, Jun 07, 2011 at 09:03:06PM -0700, Noah Birnel wrote:
 ls listing  vim listing  mv `cat listing` dest

define $EDITOR then ^x^e


Patrick



Re: [dev] dwm taskbar config

2011-03-23 Thread Patrick Haller
On Wed, Mar 23, 2011 at 10:34:57PM +0200, Le Tian wrote:
Yeah, your variant is better, but why should I make exec dwm?

I highly recommend writing a tiny looping shell script .e.g. each of the
various ideas below, and watching what they do with pstree or 'ps fax'.

#1
while true; do
exec sleep 30 
done

#2
while true; do
exec sleep 30
done

#3
while true; do
sleep 30
done


Patrick



Re: [dev] Not Using a Window Manager?

2011-03-02 Thread Patrick Haller
On Wed, Mar 02, 2011 at 09:32:40AM +0100, Anselm R Garbe wrote:

 If you understand some of the C functions of dwm as Unix processes
 than you are pretty close to realise, one can play things pretty much
 Unix like, but if the LOC adds up dramatically at the bottom line, it
 is probably not worth it.

One of the many things I like about surf is the SETPROP hack. Using X11
properties as IPC seems like a fertile and ignored technique.*

I think there's a great deal of good in making it easy for people to
hack things up and then piece them together. Adding X11 properties in
would help, so whether someone wants to try a different layout engine or
something, they can hack it up in perl or pure or whatnot.


Patrick

* yes, i'm declaring ICCCM/EWMH a wasteland for users. There's only apps
and window managers in there. With surf, it's easy to check for any
about:blank windows, send one a URL, unmap it, and push it on the things
to read queue; or any number of inane things users do. ;)



Re: [dev] Not Using a Window Manager?

2011-03-01 Thread Patrick Haller
On Wed, Mar 02, 2011 at 11:36:46AM +0800, sqweek wrote:
 
  Nice. Each task is so simple broken down like this :)

Thanks. I just added a focus manager that just makes sure focus is
returned to PointerRoot. It's not absolutely necessary to run, because
apps that exit taking focus with them can be fixed with a 
DISPLAY=:0.0 x-alt-tab 

and from then on, add x-alt-tab to the end of what spawned that beast.


Patrick



Re: [dev] Unix philosophy window manager

2011-02-28 Thread Patrick Haller
On Mon, Feb 28, 2011 at 09:30:26AM +0100, Kurt Van Dijck wrote:
 
 To make it work smoothly, 1 such program needs a SubstructureRedirectMask.
 Technically, IMHO, that 1 program _is_ the window manager.
 
 I think the subject of the thread was a bit misleading.

Perhaps. With X11 and no window manager, the top-most window under the
pointer receives Key* events. By tying XCirculateSubwindows to
XSetInputFocus'ing back to the root window, we can get around clients
that focus themselves. 

However, that provides a certainly limited Focus / Stack setup ;)


Patrick



[dev] Not Using a Window Manager?

2011-02-26 Thread Patrick Haller
Anyone here try using X11 without a window manager? 

Just using Xresources + specific tools: xbindkeys, xdotool, etc... I'm
documenting the setup and adding small tools as needed (x-alt-tab,
x-move-resize, x-session). 

https://github.com/patrickhaller/no-wm


Patrick



Re: [dev] Not Using a Window Manager?

2011-02-26 Thread Patrick Haller
On Sat, Feb 26, 2011 at 12:42:04PM +, Bjartur Thorlacius wrote:
 
 Sounds really cool, but have you figured out how to manage detached
 (off-screen) windows? Maybe windows that aren't on screen suck too
 much.

unmapped windows =
xdotool search stupid_window windowmap

mapped not viewable =
xdotool search stupid_window windowmove 0 0 

I keep a stack of unmapped windows (especially for surf, which i open unmapped),
managed via the script below.


Patrick


#!/bin/bash
dir=${HOME}/.wm-banished
[[ ! -d $dir ]]  mkdir -p $dir

[[ $1 = push ]]  {
# no window manager = we don't know what's focus'd, use getmouselocation or 
selectwindow
w_id=$(xdotool selectwindow ) 
xdotool windowunmap $w_id
touch ${dir}/${w_id}
exit
}

w_id=$( ls -tr $dir | tail -1)
[[ $w_id =  ]]  {
echo -e \n Bad news... \n no souls remain banished \n | xmessage 
-file -
exit
}
xdotool windowmap $w_id
rm -f ${dir}/${w_id}



Re: [dev] Not Using a Window Manager?

2011-02-26 Thread Patrick Haller
On Sat, Feb 26, 2011 at 11:22:50AM -0500, Steve Ryan wrote:
 
 This is very cool, however I have one question. Correct me if
 I'm wrong, but you're replacing window-manager functionality with
 various small scripts and built-in X tools, right? So wouldn't you
 just be creating a (very minimalist) window manager out of those
 tools?

yup. WMs usually bind several orthogonals: window manipulation / 
decoration, keyboard shortcuts. focus management.

Separate them. ;)


Patrick



Re: [dev] Not Using a Window Manager?

2011-02-26 Thread Patrick Haller
On Sat, Feb 26, 2011 at 11:17:50AM -0500, Kurt H Maier wrote:
 Precisely what value do you get out of hacking up shell scripts to do
 this with a dozen tools?

It's at least a good way to understand exactly what one gets from X11. ;)


Patrick



Re: [dev] which minimal os

2011-02-11 Thread Patrick Haller
On Fri, Feb 11, 2011 at 07:34:48PM +0100, Benoit Chesneau wrote:
 
 What would you choose for a really minimal OS?

arch linux, rolling binary releases reduce maintenance time.

what do you want a minimal os for? 



Patrick



Re: [dev] A Suckless Filesystem

2011-02-06 Thread Patrick Haller
On Sat, Feb 05, 2011 at 05:06:20PM -0500, Brandon LaRocque wrote:
 Which one do you use? Why do you use it? What does it have that the
 others don't?

XFS because http://www.jukie.net/bart/blog/usb2-enclosure-benchmark

Lots of tradeoffs with FSs, how about tackle userland first?


Patrick



Re: [dev] wmii unicode in the status?

2011-01-23 Thread Patrick Haller
On Sat, Jan 22, 2011 at 11:28:20AM -0500, Eitan Goldshtrom wrote:
 Hi. I'm trying to print out a progress bar sort of thing that
 represents my remaining battery life. 

Why use python? dc and printf suffice.


Patrick

percent=$1
buckets=10
# annoying math
decimal=$( dc -e 5 k $buckets $percent * 100 / p)
count=$( dc -e 0 k $decimal 1 / p )
remainder=$( dc -e 5 k $decimal $count - p )
offset=$( dc -e 0 k $remainder 8 * 1 / p )
char_hex=200A # unicode space
test $offset != 0  {
# see http://www.fileformat.info/info/unicode/char/258f/index.htm
char_dec=$( dc -e 0 k 9616 $offset - p )
char_hex=$( printf %08x $char_dec )
}

for y in $( yes | head -n $count)  ; do 
$( which printf ) \U2588
done
$( which printf ) \U${char_hex}\n




[dev] Re: [dwm] screen locker - sinac

2010-12-10 Thread Patrick Haller
On Sat, 13 Dec 2008 13:20:33, Thayer Williams thayerw_AT_gmail.com wrote:
 On Sat, Dec 13, 2008 at 9:57 AM, Neale Pickett neale_AT_woozle.org wrote: 
  Since the list is talking about slock, now might be an appropriate time 
  for me to mention again my xss project: 
  
  http://woozle.org/~neale/src/xss/ 
  
  When I mailed the list about this in April someone responded with a neat 
  thing called sinac, which is a little smaller than xss, but polls, and 
  only replaces one of the 6 programs in my package. Some folks may 
  prefer it, combined with slock or xlock: 
  
  http://lists.suckless.org/dwm/0804/5534.html 
 
 Thanks for the info! I have been using xautolock until now. I'll 
 give xss a try soon. 
 
 FWIW, I tried sinac before xautolock and I found that it consumed an 
 unusual amount of CPU resources in the range of 30-50%. Perhaps there 
 was an incompatibility with the latest Xorg server, I'm not sure. I 
 didn't stay with it long enough to find out. 

That's cause sinac.c as posted used usleep while working with seconds. 

I fixed the usleep, switched to ulongs, and removed the argv code
because processing arguments is retarded.


Patrick



/*
 *
 * xidletime
 *
 * derived from xautolock supplied by
 * Authors: Michel Eyckmans (MCE)  Stefan De Troch (SDT)
 *
 * --
 *
 * Copyright 1990,1992-1999,2001-2002 by Stefan De Troch and Michel Eyckmans.
 * Copyright 2005 by Stefan Siegl [EMAIL PROTECTED]
 * Copyright 2007 by Christian Dietrich [EMAIL PROTECTED]
 *
 * Versions 2.0 and above of xautolock are available under version 2 of the
 * GNU GPL.
 *
 * xidletime.c -Wall -L/usr/X11R6/lib -lX11 -lXss -lXext -o xidletime
 *
 */

#include X11/Xos.h
#include X11/Xlib.h
#include X11/Xutil.h
#include X11/Xatom.h
#include X11/Xresource.h
#include X11/extensions/scrnsaver.h
#include stdio.h
#include stdlib.h
#include unistd.h
#define VERSION 0.1.3

static XScreenSaverInfo* xss_info = 0;

unsigned long
msecs_idle(Display *d)
{
  if (! xss_info )
xss_info = XScreenSaverAllocInfo();
  XScreenSaverQueryInfo(d, DefaultRootWindow(d), xss_info);
  return xss_info-idle;
}

int
main (int argc, char* argv[])
{
  Display* d;
  unsigned long wait = 0, idle;

  if (getenv(X_IDLE_SECONDS) != NULL)
wait = atol(getenv(X_IDLE_SECONDS)) * 1000;

  if (!(d = XOpenDisplay (0))) {
fprintf (stderr, Couldn't connect to %s\n, XDisplayName (0));
return 1;
  }
  (void) XSync (d, 0);

  if (wait)
while ((idle = msecs_idle(d))  wait)
  usleep( (wait - idle) * 1000 );
  else
fprintf(stdout, %ld\n, msecs_idle(d));

  return 0;
}




[dev] [slock] getopt + disable XBell option

2010-09-17 Thread Patrick Haller
Hi, 

I got sick of the XBell in slock, so I added getopt support and a silent
option (default = False), patched against the mercurial tip. 

I read the manifest and some of the source code; some of the projects
use getopt, others push config elsewhere. Am not sure which should apply
to slock.


Patrick
diff -urN slock-1.0/slock.c slock-1.0-getopt//slock.c
--- slock-1.0/slock.c   2009-11-26 20:53:26.0 +0800
+++ slock-1.0-getopt//slock.c   2010-09-18 12:34:56.761712744 +0800
@@ -74,9 +74,9 @@
 
 static void
 #ifdef HAVE_BSD_AUTH
-read_password(Display *dpy)
+read_password(Display *dpy, Bool silent)
 #else
-read_password(Display *dpy, const char *pws)
+read_password(Display *dpy, const char *pws, Bool silent)
 #endif
 {
char buf[32], passwd[256];
@@ -117,7 +117,7 @@
 #else
running = strcmp(crypt(passwd, pws), pws);
 #endif
-   if (running != 0)
+   if (running != 0  silent == False)
XBell(dpy, 100);
len = 0;
break;
@@ -209,7 +209,13 @@
 
 static void
 usage(void) {
-   fprintf(stderr, usage: %s -v, __progname);
+   fprintf(stderr, slock-%s, © 2006-2008 Anselm R Garbe\n
+   usage: %s [-h|-s|-v]\n
+   \t-h show this message\n
+   \t-s silent (don't ring bell on password failure)\n
+   \t-v show this message\n
+   , VERSION, __progname
+   );
exit(EXIT_FAILURE);
 }
 
@@ -219,14 +225,19 @@
const char *pws;
 #endif
Display *dpy;
-   int nscreens, screen;
+   int nscreens, screen, opt;
+   Bool silent = False;
 
struct st_lock **locks;
 
-   if((argc == 2)  !strcmp(-v, argv[1]))
-   die(slock-%s, © 2006-2008 Anselm R Garbe, VERSION);
-   else if(argc != 1)
-   usage();
+   while ( (opt = getopt(argc, argv, hsv)) != -1) {
+   switch (opt) {
+   case 's': 
+   silent = True; break;
+   default:
+   usage();
+   }
+   }
 
 #ifndef HAVE_BSD_AUTH
pws = get_password();
@@ -248,9 +259,9 @@
 
/* Everything is now blank. Now wait for the correct password. */
 #ifdef HAVE_BSD_AUTH
-   read_password(dpy);
+   read_password(dpy, silent);
 #else
-   read_password(dpy, pws);
+   read_password(dpy, pws, silent);
 #endif
 
/* Password ok, unlock everything and quit. */