dwm-dualstatus-20251003-89e0350.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-dualstatus-20251003-89e0350.diff (5172B)
       ---
            1 From 89e03501c62b7533d7c4399e2b65feaaf8ccf1b0 Mon Sep 17 00:00:00 2001
            2 From: elbachir-one <bachiralfa@gmail.com>
            3 Date: Fri, 3 Oct 2025 10:39:34 +0100
            4 Subject: [PATCH] Fixed patch — no more errors when applying it
            5 
            6 ---
            7  config.def.h |  2 ++
            8  dwm.c        | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-
            9  2 files changed, 55 insertions(+), 1 deletion(-)
           10 
           11 diff --git a/config.def.h b/config.def.h
           12 index 3836510..d1bf68c 100644
           13 --- a/config.def.h
           14 +++ b/config.def.h
           15 @@ -5,6 +5,7 @@ static const unsigned int borderpx  = 1;        /* border pixel of windows */
           16  static const unsigned int snap      = 32;       /* snap pixel */
           17  static const int showbar            = 1;        /* 0 means no bar */
           18  static const int topbar             = 1;        /* 0 means bottom bar */
           19 +static const int extrabar           = 1;        /* 0 means no extra bar */
           20  static const char *fonts[]          = { "monospace:size=10" };
           21  static const char dmenufont[]       = "monospace:size=10";
           22  static const char col_gray1[]       = "#222222";
           23 @@ -66,6 +67,7 @@ static const Key keys[] = {
           24          { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
           25          { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
           26          { MODKEY,                       XK_b,      togglebar,      {0} },
           27 +        { MODKEY,                       XK_b,      toggleextrabar, {0} },
           28          { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
           29          { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
           30          { MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
           31 diff --git a/dwm.c b/dwm.c
           32 index 4f345ee..52149ad 100644
           33 --- a/dwm.c
           34 +++ b/dwm.c
           35 @@ -140,6 +140,13 @@ typedef struct {
           36          int monitor;
           37  } Rule;
           38  
           39 +typedef struct {
           40 +        int y;
           41 +        int show;
           42 +        Window win;
           43 +        char text[256];
           44 +} Bar;
           45 +
           46  /* function declarations */
           47  static void applyrules(Client *c);
           48  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
           49 @@ -209,6 +216,7 @@ static void tag(const Arg *arg);
           50  static void tagmon(const Arg *arg);
           51  static void tile(Monitor *m);
           52  static void togglebar(const Arg *arg);
           53 +static void toggleextrabar(const Arg *arg);
           54  static void togglefloating(const Arg *arg);
           55  static void toggletag(const Arg *arg);
           56  static void toggleview(const Arg *arg);
           57 @@ -266,6 +274,7 @@ static Display *dpy;
           58  static Drw *drw;
           59  static Monitor *mons, *selmon;
           60  static Window root, wmcheckwin;
           61 +static Bar eb;
           62  
           63  /* configuration, allows nested code to access above variables */
           64  #include "config.h"
           65 @@ -481,6 +490,8 @@ cleanup(void)
           66                  while (m->stack)
           67                          unmanage(m->stack, 0);
           68          XUngrabKey(dpy, AnyKey, AnyModifier, root);
           69 +        XUnmapWindow(dpy, eb.win);
           70 +        XDestroyWindow(dpy, eb.win);
           71          while (mons)
           72                  cleanupmon(mons);
           73          for (i = 0; i < CurLast; i++)
           74 @@ -570,6 +581,7 @@ configurenotify(XEvent *e)
           75                                          if (c->isfullscreen)
           76                                                  resizeclient(c, m->mx, m->my, m->mw, m->mh);
           77                                  XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
           78 +                                XMoveResizeWindow(dpy, eb.win, mons->wx, eb.y, mons->ww, bh);
           79                          }
           80                          focus(NULL);
           81                          arrange(NULL);
           82 @@ -745,6 +757,9 @@ drawbar(Monitor *m)
           83                  }
           84          }
           85          drw_map(drw, m->barwin, 0, 0, m->ww, bh);
           86 +        drw_setscheme(drw, scheme[SchemeNorm]);
           87 +        drw_text(drw, 0, 0, mons->ww, bh, 0, eb.text, 0);
           88 +        drw_map(drw, eb.win, 0, 0, mons->ww, bh);
           89  }
           90  
           91  void
           92 @@ -1558,6 +1573,7 @@ setup(void)
           93          sh = DisplayHeight(dpy, screen);
           94          root = RootWindow(dpy, screen);
           95          drw = drw_create(dpy, screen, root, sw, sh);
           96 +        eb.show = extrabar;
           97          if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
           98                  die("no fonts could be loaded.");
           99          lrpad = drw->fonts->h;
          100 @@ -1720,6 +1736,17 @@ togglebar(const Arg *arg)
          101          arrange(selmon);
          102  }
          103  
          104 +void
          105 +toggleextrabar(const Arg *arg)
          106 +{
          107 +        if(selmon == mons) {
          108 +                eb.show = !eb.show;
          109 +                updatebarpos(selmon);
          110 +                XMoveResizeWindow(dpy, eb.win, selmon->wx, eb.y, selmon->ww, bh);
          111 +                arrange(selmon);
          112 +        }
          113 +}
          114 +
          115  void
          116  togglefloating(const Arg *arg)
          117  {
          118 @@ -1834,6 +1861,13 @@ updatebars(void)
          119                  XMapRaised(dpy, m->barwin);
          120                  XSetClassHint(dpy, m->barwin, &ch);
          121          }
          122 +        if (!eb.win) {
          123 +                eb.win = XCreateWindow(dpy, root, mons->wx, eb.y, mons->ww, bh, 0, DefaultDepth(dpy, screen),
          124 +                           CopyFromParent, DefaultVisual(dpy, screen),
          125 +                           CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
          126 +                XDefineCursor(dpy, eb.win, cursor[CurNormal]->cursor);
          127 +                XMapRaised(dpy, eb.win);
          128 +        }
          129  }
          130  
          131  void
          132 @@ -1847,6 +1881,13 @@ updatebarpos(Monitor *m)
          133                  m->wy = m->topbar ? m->wy + bh : m->wy;
          134          } else
          135                  m->by = -bh;
          136 +
          137 +        if (m == mons && eb.show) {
          138 +                m->wh -= bh;
          139 +                eb.y = topbar ? m->wy + m->wh : m->wy;
          140 +                m->wy = m->topbar ? m->wy : m->wy + bh;
          141 +        } else
          142 +                eb.y = -bh;
          143  }
          144  
          145  void
          146 @@ -2004,8 +2045,19 @@ updatesizehints(Client *c)
          147  void
          148  updatestatus(void)
          149  {
          150 -        if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
          151 +        char text[512];
          152 +        if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { 
          153                  strcpy(stext, "dwm-"VERSION);
          154 +                eb.text[0] = '\0';
          155 +        } else {
          156 +                char *e = strchr(text, ';');
          157 +                if (e) {
          158 +                        *e = '\0'; e++;
          159 +                        strncpy(eb.text, e, sizeof(eb.text)-1);
          160 +                } else
          161 +                        eb.text[0] = '\0';
          162 +                strncpy(stext, text, sizeof(stext)-1);
          163 +        }
          164          drawbar(selmon);
          165  }
          166  
          167 -- 
          168 2.50.1
          169