[wiki] [sites] [patch][dwm] tag previews for 6.3 -- fix || explosion-mental

From: <git_AT_suckless.org>
Date: Thu, 01 Sep 2022 23:29:24 +0200

commit 83c8d8768c04734545467e3d3440f7a3425e80c5
Author: explosion-mental <explosion0mental_AT_gmail.com>
Date: Thu Sep 1 16:27:37 2022 -0500

    [patch][dwm] tag previews for 6.3 -- fix
    
    In the last patch I forgot to free() the tagmap. Taking this opportunity
    to fix that and also add the user function previewtag().

diff --git a/dwm.suckless.org/patches/tag-previews/dwm-tag-preview-6.3.diff b/dwm.suckless.org/patches/tag-previews/dwm-tag-preview-6.3.diff
index 92f4ad0a..dbee35d4 100644
--- a/dwm.suckless.org/patches/tag-previews/dwm-tag-preview-6.3.diff
+++ b/dwm.suckless.org/patches/tag-previews/dwm-tag-preview-6.3.diff
_AT_@ -1,29 +1,45 @@
-From 0e8deaa65e5193815a883bd1b9f9f74b97d68186 Mon Sep 17 00:00:00 2001
+From 841ad7d5767f945ee9da6c5afc8cff98ca2f8231 Mon Sep 17 00:00:00 2001
 From: explosion-mental <explosion0mental_AT_gmail.com>
-Date: Thu, 1 Sep 2022 11:27:44 -0500
-Subject: [PATCH] [PATCH] tag previews: easier to patch patch
+Date: Thu, 1 Sep 2022 16:21:58 -0500
+Subject: [PATCH] [PATCH] tag previews: free() tagmap and add previewtag func
 
 Allows you to see the contents of an already viewed tag. So a more
 accurate description would be to re-view a tag.
+
+Allows you to see the contents of an already viewed tag. So a more
+accurate description would be to re-view a tag.
+
 Compatibility with the alpha patch (replacing DefaultDepth() and
 DefaultVisual() with depth and visual + window masks) and hide vacants can be
 achieved, I left some lines to uncomment.
 
 added:
-- more compact structure, more probable to patch on top of other patches
+* more compact structure, more probable to patch on top of other patches
   or easier to patch manually (like not moving the Monitor struct..)
-- create the window preview in updatebars()
-- renamed switchtag() -> takepreview(), makes more sense since it's
+* create the window preview in updatebars()
+* renamed switchtag() -> takepreview(), makes more sense since it's
   "taking" the preview (basically a screenshot).
-- option previewbar, whether to show the bar in the preview or not.
+* option previewbar, whether to show the bar in the preview or not.
+* previewtag which takes a tag (unsigned int from 0 to the last tag) and
+ previews it. This allows to preview tags without using the
+ cursor/mouse (which avoids a recursive previews preview).
+ adding it to the TAGKEYS macro makes more sense so I've added it
+ replacing (keybinding wise, not functionality) toggletag.
+```
+\#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, previewtag, {.ui = TAG } },
+```
 ---
- config.def.h | 2 +
+ config.def.h | 4 +-
  config.mk | 5 +-
- dwm.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++-
- 3 files changed, 132 insertions(+), 2 deletions(-)
+ dwm.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++-
+ 3 files changed, 145 insertions(+), 3 deletions(-)
 
 diff --git a/config.def.h b/config.def.h
-index a2ac963..abd6521 100644
+index a2ac963..eb70348 100644
 --- a/config.def.h
 +++ b/config.def.h
 _AT_@ -3,6 +3,8 @@
_AT_@ -35,6 +51,15 @@ index a2ac963..abd6521 100644
  static const int showbar = 1; /* 0 means no bar */
  static const int topbar = 1; /* 0 means bottom bar */
  static const char *fonts[] = { "monospace:size=10" };
+_AT_@ -50,7 +52,7 @@ static const Layout layouts[] = {
+ { 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} },
++ { MODKEY|ControlMask|ShiftMask, KEY, previewtag, {.ui = TAG } }, \
+
+ /* helper for spawning shell commands in the pre dwm-5.0 fashion */
+ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
 diff --git a/config.mk b/config.mk
 index b6eb7e0..6f5129e 100644
 --- a/config.mk
_AT_@ -54,7 +79,7 @@ index b6eb7e0..6f5129e 100644
  # flags
  CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
 diff --git a/dwm.c b/dwm.c
-index a96f33c..3d8aac7 100644
+index a96f33c..0c0ba12 100644
 --- a/dwm.c
 +++ b/dwm.c
 _AT_@ -40,6 +40,7 @@
_AT_@ -75,17 +100,18 @@ index a96f33c..3d8aac7 100644
          char ltsymbol[16];
          float mfact;
          int nmaster;
-_AT_@ -235,6 +239,9 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
+_AT_@ -235,6 +239,10 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
  static int xerrorstart(Display *dpy, XErrorEvent *ee);
  static void zoom(const Arg *arg);
  
 +static void showtagpreview(unsigned int i);
 +static void takepreview(void);
++static void previewtag(const Arg *arg);
 +
  /* variables */
  static const char broken[] = "broken";
  static char stext[256];
-_AT_@ -438,6 +445,11 @@ buttonpress(XEvent *e)
+_AT_@ -438,6 +446,11 @@ buttonpress(XEvent *e)
                  if (i < LENGTH(tags)) {
                          click = ClkTagBar;
                          arg.ui = 1 << i;
_AT_@ -97,7 +123,7 @@ index a96f33c..3d8aac7 100644
                  } else if (ev->x < x + blw)
                          click = ClkLtSymbol;
                  else if (ev->x > selmon->ww - (int)TEXTW(stext))
-_AT_@ -498,6 +510,7 @@ void
+_AT_@ -498,6 +511,7 @@ void
  cleanupmon(Monitor *mon)
  {
          Monitor *m;
_AT_@ -105,13 +131,14 @@ index a96f33c..3d8aac7 100644
  
          if (mon == mons)
                  mons = mons->next;
-_AT_@ -505,8 +518,13 @@ cleanupmon(Monitor *mon)
+_AT_@ -505,8 +519,14 @@ cleanupmon(Monitor *mon)
                  for (m = mons; m && m->next != mon; m = m->next);
                  m->next = mon->next;
          }
 + for (i = 0; i < LENGTH(tags); i++)
 + if (mon->tagmap[i])
 + XFreePixmap(dpy, mon->tagmap[i]);
++ free(mon->tagmap);
          XUnmapWindow(dpy, mon->barwin);
          XDestroyWindow(dpy, mon->barwin);
 + XUnmapWindow(dpy, mon->tagwin);
_AT_@ -119,7 +146,7 @@ index a96f33c..3d8aac7 100644
          free(mon);
  }
  
-_AT_@ -641,6 +659,7 @@ createmon(void)
+_AT_@ -641,6 +661,7 @@ createmon(void)
          m->topbar = topbar;
          m->lt[0] = &layouts[0];
          m->lt[1] = &layouts[1 % LENGTH(layouts)];
_AT_@ -127,7 +154,7 @@ index a96f33c..3d8aac7 100644
          strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
          return m;
  }
-_AT_@ -1125,6 +1144,36 @@ motionnotify(XEvent *e)
+_AT_@ -1125,6 +1146,36 @@ motionnotify(XEvent *e)
          static Monitor *mon = NULL;
          Monitor *m;
          XMotionEvent *ev = &e->xmotion;
_AT_@ -164,7 +191,7 @@ index a96f33c..3d8aac7 100644
  
          if (ev->window != root)
                  return;
-_AT_@ -1530,6 +1579,72 @@ setmfact(const Arg *arg)
+_AT_@ -1530,6 +1581,82 @@ setmfact(const Arg *arg)
          arrange(selmon);
  }
  
_AT_@ -233,11 +260,21 @@ index a96f33c..3d8aac7 100644
 + imlib_free_image();
 + }
 +}
++
++void
++previewtag(const Arg *arg)
++{
++ if (selmon->previewshow != (arg->ui + 1))
++ selmon->previewshow = arg->ui + 1;
++ else
++ selmon->previewshow = 0;
++ showtagpreview(arg->ui);
++}
 +
  void
  setup(void)
  {
-_AT_@ -1746,6 +1861,7 @@ toggleview(const Arg *arg)
+_AT_@ -1746,6 +1873,7 @@ toggleview(const Arg *arg)
          unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
  
          if (newtagset) {
_AT_@ -245,7 +282,7 @@ index a96f33c..3d8aac7 100644
                  selmon->tagset[selmon->seltags] = newtagset;
                  focus(NULL);
                  arrange(selmon);
-_AT_@ -1811,10 +1927,18 @@ updatebars(void)
+_AT_@ -1811,10 +1939,18 @@ updatebars(void)
          XSetWindowAttributes wa = {
                  .override_redirect = True,
                  .background_pixmap = ParentRelative,
_AT_@ -265,7 +302,7 @@ index a96f33c..3d8aac7 100644
                  if (m->barwin)
                          continue;
                  m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
-_AT_@ -2043,6 +2167,7 @@ view(const Arg *arg)
+_AT_@ -2043,6 +2179,7 @@ view(const Arg *arg)
  {
          if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
                  return;
Received on Thu Sep 01 2022 - 23:29:24 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 01 2022 - 23:36:49 CEST