You are not logged in.

#1 2010-07-23 17:17:49

surreal-Arch
Member
Registered: 2010-07-23
Posts: 4

[SOLVED] XMonad dzen2 / DWM command line apps

Hello,

Been using dwm for about a week or so now and really like the tiling and minimalism.  However, I am unable to get my command line applications to launch on a specific tag.  I tested this functionality on XMonad and it works easily, but I really liked dwm's statusbar and am struggling to figure it out in XMonad.

So if someone could help me get a grasp on either:
1) launching command line apps on specific tag in dwm

2) recreating dwm's statusbar in XMonad

config.h

/* See LICENSE file for copyright and license details. */
#include "fibonacci.c"
/* appearance */
static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#333333";
static const char normbgcolor[]     = "#2D2D2D";
static const char normfgcolor[]     = "#B3B3B3"; /* titlebar font color */
static const char selbordercolor[]  = "#535353";
static const char selbgcolor[]      = "#393939";
static const char selfgcolor[]      = "#5DB8EC"; /* selected title font color */
static const unsigned int borderpx  = 1;        /* border pixel of windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const Bool showbar           = True;     /* False means no bar */
static const Bool topbar            = True;     /* False means bottom bar */

/* tagging */
static const char *tags[] = { "main", "www", "dev", "media", "chat/torrent", "misc" };

static const Rule rules[] = {
    /* class      instance    title       tags mask     isfloating   monitor */
    { "Gimp",      NULL,       NULL,       1 << 3,       True,        -1 },
    { "Namoroka",  NULL,       NULL,       1 << 1,       False,       -1 },
    { "Chromium",  NULL,       NULL,       1 << 1,       False,       -1 },
    { "Gvim",      NULL,       NULL,       1 << 2,       False,       -1 },
    { "Vlc",       NULL,       NULL,       1 << 3,       False,       -1 },
};

/* layout(s) */
static const float mfact      = 0.60; /* factor of master area size [0.05..0.95] */
static const Bool resizehints = True; /* True means respect size hints in tiled resizals */

static const Layout layouts[] = {
    /* symbol     arrange function */
    { "[T]",      tile },    /* first entry is default */
    { "[F]",      NULL },    /* no layout function means floating behavior */
    { "[M]",      monocle },
    { "[@]",      spiral },
    { "[D]",      dwindle },
};

/* key definitions */
#define MODKEY Mod1Mask
#define TAGKEYS(KEY,TAG) \
    { MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
    { MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
    { MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
    { MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

/* commands */
static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
static const char *termcmd[]  = { "urxvtc", "-tr", NULL };
static const char *mutecmd[] = { "amixer", "-q", "sset", "Master", "toggle", NULL };
static const char *volupcmd[] = { "amixer", "-q", "sset", "Master", "3+", "unmute", NULL };
static const char *voldowncmd[] = { "amixer", "-q", "sset", "Master", "3-", "unmute", NULL };
static const char *brightupcmd[] = { "sudo", "/usr/local/sbin/backlight", "up", NULL };
static const char *brightdowncmd[] = { "sudo", "/usr/local/sbin/backlight", "down", NULL };


static Key keys[] = {
    /* modifier                     key        function        argument */
    { 0,                           0x1008ff11, spawn,          {.v = voldowncmd } },
    { 0,                           0x1008ff12, spawn,          {.v = mutecmd } },
    { 0,                           0x1008ff13, spawn,          {.v = volupcmd } },
    { 0,                           0x1008ff03, spawn,          {.v = brightdowncmd } },
    { 0,                           0x1008ff02, spawn,          {.v = brightupcmd } },
    { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
    { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
    { MODKEY,                       XK_b,      togglebar,      {0} },
    { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
    { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
    { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
    { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
    { MODKEY,                       XK_Return, zoom,           {0} },
    { MODKEY,                       XK_Tab,    view,           {0} },
    { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
    { MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
    { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
    { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
    { MODKEY,                       XK_s,      setlayout,      {.v = &layouts[3]} },
    { MODKEY,                       XK_d,      setlayout,      {.v = &layouts[4]} },
    { MODKEY,                       XK_space,  setlayout,      {0} },
    { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
    { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
    { MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
    { MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
    { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
    { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
    { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
    TAGKEYS(                        XK_1,                      0)
    TAGKEYS(                        XK_2,                      1)
    TAGKEYS(                        XK_3,                      2)
    TAGKEYS(                        XK_4,                      3)
    TAGKEYS(                        XK_5,                      4)
    TAGKEYS(                        XK_6,                      5)
    TAGKEYS(                        XK_7,                      6)
    TAGKEYS(                        XK_8,                      7)
    TAGKEYS(                        XK_9,                      8)
    { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
};

/* button definitions */
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
    /* click                event mask      button          function        argument */
    { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
    { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
    { ClkWinTitle,          0,              Button2,        zoom,           {0} },
    { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
    { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
    { ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
    { ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
    { ClkTagBar,            0,              Button1,        view,           {0} },
    { ClkTagBar,            0,              Button3,        toggleview,     {0} },
    { ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
    { ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
};

#define NUMCOLORS         4
static const char colors[NUMCOLORS][ColLast][8] = {
  // border   foreground background
  { "#000033", "#B3B3B3", "#2D2D2D" },  // normal
  { "#5DB8EC", "#5DB8EC", "#393939" },  // selected
  { "#ff0000", "#000000", "#ffff00" },  // urgent/warning  (black on yellow)
  { "#ff0000", "#ffffff", "#ff0000" },  // error (white on red)
  // add more here
};

xmonad.hs

import XMonad

import XMonad.Layout.NoBorders

import XMonad.Hooks.ManageDocks

import System.IO
import Data.Monoid

import qualified XMonad.StackSet as W
import qualified Data.Map        as M

main = do
  xmonad $ defaultConfig
    {
      terminal             = myTerminal
      , modMask            = myModMask
      , borderWidth        = myBorderWidth
      , focusFollowsMouse  = myFocusFollowsMouse
      , normalBorderColor  = myNormalBorderColor
      , focusedBorderColor = myFocusedBorderColor

      -- Key Bindings
      --, keys               = myKeys
      --, mouseBindings      = myMouseBindings

      -- Workspaces
      , workspaces         = myWorkspaces

      -- Hooks and Layouts

      , layoutHook         = myLayout
      , manageHook         = myManageHook
      , handleEventHook    = myEventHook
      , logHook            = myLogHook
      , startupHook        = myStartupHook
    } 
    
myTerminal           = "urxvtc -tr"
myModMask            = mod1Mask
myBorderWidth        = 2
myFocusFollowsMouse  = False
myNormalBorderColor  = "#393939"
myFocusedBorderColor = "#5DB8EC"
--myKeys               =
--myMouseBindings      =
myWorkspaces         = [ "main", "www", "dev", "media", "chat/torrent", "misc" ]
myLayout             = avoidStruts $ smartBorders tiled ||| smartBorders (Mirror tiled) ||| noBorders Full
    where
        tiled   = Tall nmaster delta ratio
        nmaster = 1
        ratio   = 1/2
        delta   = 3/100
myManageHook         = composeAll [ title =? "ncmpcpp" --> doF (W.shift "media") ]
myEventHook          = mempty
myLogHook            = return ()
myStartupHook        = return ()

Appreciate any help that people can offer.

Thanks

Last edited by surreal-Arch (2010-07-25 01:56:01)

Offline

#2 2010-07-23 17:27:40

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] XMonad dzen2 / DWM command line apps

As long as you're matching the class/instance/title of a window, it will obey the rules defined in config.h. If windows are not adhering the these rules, then the class/instance/title is not being matched. It's really that simple. I use this script to pare down the info generated by xprop:

#!/bin/bash
xprop |awk '
    /^WM_CLASS/{sub(/.* =/, "instance:"); sub(/,/, "\nclass:"); print}
    /^WM_NAME/{sub(/.* =/, "title:"); print}'

Run the script, click on the window in question, fix your rule, recompile dwm. Remember that case matters.

As for a DWM-like status bar in Xmonad, you'll need to use something such as xmobar or dzen2. Xmonad has no status bar of its own.

Offline

#3 2010-07-23 20:11:56

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

Re: [SOLVED] XMonad dzen2 / DWM command line apps

I don't use tag/app control in dwm, but when I set it up in other wm's I tended to launch them in urxvt (actually urxvtc) and specified a title using the "-title" option. Then I can just match on the title - which I can control.

I bind all my keys using xbindkey (that way I don't have to change anything from one wm to another) and here's how I launch mutt, for example:

"urxvtc -title Mail -e bash -i -c mutt"
    m:0x40 + c:68
    Mod4 + F2

"...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

#4 2010-07-24 09:38:32

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] XMonad dzen2 / DWM command line apps

A little OT:
skanky, have you tried 'urxvtc -title Mail -e mutt'? And specifying bash as interactive ('-i') is plain weird in this situation.

Caveat: I never used xbindkeys, so I don't know if your keybindings will still work w/o bash.

Last edited by karol (2010-07-24 09:39:45)

Offline

#5 2010-07-24 09:44:32

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] XMonad dzen2 / DWM command line apps

static const Rule rules[] = {
    /* class         instance    title       tags mask     isfloating   monitor */
        {  NULL,         NULL,      "mutt",      1 << 2,       False,       -1 },          }

static const char   *mailcmd[] = { "urxvtc", "-title", "mutt", "-e", "mutt", NULL };

static Key keys[] = {
    /*   modifier                   key        function        argument        */
        { ControlMask|Mod1Mask,         XK_m,      spawn,          {.v = mailcmd } },
   }

works for me


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#6 2010-07-24 19:07:52

surreal-Arch
Member
Registered: 2010-07-23
Posts: 4

Re: [SOLVED] XMonad dzen2 / DWM command line apps

I was able to get dwm apps working big_smile

Thanks everyone for the help

Offline

#7 2010-07-26 09:33:09

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

Re: [SOLVED] XMonad dzen2 / DWM command line apps

karol wrote:

A little OT:
skanky, have you tried 'urxvtc -title Mail -e mutt'? And specifying bash as interactive ('-i') is plain weird in this situation.

Caveat: I never used xbindkeys, so I don't know if your keybindings will still work w/o bash.

Ah, my mistake. That's because I don't actually call "mutt" but instead call a function called "mail". I've set-up app independent functions for all my common stuff (mail, web, news, music, etc.) so that I can change the application used, but don't accidentally type the old one through habit. I also use those functions in xbindkeys so that I don't have to remember to change the call there. Also, and this is especially true in mutt, some config files use functions inside them. The thing is though, my functions are only sourced in interactive sessions. 

I could stop using interactive if I moved them all to scripts (I have two terminal ones as scripts - tmnl and tmnlnc that start urxvtc and urxvtc with no clock that are also used in the xbindkeys set-up), but I want to keep those ones as functions. There may be a better way to do it, but this "works for me"(tm). smile

Anyway, the relevance here was that I wanted to simplify all that in my post above, so removed all the function wrappers, but forgot to remove the -i as well. But yes, I agree with you otherwise. smile


(EDIT) Nice one surreal-Arch smile

Last edited by skanky (2010-07-26 09:33:37)


"...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