Added `findemacs` function to focus an emacs frame.
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Mon, 15 Feb 2016 19:27:49 +0000 (20:27 +0100)
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>
Mon, 15 Feb 2016 19:27:49 +0000 (20:27 +0100)
config.def.h
config.h [deleted file]
dwm.1
dwm.c

index 88ca344..4e21b76 100644 (file)
@@ -52,8 +52,6 @@ static const Layout layouts[] = {
 static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
 static const char *termcmd[]  = { "x-terminal-emulator", NULL };
 static const char *lockcmd[]  = { "slock", NULL };
-static const char *emacscmd[] = { "emacs", NULL };
-static const char *torcmd[]   = { "torbrowser", NULL};
 static const char *sshadd[]   = { "ssh-add-x", NULL}; /* add .ssh/id_rsa to the ssh agent */
 /* run rsync on the server's maildir. Run ssh-add before doing this.*/
 static const char *getmail[]   = { "/home/gpcf/software/mail/getmail.sh", NULL}; 
@@ -66,9 +64,8 @@ static Key keys[] = {
        { MODKEY,                       XK_s,      spawn,          {.v = sendmail} },
        { MODKEY,                       XK_g,      spawn,          {.v = getmail} },
        { MODKEY,                       XK_x,      spawn,          {.v = dmenucmd } },
-       { MODKEY,                       XK_n,      spawn,          {.v = torcmd} },
        { MODKEY|ShiftMask,             XK_l,      spawn,          {.v = lockcmd } },
-       { MODKEY,                       XK_e,      spawn,          {.v = emacscmd} },
+       { MODKEY,                       XK_e,      findemacs,      {0} },
        { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
        { MODKEY,                       XK_b,      togglebar,      {0} },
        { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
@@ -91,6 +88,7 @@ static Key keys[] = {
        { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
        { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
        { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
+       { MODKEY,                       XK_w,      list_clients,   {0} },
        TAGKEYS(                        XK_1,                      0)
        TAGKEYS(                        XK_2,                      1)
        TAGKEYS(                        XK_3,                      2)
diff --git a/config.h b/config.h
deleted file mode 100644 (file)
index 88ca344..0000000
--- a/config.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-
-/* appearance */
-static const char font[]            = "Latin Modern Mono 9";
-static const char normbordercolor[] = "#444444";
-static const char normbgcolor[]     = "#000022";
-static const char normfgcolor[]     = "#ddff00";
-static const char selbordercolor[]  = "#000088";
-static const char selbgcolor[]      = "#000022";
-static const char selfgcolor[]      = "#ffffff";
-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 */
-static const Bool statusmarkup      = True;     /* True means use pango markup in status message */
-
-/* tagging */
-static const char *tags[] = { "one",  "two", "three", "four", "five" };
-
-static const Rule rules[] = {
-       /* class      instance    title       tags mask     isfloating   monitor */
-       { "Gimp",       NULL,       NULL,       1 << 3,            True,        -1 },
-       { "Iceweasel",  NULL,       NULL,       1 << 4,       False,       -1 },
-       { "Firefox",    NULL,       NULL,       1 << 4,       False,       -1 },
-       { "Emacs",      NULL,       NULL,       1,            False,       -1 },
-};
-
-/* layout(s) */
-static const float mfact      = 0.66; /* factor of master area size [0.05..0.95] */
-static const int nmaster      = 1;    /* number of clients in master area */
-static const Bool resizehints = False; /* True means respect size hints in tiled resizals */
-
-static const Layout layouts[] = {
-       /* symbol     arrange function */
-       { "[M]",      monocle },
-       { "[]=",      tile },    /* first entry is default */
-       { "><>",      NULL },    /* no layout function means floating behavior */
-};
-
-/* key definitions */
-#define MODKEY Mod4Mask
-#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[]  = { "x-terminal-emulator", NULL };
-static const char *lockcmd[]  = { "slock", NULL };
-static const char *emacscmd[] = { "emacs", NULL };
-static const char *torcmd[]   = { "torbrowser", NULL};
-static const char *sshadd[]   = { "ssh-add-x", NULL}; /* add .ssh/id_rsa to the ssh agent */
-/* run rsync on the server's maildir. Run ssh-add before doing this.*/
-static const char *getmail[]   = { "/home/gpcf/software/mail/getmail.sh", NULL}; 
-/* run script that sends emails over ssh */
-static const char *sendmail[] = { "/home/gpcf/software/mail/sendmail.sh", NULL};
-
-static Key keys[] = {
-       /* modifier                     key        function        argument */
-        { MODKEY,                       XK_a,      spawn,          {.v = sshadd} },
-       { MODKEY,                       XK_s,      spawn,          {.v = sendmail} },
-       { MODKEY,                       XK_g,      spawn,          {.v = getmail} },
-       { MODKEY,                       XK_x,      spawn,          {.v = dmenucmd } },
-       { MODKEY,                       XK_n,      spawn,          {.v = torcmd} },
-       { MODKEY|ShiftMask,             XK_l,      spawn,          {.v = lockcmd } },
-       { MODKEY,                       XK_e,      spawn,          {.v = emacscmd} },
-       { 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_i,      incnmaster,     {.i = +1 } },
-       { MODKEY,                       XK_d,      incnmaster,     {.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[1]} },
-       { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[2]} },
-       { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[0]} },
-       { 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} },
-};
diff --git a/dwm.1 b/dwm.1
index ca17e5f..e8b2c46 100644 (file)
--- a/dwm.1
+++ b/dwm.1
@@ -61,8 +61,9 @@ Start
 .BR rxvt-unicode (1).
 .TP
 .B Super\-e
-Run
+Focuses a running
 .BR emacs (1)
+frame, if it finds one.
 .TP
 .B Super\-x
 Shows a menu with programs you can run if you have
@@ -93,9 +94,6 @@ Sets floating layout.
 .B Super\-m
 Sets monocle layout.
 .TP
-.B Super\-n
-Starts torbrowser
-.TP
 .B Super\-space
 Toggles between current and previous layout.
 .TP
diff --git a/dwm.c b/dwm.c
index 8fae3ba..26f24a7 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -193,6 +193,7 @@ static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[C
 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
 static void enternotify(XEvent *e);
 static void expose(XEvent *e);
+static void findemacs(const Arg *arg);
 static void focus(Client *c);
 static void focusin(XEvent *e);
 static void focusmon(const Arg *arg);
@@ -207,6 +208,8 @@ static void incnmaster(const Arg *arg);
 static void initfont(const char *fontstr);
 static void keypress(XEvent *e);
 static void killclient(const Arg *arg);
+static void list_clients(const Arg *arg);
+static void listclients(void);
 static void manage(Window w, XWindowAttributes *wa);
 static void mappingnotify(XEvent *e);
 static void maprequest(XEvent *e);
@@ -301,6 +304,8 @@ static Window root;
 /* compile-time check if all tags fit into an unsigned int bit array. */
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
 
+
+
 /* function implementations */
 void
 applyrules(Client *c) {
@@ -861,6 +866,26 @@ expose(XEvent *e) {
 }
 
 void
+findemacs (const Arg *arg) {
+  /* Tries to find an emacs instance. If it finds one,
+   it displays it. */
+  Arg a;
+  Monitor *m;
+  Client *c;
+  for (m=mons; m; m = m->next)
+      for (c=m->clients; c; c=c->next)
+       if (strspn("emacs",c->name)) {
+         a.ui = c->tags;
+         view(&a);
+         unfocus(selmon->sel, True); /* this should focus the right monitor (not tested)*/
+         selmon = m;
+         focus(c);
+         restack(selmon);
+         return;
+       }
+}
+
+void
 focus(Client *c) {
        if(!c || !ISVISIBLE(c))
                for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
@@ -1116,6 +1141,24 @@ killclient(const Arg *arg) {
 }
 
 void
+list_clients(const Arg *arg) {
+  /* wrapper function */
+  listclients();
+}
+void
+listclients (void) {
+  /* List the names of all clients */
+  Monitor *m;
+  FILE *clist;
+  Client *c;
+  clist = fopen("/tmp/clients", "w");
+  for (m=mons; m; m = m->next)
+    for (c=m->clients; c; c = c->next)
+      fprintf(clist, "%s %o\n", c->name, c->tags);
+  fclose(clist);
+}
+
+void
 manage(Window w, XWindowAttributes *wa) {
        Client *c, *t = NULL;
        Window trans = None;