summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorProsperousPotato <ProsperousPotato@users.noreply.github.com>2025-03-15 13:54:09 +0000
committerProsperousPotato <ProsperousPotato@users.noreply.github.com>2025-03-31 18:31:28 +0100
commita642d6858229b86358313e38171bbada1f65ef6c (patch)
tree76bd208819ef00cbba482332c21e85dc885c9caf /dwm.c
parent899ea777a2356c753299299f0987a8ceae46042f (diff)
rewrite from original source
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c585
1 files changed, 155 insertions, 430 deletions
diff --git a/dwm.c b/dwm.c
index bcb716f..bd3a526 100644
--- a/dwm.c
+++ b/dwm.c
@@ -22,7 +22,6 @@
*/
#include <errno.h>
#include <locale.h>
-#include <stdbool.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
@@ -37,11 +36,12 @@
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
+#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
+#endif /* XINERAMA */
#include <X11/Xft/Xft.h>
#include <X11/Xlib-xcb.h>
#include <xcb/res.h>
-#include <xcb/xcb.h>
#ifdef __OpenBSD__
#include <sys/sysctl.h>
#include <kvm.h>
@@ -56,8 +56,6 @@
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
-#define HIDDEN(C) ((getstate(C->win) == IconicState))
-#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
@@ -66,7 +64,7 @@
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
-enum { SchemeNorm, SchemeSel, SchemeHid, SchemeStatus, SchemeTagsSel, SchemeTagsNorm, SchemeInfoSel, SchemeInfoNorm }; /* color schemes */
+enum { SchemeNorm, SchemeSel, SchemeStatus, SchemeTagsSel, SchemeTagsNorm, SchemeInfoSel, SchemeInfoNorm }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
@@ -100,10 +98,10 @@ struct Client {
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow;
- pid_t pid;
+ pid_t pid;
Client *next;
Client *snext;
- Client *swallowing;
+ Client *swallowing;
Monitor *mon;
Window win;
};
@@ -126,8 +124,6 @@ struct Monitor {
int nmaster;
int num;
int by; /* bar geometry */
- int btw; /* width of tasks portion of bar */
- int bt; /* number of tasks */
int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */
unsigned int seltags;
@@ -135,7 +131,6 @@ struct Monitor {
unsigned int tagset[2];
int showbar;
int topbar;
- int hidsel;
Client *clients;
Client *sel;
Client *stack;
@@ -150,8 +145,8 @@ typedef struct {
const char *title;
unsigned int tags;
int isfloating;
- int isterminal;
- int noswallow;
+ int isterminal;
+ int noswallow;
int monitor;
} Rule;
@@ -182,17 +177,13 @@ static void expose(XEvent *e);
static void focus(Client *c);
static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
-static void focusstackvis(const Arg *arg);
-static void movestack(const Arg *arg);
-static void focusstack(int inc, int vis);
+static void focusstack(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y);
static long getstate(Window w);
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, int focused);
static void grabkeys(void);
-static void hide(const Arg *arg);
-static void hidewin(Client *c);
static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void killclient(const Arg *arg);
@@ -201,7 +192,6 @@ static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
-static void moveresize(const Arg *arg);
static void movemouse(const Arg *arg);
static unsigned int nexttag(void);
static unsigned int prevtag(void);
@@ -229,8 +219,6 @@ static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
-static void showall(const Arg *arg);
-static void showwin(Client *c);
static void showhide(Client *c);
static void sighup(int unused);
static void sigterm(int unused);
@@ -240,7 +228,6 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
-static void togglefullscr(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
@@ -273,7 +260,6 @@ static pid_t winpid(Window w);
/* variables */
static const char broken[] = "broken";
static char stext[256];
-static bool showtags;
static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh; /* bar height */
@@ -299,6 +285,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
static Atom wmatom[WMLast], netatom[NetLast];
static int restart = 0;
static int running = 1;
+static int showtags = 0;
static Cur *cursor[CurLast];
static Clr **scheme;
static Display *dpy;
@@ -337,8 +324,8 @@ applyrules(Client *c)
&& (!r->class || strstr(class, r->class))
&& (!r->instance || strstr(instance, r->instance)))
{
- c->isterminal = r->isterminal;
- c->noswallow = r->noswallow;
+ c->isterminal = r->isterminal;
+ c->noswallow = r->noswallow;
c->isfloating = r->isfloating;
c->tags |= r->tags;
for (m = mons; m && m->num != r->monitor; m = m->next);
@@ -530,25 +517,10 @@ buttonpress(XEvent *e)
arg.ui = 1 << i;
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
click = ClkLtSymbol;
- /* 2px right padding */
- else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
+ else if (ev->x > selmon->ww - (int)TEXTW(stext))
click = ClkStatusText;
- else {
- x += TEXTW(selmon->ltsymbol);
- c = m->clients;
-
- if (c) {
- do {
- if (!ISVISIBLE(c))
- continue;
- else
- x +=(1.0 / (double)m->bt) * m->btw;
- } while (ev->x > x && (c = c->next));
-
- click = ClkWinTitle;
- arg.v = c;
- }
- }
+ else
+ click = ClkWinTitle;
} else if ((c = wintoclient(ev->window))) {
focus(c);
restack(selmon);
@@ -558,7 +530,7 @@ buttonpress(XEvent *e)
for (i = 0; i < LENGTH(buttons); i++)
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
- buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
+ buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
}
void
@@ -759,8 +731,9 @@ destroynotify(XEvent *e)
if ((c = wintoclient(ev->window)))
unmanage(c, 1);
- else if ((c = swallowingclient(ev->window)))
- unmanage(c->swallowing, 1);
+
+ else if ((c = swallowingclient(ev->window)))
+ unmanage(c->swallowing, 1);
}
void
@@ -804,86 +777,78 @@ dirtomon(int dir)
void
drawbar(Monitor *m)
{
- int x, w, tw = 0, n = 0, scm;
- unsigned int i, occ = 0, urg = 0;
+ int x, w, tw = 0, mw, ew = 0;
+ int boxs = drw->fonts->h / 9;
+ int boxw = drw->fonts->h / 6 + 2;
+ unsigned int i, occ = 0, urg = 0, n = 0;
Client *c;
if (!m->showbar)
return;
- drw_setscheme(drw, scheme[SchemeStatus]);
- tw = TEXTW(stext) - lrpad + 2;
- drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
- drw_map(drw, m->barwin, 0, 0, m->ww, bh);
+ /* draw status first so it can be overdrawn by tags later */
+ if (m == selmon) { /* status is only drawn on selected monitor */
+ drw_setscheme(drw, scheme[SchemeStatus]);
+ tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+ drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
+ }
for (c = m->clients; c; c = c->next) {
if (ISVISIBLE(c))
n++;
- occ |= c->tags;
+ occ |= c->tags == TAGMASK ? 0 : c->tags;
if (c->isurgent)
urg |= c->tags;
}
- int tag_width = 0;
- for (i = 0; i < LENGTH(tags); i++) {
- if (m->tagset[m->seltags] & 1 << i || occ & 1 <<i) {
- tag_width += TEXTW(tags[i]);
- }
- }
- int center_x = (m->ww - tag_width) / 2;
-
- x = center_x;
- for (i = 0; i < LENGTH(tags); i++) {
- w = TEXTW(tags[i]);
- if (!(m->tagset[m->seltags] & 1 << i || occ & 1 <<i)) continue;
- if (showtags || n == 0) {
+ x = 0;
+ if (showtags == 1) {
+ for (i = 0; i < LENGTH(tags); i++) {
+ if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
+ continue;
+ w = TEXTW(tags[i]);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeTagsSel : SchemeTagsNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
- drw_map(drw, m->barwin, 0, 0, m->ww, bh);
- } else {
- drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeTagsSel : SchemeTagsNorm]);
- drw_text(drw, x, 0, w, bh, lrpad / 2, "", urg & 1 << i);
+ x += w;
}
- x += w;
}
- x = 0;
if ((w = m->ww - tw - x) > bh) {
if (n > 0) {
- int remainder = w % n;
- int tabw = (1.0 / (double)n) * w + 1;
+ tw = TEXTW(m->sel->name) + lrpad;
+ mw = (tw >= w || n == 1) ? 0 : (w - tw) / (n - 1);
+
+ i = 0;
for (c = m->clients; c; c = c->next) {
- if (!ISVISIBLE(c))
+ if (!ISVISIBLE(c) || c == m->sel)
continue;
- if (m->sel == c)
- scm = SchemeInfoSel;
- else if (HIDDEN(c))
- scm = SchemeHid;
+ tw = TEXTW(c->name);
+ if(tw < mw)
+ ew += (mw - tw);
else
- scm = SchemeInfoNorm;
- drw_setscheme(drw, scheme[scm]);
-
- if (remainder >= 0) {
- if (remainder == 0) {
- tabw--;
- }
- remainder--;
- }
- if (!showtags) {
- drw_text(drw, x, 0, tabw, bh, (TEXTW(c->name) < tabw ? (tabw - c->incw - TEXTW(c->name) + lrpad) / 2 : lrpad / 2), c->name, 0);
- drw_map(drw, m->barwin, 0, 0, m->ww, bh);
- } else {
- drw_text(drw, x, 0, tabw, bh, (TEXTW(c->name) < tabw ? (tabw - c->incw - TEXTW(c->name) + lrpad) / 2 : lrpad / 2), "", 0);
- }
- x += tabw;
+ i++;
+ }
+ if (i > 0)
+ mw += ew / i;
+
+ for (c = m->clients; c; c = c->next) {
+ if (!ISVISIBLE(c))
+ continue;
+ tw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
+
+ drw_setscheme(drw, scheme[m == selmon && m->sel == c ? SchemeInfoSel : SchemeInfoNorm]);
+ if (tw > lrpad / 2)
+ drw_text(drw, x, 0, tw, bh, lrpad / 2, c->name, 0);
+ if (c->isfloating)
+ drw_rect(drw, x + boxs, boxs, boxw, boxw, c->isfixed, 0);
+ x += tw;
+ w -= tw;
}
- } else {
- drw_setscheme(drw, scheme[SchemeTagsNorm]);
- drw_rect(drw, x, 0, w, bh, 1, 1);
}
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_rect(drw, x, 0, w, bh, 1, 1);
}
- m->bt = n;
- m->btw = w;
+ drw_map(drw, m->barwin, 0, 0, m->ww, bh);
}
void
@@ -928,17 +893,9 @@ void
focus(Client *c)
{
if (!c || !ISVISIBLE(c))
- for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext);
- if (selmon->sel && selmon->sel != c) {
+ for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
+ if (selmon->sel && selmon->sel != c)
unfocus(selmon->sel, 0);
-
- if (selmon->hidsel) {
- hidewin(selmon->sel);
- if (c)
- arrange(c->mon);
- selmon->hidsel = 0;
- }
- }
if (c) {
if (c->mon != selmon)
selmon = c->mon;
@@ -954,7 +911,7 @@ focus(Client *c)
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
}
selmon->sel = c;
- drawbars();
+ drawbars();
}
/* there are some broken focus acquiring clients needing extra handling */
@@ -979,106 +936,33 @@ focusmon(const Arg *arg)
unfocus(selmon->sel, 0);
selmon = m;
focus(NULL);
- if (selmon->sel)
- XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2);
}
void
-focusstackvis(const Arg *arg)
-{
- focusstack(arg->i, 0);
-}
-
-void
-movestack(const Arg *arg)
-{
- Client *c = NULL, *p = NULL, *pc = NULL, *i;
-
- if(arg->i > 0) {
- /* find the client after selmon->sel */
- for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
- if(!c)
- for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
-
- }
- else {
- /* find the client before selmon->sel */
- for(i = selmon->clients; i != selmon->sel; i = i->next)
- if(ISVISIBLE(i) && !i->isfloating)
- c = i;
- if(!c)
- for(; i; i = i->next)
- if(ISVISIBLE(i) && !i->isfloating)
- c = i;
- }
- /* find the client before selmon->sel and c */
- for(i = selmon->clients; i && (!p || !pc); i = i->next) {
- if(i->next == selmon->sel)
- p = i;
- if(i->next == c)
- pc = i;
- }
-
- /* swap c and selmon->sel selmon->clients in the selmon->clients list */
- if(c && c != selmon->sel) {
- Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
- selmon->sel->next = c->next==selmon->sel?c:c->next;
- c->next = temp;
-
- if(p && p != c)
- p->next = c;
- if(pc && pc != selmon->sel)
- pc->next = selmon->sel;
-
- if(selmon->sel == selmon->clients)
- selmon->clients = c;
- else if(c == selmon->clients)
- selmon->clients = selmon->sel;
-
- arrange(selmon);
- }
- showtags = false;
-}
-
-void
-focusstack(int inc, int hid)
+focusstack(const Arg *arg)
{
Client *c = NULL, *i;
- showtags = false;
+ showtags = 0;
- if ((!selmon->sel && !hid) || (selmon->sel && selmon->sel->isfullscreen && lockfullscreen))
+ if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
return;
- if (!selmon->clients)
- return;
- if (inc > 0) {
- if (selmon->sel)
- for (c = selmon->sel->next;
- c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
- c = c->next);
+ if (arg->i > 0) {
+ for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
if (!c)
- for (c = selmon->clients;
- c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
- c = c->next);
+ for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
} else {
- if (selmon->sel) {
- for (i = selmon->clients; i != selmon->sel; i = i->next)
- if (ISVISIBLE(i) && !(!hid && HIDDEN(i)))
- c = i;
- } else
- c = selmon->clients;
+ for (i = selmon->clients; i != selmon->sel; i = i->next)
+ if (ISVISIBLE(i))
+ c = i;
if (!c)
for (; i; i = i->next)
- if (ISVISIBLE(i) && !(!hid && HIDDEN(i)))
+ if (ISVISIBLE(i))
c = i;
}
if (c) {
focus(c);
restack(selmon);
- if (HIDDEN(c)) {
- showwin(c);
- c->mon->hidsel = 1;
- }
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
}
}
@@ -1200,36 +1084,6 @@ grabkeys(void)
}
void
-hide(const Arg *arg)
-{
- hidewin(selmon->sel);
- focus(NULL);
- arrange(selmon);
-}
-
-void
-hidewin(Client *c) {
- if (!c || HIDDEN(c))
- return;
-
- Window w = c->win;
- static XWindowAttributes ra, ca;
-
- // more or less taken directly from blackbox's hide() function
- XGrabServer(dpy);
- XGetWindowAttributes(dpy, root, &ra);
- XGetWindowAttributes(dpy, w, &ca);
- // prevent UnmapNotify events
- XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
- XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
- XUnmapWindow(dpy, w);
- setclientstate(c, IconicState);
- XSelectInput(dpy, root, ra.your_event_mask);
- XSelectInput(dpy, w, ca.your_event_mask);
- XUngrabServer(dpy);
-}
-
-void
incnmaster(const Arg *arg)
{
selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
@@ -1289,7 +1143,7 @@ manage(Window w, XWindowAttributes *wa)
c = ecalloc(1, sizeof(Client));
c->win = w;
- c->pid = winpid(w);
+ c->pid = winpid(w);
/* geometry */
c->x = c->oldx = wa->x;
c->y = c->oldy = wa->y;
@@ -1304,7 +1158,7 @@ manage(Window w, XWindowAttributes *wa)
} else {
c->mon = selmon;
applyrules(c);
- term = termforwin(c);
+ term = termforwin(c);
}
if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
@@ -1335,17 +1189,14 @@ manage(Window w, XWindowAttributes *wa)
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1);
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
- if (!HIDDEN(c))
- setclientstate(c, NormalState);
+ setclientstate(c, NormalState);
if (c->mon == selmon)
unfocus(selmon->sel, 0);
c->mon->sel = c;
arrange(c->mon);
- if (!HIDDEN(c))
- XMapWindow(dpy, c->win);
- if (term) {
- swallow(term, c);
- }
+ XMapWindow(dpy, c->win);
+ if (term)
+ swallow(term, c);
focus(NULL);
}
@@ -1432,7 +1283,6 @@ movemouse(const Arg *arg)
handler[ev.type](&ev);
break;
case MotionNotify:
-
nx = ocx + (ev.xmotion.x - x);
ny = ocy + (ev.xmotion.y - y);
if (abs(selmon->wx - nx) < snap)
@@ -1459,74 +1309,10 @@ movemouse(const Arg *arg)
}
}
-void
-moveresize(const Arg *arg) {
- Client *c;
- c = selmon->sel;
- int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh;
- char xAbs, yAbs, wAbs, hAbs;
- int msx, msy, dx, dy, nmx, nmy;
- unsigned int dui;
- Window dummy;
-
- if (!c || !arg)
- return;
- if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
- return;
- if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8)
- return;
-
- nw = c->w + w;
- if (wAbs == 'W')
- nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw;
-
- nh = c->h + h;
- if (hAbs == 'H')
- nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * c->bw;
-
- nx = c->x + x;
- if (xAbs == 'X') {
- if (x < selmon->mx)
- nx = selmon->mx;
- else if (x > selmon->mx + selmon->mw)
- nx = selmon->mx + selmon->mw - nw - 2 * c->bw;
- else
- nx = x;
- }
-
- ny = c->y + y;
- if (yAbs == 'Y') {
- if (y < selmon->my)
- ny = selmon->my;
- else if (y > selmon->my + selmon->mh)
- ny = selmon->my + selmon->mh - nh - 2 * c->bw;
- else
- ny = y;
- }
-
- ox = c->x;
- oy = c->y;
- ow = c->w;
- oh = c->h;
-
- XRaiseWindow(dpy, c->win);
- Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui);
- resize(c, nx, ny, nw, nh, True);
-
- /* move cursor along with the window to avoid problems */
- if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy)
- {
- nmx = c->x - ox + c->w - ow;
- nmy = c->y - oy + c->h - oh;
- /* make sure the cursor stays inside the window */
- if ((msx + nmx) > c->x && (msy + nmy) > c->y)
- XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy);
- }
-}
-
unsigned int
nexttag(void)
{
+ showtags = 1;
unsigned int seltag = selmon->tagset[selmon->seltags];
return seltag == (1 << (LENGTH(tags) - 1)) ? 1 : seltag << 1;
}
@@ -1534,6 +1320,7 @@ nexttag(void)
unsigned int
prevtag(void)
{
+ showtags = 1;
unsigned int seltag = selmon->tagset[selmon->seltags];
return seltag == 1 ? (1 << (LENGTH(tags) - 1)) : seltag >> 1;
}
@@ -1545,8 +1332,7 @@ tagtonext(const Arg *arg)
if (selmon->sel == NULL)
return;
-
- showtags = true;
+
tmp = nexttag();
tag(&(const Arg){.ui = tmp});
view(&(const Arg){.ui = tmp});
@@ -1560,7 +1346,6 @@ tagtoprev(const Arg *arg)
if (selmon->sel == NULL)
return;
- showtags = true;
tmp = prevtag();
tag(&(const Arg){.ui = tmp});
view(&(const Arg){.ui = tmp});
@@ -1569,21 +1354,19 @@ tagtoprev(const Arg *arg)
void
viewnext(const Arg *arg)
{
- showtags = true;
view(&(const Arg){.ui = nexttag()});
}
void
viewprev(const Arg *arg)
{
- showtags = true;
view(&(const Arg){.ui = prevtag()});
}
Client *
nexttiled(Client *c)
{
- for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next);
+ for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
return c;
}
@@ -1636,16 +1419,7 @@ propertynotify(XEvent *e)
void
quit(const Arg *arg)
{
- Monitor *m;
- Client *c;
- for (m = mons; m; m = m->next) {
- if (m) {
- for (c = m->stack; c; c = c->next)
- if (c && HIDDEN(c)) showwin(c);
- }
- }
-
- if(arg->i) restart = 1;
+ if(arg->i) restart = 1;
running = 0;
}
@@ -1674,12 +1448,26 @@ void
resizeclient(Client *c, int x, int y, int w, int h)
{
XWindowChanges wc;
+ unsigned int n;
+ Client *nbc;
c->oldx = c->x; c->x = wc.x = x;
c->oldy = c->y; c->y = wc.y = y;
c->oldw = c->w; c->w = wc.width = w;
c->oldh = c->h; c->h = wc.height = h;
- wc.border_width = c->bw;
+ wc.border_width = c->bw;
+
+ for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);
+
+ if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
+ } else {
+ if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
+ wc.border_width = 0;
+ c->w = wc.width += c->bw * 2;
+ c->h = wc.height += c->bw * 2;
+ }
+ }
+
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);
@@ -1688,35 +1476,23 @@ resizeclient(Client *c, int x, int y, int w, int h)
void
resizemouse(const Arg *arg)
{
- int ocx, ocy, nw, nh;
- int ocx2, ocy2, nx, ny;
+ int x, y, ocw, och, nw, nh;
Client *c;
Monitor *m;
XEvent ev;
- int horizcorner, vertcorner;
- int di;
- unsigned int dui;
- Window dummy;
if (!(c = selmon->sel))
return;
if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
return;
restack(selmon);
- ocx = c->x;
- ocy = c->y;
- ocx2 = c->x + c->w;
- ocy2 = c->y + c->h;
+ ocw = c->w;
+ och = c->h;
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
return;
- if (!XQueryPointer (dpy, c->win, &dummy, &dummy, &di, &di, &nx, &ny, &dui))
+ if(!getrootptr(&x, &y))
return;
- horizcorner = nx < c->w / 2;
- vertcorner = ny < c->h / 2;
- XWarpPointer (dpy, None, c->win, 0, 0, 0, 0,
- horizcorner ? (-c->bw) : (c->w + c->bw -1),
- vertcorner ? (-c->bw) : (c->h + c->bw -1));
do {
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
switch(ev.type) {
@@ -1726,18 +1502,11 @@ resizemouse(const Arg *arg)
handler[ev.type](&ev);
break;
case MotionNotify:
-
- nx = horizcorner && ocx2 - ev.xmotion.x >= c->minw ? ev.xmotion.x : c->x;
- ny = vertcorner && ocy2 - ev.xmotion.y >= c->minh ? ev.xmotion.y : c->y;
- nw = MAX(horizcorner ? (ocx2 - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1);
- nh = MAX(vertcorner ? (ocy2 - ny) : (ev.xmotion.y - ocy - 2 * c->bw + 1), 1);
-
- if (horizcorner && ev.xmotion.x > ocx2)
- nx = ocx2 - (nw = c->minw);
- if (vertcorner && ev.xmotion.y > ocy2)
- ny = ocy2 - (nh = c->minh);
-
- if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
+// nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
+// nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
+ nw = MAX(ocw + (ev.xmotion.x - x), 1);
+ nh = MAX(och + (ev.xmotion.y - y), 1);
+ if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
{
if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
@@ -1745,13 +1514,10 @@ resizemouse(const Arg *arg)
togglefloating(NULL);
}
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
- resize(c, nx, ny, nw, nh, 1);
+ resize(c, c->x, c->y, nw, nh, 1);
break;
}
} while (ev.type != ButtonRelease);
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
- horizcorner ? (-c->bw) : (c->w + c->bw - 1),
- vertcorner ? (-c->bw) : (c->h + c->bw - 1));
XUngrabPointer(dpy, CurrentTime);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
@@ -1829,20 +1595,15 @@ sendmon(Client *c, Monitor *m)
{
if (c->mon == m)
return;
- int hadfocus = (c == selmon->sel);
unfocus(c, 1);
detach(c);
detachstack(c);
- arrange(c->mon);
c->mon = m;
- attach(c);
+ c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
+ attach(c);
attachstack(c);
- arrange(m);
- if (hadfocus) {
- focus(c);
- restack(m);
- } else
- focus(NULL);
+ focus(NULL);
+ arrange(NULL);
}
void
@@ -1904,7 +1665,6 @@ setfullscreen(Client *c, int fullscreen)
c->isfloating = 1;
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
XRaiseWindow(dpy, c->win);
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
} else if (!fullscreen && c->isfullscreen){
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)0, 0);
@@ -1966,8 +1726,8 @@ setup(void)
/* clean up any zombies (inherited from .xinitrc etc) immediately */
while (waitpid(-1, NULL, WNOHANG) > 0);
- signal(SIGHUP, sighup);
- signal(SIGTERM, sigterm);
+ signal(SIGHUP, sighup);
+ signal(SIGTERM, sigterm);
/* init screen */
screen = DefaultScreen(dpy);
@@ -2043,42 +1803,14 @@ seturgent(Client *c, int urg)
}
void
-showall(const Arg *arg)
-{
- Client *c = NULL;
- selmon->hidsel = 0;
- for (c = selmon->clients; c; c = c->next) {
- if (ISVISIBLE(c))
- showwin(c);
- }
- if (!selmon->sel) {
- for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
- if (c)
- focus(c);
- }
- restack(selmon);
-}
-
-void
-showwin(Client *c)
-{
- if (!c || !HIDDEN(c))
- return;
-
- XMapWindow(dpy, c->win);
- setclientstate(c, NormalState);
- arrange(c->mon);
-}
-
-void
showhide(Client *c)
{
if (!c)
return;
if (ISVISIBLE(c)) {
/* show clients top down */
- XMoveWindow(dpy, c->win, c->x, c->y);
- if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
+ XMoveWindow(dpy, c->win, c->x, c->y);
+ if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
resize(c, c->x, c->y, c->w, c->h, 0);
showhide(c->snext);
} else {
@@ -2091,15 +1823,15 @@ showhide(Client *c)
void
sighup(int unused)
{
- Arg a = {.i = 1};
- quit(&a);
+ Arg a = {.i = 1};
+ quit(&a);
}
void
sigterm(int unused)
{
- Arg a = {.i = 0};
- quit(&a);
+ Arg a = {.i = 0};
+ quit(&a);
}
void
@@ -2107,7 +1839,8 @@ spawn(const Arg *arg)
{
struct sigaction sa;
- showtags = false;
+ showtags = 0;
+
if (arg->v == dmenucmd)
dmenumon[0] = '0' + selmon->num;
if (fork() == 0) {
@@ -2150,7 +1883,6 @@ tile(Monitor *m)
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
-
if (n == 0)
return;
@@ -2159,7 +1891,7 @@ tile(Monitor *m)
else
mw = m->ww;
for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
- if (i < m->nmaster) {
+ if (i < m->nmaster) {
h = (m->wh - my) / (MIN(n, m->nmaster) - i);
resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
if (my + HEIGHT(c) < m->wh)
@@ -2196,20 +1928,13 @@ togglefloating(const Arg *arg)
}
void
-togglefullscr(const Arg *arg)
-{
- if(selmon->sel)
- setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
-}
-
-void
toggletag(const Arg *arg)
{
unsigned int newtags;
if (!selmon->sel)
return;
- showtags = true;
+ showtags = 1;
newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
if (newtags) {
selmon->sel->tags = newtags;
@@ -2223,7 +1948,7 @@ toggleview(const Arg *arg)
{
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
- showtags = true;
+ showtags = 1;
if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
focus(NULL);
@@ -2250,19 +1975,19 @@ unmanage(Client *c, int destroyed)
Monitor *m = c->mon;
XWindowChanges wc;
- if (c->swallowing) {
- unswallow(c);
- return;
- }
+ if (c->swallowing) {
+ unswallow(c);
+ return;
+ }
- Client *s = swallowingclient(c->win);
- if(s) {
- free(s->swallowing);
- s->swallowing = NULL;
- arrange(m);
- focus(NULL);
- return;
- }
+ Client *s = swallowingclient(c->win);
+ if (s) {
+ free(s->swallowing);
+ s->swallowing = NULL;
+ arrange(m);
+ focus(NULL);
+ return;
+ }
detach(c);
detachstack(c);
@@ -2279,11 +2004,12 @@ unmanage(Client *c, int destroyed)
XUngrabServer(dpy);
}
free(c);
- if (!s) {
- arrange(m);
- focus(NULL);
- updateclientlist();
- }
+
+ if (!s) {
+ arrange(m);
+ focus(NULL);
+ updateclientlist();
+ }
}
void
@@ -2336,7 +2062,7 @@ updatebarpos(Monitor *m)
}
void
-updateclientlist()
+updateclientlist(void)
{
Client *c;
Monitor *m;
@@ -2490,8 +2216,8 @@ updatesizehints(Client *c)
void
updatestatus(void)
{
- if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
- strcpy(stext, "");
+ // if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
+ // strcpy(stext, "dwm-"VERSION);
drawbar(selmon);
}
@@ -2540,7 +2266,7 @@ view(const Arg *arg)
{
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
- showtags = true;
+ showtags = 1;
selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
@@ -2767,9 +2493,8 @@ main(int argc, char *argv[])
fputs("warning: no locale support\n", stderr);
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
- if (!(xcon = XGetXCBConnection(dpy))) {
- die("dwm: cannot get xcb connection\n");
- }
+ if (!(xcon = XGetXCBConnection(dpy)))
+ die("dwm: cannot get xcb connection\n");
checkotherwm();
setup();
#ifdef __OpenBSD__
@@ -2778,7 +2503,7 @@ main(int argc, char *argv[])
#endif /* __OpenBSD__ */
scan();
run();
- if(restart) execvp(argv[0], argv);
+ if(restart) execvp(argv[0], argv);
cleanup();
XCloseDisplay(dpy);
return EXIT_SUCCESS;