You are not logged in.

#126 2012-11-15 12:31:52

c00kiemon5ter
Member
From: Greece
Registered: 2010-06-01
Posts: 562
Website

Re: Dmenu Hacking Thread

give this a try.
It definitely needs some work though


.:[ git me! ] :.

Offline

#127 2012-11-16 21:27:34

flipper T
Member
Registered: 2012-09-14
Posts: 419

Re: Dmenu Hacking Thread

Hi, I use i3wm which has dmenu as standard and initiates it with

bindsym $mod+d exec dmenu_run

Unfortunately, the font size is way too small for my old eyes.

So, is there a very easy way to increase the font size ? I have read the man page, but unfortunately there is no example there.

Sorry if silly question, but i have found little help by googling & what there is, is pitched at a technical level far beyond my understanding.


If I'm curt with you it's because time is a factor. I think fast, I talk fast and I need you guys to act fast if you wanna get out of this. So, pretty please... with sugar on top. Clean the [censored] car. -The Wolf

Offline

#128 2012-11-16 22:47:09

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,843
Website

Re: Dmenu Hacking Thread

flipper, unless I'm missing something, you'd just need the "-fn" option.  use `dmenu_run -fn <fontname>` where fontname is a full X11 fontstring.  The easiest way to get a suitable fontstring is from xfontsel.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Online

#129 2012-11-17 01:04:13

flipper T
Member
Registered: 2012-09-14
Posts: 419

Re: Dmenu Hacking Thread

Thanks trilby, after a lot of messing about with xfontsel, finally got a more legible font size.

For anyone with same problem:

exec dmenu_run -fn -misc-fixed-*-*-*-*-20-200-*-*-*-*-*-*

worked for me.

thx again.


If I'm curt with you it's because time is a factor. I think fast, I talk fast and I need you guys to act fast if you wanna get out of this. So, pretty please... with sugar on top. Clean the [censored] car. -The Wolf

Offline

#130 2012-11-18 18:59:38

rix
Member
Registered: 2012-07-25
Posts: 221

Re: Dmenu Hacking Thread

Hello,

My first attempt: send an e-mail through Mutt.

#!/bin/bash

dmn="dmenu -i -b -fn -*-terminus-medium-r-*-*-13-*-*-*-*-*-*-* -nb black -nf white -sb black -sf yellow"

t=$(echo | $dmn -p "Text:")
s=$(echo | $dmn -p "Subject:")
ad=$(echo | $dmn -p "Address:")
at=$(echo | $dmn -p "Attachment:")
        
if [ "$ad" != "" ]
    then
        if [ "$at" != "" ]
            then
                echo "Text: $t; subject: $s; to: $ad; attachment: $at" | $dmn &> /dev/null
                echo $t | mutt -s $s $ad -a $at && echo "Sent." | $dmn &> /dev/null
            else
                echo "Text: $t; subject: $s; to: $ad" | $dmn &> /dev/null
                echo $t | mutt -s $s $ad && echo "Sent." | $dmn &> /dev/null
        fi
    else
        echo "You didn't insert any address." | $dmn &> /dev/null
        exit 1
fi

exit 0

Last edited by rix (2012-11-19 13:18:45)

Offline

#131 2012-11-19 21:57:23

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: Dmenu Hacking Thread

I have a question about the actual code of dmenu. In the DWM hacking thread, Ivoarch shared a runorraise patch: https://gist.github.com/4107047

I was wondering if this could also be implemented somewhere in dmenu? To just switch to the open application running, if there is one. If not, launch that application.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#132 2012-11-23 20:20:24

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: Dmenu Hacking Thread

I tried patching dmenu myself by taking Ivoarch's patch and the different DWM functions at hand and I came up with this:

--- dmenu.c.orig	2012-11-22 22:36:31.698980119 +0100
+++ dmenu.c.patched	2012-11-23 21:10:13.922942154 +0100
@@ -38,6 +38,7 @@
 static void paste(void);
 static void readstdin(void);
 static void run(void);
+static void runorraise(void);
 static void setup(void);
 static void usage(void);
 
@@ -121,7 +122,7 @@
 		grabkeyboard();
 	}
 	setup();
-	run();
+	runorraise();
 
 	cleanup();
 	return ret;
@@ -532,6 +533,19 @@
 }
 
 void
+runorraise(void) {
+	XClassHint hint = { NULL, NULL };
+
+	XGetClassHint(dc->dpy, win, &hint);
+	if (hint.res_class) {
+		XSetInputFocus(dc->dpy, win, RevertToPointerRoot, CurrentTime);
+		//sendevent(win, XInternAtom(dc->dpy, "WM_TAKE_FOCUS", False), NoEventMask, XInternAtom(dc->dpy, "WM_TAKE_FOCUS", False), CurrentTime, 0, 0, 0);
+		return;
+	}
+	run();
+}
+
+void
 setup(void) {
 	int x, y, screen = DefaultScreen(dc->dpy);
 	Window root = RootWindow(dc->dpy, screen);

Now it compiles fine but obviously doesn't work as expected. I'm not sure how to make it read the name of the application you try to run and getting the Class of that application accordingly. Ivoarch uses the config.h of DWM so we can apply certain classes in there, as per so:

static const char *emacs[] = { "emacs", NULL, "Emacs" };
 
{ Modkey, XK_e, runorraise, {.v = emacs } }, 

But obviously we can't do that in dmenu. I have no idea how to do that, but if anyone knows feel free to chime in and get this working! smile


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#133 2012-11-23 20:52:29

earsplit
Member
Registered: 2012-03-31
Posts: 187
Website

Re: Dmenu Hacking Thread

Didn't see this on here so I figured I'd share it.

This is a simple openbox menu for any wndow manager. I bound it to my middle click. One middle click opens, the next middle click closes.

It is configured using a seperate file, making it very easy to modify on the fly. I modified some version I found online.

menu.sh

#!/bin/sh

WIDTH=60
FONT='-*-lime-*-*-*-*-*-*-*-*-*-*-*-*'


# Width of the graphical separator (default 80% of window's width)
SEPARATOR_WIDTH=`expr $WIDTH - \( $WIDTH / 100 \) \* 20`

#Position
X=$(getcurpos | cut -c1-4)
Y=$(getcurpos | cut -c5-10)


[ -f "$1" ] && MENUFILE="$1" || exit

# number of visible menu entries (access the others through scrolling up/down)
LINES=`wc -l "$MENUFILE"|sed -e 's/ .*//'`
[ $LINES -gt 20 ] && LINES=20

# if process already exists, kill it. We dont want more than one instance
if [ $(pgrep dzen | wc -w) -gt 2 ]; then
	kill $(pgrep dzen | tail -n1)
	exit
fi

execute () {
        read PROG

        while read LINE; do 
                LBL=;APP=
                LBL=$(echo $LINE|sed -e 's/:.*$//' -e 's/^[ \t]*//' -e 's/[ \t]*$//')
                APP=$(echo $LINE|sed -e 's/^.*://' -e 's/^[ \t]*//' -e 's/[ \t]*$//')
             
                if [ x"$APP" = x"exit" ]; then
                        exit
                elif [ x"$LBL" = x"$PROG" ]; then
                       if [ x"$APP" = x"" ]; then
                          $LBL&
                       else
                          $APP&
                       fi
                       exit
                fi
        done < "$MENUFILE"
}


(
echo "^bg(#556c85)^fg(#000000)            "   
sed -e 's/:.*$//' \
    -e 's/^.--*/^r('${SEPARATOR_WIDTH}'x1)/' "$MENUFILE" 
) | \
dzen2 -l $LINES -w $WIDTH -x $X -y $Y -fn $FONT -bg '#000000' -fg '#FFFFFF' -p -m -sa l -e 'onstart=uncollapse,scrollhome;button1=menuprint_noparse,exit;button3=exit;button4=scrollup;button5=scrolldown' | execute

config

 ^fg(#556c85)^i(/home/sunn/.dzen/arch.xbm)^fg() term:urxvt
 ^fg(#556c85)^i(/home/sunn/.dzen/fs_01.xbm)^fg() www:chromium
 ^fg(#556c85)^i(/home/sunn/.dzen/diskette.xbm)^fg() pdf:zathura
 ^fg(#556c85)^i(/home/sunn/.dzen/plug.xbm)^fg() doc:lowriter
 ^fg(#556c85)^i(/home/sunn/.dzen/stop.xbm)^fg() xls:localc
 ^fg(#556c85)^i(/home/sunn/.dzen/ac.xbm)^fg() ppt:loimpress
 ^fg(#556c85)^i(/home/sunn/.dzen/fox.xbm)^fg() gimp:gimp
 ^fg(#556c85)^i(/home/sunn/.dzen/cpu.xbm)^fg() ise:ise
 ^fg(#556c85)^i(/home/sunn/.dzen/mem.xbm)^fg() matlab:urxvt -e matlab -nodesktop -nosplash
----------
 ^fg(#556c85)^i(/home/sunn/.dzen/play.xbm)^fg() run:gmrun
 ^fg(#556c85)^i(/home/sunn/.dzen/full.xbm)^fg() suspend:sudo pm-suspend
 ^fg(#556c85)^i(/home/sunn/.dzen/half.xbm)^fg() restart:sudo reboot
 ^fg(#556c85)^i(/home/sunn/.dzen/empty.xbm)^fg() shutdown:sudo shutdown -h now

Make executable, place a symlink in /usr/bin and execute with

menu config

The only thing you may have to modify is the number of dzen processes running. In my Xmonad config, I have two dzen processes running, so when searching for the process I simply checked the count and restarted the last one. There is probably a better way to do this, but this is just a quick edit.

Sharing this because it took me forever to find. It makes my Xmonad setup usable by everyone that wants to borrow my laptop. No more "WHERES THE LAUNCHER" questions

Last edited by earsplit (2012-11-23 20:54:41)


((( configs :: website )))

Offline

#134 2012-11-23 21:58:40

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,843
Website

Re: Dmenu Hacking Thread

Earsplit, did you mean to post that in the dzen thread?  How is it relevant to dmenu?


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Online

#135 2012-12-11 05:35:10

ninjaaron
Member
Registered: 2010-12-10
Posts: 289

Re: Dmenu Hacking Thread

I just figured out what dmenu actually does... and my mind is blown.

Offline

#136 2013-01-02 19:45:00

graph
Member
Registered: 2010-12-21
Posts: 105

Re: Dmenu Hacking Thread

#125 & #126
I just made this. It lists running applications and switches to the tag they're in. It depends on xdotool and dmenu:

#!/bin/bash
# Search through open programs and switch to their tag

# List all applications (and ignore "plugin-container", since it's flash in firefox)
application=$(xlsclients | grep -v "plugin-container" | cut -d" " -f3 | dmenu -i -p "Switch to")

# Switch to application
xdotool search "$application" windowactivate &> /dev/null

EDIT: Seems like some applications are immune to the approach above (so far gimp, truecrypt and libreoffice).
Here's a version that works with libreoffice and virtualbox but NOT gimp/truecrypt.
EDIT2: And here's a version that works with gimp/truecrypt too, thanks to Army.

Last edited by graph (2013-01-03 09:52:47)

Offline

#137 2013-01-03 07:53:30

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

For Gimp, you have to use

xdotool search --onlyvisible -classname "$application" windowactivate

At least that's how it works here.

Offline

#138 2013-01-03 09:48:49

graph
Member
Registered: 2010-12-21
Posts: 105

Re: Dmenu Hacking Thread

@Army
Yep, that works for gimp and truecrypt. Thank you very much.
Here's the updated script with all the bells and whistles (as in, works with everything I usually have running).

Last edited by graph (2013-01-03 09:55:30)

Offline

#139 2013-01-03 12:38:06

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

To be more precise, my line seems to work for everything, doesn't it? (I didn't invest that much time testing it)

Offline

#140 2013-01-03 12:49:42

graph
Member
Registered: 2010-12-21
Posts: 105

Re: Dmenu Hacking Thread

It doesn't work with firefox and libreoffice/soffice, but otherwise you seem to be right.

Last edited by graph (2013-01-03 12:52:39)

Offline

#141 2013-01-03 13:03:00

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

You're right. It looks like you can just put the different versions of the command line after each other. One of them will work eventually. Here's how I have it right now

#!/bin/bash
# Search through open programs and switch to their tag

# List all applications (and ignore "plugin-container", since it's flash in firefox)
application=$(xlsclients | grep -v "plugin-container" | cut -d" " -f3 | dmenu -i -p "switch to")

# Switch to application
xdotool search --onlyvisible -classname "$application" windowactivate
xdotool search --onlyvisible -name "$application" windowactivate

(This  &> /dev/null at the end doesn't seem to be required)

Pretty neat, except if you run multiple terminals. For this to work you have to give each instance a name for xdotool to pick the right one. But xlsclients doesn't list the terminals by its name.

Last edited by Army (2013-01-03 13:07:19)

Offline

#142 2013-01-03 13:15:25

graph
Member
Registered: 2010-12-21
Posts: 105

Re: Dmenu Hacking Thread

Army wrote:

(This  &> /dev/null at the end doesn't seem to be required)

You're right. It's there because i did not provide a class to search, which resulted in a "switching to default"-message being printed, which annoyed me - Your solution is better.
My OCD tells me to end the first xdotool command with a "&& exit 0", so we possibly avoid starting another xdotool-instance (if something is found on the first one, no need to execute the last one).
EDIT: My OCD is wrong, "&& exit 0" won't work with e.g. Firefox.

Army wrote:

Pretty neat, except if you run multiple terminals.

I have a single urxvtc-window which connects to a tmux-session running multiple terminals, so that's not a problem for me.

NB: Your solution will not work with VirtualBox and LibreOffice, since they're started by a weird command - see the updated script above.

Last edited by graph (2013-01-04 16:24:11)

Offline

#143 2013-02-12 20:26:55

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

On the suckless mailing list this problem was solved in a VERY nice way!

This script depends on lsw, which is also a suckless project and available in the AUR.

#!/bin/bash

declare -i active_id
declare -i win_id

winlist=$(xprop -root _NET_CLIENT_LIST|cut -d "#" -f 2|tr "," " ")
count=$(echo $winlist|wc -w)
active_id=$(xprop -root _NET_ACTIVE_WINDOW|awk -F' ' '{ print $NF }')
foo=$(for i in $winlist; do
        win_id="${i}"
        if [ $win_id -eq $active_id ]; then
                focustag="*"
        else
                focustag=" "
        fi
          
        win_class=$(xprop -id ${win_id} WM_CLASS | cut -d'"' -f2)
        win_title=$(xprop -id ${win_id} WM_NAME | cut -d'=' -f2-)
        printf  "%10.10s${focustag}| %60.60s | 0x%7.7x\n" "${win_class}" "${win_title}" "${win_id}"
done |sort| dmenu -i -l $count)


if [ $? -eq 0 ]; then
        xdotool windowactivate $(echo $foo | awk -F'|' '{ print $NF }')
fi

Works for firefox and libreoffice as well. Perfect! (Slowly but surely it's getting hard to find a not already used shortcut for all those fine dmenu tools!)

Last edited by Army (2013-02-12 20:27:09)

Offline

#144 2013-02-12 23:53:21

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,843
Website

Re: Dmenu Hacking Thread

Army wrote:

Slowly but surely it's getting hard to find a not already used shortcut for all those fine dmenu tools!

You may have to make a dmenu tool to list and select which dmenu tool you wish to use. wink


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Online

#145 2013-02-13 08:40:07

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

Brilliant idea! big_smile

Offline

#146 2013-02-13 09:26:00

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Dmenu Hacking Thread

Would it be the first entry inside itself?


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#147 2013-02-13 16:47:15

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

Don't need it yet, but as soon as this gets out of hand I'll make a script to list and select tools I don't use that often. But no, it won't be the first entry inside itself wink But it makes more sense to list it by ranking.

I think I'll write one soon and of course then share it here.

Offline

#148 2013-02-13 17:09:32

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Dmenu Hacking Thread

Army wrote:

Don't need it yet, but as soon as this gets out of hand I'll make a script to list and select tools I don't use that often. But no, it won't be the first entry inside itself wink But it makes more sense to list it by ranking.

I think I'll write one soon and of course then share it here.

Actually, the obvious entry for it inside itself is to edit its config. That's where my dedit script (above) has itself inside it.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#149 2013-02-13 19:11:57

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

I thought I'll get those entries automatically by naming the scripts e.g. dmenu-nso-* (nso = not so often). Maybe this will be too hard for me, since I'm a horrible scripter. But providing an entry to edit the config makes perfectly sense!

Offline

#150 2013-02-13 20:21:25

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Dmenu Hacking Thread

You could adapt this - https://bbs.archlinux.org/viewtopic.php … 5#p1118255
There's a simpler version a couple of posts further up.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

Board footer

Powered by FluxBB