You are not logged in.

#1 2008-08-25 18:20:11

fresch
Member
Registered: 2008-08-06
Posts: 17

dmenu patch for adding a vertical list and chaning its size/offsets

Hi,

I always liked the way one could search a huge xmms playlist for a song, sonata + mpd has a similar option, but it is really slow. using dmenu for displaying a mpd playlist like shown here http://mpd.wikia.com/wiki/Hack:Mpc-dmenu and applying a filter to it is fast, but kinda unusable when displayed the horizontal way.
So I wrote a patch for dmenu to display a vertical-style list and another one for changing offsets and size..

what can be done now
dmenuvd1.th.png

the patches are available here ...
http://schiewek.net/fresch/dmenu-3.8-vlist.diff
http://schiewek.net/fresch/dmenu-3.8-vlist-size.diff

Added options:

vlist.diff
[-l <#items>] activates vertical list mode, window will be adjusted for displaying #items
[-c] displays a counter in vlist mode (hits on applied filter)

vlist-size.diff 
[-r] align right
[-w <width>] window width
[-h <height>] window height. you can breath a wish here, but it gets recalculated internally ( simplified: #items = height / font.height )
[-bo <width>] border width
[-x <xoffset>] distance to left or right side of the screen, depends on [-r]
[-y <yoffset>] distance to top or bottom of the screen, depends on [-b]

some things you should know about the added options:
[-h] has higher priority then [-l]
[-bo],[-x] and [-y] can be mixed. e.g: -bo 5 -r -x 10 will display the window aligned to the right, with a 5px distance to the top and
5px + 10px to right side of the screen

and be careful with those width and offset options, use appropriate values.. no error checking is done here. you have been warned: if you give evil values to this patched version of dmenu, it may display nothing, just crash or burn your computer...

examples:

mpc play `mpc playlist | dmenu -p "Find:" -r -l 10 -w 400 -y 5 -x 5| cut -c 2- - | sed -r s/"\).*$"/""/`

this would pop up a 400px-wide dmenu-window on the right side of the screen, with space for 10 items. distance to the right side and the top of the screen would be 5px.

mpc play `mpc playlist | dmenu -p "Find:" -h 150 -w 300 -bo 5| cut -c 2- - | sed -r s/"\).*$"/""/`

the window would show up in the top/left corner of the screen, with a 5px distance to the top and the left side,
height would be somewhere around 150px, width 300px.

I'll let the developer/s on http://www.mail-archive.com/dwm@suckless.org/ know about that.. stay tuned and have fun

suggestions and comments are welcome
fresch

Offline

#2 2008-08-26 04:47:28

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Wow this looks awesome. I will try it tomorrow evening.

Offline

#3 2008-09-14 10:57:09

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: dmenu patch for adding a vertical list and chaning its size/offsets

This is actually pretty nice.  The only thing I'd like to see if I can add is changing the window size per # of matches, with a defined maximum size.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#4 2008-09-14 11:47:37

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Works great. Looks great. Needs to be in the official release.

The ^ and v lines are redundant, I think.

It works nice as an OSD too now. xcowsay was so slow.

Offline

#5 2008-09-14 15:04:46

fresch
Member
Registered: 2008-08-06
Posts: 17

Re: dmenu patch for adding a vertical list and chaning its size/offsets

rson451 wrote:

This is actually pretty nice.  The only thing I'd like to see if I can add is changing the window size per # of matches, with a defined maximum size.

I'll include this option and update the patches for dmenu 3.9.

Procyon wrote:

The ^ and v lines are redundant, I think.

... you don't want to know that there are actually more items on the list than displayed? roll
Well, those indicators may be redundant when the counter is enabled?!

thanks so far
fresch

Offline

#6 2008-09-14 16:48:54

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: dmenu patch for adding a vertical list and chaning its size/offsets

fresch wrote:

I'll include this option and update the patches for dmenu 3.9.

Sweeeet. saves me the time. smile


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#7 2008-09-15 00:30:10

fresch
Member
Registered: 2008-08-06
Posts: 17

Re: dmenu patch for adding a vertical list and chaning its size/offsets

http://schiewek.net/fresch/dmenu-3.9-fresch.diff

I removed the [-bo] option. The offset and size options should be enough..
but there are some new options, too

[-ms] multi-select; changes standard-behavior: selecting an item and pressing return won't close dmenu,
but leave you the opportunity to select some more items
[-nl] seperates standard output by newlines. could come in handy when using [-ms]
[-rs] resize; adjust window-size to display the matching items. [-l] defines the max.
[-ml] mark last item
[-lb] bg-color of last item
[-lf] fg-color of last item

some usage example: it now works more like a "real" playlist

mpc playlist | dmenu -i -nb "#000" -nf "#7af" -sb "#000" -sf "#bdf" -lf "#fff" -lb "#000" -p "Find:" -l 20 -y 10 -x 10 -w 400 -nl -rs -ms -ml | mpcplay
// mpcplay
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>

#define MAX 6

int main(void)
{
        char c, buf[MAX], *args[] = {"mpc", "play", buf, NULL};
        unsigned int i = 0;;

        while ((c = fgetc(stdin)) != EOF) {
                if (isdigit(c))
                        buf[i+1>MAX?i:i++] = c;
                else if (c == ')')
                        buf[i+1>MAX?i:i++] = '\0';
                else if (c == '\n') {
                        i = 0;
                        if (!fork())
                                execv("/usr/bin/mpc", args);
                }
        }
        return 0;
}

@rson451: is [-rs] what you had in mind?

Last edited by fresch (2008-09-15 16:34:07)

Offline

#8 2008-09-15 02:21:03

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Exactly.  Still taking suggestions?  If so, possibly add options for center horizontally and possibly vertically (at least initially if -rs is specified).  I'm thinking this would make a very nice suckless netcfg2 menu that could pop up right in the middle of the screen.  If those aren't things you want to add I'll play with it.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#9 2008-09-15 12:18:30

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: dmenu patch for adding a vertical list and chaning its size/offsets

You made a typo in your post:

[-cb] bg-color of last item
[-cf] fg-color of last item

are options -lb, -lf

But I don't notice any difference when using them with -ml.

Offline

#10 2008-09-15 16:33:36

fresch
Member
Registered: 2008-08-06
Posts: 17

Re: dmenu patch for adding a vertical list and chaning its size/offsets

hm, you are right, thanks smile

and suggestions are welcome.

@rson451 you can use the size and offset options to center the initial window... but the hole positioning/size thingy somehow sucks hmm


But I don't notice any difference when using them with -ml.

tried using it with -ml and -ms? you wont see a differently colored item, if dmenu immediately closes after selecting one -> it just works in multi-select-mode

but its current behavior is definitely arguable ...

share some screenshots showing how you use it!

fresch

Offline

#11 2008-09-15 17:55:57

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Oh I understand -ml now, I didn't try it with -ms. I thought it did something else.

share some screenshots showing how you use it!

I said I'd use it as an OSD, so here's a screenshot of it in action (using a cmus script). I still think it could do without ^ and v lines.

scrot20080915194203qr3.th.png

Offline

#12 2008-09-16 18:14:34

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: dmenu patch for adding a vertical list and chaning its size/offsets

I delved in and did it myself.

http://paste.pocoo.org/show/Jt26enSz3uLBZ6Wsx75p/
Adds the option -osd, that will hide the ^ and v lines.

And here is the patch for fresch's .c file, because I am not good with C and patches, so you can spot dangerous things easier.
http://paste.pocoo.org/show/XDT38XdcbppD75T6Kmaq/

EDIT:
By the way, I just see it while looking over the patch, it only works for topbar. If you want I can update that.

And I forgot to copy the config.h stuff.
Here is the full patch then, everything at patch -p0 level
http://paste.pocoo.org/show/AhS00FV150xIoK46jFZZ/

EDIT:
I said it doesn't work for topbar, but I meant it only works for topbar.

Last edited by Procyon (2008-09-17 10:18:54)

Offline

#13 2008-09-19 03:30:49

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: dmenu patch for adding a vertical list and chaning its size/offsets

I used fresch's 3.9 patch and made a package in the AUR: http://aur.archlinux.org/packages.php?ID=20063.

Offline

#14 2008-09-19 09:38:17

Blµb
Member
Registered: 2008-02-10
Posts: 223

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Unbelievably evil me took the liberty of modifying fresch's mpcplay to be a little bit more general so I can use a dmenu script similar to the ones above to add folders to the playlist.

addtodbkt0.th.png

Enjoy:

#! /bin/sh
exec mpc listall | \
  grep -o '.*/'| \
  awk '!x[$0]++' | \
  dmenu -i -nb "#000" -nf "#7af" -sb "#000" -sf "#bdf" -lf "#fff" -lb "#000" -p "Find:" -l 20 -y 10 -x 10 -w 400 -nl -rs -ms -ml | \
  mpcplay add
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>

static char buf[128];

int usage()
{
    printf(
        "Usage: mpcplay [command]\n"
        "    Reads lines from stdin and executes `mpc <command> <line>\n"
        );
    return 1;
}

int main(int argc, char **argv)
{
    char c, *args[] = {"mpc", NULL, buf, NULL};
    unsigned int i = 0;
    
    /*
      we're too nice... since it is now a more general tool, this part should be up to the
      executing shell script or whatever...
    */
    int digits_only;

    if(argc < 2)
        args[1] = "play";
    else if(argc == 2)
        args[1] = argv[1];
    else
        return usage();

    digits_only = (strcmp(args[1], "play") == 0);

    while ((c = fgetc(stdin)) != EOF) {
        if(c != '\n')
        {
            if(!digits_only || isdigit(c))
                buf[i+1>sizeof(buf)?i:i++] = c;
            else if(c == ')')
                buf[i+1>sizeof(buf)?i:i++] = '\0';
        }
        else
        {
            i = 0;
            if (!fork())
                execv("/usr/bin/mpc", args);
        }
    }
    return 0;
}

You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.

Offline

#15 2008-09-19 11:11:56

fresch
Member
Registered: 2008-08-06
Posts: 17

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Procyon wrote:

I delved in and did it myself.

I'll include your changes, but renaming -osd to something like -ri for "remove indicators"... if you don't mind. And I think it then should be available for standard dmenu, too.

peets wrote:

I used fresch's 3.9 patch and made a package in the AUR: http://aur.archlinux.org/packages.php?ID=20063.

Thanks a lot! But now I/we should update the manpage, as well.

Blµb wrote:

Unbelievably evil me took the liberty of modifying fresch's mpcplay to be a little bit more general so I can use a dmenu script similar to the ones above to add folders to the playlist.

99.gif


fresch

Offline

#16 2008-09-19 13:13:02

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: dmenu patch for adding a vertical list and chaning its size/offsets

fresch wrote:
Procyon wrote:

I delved in and did it myself.

I'll include your changes, but renaming -osd to something like -ri for "remove indicators"... if you don't mind. And I think it then should be available for standard dmenu, too.

Great, thanks!
I took another peek at the code and experimented with topbar off, and unlike what I said it does seem to work.
One redundant change seems to be:
ry = topbar ? (displaymoreless ? y : 0) + yoffset : y - rmh + (dc.font.height + 2) - yoffset;
Just y + yoffset works the same, and that was the only time topbar seemed to make a difference on the changed code.

Offline

#17 2008-10-03 13:55:07

Anklyne
Member
Registered: 2008-10-03
Posts: 2

Re: dmenu patch for adding a vertical list and chaning its size/offsets

I just used the AUR version (v3.9) and installed etc, but now searching is case sensitive and it doesn't actually work.

I'm using this script and when I run it through the console I get this:

[anklyne@anklin ~]$ ~/mpc-dmenu
skipping: 1)
skipping: AC/DC
skipping: -
skipping: Highway
skipping: to
error parsing song numbers from: Hell

then it shows the status, like mpc does.
Now I'm no coding genius, but I'm guessing dmenu isn't outputting a song number like it probably should be.

Any body have any ideas as how to fix it?

Edit:

I fixed the case sensitive "problem". I just had to use the -i option for dmenu.

I still haven't got it changing songs yet though hmm

Edit:

All fixed big_smile

Just had to remove the $ from this command:

sed -r s/"\).*$"/""/

Thanks for all your help my good men tongue

Last edited by Anklyne (2008-10-03 16:12:52)

Offline

#18 2008-10-03 16:13:57

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Maybe the script's author has a different version of dmenu or sed than you and I: dmenu removes the newline at the end of its output, and sed's "$" doesn't match when there is no newline, so it doesn't do anything. I edited the page on the mpd wiki. Just change the sed regexp from

s/"\).*$"/""/

to

s/"\).*"/""/

Edit: Beat! Hehe.

Last edited by peets (2008-10-03 16:14:59)

Offline

#19 2008-10-03 16:36:02

Anklyne
Member
Registered: 2008-10-03
Posts: 2

Re: dmenu patch for adding a vertical list and chaning its size/offsets

peets wrote:

Maybe the script's author has a different version of dmenu or sed than you and I: dmenu removes the newline at the end of its output, and sed's "$" doesn't match when there is no newline, so it doesn't do anything. I edited the page on the mpd wiki. Just change the sed regexp from

s/"\).*$"/""/

to

s/"\).*"/""/

Edit: Beat! Hehe.

It worked perfectly fine before I changed to fresch's patched version, so it must've been dmenu.

Yeah, a little too late tongue
Thanks anyway.

Last edited by Anklyne (2008-10-03 16:36:40)

Offline

#20 2008-10-04 01:07:10

fresch
Member
Registered: 2008-08-06
Posts: 17

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Anklyne wrote:

It worked perfectly fine before I changed to fresch's patched version, so it must've been dmenu.

should be fixed with this one:

http://schiewek.net/fresch/dmenu-3.9-fresch-2.diff

this patch also adds the option to remove those unpopular ^v indicators.

And I edited the manpage: may anyone please have a look at this and let me know if the descriptions are ok?!

when this is done, I'm sure peets won't mind updating the package

Last edited by fresch (2008-10-04 01:08:35)

Offline

#21 2008-10-05 00:50:29

fresch
Member
Registered: 2008-08-06
Posts: 17

Re: dmenu patch for adding a vertical list and chaning its size/offsets

next one

http://schiewek.net/fresch/dmenu-3.9-fresch-3.diff

using -xs, the search now works like in the xmms playlist.

hope this one has fewer mistakes than the one from yesterday ;D someone should definitely review this.. at least to prove that the options do what the manpage promises

Offline

#22 2008-10-05 02:19:40

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: dmenu patch for adding a vertical list and chaning its size/offsets

Just updated package. Please try and report any errors! fresch: I'll be reading the manpage soon.

http://aur.archlinux.org/packages.php?ID=20063

Offline

#23 2008-10-05 15:44:20

IdoMcFly
Member
Registered: 2007-12-18
Posts: 28

Re: dmenu patch for adding a vertical list and chaning its size/offsets

I've found on the dwm mailing list a patch to add a history to dmenu. I've combine the original version with a correction to avoid a crash :
http://idomcfly.free.fr/patch/dmenu_history.diff

Offline

#24 2008-10-05 15:54:15

IdoMcFly
Member
Registered: 2007-12-18
Posts: 28

Re: dmenu patch for adding a vertical list and chaning its size/offsets

fresch wrote:

using -xs, the search now works like in the xmms playlist.

What does it mean?

Offline

#25 2008-10-05 16:32:41

fresch
Member
Registered: 2008-08-06
Posts: 17

Re: dmenu patch for adding a vertical list and chaning its size/offsets

IdoMcFly wrote:

I've found on the dwm mailing list a patch to add a history to dmenu. I've combine the original version with a correction to avoid a crash :
http://idomcfly.free.fr/patch/dmenu_history.diff

looks like it does something simliar to this:
cat histfile >> tmpfile && $cmd >> tmpfile && cat tmpfile | ./dmenu -nl >> histfile

I already thought about having something like a history or favorites for dmenu.. but I guess I will end up
programming my own mpd client hmm


never used xmms, hm?

the filter is splitted into tokens using space as separator.
now dmenu will only show items that contain every token.

this is quite nice, when dmenu is used as a playlist for mpd. you can type the first few letters of the artists name followed by some letters of the song title, like: "ram she". and if you are a ramones fan, your dmenu will now probably show "Ramones - Sheena Is A Punk Rocker"

Offline

Board footer

Powered by FluxBB