[wiki] [sites] a patch for dwm that provides mark&swap feature. || phi
commit 1a6842dd9b18a36c66f377feec355b64124067b8
Author: phi <crispyfrog_AT_163.com>
Date: Sat Feb 20 18:11:06 2016 +0800
a patch for dwm that provides mark&swap feature.
diff --git a/dwm.suckless.org/patches/dwm-6.1-mark.diff b/dwm.suckless.org/patches/dwm-6.1-mark.diff
new file mode 100644
index 0000000..ebb0e27
--- /dev/null
+++ b/dwm.suckless.org/patches/dwm-6.1-mark.diff
_AT_@ -0,0 +1,231 @@
+diff -Naur dwm-6.1/config.def.h dwm-6.1-patched/config.def.h
+--- dwm-6.1/config.def.h 2015-11-09 06:39:37.000000000 +0800
++++ dwm-6.1-patched/config.def.h 2016-02-17 16:46:11.137603047 +0800
+_AT_@ -11,6 +11,8 @@
+ static const char selbordercolor[] = "#005577";
+ static const char selbgcolor[] = "#005577";
+ static const char selfgcolor[] = "#eeeeee";
++static const char normmarkcolor[] = "#775500";
++static const char selmarkcolor[] = "#775577";
+ static const unsigned int borderpx = 1; /* border pixel of windows */
+ static const unsigned int snap = 32; /* snap pixel */
+ static const int showbar = 1; /* 0 means no bar */
+_AT_@ -68,7 +70,6 @@
+ { 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[0]} },
+_AT_@ -82,6 +83,9 @@
+ { MODKEY, XK_period, focusmon, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
+ { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
++ { MODKEY, XK_Return, swapclient, {0} },
++ { MODKEY, XK_o, swapfocus, {0} },
++ { MODKEY, XK_semicolon, togglemark, {0} },
+ TAGKEYS( XK_1, 0)
+ TAGKEYS( XK_2, 1)
+ TAGKEYS( XK_3, 2)
+diff -Naur dwm-6.1/drw.h dwm-6.1-patched/drw.h
+--- dwm-6.1/drw.h 2015-11-09 06:39:37.000000000 +0800
++++ dwm-6.1-patched/drw.h 2016-02-17 16:18:47.424219808 +0800
+_AT_@ -23,6 +23,7 @@
+ Clr *fg;
+ Clr *bg;
+ Clr *border;
++ Clr *mark;
+ } ClrScheme;
+
+ typedef struct {
+diff -Naur dwm-6.1/dwm.c dwm-6.1-patched/dwm.c
+--- dwm-6.1/dwm.c 2015-11-09 06:39:37.000000000 +0800
++++ dwm-6.1-patched/dwm.c 2016-02-17 16:41:55.737595294 +0800
+_AT_@ -201,16 +201,20 @@
+ static void setfocus(Client *c);
+ static void setfullscreen(Client *c, int fullscreen);
+ static void setlayout(const Arg *arg);
++static void stemark(const Arg *arg);
+ static void setmfact(const Arg *arg);
+ static void setup(void);
+ static void showhide(Client *c);
+ static void sigchld(int unused);
+ static void spawn(const Arg *arg);
++static void swapclient(const Arg *arg);
++static void swapfocus(const Arg *arg);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static void tile(Monitor *);
+ static void togglebar(const Arg *arg);
+ static void togglefloating(const Arg *arg);
++static void togglemark(const Arg *arg);
+ static void toggletag(const Arg *arg);
+ static void toggleview(const Arg *arg);
+ static void unfocus(Client *c, int setfocus);
+_AT_@ -266,6 +270,7 @@
+ static Drw *drw;
+ static Monitor *mons, *selmon;
+ static Window root;
++static Client *mark;
+
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+_AT_@ -482,6 +487,7 @@
+ for (i = 0; i < CurLast; i++)
+ drw_cur_free(drw, cursor[i]);
+ for (i = 0; i < SchemeLast; i++) {
++ drw_clr_free(scheme[i].mark);
+ drw_clr_free(scheme[i].border);
+ drw_clr_free(scheme[i].bg);
+ drw_clr_free(scheme[i].fg);
+_AT_@ -807,7 +813,12 @@
+ detachstack(c);
+ attachstack(c);
+ grabbuttons(c, 1);
+- XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix);
++ if (c == mark)
++ XSetWindowBorder(dpy, c->win,
++ scheme[SchemeSel].mark->pix);
++ else
++ XSetWindowBorder(dpy, c->win,
++ scheme[SchemeSel].border->pix);
+ setfocus(c);
+ } else {
+ XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+_AT_@ -1018,6 +1029,8 @@
+ {
+ if (!selmon->sel)
+ return;
++ if (mark == selmon->sel)
++ setmark(0);
+ if (!sendevent(selmon->sel, wmatom[WMDelete])) {
+ XGrabServer(dpy);
+ XSetErrorHandler(xerrordummy);
+_AT_@ -1065,7 +1078,10 @@
+
+ wc.border_width = c->bw;
+ XConfigureWindow(dpy, w, CWBorderWidth, &wc);
+- XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix);
++ if (c == mark)
++ XSetWindowBorder(dpy, w, scheme[SchemeNorm].mark->pix);
++ else
++ XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix);
+ configure(c); /* propagates border_width, if size doesn't change */
+ updatewindowtype(c);
+ updatesizehints(c);
+_AT_@ -1528,6 +1544,23 @@
+ drawbar(selmon);
+ }
+
++void
++setmark(Client *c)
++{
++ if (c == mark)
++ return;
++ if (mark) {
++ XSetWindowBorder(dpy, mark->win, scheme[mark == selmon->sel
++ ? SchemeSel : SchemeNorm].border->pix);
++ mark = 0;
++ }
++ if (c) {
++ XSetWindowBorder(dpy, c->win, scheme[c == selmon->sel
++ ? SchemeSel : SchemeNorm].mark->pix);
++ mark = c;
++ }
++}
++
+ /* arg > 1.0 will set mfact absolutly */
+ void
+ setmfact(const Arg *arg)
+_AT_@ -1580,9 +1613,11 @@
+ cursor[CurResize] = drw_cur_create(drw, XC_sizing);
+ cursor[CurMove] = drw_cur_create(drw, XC_fleur);
+ /* init appearance */
++ scheme[SchemeNorm].mark = drw_clr_create(drw, normmarkcolor);
+ scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor);
+ scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
+ scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
++ scheme[SchemeSel].mark = drw_clr_create(drw, selmarkcolor);
+ scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor);
+ scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
+ scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
+_AT_@ -1646,6 +1681,50 @@
+ }
+
+ void
++swapclient(const Arg *arg)
++{
++ Client *s, *m, t;
++
++ if (!mark) {
++ zoom(0);
++ return;
++ }
++ s = selmon->sel;
++ m = mark;
++ if (!s || m == s || !selmon->lt[selmon->sellt]->arrange)
++ return;
++ t = *s;
++ strcpy(s->name, m->name);
++ strcpy(m->name, t.name);
++ s->win = m->win;
++ m->win = t.win;
++ XMoveResizeWindow(dpy, s->win, s->x + 2 * sw, s->y, s->w, s->h);
++ arrange(s->mon);
++ XMapWindow(dpy, s->win);
++ XMoveResizeWindow(dpy, m->win, m->x + 2 * sw, m->y, m->w, m->h);
++ arrange(m->mon);
++ XMapWindow(dpy, m->win);
++
++ selmon->sel = m;
++ mark = s;
++ focus(s);
++ setmark(m);
++}
++
++void
++swapfocus(const Arg *arg)
++{
++ Client *t;
++
++ if (!selmon->sel || !mark || selmon->sel == mark) {
++ return;
++ }
++ t = mark;
++ setmark(selmon->sel);
++ focus(t);
++}
++
++void
+ tag(const Arg *arg)
+ {
+ if (selmon->sel && arg->ui & TAGMASK) {
+_AT_@ -1713,6 +1792,15 @@
+ }
+
+ void
++togglemark(const Arg *arg)
++{
++ if (!selmon->sel) {
++ return;
++ }
++ setmark(selmon->sel == mark ? 0 : selmon->sel);
++}
++
++void
+ toggletag(const Arg *arg)
+ {
+ unsigned int newtags;
+_AT_@ -1745,7 +1833,10 @@
+ if (!c)
+ return;
+ grabbuttons(c, 0);
+- XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix);
++ if (c == mark)
++ XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].mark->pix);
++ else
++ XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix);
+ if (setfocus) {
+ XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+ XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
diff --git a/dwm.suckless.org/patches/mark.md b/dwm.suckless.org/patches/mark.md
new file mode 100644
index 0000000..9be008f
--- /dev/null
+++ b/dwm.suckless.org/patches/mark.md
_AT_@ -0,0 +1,38 @@
+
+Mark
+====
+
+Description
+-----------
+
+This patch provides an mechanism to easily jump between any clients, or to swap any clients through shortcuts by introcuding mark. The mark is global, and only one mark is allowed at the same time. The marked client is distinguished from other clients by having a different border color.
+This patch adds 3 functions and 2 variables:
+* functions:
+ togglemark - mark/unmark current focused client.
+ swapclient - swap focused client with marked client, falls back to
+ zoom() if the mark is not being set.
+ swapfocus - swap focus with mark.
+* variables:
+ normmarkcolor - border color for marked client.
+ selmarkcolor - border color for current focused client that is
+ also being marked.
+And example of key mappings for this patch:
+ { MODKEY, XK_semicolon,togglemark, {0} },
+ { MODKEY, XK_o, swapfocus, {0} },
+ { MODKEY, XK_Return, swapclient, {0} },
+/*togglemark twice to remove the mark, emulates the behaviour of zoom()*/
+ { MODKEY, XK_Return, togglemark, {0} },
+ { MODKEY, XK_Return, togglemark, {0} },
+ { MODKEY, XK_u, swapclient, {0} },
+/*swapclient and swapfocus at the same time, it's useful in some cases*/
+ { MODKEY, XK_i, swapclient, {0} },
+ { MODKEY, XK_i, swapfocus, {0} },
+
+Download
+--------
+
+* [dwm-6.1-mark.diff](dwm-6.1-mark.diff) (7161b) (20160220)
+
+Author
+------
+* phi <crispyforg_AT_163.com>
Received on Sat Feb 20 2016 - 11:20:52 CET
This archive was generated by hypermail 2.3.0
: Sat Feb 20 2016 - 11:24:12 CET