2760 lines
86 KiB
C
2760 lines
86 KiB
C
/* See LICENSE file for copyright and license details. */
|
|||
|
|
/* ANODE DWM - Pango/HarfBuzz + First-class Systray + EWMH Struts + Fractional DPI */
|
||
|
|
#include <errno.h>
|
||
|
|
#include <locale.h>
|
||
|
|
#include <math.h>
|
||
|
|
#include <poll.h>
|
||
|
|
#include <signal.h>
|
||
|
|
#include <stdarg.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <sys/types.h>
|
||
|
|
#include <sys/wait.h>
|
||
|
|
#include <time.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
#include <X11/cursorfont.h>
|
||
|
|
#include <X11/keysym.h>
|
||
|
|
#include <X11/Xatom.h>
|
||
|
|
#include <X11/XKBlib.h>
|
||
|
|
#include <X11/Xlib.h>
|
||
|
|
#include <X11/Xproto.h>
|
||
|
|
#include <X11/Xresource.h>
|
||
|
|
#include <X11/Xutil.h>
|
||
|
|
#ifdef XINERAMA
|
||
|
|
#include <X11/extensions/Xinerama.h>
|
||
|
|
#endif
|
||
|
|
#include <X11/Xft/Xft.h>
|
||
|
|
|
||
|
|
#include "drw.h"
|
||
|
|
#include "util.h"
|
||
|
|
#include "anode_scale.h"
|
||
|
|
|
||
|
|
/* macros */
|
||
|
|
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||
|
|
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
||
|
|
#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 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)
|
||
|
|
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||
|
|
#define TEXTW(X) (drw_font_getwidth(drw, (X), False) + lrpad)
|
||
|
|
|
||
|
|
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
||
|
|
#define XEMBED_EMBEDDED_NOTIFY 0
|
||
|
|
#define XEMBED_WINDOW_ACTIVATE 1
|
||
|
|
#define XEMBED_WINDOW_DEACTIVATE 2
|
||
|
|
#define XEMBED_FOCUS_IN 4
|
||
|
|
#define XEMBED_MODALITY_ON 10
|
||
|
|
#define XEMBED_MAPPED (1 << 0)
|
||
|
|
#define XEMBED_EMBEDDED_VERSION 0
|
||
|
|
#define VERSION_MAJOR 0
|
||
|
|
#define VERSION_MINOR 0
|
||
|
|
#define XEMBED_EMBEDDED_VERSION_VAL ((VERSION_MAJOR << 16) | VERSION_MINOR)
|
||
|
|
|
||
|
|
enum { CurNormal, CurResize, CurMove, CurLast };
|
||
|
|
enum { SchemeNorm, SchemeSel };
|
||
|
|
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
||
|
|
NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation,
|
||
|
|
NetSystemTrayOrientationHorz, NetSystemTrayVisual,
|
||
|
|
NetWMFullscreen, NetActiveWindow, NetWorkarea,
|
||
|
|
NetWMWindowType, NetWMWindowTypeDialog, NetWMWindowTypeDock,
|
||
|
|
NetWMStrutPartial, NetWMStrut, NetClientList, NetLast };
|
||
|
|
enum { Manager, Xembed, XembedInfo, XLast };
|
||
|
|
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast };
|
||
|
|
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkLauncher,
|
||
|
|
ClkCloseBtn, ClkClientWin, ClkRootWin, ClkLast };
|
||
|
|
|
||
|
|
typedef union {
|
||
|
|
int i;
|
||
|
|
unsigned int ui;
|
||
|
|
float f;
|
||
|
|
const void *v;
|
||
|
|
} Arg;
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
unsigned int click;
|
||
|
|
unsigned int mask;
|
||
|
|
unsigned int button;
|
||
|
|
void (*func)(const Arg *arg);
|
||
|
|
const Arg arg;
|
||
|
|
} Button;
|
||
|
|
|
||
|
|
typedef struct Monitor Monitor;
|
||
|
|
typedef struct Client Client;
|
||
|
|
struct Client {
|
||
|
|
char name[256];
|
||
|
|
float mina, maxa;
|
||
|
|
int x, y, w, h;
|
||
|
|
int oldx, oldy, oldw, oldh;
|
||
|
|
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
|
||
|
|
int bw, oldbw;
|
||
|
|
unsigned int tags;
|
||
|
|
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
|
||
|
|
Client *next;
|
||
|
|
Client *snext;
|
||
|
|
Monitor *mon;
|
||
|
|
Window win;
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
unsigned int mod;
|
||
|
|
KeySym keysym;
|
||
|
|
void (*func)(const Arg *);
|
||
|
|
const Arg arg;
|
||
|
|
} Key;
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
const char *symbol;
|
||
|
|
void (*arrange)(Monitor *);
|
||
|
|
} Layout;
|
||
|
|
|
||
|
|
struct Monitor {
|
||
|
|
char ltsymbol[16];
|
||
|
|
float mfact;
|
||
|
|
int nmaster;
|
||
|
|
int num;
|
||
|
|
int by;
|
||
|
|
int mx, my, mw, mh;
|
||
|
|
int wx, wy, ww, wh;
|
||
|
|
unsigned int seltags;
|
||
|
|
unsigned int sellt;
|
||
|
|
unsigned int tagset[2];
|
||
|
|
int showbar;
|
||
|
|
int topbar;
|
||
|
|
Client *clients;
|
||
|
|
Client *sel;
|
||
|
|
Client *stack;
|
||
|
|
Monitor *next;
|
||
|
|
Window barwin;
|
||
|
|
const Layout *lt[2];
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
const char *class;
|
||
|
|
const char *instance;
|
||
|
|
const char *title;
|
||
|
|
unsigned int tags;
|
||
|
|
int isfloating;
|
||
|
|
int monitor;
|
||
|
|
} Rule;
|
||
|
|
|
||
|
|
typedef struct Systray Systray;
|
||
|
|
struct Systray {
|
||
|
|
Window win;
|
||
|
|
Client *icons;
|
||
|
|
Visual *visual;
|
||
|
|
int depth;
|
||
|
|
Colormap colormap;
|
||
|
|
int use_argb;
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef struct DockWin DockWin;
|
||
|
|
struct DockWin {
|
||
|
|
Window win;
|
||
|
|
unsigned long strut[12];
|
||
|
|
DockWin *next;
|
||
|
|
};
|
||
|
|
|
||
|
|
/* function declarations */
|
||
|
|
static void applyrules(Client *c);
|
||
|
|
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
|
||
|
|
static void arrange(Monitor *m);
|
||
|
|
static void arrangemon(Monitor *m);
|
||
|
|
static void attach(Client *c);
|
||
|
|
static void attachstack(Client *c);
|
||
|
|
static void buttonpress(XEvent *e);
|
||
|
|
static void checkotherwm(void);
|
||
|
|
static void cleanup(void);
|
||
|
|
static void cleanupmon(Monitor *mon);
|
||
|
|
static void clientmessage(XEvent *e);
|
||
|
|
static void configure(Client *c);
|
||
|
|
static void configurenotify(XEvent *e);
|
||
|
|
static void configurerequest(XEvent *e);
|
||
|
|
static Monitor *createmon(void);
|
||
|
|
static void destroynotify(XEvent *e);
|
||
|
|
static void detach(Client *c);
|
||
|
|
static void detachstack(Client *c);
|
||
|
|
static Monitor *dirtomon(int dir);
|
||
|
|
static void drawbar(Monitor *m);
|
||
|
|
static void drawbars(void);
|
||
|
|
static void enternotify(XEvent *e);
|
||
|
|
static void expose(XEvent *e);
|
||
|
|
static void focus(Client *c);
|
||
|
|
static void focusin(XEvent *e);
|
||
|
|
static void focusmon(const Arg *arg);
|
||
|
|
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 unsigned int getsystraywidth(void);
|
||
|
|
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 grid(Monitor *m);
|
||
|
|
static void incnmaster(const Arg *arg);
|
||
|
|
static void keypress(XEvent *e);
|
||
|
|
static void keyrelease(XEvent *e);
|
||
|
|
static void killclient(const Arg *arg);
|
||
|
|
static void loadxres(void);
|
||
|
|
static void manage(Window w, XWindowAttributes *wa);
|
||
|
|
static void mappingnotify(XEvent *e);
|
||
|
|
static void maprequest(XEvent *e);
|
||
|
|
static void monocle(Monitor *m);
|
||
|
|
static void motionnotify(XEvent *e);
|
||
|
|
static void movemouse(const Arg *arg);
|
||
|
|
static Client *nexttiled(Client *c);
|
||
|
|
static unsigned long long now_ms(void);
|
||
|
|
static void pop(Client *c);
|
||
|
|
static void propertynotify(XEvent *e);
|
||
|
|
static void quit(const Arg *arg);
|
||
|
|
static Monitor *recttomon(int x, int y, int w, int h);
|
||
|
|
static void reloadxres(const Arg *arg);
|
||
|
|
static void removesystrayicon(Client *i);
|
||
|
|
static void resize(Client *c, int x, int y, int w, int h, int interact);
|
||
|
|
static void resizebarwin(Monitor *m);
|
||
|
|
static void resizeclient(Client *c, int x, int y, int w, int h);
|
||
|
|
static void resizemouse(const Arg *arg);
|
||
|
|
static void resizerequest(XEvent *e);
|
||
|
|
static void restack(Monitor *m);
|
||
|
|
static void run(void);
|
||
|
|
static void scan(void);
|
||
|
|
static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
|
||
|
|
static void sendmon(Client *c, Monitor *m);
|
||
|
|
static void setclientstate(Client *c, long state);
|
||
|
|
static void setfocus(Client *c);
|
||
|
|
static void setfullscreen(Client *c, int fullscreen);
|
||
|
|
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 showhide(Client *c);
|
||
|
|
static void sigchld_handler(int sig);
|
||
|
|
static void sighup_handler(int sig);
|
||
|
|
static void sigusr1_handler(int sig);
|
||
|
|
static void spawn(const Arg *arg);
|
||
|
|
static Monitor *systraytomon(Monitor *m);
|
||
|
|
static void tag(const Arg *arg);
|
||
|
|
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 toggletag(const Arg *arg);
|
||
|
|
static void toggleview(const Arg *arg);
|
||
|
|
static void unfocus(Client *c, int setfocus);
|
||
|
|
static void unmanage(Client *c, int destroyed);
|
||
|
|
static void unmapnotify(XEvent *e);
|
||
|
|
static void mapnotify(XEvent *e);
|
||
|
|
static void reparentnotify(XEvent *e);
|
||
|
|
static void updatebarpos(Monitor *m);
|
||
|
|
static void updatebars(void);
|
||
|
|
static void updateclientlist(void);
|
||
|
|
static int updategeom(void);
|
||
|
|
static void updatenumlockmask(void);
|
||
|
|
static void updatesizehints(Client *c);
|
||
|
|
static void updatestatus(void);
|
||
|
|
static void updatesystray(int updatebar);
|
||
|
|
static void updatesystrayicongeom(Client *i, int w, int h);
|
||
|
|
static void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
|
||
|
|
static unsigned long systray_bg_pixel(void);
|
||
|
|
static int getxembedflags(Window w, long *flags_out);
|
||
|
|
static int isdockwin(Window w);
|
||
|
|
static void dockadd(Window w);
|
||
|
|
static int dockremove(Window w);
|
||
|
|
static void dockupdate(Window w);
|
||
|
|
static void recalcworkareas(void);
|
||
|
|
static void updateworkarea(void);
|
||
|
|
static void updatetitle(Client *c);
|
||
|
|
static void updatewindowtype(Client *c);
|
||
|
|
static void updatewmhints(Client *c);
|
||
|
|
static void view(const Arg *arg);
|
||
|
|
static Client *wintoclient(Window w);
|
||
|
|
static Monitor *wintomon(Window w);
|
||
|
|
static Client *wintosystrayicon(Window w);
|
||
|
|
static int xerror(Display *dpy, XErrorEvent *ee);
|
||
|
|
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||
|
|
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||
|
|
static void zoom(const Arg *arg);
|
||
|
|
|
||
|
|
/* variables */
|
||
|
|
static Systray *systray = NULL;
|
||
|
|
static DockWin *docks = NULL;
|
||
|
|
static const char broken[] = "broken";
|
||
|
|
static char stext[512];
|
||
|
|
static char xres_font[256] = "";
|
||
|
|
static double ui_scale = 1.0;
|
||
|
|
static int launcher_w = 42;
|
||
|
|
static int closebtn_w = 38;
|
||
|
|
static int screen;
|
||
|
|
static int sw, sh;
|
||
|
|
static int bh;
|
||
|
|
static int lrpad;
|
||
|
|
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||
|
|
static unsigned int numlockmask = 0;
|
||
|
|
static volatile sig_atomic_t reload_pending = 0;
|
||
|
|
static volatile sig_atomic_t restart_dwm = 0;
|
||
|
|
static int super_down = 0;
|
||
|
|
static int super_dirty = 0;
|
||
|
|
static unsigned long long super_down_ms = 0;
|
||
|
|
static int super_latched = 0;
|
||
|
|
static unsigned long long super_latch_until = 0;
|
||
|
|
|
||
|
|
static void (*handler[LASTEvent])(XEvent *) = {
|
||
|
|
[ButtonPress] = buttonpress,
|
||
|
|
[ClientMessage] = clientmessage,
|
||
|
|
[ConfigureRequest] = configurerequest,
|
||
|
|
[ConfigureNotify] = configurenotify,
|
||
|
|
[DestroyNotify] = destroynotify,
|
||
|
|
[EnterNotify] = enternotify,
|
||
|
|
[Expose] = expose,
|
||
|
|
[FocusIn] = focusin,
|
||
|
|
[KeyPress] = keypress,
|
||
|
|
[KeyRelease] = keyrelease,
|
||
|
|
[MapNotify] = mapnotify,
|
||
|
|
[MappingNotify] = mappingnotify,
|
||
|
|
[MapRequest] = maprequest,
|
||
|
|
[MotionNotify] = motionnotify,
|
||
|
|
[PropertyNotify] = propertynotify,
|
||
|
|
[ReparentNotify] = reparentnotify,
|
||
|
|
[ResizeRequest] = resizerequest,
|
||
|
|
[UnmapNotify] = unmapnotify
|
||
|
|
};
|
||
|
|
static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
|
||
|
|
static int running = 1;
|
||
|
|
static Cur *cursor[CurLast];
|
||
|
|
static Clr **scheme;
|
||
|
|
static Display *dpy;
|
||
|
|
static Drw *drw;
|
||
|
|
static Fnt *dwmfont = NULL;
|
||
|
|
static Monitor *mons, *selmon;
|
||
|
|
static Window root, wmcheckwin;
|
||
|
|
|
||
|
|
#include "config.h"
|
||
|
|
|
||
|
|
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
|
||
|
|
|
||
|
|
static unsigned long long now_ms(void) {
|
||
|
|
struct timespec ts;
|
||
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||
|
|
return (unsigned long long)ts.tv_sec * 1000ULL + (unsigned long long)ts.tv_nsec / 1000000ULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void applyrules(Client *c) {
|
||
|
|
const char *class, *instance;
|
||
|
|
unsigned int i;
|
||
|
|
const Rule *r;
|
||
|
|
Monitor *m;
|
||
|
|
XClassHint ch = { NULL, NULL };
|
||
|
|
|
||
|
|
c->isfloating = 0;
|
||
|
|
c->tags = 0;
|
||
|
|
XGetClassHint(dpy, c->win, &ch);
|
||
|
|
class = ch.res_class ? ch.res_class : broken;
|
||
|
|
instance = ch.res_name ? ch.res_name : broken;
|
||
|
|
|
||
|
|
for (i = 0; i < LENGTH(rules); i++) {
|
||
|
|
r = &rules[i];
|
||
|
|
if ((!r->title || strstr(c->name, r->title)) &&
|
||
|
|
(!r->class || strstr(class, r->class)) &&
|
||
|
|
(!r->instance || strstr(instance, r->instance))) {
|
||
|
|
c->isfloating = r->isfloating;
|
||
|
|
c->tags |= r->tags;
|
||
|
|
for (m = mons; m && m->num != r->monitor; m = m->next) ;
|
||
|
|
if (m) c->mon = m;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (ch.res_class) XFree(ch.res_class);
|
||
|
|
if (ch.res_name) XFree(ch.res_name);
|
||
|
|
c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
|
||
|
|
}
|
||
|
|
|
||
|
|
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) {
|
||
|
|
int baseismin;
|
||
|
|
Monitor *m = c->mon;
|
||
|
|
|
||
|
|
*w = MAX(1, *w);
|
||
|
|
*h = MAX(1, *h);
|
||
|
|
if (interact) {
|
||
|
|
if (*x > sw) *x = sw - WIDTH(c);
|
||
|
|
if (*y > sh) *y = sh - HEIGHT(c);
|
||
|
|
if (*x + *w + 2 * c->bw < 0) *x = 0;
|
||
|
|
if (*y + *h + 2 * c->bw < 0) *y = 0;
|
||
|
|
} else {
|
||
|
|
if (*x >= m->wx + m->ww) *x = m->wx + m->ww - WIDTH(c);
|
||
|
|
if (*y >= m->wy + m->wh) *y = m->wy + m->wh - HEIGHT(c);
|
||
|
|
if (*x + *w + 2 * c->bw <= m->wx) *x = m->wx;
|
||
|
|
if (*y + *h + 2 * c->bw <= m->wy) *y = m->wy;
|
||
|
|
}
|
||
|
|
if (*h < bh) *h = bh;
|
||
|
|
if (*w < bh) *w = bh;
|
||
|
|
if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
|
||
|
|
if (!c->hintsvalid) updatesizehints(c);
|
||
|
|
baseismin = c->basew == c->minw && c->baseh == c->minh;
|
||
|
|
if (!baseismin) {
|
||
|
|
*w -= c->basew;
|
||
|
|
*h -= c->baseh;
|
||
|
|
}
|
||
|
|
if (c->mina > 0 && c->maxa > 0) {
|
||
|
|
if (c->maxa < (float)*w / *h) *w = (int)(*h * c->maxa + 0.5);
|
||
|
|
else if (c->mina < (float)*h / *w) *h = (int)(*w * c->mina + 0.5);
|
||
|
|
}
|
||
|
|
if (baseismin) {
|
||
|
|
*w -= c->basew;
|
||
|
|
*h -= c->baseh;
|
||
|
|
}
|
||
|
|
if (c->incw) *w -= *w % c->incw;
|
||
|
|
if (c->inch) *h -= *h % c->inch;
|
||
|
|
*w = MAX(*w + c->basew, c->minw);
|
||
|
|
*h = MAX(*h + c->baseh, c->minh);
|
||
|
|
if (c->maxw) *w = MIN(*w, c->maxw);
|
||
|
|
if (c->maxh) *h = MIN(*h, c->maxh);
|
||
|
|
}
|
||
|
|
return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void arrange(Monitor *m) {
|
||
|
|
if (m) showhide(m->stack);
|
||
|
|
else for (m = mons; m; m = m->next) showhide(m->stack);
|
||
|
|
if (m) {
|
||
|
|
arrangemon(m);
|
||
|
|
restack(m);
|
||
|
|
} else {
|
||
|
|
for (m = mons; m; m = m->next) arrangemon(m);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void arrangemon(Monitor *m) {
|
||
|
|
snprintf(m->ltsymbol, sizeof m->ltsymbol, "%s", m->lt[m->sellt]->symbol);
|
||
|
|
if (m->lt[m->sellt]->arrange)
|
||
|
|
m->lt[m->sellt]->arrange(m);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void attach(Client *c) {
|
||
|
|
c->next = c->mon->clients;
|
||
|
|
c->mon->clients = c;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void attachstack(Client *c) {
|
||
|
|
c->snext = c->mon->stack;
|
||
|
|
c->mon->stack = c;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void buttonpress(XEvent *e) {
|
||
|
|
unsigned int i, x, click;
|
||
|
|
Arg arg = {0};
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
XButtonPressedEvent *ev = &e->xbutton;
|
||
|
|
|
||
|
|
click = ClkRootWin;
|
||
|
|
if ((m = wintomon(ev->window)) && m != selmon) {
|
||
|
|
unfocus(selmon->sel, 1);
|
||
|
|
selmon = m;
|
||
|
|
focus(NULL);
|
||
|
|
}
|
||
|
|
if (ev->window == selmon->barwin) {
|
||
|
|
int stw = (showsystray && selmon == systraytomon(selmon) && !systrayonleft)
|
||
|
|
? (int)getsystraywidth() : 0;
|
||
|
|
int tw = (int)TEXTW(stext) - lrpad + 4;
|
||
|
|
if (ev->x < launcher_w) {
|
||
|
|
click = ClkLauncher;
|
||
|
|
} else {
|
||
|
|
i = 0;
|
||
|
|
x = (unsigned int)launcher_w;
|
||
|
|
do {
|
||
|
|
x += (int)TEXTW(tags[i]);
|
||
|
|
} while (ev->x >= (int)x && ++i < LENGTH(tags));
|
||
|
|
if (i < LENGTH(tags)) {
|
||
|
|
click = ClkTagBar;
|
||
|
|
arg.ui = 1U << i;
|
||
|
|
} else if (ev->x < (int)x + (int)TEXTW(selmon->ltsymbol)) {
|
||
|
|
click = ClkLtSymbol;
|
||
|
|
} else if (ev->x > selmon->ww - tw - stw) {
|
||
|
|
click = ClkStatusText;
|
||
|
|
} else if (selmon->sel && ev->x > selmon->ww - tw - stw - closebtn_w) {
|
||
|
|
click = ClkCloseBtn;
|
||
|
|
} else {
|
||
|
|
click = ClkWinTitle;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else if ((c = wintoclient(ev->window))) {
|
||
|
|
focus(c);
|
||
|
|
restack(selmon);
|
||
|
|
XAllowEvents(dpy, ReplayPointer, CurrentTime);
|
||
|
|
click = ClkClientWin;
|
||
|
|
}
|
||
|
|
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 && buttons[i].arg.i == 0) ? &arg : &buttons[i].arg);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void checkotherwm(void) {
|
||
|
|
xerrorxlib = XSetErrorHandler(xerrorstart);
|
||
|
|
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
|
||
|
|
XSync(dpy, False);
|
||
|
|
XSetErrorHandler(xerror);
|
||
|
|
XSync(dpy, False);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void cleanup(void) {
|
||
|
|
Arg a = {.ui = ~0U};
|
||
|
|
Layout foo = { "", NULL };
|
||
|
|
Monitor *m;
|
||
|
|
size_t i;
|
||
|
|
|
||
|
|
view(&a);
|
||
|
|
selmon->lt[selmon->sellt] = &foo;
|
||
|
|
for (m = mons; m; m = m->next)
|
||
|
|
while (m->stack) unmanage(m->stack, 0);
|
||
|
|
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||
|
|
while (mons) cleanupmon(mons);
|
||
|
|
|
||
|
|
if (showsystray && systray) {
|
||
|
|
while (systray->icons) {
|
||
|
|
Client *c = systray->icons;
|
||
|
|
systray->icons = c->next;
|
||
|
|
free(c);
|
||
|
|
}
|
||
|
|
XUnmapWindow(dpy, systray->win);
|
||
|
|
XDestroyWindow(dpy, systray->win);
|
||
|
|
if (systray->use_argb && systray->colormap)
|
||
|
|
XFreeColormap(dpy, systray->colormap);
|
||
|
|
free(systray);
|
||
|
|
}
|
||
|
|
while (docks) {
|
||
|
|
DockWin *d = docks;
|
||
|
|
docks = d->next;
|
||
|
|
free(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
for (i = 0; i < CurLast; i++) drw_cur_free(drw, cursor[i]);
|
||
|
|
free(scheme[SchemeNorm]);
|
||
|
|
free(scheme[SchemeSel]);
|
||
|
|
free(scheme);
|
||
|
|
XDestroyWindow(dpy, wmcheckwin);
|
||
|
|
drw_free(drw);
|
||
|
|
XSync(dpy, False);
|
||
|
|
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
||
|
|
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void cleanupmon(Monitor *mon) {
|
||
|
|
Monitor *m;
|
||
|
|
if (mon == mons) mons = mons->next;
|
||
|
|
else {
|
||
|
|
for (m = mons; m && m->next != mon; m = m->next) ;
|
||
|
|
m->next = mon->next;
|
||
|
|
}
|
||
|
|
XUnmapWindow(dpy, mon->barwin);
|
||
|
|
XDestroyWindow(dpy, mon->barwin);
|
||
|
|
free(mon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void clientmessage(XEvent *e) {
|
||
|
|
XWindowAttributes wa;
|
||
|
|
XSetWindowAttributes swa;
|
||
|
|
XClientMessageEvent *cme = &e->xclient;
|
||
|
|
Client *c = wintoclient(cme->window);
|
||
|
|
|
||
|
|
if (showsystray && systray && cme->window == systray->win &&
|
||
|
|
cme->message_type == netatom[NetSystemTrayOP]) {
|
||
|
|
if (cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) {
|
||
|
|
Window iw = (Window)cme->data.l[2];
|
||
|
|
if (!iw || wintosystrayicon(iw))
|
||
|
|
return;
|
||
|
|
if (!(c = (Client *)calloc(1, sizeof(Client))))
|
||
|
|
die("fatal: could not malloc() %zu bytes\n", sizeof(Client));
|
||
|
|
c->win = iw;
|
||
|
|
c->mon = systraytomon(NULL);
|
||
|
|
c->next = systray->icons;
|
||
|
|
systray->icons = c;
|
||
|
|
if (!XGetWindowAttributes(dpy, c->win, &wa)) {
|
||
|
|
wa.width = bh;
|
||
|
|
wa.height = bh;
|
||
|
|
wa.border_width = 0;
|
||
|
|
wa.depth = DefaultDepth(dpy, screen);
|
||
|
|
}
|
||
|
|
c->x = c->oldx = c->y = c->oldy = 0;
|
||
|
|
c->w = c->oldw = wa.width;
|
||
|
|
c->h = c->oldh = wa.height;
|
||
|
|
c->oldbw = wa.border_width;
|
||
|
|
c->bw = 0;
|
||
|
|
c->isfloating = True;
|
||
|
|
long flags = 0;
|
||
|
|
c->tags = getxembedflags(c->win, &flags) ? ((flags & XEMBED_MAPPED) ? 1 : 0) : 1;
|
||
|
|
updatesizehints(c);
|
||
|
|
updatesystrayicongeom(c, wa.width, wa.height);
|
||
|
|
XAddToSaveSet(dpy, c->win);
|
||
|
|
XSelectInput(dpy, c->win, StructureNotifyMask | SubstructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
|
||
|
|
XReparentWindow(dpy, c->win, systray->win, 0, 0);
|
||
|
|
if (!systray->use_argb && wa.depth == DefaultDepth(dpy, screen)) {
|
||
|
|
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
|
||
|
|
XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa);
|
||
|
|
}
|
||
|
|
sendevent(c->win, xatom[Xembed], StructureNotifyMask, CurrentTime,
|
||
|
|
XEMBED_EMBEDDED_NOTIFY, 0, (long)systray->win, XEMBED_EMBEDDED_VERSION_VAL);
|
||
|
|
if (c->tags) {
|
||
|
|
XMapRaised(dpy, c->win);
|
||
|
|
setclientstate(c, NormalState);
|
||
|
|
sendevent(c->win, xatom[Xembed], StructureNotifyMask, CurrentTime,
|
||
|
|
XEMBED_WINDOW_ACTIVATE, 0, (long)systray->win, XEMBED_EMBEDDED_VERSION_VAL);
|
||
|
|
} else {
|
||
|
|
setclientstate(c, WithdrawnState);
|
||
|
|
}
|
||
|
|
XSync(dpy, False);
|
||
|
|
updatesystray(1);
|
||
|
|
drawbars();
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!c) return;
|
||
|
|
if (cme->message_type == netatom[NetWMState]) {
|
||
|
|
if ((Atom)cme->data.l[1] == netatom[NetWMFullscreen] ||
|
||
|
|
(Atom)cme->data.l[2] == netatom[NetWMFullscreen]) {
|
||
|
|
setfullscreen(c, (cme->data.l[0] == 1 ||
|
||
|
|
(cme->data.l[0] == 2 && !c->isfullscreen)));
|
||
|
|
}
|
||
|
|
} else if (cme->message_type == netatom[NetActiveWindow]) {
|
||
|
|
if (c != selmon->sel && !c->isurgent)
|
||
|
|
seturgent(c, 1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void configure(Client *c) {
|
||
|
|
XConfigureEvent ce;
|
||
|
|
ce.type = ConfigureNotify;
|
||
|
|
ce.display = dpy;
|
||
|
|
ce.event = c->win;
|
||
|
|
ce.window = c->win;
|
||
|
|
ce.x = c->x;
|
||
|
|
ce.y = c->y;
|
||
|
|
ce.width = c->w;
|
||
|
|
ce.height = c->h;
|
||
|
|
ce.border_width = c->bw;
|
||
|
|
ce.above = None;
|
||
|
|
ce.override_redirect = False;
|
||
|
|
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void configurenotify(XEvent *e) {
|
||
|
|
Monitor *m;
|
||
|
|
Client *c;
|
||
|
|
XConfigureEvent *ev = &e->xconfigure;
|
||
|
|
int dirty;
|
||
|
|
|
||
|
|
if (ev->window == root) {
|
||
|
|
dirty = (sw != ev->width || sh != ev->height);
|
||
|
|
sw = ev->width;
|
||
|
|
sh = ev->height;
|
||
|
|
if (updategeom() || dirty) {
|
||
|
|
drw_resize(drw, (unsigned int)sw, (unsigned int)bh);
|
||
|
|
updatebars();
|
||
|
|
for (m = mons; m; m = m->next) {
|
||
|
|
for (c = m->clients; c; c = c->next)
|
||
|
|
if (c->isfullscreen) resizeclient(c, m->mx, m->my, m->mw, m->mh);
|
||
|
|
resizebarwin(m);
|
||
|
|
}
|
||
|
|
updatesystray(1);
|
||
|
|
updateworkarea();
|
||
|
|
focus(NULL);
|
||
|
|
arrange(NULL);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void configurerequest(XEvent *e) {
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||
|
|
XWindowChanges wc;
|
||
|
|
|
||
|
|
if ((c = wintoclient(ev->window))) {
|
||
|
|
if (ev->value_mask & CWBorderWidth)
|
||
|
|
c->bw = ev->border_width;
|
||
|
|
else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) {
|
||
|
|
m = c->mon;
|
||
|
|
if (ev->value_mask & CWX) { c->oldx = c->x; c->x = m->mx + ev->x; }
|
||
|
|
if (ev->value_mask & CWY) { c->oldy = c->y; c->y = m->my + ev->y; }
|
||
|
|
if (ev->value_mask & CWWidth) { c->oldw = c->w; c->w = ev->width; }
|
||
|
|
if (ev->value_mask & CWHeight) { c->oldh = c->h; c->h = ev->height; }
|
||
|
|
if ((c->x + c->w) > m->mx + m->mw && c->isfloating)
|
||
|
|
c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2);
|
||
|
|
if ((c->y + c->h) > m->my + m->mh && c->isfloating)
|
||
|
|
c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2);
|
||
|
|
if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
|
||
|
|
configure(c);
|
||
|
|
if (ISVISIBLE(c))
|
||
|
|
XMoveResizeWindow(dpy, c->win, c->x, c->y, (unsigned int)c->w, (unsigned int)c->h);
|
||
|
|
} else {
|
||
|
|
configure(c);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
wc.x = ev->x;
|
||
|
|
wc.y = ev->y;
|
||
|
|
wc.width = ev->width;
|
||
|
|
wc.height = ev->height;
|
||
|
|
wc.border_width = ev->border_width;
|
||
|
|
wc.sibling = ev->above;
|
||
|
|
wc.stack_mode = ev->detail;
|
||
|
|
XConfigureWindow(dpy, ev->window, (unsigned int)ev->value_mask, &wc);
|
||
|
|
}
|
||
|
|
XSync(dpy, False);
|
||
|
|
}
|
||
|
|
|
||
|
|
static Monitor *createmon(void) {
|
||
|
|
Monitor *m = ecalloc(1, sizeof(Monitor));
|
||
|
|
m->tagset[0] = m->tagset[1] = 1;
|
||
|
|
m->mfact = mfact;
|
||
|
|
m->nmaster = nmaster;
|
||
|
|
m->showbar = showbar;
|
||
|
|
m->topbar = topbar;
|
||
|
|
m->lt[0] = &layouts[0];
|
||
|
|
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||
|
|
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||
|
|
return m;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void destroynotify(XEvent *e) {
|
||
|
|
Client *c;
|
||
|
|
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||
|
|
if ((c = wintoclient(ev->window)))
|
||
|
|
unmanage(c, 1);
|
||
|
|
else if ((c = wintosystrayicon(ev->window))) {
|
||
|
|
removesystrayicon(c);
|
||
|
|
updatesystray(1);
|
||
|
|
drawbars();
|
||
|
|
} else if (dockremove(ev->window)) {
|
||
|
|
recalcworkareas();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void detach(Client *c) {
|
||
|
|
Client **tc;
|
||
|
|
for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next) ;
|
||
|
|
*tc = c->next;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void detachstack(Client *c) {
|
||
|
|
Client **tc, *t;
|
||
|
|
for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext) ;
|
||
|
|
*tc = c->snext;
|
||
|
|
if (c == c->mon->sel) {
|
||
|
|
for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext) ;
|
||
|
|
c->mon->sel = t;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static Monitor *dirtomon(int dir) {
|
||
|
|
Monitor *m = NULL;
|
||
|
|
if (dir > 0) {
|
||
|
|
if (!(m = selmon->next)) m = mons;
|
||
|
|
} else if (selmon == mons) {
|
||
|
|
for (m = mons; m->next; m = m->next) ;
|
||
|
|
} else {
|
||
|
|
for (m = mons; m->next != selmon; m = m->next) ;
|
||
|
|
}
|
||
|
|
return m;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void drawbar(Monitor *m) {
|
||
|
|
int x, w, tw = 0, stw = 0;
|
||
|
|
int boxs = (int)drw->font->h / 9;
|
||
|
|
int boxw = (int)drw->font->h / 6 + 2;
|
||
|
|
unsigned int i, occ = 0, urg = 0;
|
||
|
|
Client *c;
|
||
|
|
|
||
|
|
if (!m->showbar) return;
|
||
|
|
|
||
|
|
if (showsystray && m == systraytomon(m) && !systrayonleft)
|
||
|
|
stw = (int)getsystraywidth();
|
||
|
|
|
||
|
|
if (m == selmon) {
|
||
|
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||
|
|
tw = (int)TEXTW(stext) - lrpad / 2 + 2;
|
||
|
|
drw_text(drw, m->ww - tw - stw, 0, (unsigned int)tw, (unsigned int)bh, lrpad / 2 - 2, stext, 0, False);
|
||
|
|
}
|
||
|
|
|
||
|
|
for (c = m->clients; c; c = c->next) {
|
||
|
|
occ |= c->tags;
|
||
|
|
if (c->isurgent) urg |= c->tags;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Launcher touch button */
|
||
|
|
drw_setscheme(drw, scheme[SchemeSel]);
|
||
|
|
int lpad = (launcher_w - (int)drw_font_getwidth(drw, "\xef\x83\x89", False)) / 2;
|
||
|
|
drw_text(drw, 0, 0, (unsigned int)launcher_w, (unsigned int)bh, (unsigned int)MAX(lpad, 4), "\xef\x83\x89", 0, False);
|
||
|
|
x = launcher_w;
|
||
|
|
|
||
|
|
for (i = 0; i < LENGTH(tags); i++) {
|
||
|
|
w = (int)TEXTW(tags[i]);
|
||
|
|
drw_setscheme(drw, scheme[m->tagset[m->seltags] & (1U << i) ? SchemeSel : SchemeNorm]);
|
||
|
|
drw_text(drw, x, 0, (unsigned int)w, (unsigned int)bh, lrpad / 2, tags[i], (urg & (1U << i)) != 0, False);
|
||
|
|
if (occ & (1U << i))
|
||
|
|
drw_rect(drw, x + boxs, boxs, (unsigned int)boxw, (unsigned int)boxw,
|
||
|
|
(m == selmon && selmon->sel && (selmon->sel->tags & (1U << i))),
|
||
|
|
(urg & (1U << i)) != 0);
|
||
|
|
x += w;
|
||
|
|
}
|
||
|
|
|
||
|
|
w = (int)TEXTW(m->ltsymbol);
|
||
|
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||
|
|
x = drw_text(drw, x, 0, (unsigned int)w, (unsigned int)bh, lrpad / 2, m->ltsymbol, 0, False);
|
||
|
|
|
||
|
|
int avail = m->ww - tw - stw - x;
|
||
|
|
if (avail > bh) {
|
||
|
|
if (m->sel) {
|
||
|
|
int title_w = avail > closebtn_w + 24 ? avail - closebtn_w : avail;
|
||
|
|
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||
|
|
drw_text(drw, x, 0, (unsigned int)title_w, (unsigned int)bh, lrpad / 2, m->sel->name, 0, False);
|
||
|
|
if (m->sel->isfloating)
|
||
|
|
drw_rect(drw, x + boxs, boxs, (unsigned int)boxw, (unsigned int)boxw, m->sel->isfixed, 0);
|
||
|
|
if (avail > closebtn_w + 24) {
|
||
|
|
int cpad = (closebtn_w - (int)drw_font_getwidth(drw, "\xc3\x97", False)) / 2;
|
||
|
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||
|
|
drw_text(drw, x + title_w, 0, (unsigned int)closebtn_w, (unsigned int)bh, (unsigned int)MAX(cpad, 4), "\xc3\x97", 0, False);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
drw_setscheme(drw, scheme[SchemeNorm]);
|
||
|
|
drw_rect(drw, x, 0, (unsigned int)avail, (unsigned int)bh, 1, 1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
drw_map(drw, m->barwin, 0, 0, (unsigned int)(m->ww - stw), (unsigned int)bh);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void drawbars(void) {
|
||
|
|
Monitor *m;
|
||
|
|
for (m = mons; m; m = m->next) drawbar(m);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void enternotify(XEvent *e) {
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
XCrossingEvent *ev = &e->xcrossing;
|
||
|
|
if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
|
||
|
|
return;
|
||
|
|
c = wintoclient(ev->window);
|
||
|
|
m = c ? c->mon : wintomon(ev->window);
|
||
|
|
if (m != selmon) {
|
||
|
|
Monitor *oldm = selmon;
|
||
|
|
unfocus(selmon->sel, 1);
|
||
|
|
selmon = m;
|
||
|
|
if (showsystray && !systraypinning && oldm) {
|
||
|
|
resizebarwin(oldm);
|
||
|
|
resizebarwin(m);
|
||
|
|
updatesystray(1);
|
||
|
|
}
|
||
|
|
} else if (!c || c == selmon->sel) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
focus(c);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void expose(XEvent *e) {
|
||
|
|
Monitor *m;
|
||
|
|
XExposeEvent *ev = &e->xexpose;
|
||
|
|
if (ev->count == 0 && (m = wintomon(ev->window))) {
|
||
|
|
drawbar(m);
|
||
|
|
if (m == selmon) updatesystray(0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void focus(Client *c) {
|
||
|
|
if (!c || !ISVISIBLE(c))
|
||
|
|
for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext) ;
|
||
|
|
if (selmon->sel && selmon->sel != c)
|
||
|
|
unfocus(selmon->sel, 0);
|
||
|
|
if (c) {
|
||
|
|
if (c->mon != selmon) selmon = c->mon;
|
||
|
|
if (c->isurgent) seturgent(c, 0);
|
||
|
|
detachstack(c);
|
||
|
|
attachstack(c);
|
||
|
|
grabbuttons(c, 1);
|
||
|
|
XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
|
||
|
|
setfocus(c);
|
||
|
|
} else {
|
||
|
|
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||
|
|
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
||
|
|
}
|
||
|
|
selmon->sel = c;
|
||
|
|
drawbars();
|
||
|
|
}
|
||
|
|
|
||
|
|
static void focusin(XEvent *e) {
|
||
|
|
XFocusChangeEvent *ev = &e->xfocus;
|
||
|
|
if (ev->mode == NotifyGrab || ev->mode == NotifyWhileGrabbed)
|
||
|
|
return;
|
||
|
|
if (selmon->sel && ev->window != selmon->sel->win)
|
||
|
|
setfocus(selmon->sel);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void focusmon(const Arg *arg) {
|
||
|
|
Monitor *m;
|
||
|
|
if (!mons->next) return;
|
||
|
|
if ((m = dirtomon(arg->i)) == selmon) return;
|
||
|
|
Monitor *oldm = selmon;
|
||
|
|
unfocus(selmon->sel, 0);
|
||
|
|
selmon = m;
|
||
|
|
if (showsystray && !systraypinning) {
|
||
|
|
resizebarwin(oldm);
|
||
|
|
resizebarwin(m);
|
||
|
|
updatesystray(1);
|
||
|
|
}
|
||
|
|
focus(NULL);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void focusstack(const Arg *arg) {
|
||
|
|
Client *c = NULL, *i;
|
||
|
|
if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
|
||
|
|
return;
|
||
|
|
if (arg->i > 0) {
|
||
|
|
for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next) ;
|
||
|
|
if (!c)
|
||
|
|
for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next) ;
|
||
|
|
} else {
|
||
|
|
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)) c = i;
|
||
|
|
}
|
||
|
|
if (c) {
|
||
|
|
focus(c);
|
||
|
|
restack(selmon);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static Atom getatomprop(Client *c, Atom prop) {
|
||
|
|
int di;
|
||
|
|
unsigned long dl;
|
||
|
|
unsigned char *p = NULL;
|
||
|
|
Atom da, atom = None;
|
||
|
|
if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
|
||
|
|
&da, &di, &dl, &dl, &p) == Success && p) {
|
||
|
|
atom = *(Atom *)p;
|
||
|
|
XFree(p);
|
||
|
|
}
|
||
|
|
return atom;
|
||
|
|
}
|
||
|
|
|
||
|
|
static int getrootptr(int *x, int *y) {
|
||
|
|
int di;
|
||
|
|
unsigned int dui;
|
||
|
|
Window dummy;
|
||
|
|
return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
|
||
|
|
}
|
||
|
|
|
||
|
|
static long getstate(Window w) {
|
||
|
|
int format;
|
||
|
|
long result = -1;
|
||
|
|
unsigned char *p = NULL;
|
||
|
|
unsigned long n, extra;
|
||
|
|
Atom real;
|
||
|
|
if (XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
|
||
|
|
&real, &format, &n, &extra, (unsigned char **)&p) != Success)
|
||
|
|
return -1;
|
||
|
|
if (n != 0) result = *p;
|
||
|
|
XFree(p);
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
static unsigned int getsystraywidth(void) {
|
||
|
|
unsigned int w = 0;
|
||
|
|
Client *i;
|
||
|
|
if (showsystray && systray) {
|
||
|
|
for (i = systray->icons; i; i = i->next)
|
||
|
|
if (i->tags) w += (unsigned int)i->w + systrayspacing;
|
||
|
|
}
|
||
|
|
return w ? w + systrayspacing : 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static int gettextprop(Window w, Atom atom, char *text, unsigned int size) {
|
||
|
|
char **list = NULL;
|
||
|
|
int n;
|
||
|
|
XTextProperty name;
|
||
|
|
|
||
|
|
if (!text || size == 0) return 0;
|
||
|
|
text[0] = '\0';
|
||
|
|
if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems) return 0;
|
||
|
|
if (name.encoding == XA_STRING) {
|
||
|
|
strncpy(text, (char *)name.value, size - 1);
|
||
|
|
} else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) {
|
||
|
|
strncpy(text, *list, size - 1);
|
||
|
|
XFreeStringList(list);
|
||
|
|
}
|
||
|
|
text[size - 1] = '\0';
|
||
|
|
XFree(name.value);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void grabbuttons(Client *c, int focused) {
|
||
|
|
updatenumlockmask();
|
||
|
|
unsigned int i, j;
|
||
|
|
unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
|
||
|
|
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||
|
|
if (!focused)
|
||
|
|
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
|
||
|
|
BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
|
||
|
|
for (i = 0; i < LENGTH(buttons); i++) {
|
||
|
|
if (buttons[i].click == ClkClientWin) {
|
||
|
|
for (j = 0; j < LENGTH(modifiers); j++) {
|
||
|
|
XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j],
|
||
|
|
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||
|
|
if (buttons[i].mask & Mod4Mask) {
|
||
|
|
XGrabButton(dpy, buttons[i].button, buttons[i].mask | Mod5Mask | modifiers[j],
|
||
|
|
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void grabkeys(void) {
|
||
|
|
updatenumlockmask();
|
||
|
|
unsigned int i, j;
|
||
|
|
unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
|
||
|
|
int active_latch = super_latched && (now_ms() <= super_latch_until);
|
||
|
|
|
||
|
|
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||
|
|
|
||
|
|
/* Monitor Super_L (Fn+Alt) for comfortable one-shot tap-latch fallback */
|
||
|
|
KeyCode super_kc = XKeysymToKeycode(dpy, XK_Super_L);
|
||
|
|
if (super_kc) {
|
||
|
|
for (j = 0; j < LENGTH(modifiers); j++) {
|
||
|
|
XGrabKey(dpy, super_kc, modifiers[j], root, True, GrabModeSync, GrabModeAsync);
|
||
|
|
XGrabKey(dpy, super_kc, Mod5Mask | modifiers[j], root, True, GrabModeSync, GrabModeAsync);
|
||
|
|
XGrabKey(dpy, super_kc, Mod1Mask | modifiers[j], root, True, GrabModeSync, GrabModeAsync);
|
||
|
|
XGrabKey(dpy, super_kc, Mod1Mask | Mod5Mask | modifiers[j], root, True, GrabModeSync, GrabModeAsync);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
int min_kc = 8, max_kc = 255;
|
||
|
|
XDisplayKeycodes(dpy, &min_kc, &max_kc);
|
||
|
|
|
||
|
|
for (i = 0; i < LENGTH(keys); i++) {
|
||
|
|
int kc_i;
|
||
|
|
for (kc_i = min_kc; kc_i <= max_kc; kc_i++) {
|
||
|
|
KeyCode kc = (KeyCode)kc_i;
|
||
|
|
KeySym s0 = XkbKeycodeToKeysym(dpy, kc, 0, 0);
|
||
|
|
KeySym s2 = XkbKeycodeToKeysym(dpy, kc, 0, 2);
|
||
|
|
KeySym s3 = XkbKeycodeToKeysym(dpy, kc, 0, 3);
|
||
|
|
|
||
|
|
if (s0 == keys[i].keysym) {
|
||
|
|
for (j = 0; j < LENGTH(modifiers); j++) {
|
||
|
|
XGrabKey(dpy, kc, keys[i].mod | modifiers[j], root, True, GrabModeAsync, GrabModeAsync);
|
||
|
|
if (keys[i].mod & Mod4Mask) {
|
||
|
|
/* Fn+Alt frequently preserves Mod1Mask and/or Mod5Mask alongside Mod4Mask under XKB */
|
||
|
|
XGrabKey(dpy, kc, keys[i].mod | Mod5Mask | modifiers[j], root, True, GrabModeAsync, GrabModeAsync);
|
||
|
|
XGrabKey(dpy, kc, keys[i].mod | Mod1Mask | modifiers[j], root, True, GrabModeAsync, GrabModeAsync);
|
||
|
|
XGrabKey(dpy, kc, keys[i].mod | Mod1Mask | Mod5Mask | modifiers[j], root, True, GrabModeAsync, GrabModeAsync);
|
||
|
|
if (active_latch) {
|
||
|
|
XGrabKey(dpy, kc, (keys[i].mod & ~Mod4Mask) | modifiers[j], root, True, GrabModeAsync, GrabModeAsync);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else if (!(keys[i].mod & Mod4Mask) && s2 == keys[i].keysym && s0 != keys[i].keysym) {
|
||
|
|
/* Grab Fn (ISO_Level3_Shift / Mod5Mask) Layer-3 multimedia/system keys */
|
||
|
|
for (j = 0; j < LENGTH(modifiers); j++) {
|
||
|
|
XGrabKey(dpy, kc, keys[i].mod | Mod5Mask | modifiers[j], root, True, GrabModeAsync, GrabModeAsync);
|
||
|
|
}
|
||
|
|
} else if (!(keys[i].mod & Mod4Mask) && s3 == keys[i].keysym && s2 != keys[i].keysym && s0 != keys[i].keysym) {
|
||
|
|
/* Grab Shift+Fn (ShiftMask | Mod5Mask) Layer-4 keysyms */
|
||
|
|
for (j = 0; j < LENGTH(modifiers); j++) {
|
||
|
|
XGrabKey(dpy, kc, keys[i].mod | ShiftMask | Mod5Mask | modifiers[j], root, True, GrabModeAsync, GrabModeAsync);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void grid(Monitor *m) {
|
||
|
|
unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
|
||
|
|
Client *c;
|
||
|
|
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
|
||
|
|
if (n == 0) return;
|
||
|
|
|
||
|
|
for (cols = 0; cols <= n / 2; cols++)
|
||
|
|
if (cols * cols >= n) break;
|
||
|
|
if (n == 5) cols = 2;
|
||
|
|
rows = (cols && (cols - 1) * cols >= n) ? cols - 1 : cols;
|
||
|
|
if (rows == 0) rows = 1;
|
||
|
|
ch = (unsigned int)m->wh / rows;
|
||
|
|
cw = (unsigned int)(m->ww / (cols ? cols : 1));
|
||
|
|
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||
|
|
cx = (unsigned int)m->wx + (i / rows) * cw;
|
||
|
|
cy = (unsigned int)m->wy + (i % rows) * ch;
|
||
|
|
ah = (i + 1) % rows == 0 ? (unsigned int)m->wh - (i % rows) * ch : ch;
|
||
|
|
aw = (i / rows + 1) >= cols ? (unsigned int)m->ww - (i / rows) * cw : cw;
|
||
|
|
resize(c, (int)cx, (int)cy, (int)aw - 2 * c->bw, (int)ah - 2 * c->bw, 0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void incnmaster(const Arg *arg) {
|
||
|
|
selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void keypress(XEvent *e) {
|
||
|
|
unsigned int i;
|
||
|
|
XKeyEvent *ev = &e->xkey;
|
||
|
|
KeySym sym_ev = XLookupKeysym(ev, 0);
|
||
|
|
KeySym sym0 = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0);
|
||
|
|
KeySym sym_lvl2 = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 2);
|
||
|
|
KeySym sym_lvl3 = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 3);
|
||
|
|
unsigned long long t = now_ms();
|
||
|
|
int active_latch = super_latched && (t <= super_latch_until);
|
||
|
|
|
||
|
|
if (sym0 == XK_Super_L || sym_ev == XK_Super_L) {
|
||
|
|
super_down = 1;
|
||
|
|
super_dirty = 0;
|
||
|
|
super_down_ms = t;
|
||
|
|
XAllowEvents(dpy, ReplayKeyboard, ev->time);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (super_down && sym0 != XK_Alt_L && sym0 != XK_ISO_Level3_Shift &&
|
||
|
|
sym0 != XK_Shift_L && sym0 != XK_Shift_R &&
|
||
|
|
sym0 != XK_Control_L && sym0 != XK_Control_R) {
|
||
|
|
super_dirty = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (i = 0; i < LENGTH(keys); i++) {
|
||
|
|
int matched = 0;
|
||
|
|
if (sym0 == keys[i].keysym || sym_ev == keys[i].keysym) {
|
||
|
|
if (CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)) {
|
||
|
|
matched = 1;
|
||
|
|
} else if ((keys[i].mod & Mod4Mask) &&
|
||
|
|
CLEANMASK(keys[i].mod) == CLEANMASK(ev->state & ~(Mod1Mask | Mod5Mask))) {
|
||
|
|
matched = 1;
|
||
|
|
} else if (active_latch && (keys[i].mod & Mod4Mask) &&
|
||
|
|
CLEANMASK(keys[i].mod & ~Mod4Mask) == CLEANMASK(ev->state & ~(Mod1Mask | Mod5Mask))) {
|
||
|
|
matched = 1;
|
||
|
|
super_latched = 0;
|
||
|
|
grabkeys();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!matched && !(keys[i].mod & Mod4Mask) &&
|
||
|
|
(ev->state & Mod5Mask) && !(ev->state & (Mod4Mask | Mod1Mask)) &&
|
||
|
|
sym_lvl2 == keys[i].keysym && sym0 != keys[i].keysym) {
|
||
|
|
if (CLEANMASK(keys[i].mod) == CLEANMASK(ev->state & ~Mod5Mask))
|
||
|
|
matched = 1;
|
||
|
|
}
|
||
|
|
if (!matched && !(keys[i].mod & Mod4Mask) &&
|
||
|
|
(ev->state & (ShiftMask | Mod5Mask)) == (ShiftMask | Mod5Mask) &&
|
||
|
|
!(ev->state & (Mod4Mask | Mod1Mask)) &&
|
||
|
|
sym_lvl3 == keys[i].keysym && sym_lvl2 != keys[i].keysym && sym0 != keys[i].keysym) {
|
||
|
|
if (CLEANMASK(keys[i].mod) == CLEANMASK(ev->state & ~(ShiftMask | Mod5Mask)))
|
||
|
|
matched = 1;
|
||
|
|
}
|
||
|
|
if (matched && keys[i].func) {
|
||
|
|
keys[i].func(&(keys[i].arg));
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (active_latch) {
|
||
|
|
super_latched = 0;
|
||
|
|
grabkeys();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void keyrelease(XEvent *e) {
|
||
|
|
XKeyEvent *ev = &e->xkey;
|
||
|
|
KeySym sym0 = XkbKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0, 0);
|
||
|
|
unsigned long long t = now_ms();
|
||
|
|
|
||
|
|
if ((sym0 == XK_Super_L || XLookupKeysym(ev, 0) == XK_Super_L) && super_down) {
|
||
|
|
super_down = 0;
|
||
|
|
if (!super_dirty && (t - super_down_ms) < 550ULL) {
|
||
|
|
super_latched = !super_latched;
|
||
|
|
super_latch_until = t + 1500ULL;
|
||
|
|
grabkeys();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void killclient(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
if (!selmon->sel) return;
|
||
|
|
if (!sendevent(selmon->sel->win, wmatom[WMDelete], NoEventMask,
|
||
|
|
(long)wmatom[WMDelete], CurrentTime, 0, 0, 0)) {
|
||
|
|
XGrabServer(dpy);
|
||
|
|
XSetErrorHandler(xerrordummy);
|
||
|
|
XSetCloseDownMode(dpy, DestroyAll);
|
||
|
|
XKillClient(dpy, selmon->sel->win);
|
||
|
|
XSync(dpy, False);
|
||
|
|
XSetErrorHandler(xerror);
|
||
|
|
XUngrabServer(dpy);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static const char *xrm_lookup(XrmDatabase db, const char *k1, const char *k2, const char *k3) {
|
||
|
|
char *type = NULL;
|
||
|
|
XrmValue val;
|
||
|
|
if (k1 && XrmGetResource(db, k1, "*", &type, &val) && val.addr && val.addr[0])
|
||
|
|
return val.addr;
|
||
|
|
if (k2 && XrmGetResource(db, k2, "*", &type, &val) && val.addr && val.addr[0])
|
||
|
|
return val.addr;
|
||
|
|
if (k3 && XrmGetResource(db, k3, "*", &type, &val) && val.addr && val.addr[0])
|
||
|
|
return val.addr;
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void loadxres(void) {
|
||
|
|
XrmInitialize();
|
||
|
|
XrmDatabase db = anode_open_xres_db(dpy);
|
||
|
|
double dpi = 96.0;
|
||
|
|
anode_read_xres_scale_from_db(db, dpy, &dpi, &ui_scale, NULL);
|
||
|
|
|
||
|
|
borderpx = (unsigned int)anode_scale_px((int)base_borderpx, ui_scale);
|
||
|
|
snap = (unsigned int)anode_scale_px((int)base_snap, ui_scale);
|
||
|
|
systrayspacing = (unsigned int)anode_scale_px((int)base_systrayspacing, ui_scale);
|
||
|
|
launcher_w = anode_scale_px(42, ui_scale);
|
||
|
|
closebtn_w = anode_scale_px(38, ui_scale);
|
||
|
|
|
||
|
|
const char *v;
|
||
|
|
if (db && (v = xrm_lookup(db, "dwm.font", NULL, NULL))) {
|
||
|
|
snprintf(xres_font, sizeof(xres_font), "%s", v);
|
||
|
|
font = xres_font;
|
||
|
|
} else {
|
||
|
|
const char *ff = db ? xrm_lookup(db, "theme.fontFace", NULL, NULL) : NULL;
|
||
|
|
const char *ic = db ? xrm_lookup(db, "theme.iconFontFace", NULL, NULL) : NULL;
|
||
|
|
const char *bs = db ? xrm_lookup(db, "theme.baseFontSize", NULL, NULL) : NULL;
|
||
|
|
int px = bs ? atoi(bs) : anode_scale_px(15, ui_scale);
|
||
|
|
if (px < 8 || px > 96) px = anode_scale_px(15, ui_scale);
|
||
|
|
snprintf(xres_font, sizeof(xres_font), "%s, %s %dpx",
|
||
|
|
ff ? ff : "Fira Code",
|
||
|
|
ic ? ic : "DejaVuSansM Nerd Font", px);
|
||
|
|
font = xres_font;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (db) {
|
||
|
|
if ((v = xrm_lookup(db, "dwm.normbgcolor", "dwm.background", "theme.bgBar")))
|
||
|
|
snprintf(normbgcolor, sizeof(normbgcolor), "%s", v);
|
||
|
|
if ((v = xrm_lookup(db, "dwm.normfgcolor", "dwm.foreground", "theme.fgMain")))
|
||
|
|
snprintf(normfgcolor, sizeof(normfgcolor), "%s", v);
|
||
|
|
if ((v = xrm_lookup(db, "dwm.normbordercolor", "dwm.border", "theme.border")))
|
||
|
|
snprintf(normbordercolor, sizeof(normbordercolor), "%s", v);
|
||
|
|
if ((v = xrm_lookup(db, "dwm.selbgcolor", "dwm.selbackground", "theme.selBg")))
|
||
|
|
snprintf(selbgcolor, sizeof(selbgcolor), "%s", v);
|
||
|
|
if ((v = xrm_lookup(db, "dwm.selfgcolor", "dwm.selforeground", "theme.selFg")))
|
||
|
|
snprintf(selfgcolor, sizeof(selfgcolor), "%s", v);
|
||
|
|
if ((v = xrm_lookup(db, "dwm.selbordercolor", "dwm.selborder", "theme.accent")))
|
||
|
|
snprintf(selbordercolor, sizeof(selbordercolor), "%s", v);
|
||
|
|
if ((v = xrm_lookup(db, "dwm.borderpx", NULL, NULL))) {
|
||
|
|
int b = atoi(v);
|
||
|
|
if (b >= 1 && b <= 12) borderpx = (unsigned int)b;
|
||
|
|
}
|
||
|
|
XrmDestroyDatabase(db);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void reloadxres(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
Monitor *m;
|
||
|
|
Client *c;
|
||
|
|
loadxres();
|
||
|
|
if (dwmfont) {
|
||
|
|
drw_font_free(dwmfont);
|
||
|
|
dwmfont = NULL;
|
||
|
|
}
|
||
|
|
dwmfont = drw_font_create(drw, font);
|
||
|
|
drw_setfont(drw, dwmfont);
|
||
|
|
lrpad = (int)dwmfont->h + anode_scale_px(4, ui_scale);
|
||
|
|
bh = MAX((int)dwmfont->h + anode_scale_px(12, ui_scale), anode_scale_px(30, ui_scale));
|
||
|
|
drw_resize(drw, (unsigned int)sw, (unsigned int)bh);
|
||
|
|
|
||
|
|
free(scheme[SchemeNorm]);
|
||
|
|
free(scheme[SchemeSel]);
|
||
|
|
scheme[SchemeNorm] = drw_scm_create(drw, (const char **)colors[SchemeNorm], 3);
|
||
|
|
scheme[SchemeSel] = drw_scm_create(drw, (const char **)colors[SchemeSel], 3);
|
||
|
|
|
||
|
|
updatebars();
|
||
|
|
for (m = mons; m; m = m->next) {
|
||
|
|
updatebarpos(m);
|
||
|
|
resizebarwin(m);
|
||
|
|
for (c = m->clients; c; c = c->next) {
|
||
|
|
c->bw = (int)borderpx;
|
||
|
|
XSetWindowBorder(dpy, c->win,
|
||
|
|
scheme[c == selmon->sel ? SchemeSel : SchemeNorm][ColBorder].pixel);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (showsystray && systray) {
|
||
|
|
for (c = systray->icons; c; c = c->next)
|
||
|
|
updatesystrayicongeom(c, c->w, c->h);
|
||
|
|
}
|
||
|
|
updatesystray(1);
|
||
|
|
updateworkarea();
|
||
|
|
arrange(NULL);
|
||
|
|
drawbars();
|
||
|
|
XSync(dpy, False);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void manage(Window w, XWindowAttributes *wa) {
|
||
|
|
Client *c, *t = NULL;
|
||
|
|
Window trans = None;
|
||
|
|
XWindowChanges wc;
|
||
|
|
|
||
|
|
c = ecalloc(1, sizeof(Client));
|
||
|
|
c->win = w;
|
||
|
|
c->x = c->oldx = wa->x;
|
||
|
|
c->y = c->oldy = wa->y;
|
||
|
|
c->w = c->oldw = wa->width;
|
||
|
|
c->h = c->oldh = wa->height;
|
||
|
|
c->oldbw = wa->border_width;
|
||
|
|
|
||
|
|
updatetitle(c);
|
||
|
|
if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
|
||
|
|
c->mon = t->mon;
|
||
|
|
c->tags = t->tags;
|
||
|
|
} else {
|
||
|
|
c->mon = selmon;
|
||
|
|
applyrules(c);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
|
||
|
|
c->x = c->mon->wx + c->mon->ww - WIDTH(c);
|
||
|
|
if (c->y + HEIGHT(c) > c->mon->wy + c->mon->wh)
|
||
|
|
c->y = c->mon->wy + c->mon->wh - HEIGHT(c);
|
||
|
|
c->x = MAX(c->x, c->mon->wx);
|
||
|
|
c->y = MAX(c->y, c->mon->wy);
|
||
|
|
c->bw = (int)borderpx;
|
||
|
|
|
||
|
|
wc.border_width = c->bw;
|
||
|
|
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
|
||
|
|
XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
|
||
|
|
configure(c);
|
||
|
|
updatewindowtype(c);
|
||
|
|
updatesizehints(c);
|
||
|
|
updatewmhints(c);
|
||
|
|
XSelectInput(dpy, w, EnterWindowMask | FocusChangeMask | PropertyChangeMask | StructureNotifyMask);
|
||
|
|
grabbuttons(c, 0);
|
||
|
|
if (!c->isfloating)
|
||
|
|
c->isfloating = c->oldstate = (trans != None || c->isfixed);
|
||
|
|
if (c->isfloating && !c->isfullscreen && wa->x == 0 && wa->y == 0) {
|
||
|
|
c->x = c->mon->wx + (c->mon->ww - WIDTH(c)) / 2;
|
||
|
|
c->y = c->mon->wy + (c->mon->wh - HEIGHT(c)) / 2;
|
||
|
|
if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
|
||
|
|
c->x = c->mon->wx + c->mon->ww - WIDTH(c);
|
||
|
|
if (c->y + HEIGHT(c) > c->mon->wy + c->mon->wh)
|
||
|
|
c->y = c->mon->wy + c->mon->wh - HEIGHT(c);
|
||
|
|
c->x = MAX(c->x, c->mon->wx);
|
||
|
|
c->y = MAX(c->y, c->mon->wy);
|
||
|
|
}
|
||
|
|
if (c->isfloating)
|
||
|
|
XRaiseWindow(dpy, c->win);
|
||
|
|
attach(c);
|
||
|
|
attachstack(c);
|
||
|
|
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||
|
|
(unsigned char *)&(c->win), 1);
|
||
|
|
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, (unsigned int)c->w, (unsigned int)c->h);
|
||
|
|
setclientstate(c, NormalState);
|
||
|
|
if (c->mon == selmon) unfocus(selmon->sel, 0);
|
||
|
|
c->mon->sel = c;
|
||
|
|
arrange(c->mon);
|
||
|
|
XMapWindow(dpy, c->win);
|
||
|
|
focus(NULL);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void mappingnotify(XEvent *e) {
|
||
|
|
XMappingEvent *ev = &e->xmapping;
|
||
|
|
XRefreshKeyboardMapping(ev);
|
||
|
|
if (ev->request == MappingKeyboard) grabkeys();
|
||
|
|
}
|
||
|
|
|
||
|
|
static void mapnotify(XEvent *e) {
|
||
|
|
XMapEvent *ev = &e->xmap;
|
||
|
|
if (ev->window == root || (systray && ev->window == systray->win))
|
||
|
|
return;
|
||
|
|
if (!wintoclient(ev->window) && !wintosystrayicon(ev->window) && isdockwin(ev->window)) {
|
||
|
|
XSelectInput(dpy, ev->window, PropertyChangeMask);
|
||
|
|
dockadd(ev->window);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void reparentnotify(XEvent *e) {
|
||
|
|
XReparentEvent *ev = &e->xreparent;
|
||
|
|
Client *i;
|
||
|
|
if ((i = wintosystrayicon(ev->window)) && systray && ev->parent != systray->win) {
|
||
|
|
removesystrayicon(i);
|
||
|
|
updatesystray(1);
|
||
|
|
drawbars();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void maprequest(XEvent *e) {
|
||
|
|
static XWindowAttributes wa;
|
||
|
|
XMapRequestEvent *ev = &e->xmaprequest;
|
||
|
|
Client *i;
|
||
|
|
if ((i = wintosystrayicon(ev->window))) {
|
||
|
|
long flags = 0;
|
||
|
|
int mapped = getxembedflags(i->win, &flags) ? ((flags & XEMBED_MAPPED) ? 1 : 0) : 1;
|
||
|
|
i->tags = mapped ? 1 : 0;
|
||
|
|
if (mapped) {
|
||
|
|
XMapRaised(dpy, i->win);
|
||
|
|
setclientstate(i, NormalState);
|
||
|
|
sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime,
|
||
|
|
XEMBED_WINDOW_ACTIVATE, 0, (long)systray->win, XEMBED_EMBEDDED_VERSION_VAL);
|
||
|
|
}
|
||
|
|
updatesystray(1);
|
||
|
|
drawbars();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (isdockwin(ev->window)) {
|
||
|
|
XSelectInput(dpy, ev->window, StructureNotifyMask | PropertyChangeMask);
|
||
|
|
dockadd(ev->window);
|
||
|
|
XMapWindow(dpy, ev->window);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (!XGetWindowAttributes(dpy, ev->window, &wa) || wa.override_redirect)
|
||
|
|
return;
|
||
|
|
if (!wintoclient(ev->window))
|
||
|
|
manage(ev->window, &wa);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void monocle(Monitor *m) {
|
||
|
|
unsigned int n = 0;
|
||
|
|
Client *c;
|
||
|
|
for (c = m->clients; c; c = c->next)
|
||
|
|
if (ISVISIBLE(c)) n++;
|
||
|
|
if (n > 0)
|
||
|
|
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%u]", n);
|
||
|
|
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
||
|
|
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void motionnotify(XEvent *e) {
|
||
|
|
static Monitor *mon = NULL;
|
||
|
|
Monitor *m;
|
||
|
|
XMotionEvent *ev = &e->xmotion;
|
||
|
|
if (ev->window != root) return;
|
||
|
|
if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
|
||
|
|
Monitor *oldm = selmon;
|
||
|
|
unfocus(selmon->sel, 1);
|
||
|
|
selmon = m;
|
||
|
|
if (showsystray && !systraypinning && oldm && oldm != m) {
|
||
|
|
resizebarwin(oldm);
|
||
|
|
resizebarwin(m);
|
||
|
|
updatesystray(1);
|
||
|
|
}
|
||
|
|
focus(NULL);
|
||
|
|
}
|
||
|
|
mon = m;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void movemouse(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
int x, y, ocx, ocy, nx, ny;
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
XEvent ev;
|
||
|
|
Time lasttime = 0;
|
||
|
|
|
||
|
|
if (!(c = selmon->sel) || c->isfullscreen) return;
|
||
|
|
restack(selmon);
|
||
|
|
ocx = c->x;
|
||
|
|
ocy = c->y;
|
||
|
|
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||
|
|
None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
|
||
|
|
return;
|
||
|
|
if (!getrootptr(&x, &y)) return;
|
||
|
|
do {
|
||
|
|
XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
||
|
|
switch (ev.type) {
|
||
|
|
case ConfigureRequest:
|
||
|
|
case Expose:
|
||
|
|
case MapRequest:
|
||
|
|
handler[ev.type](&ev);
|
||
|
|
break;
|
||
|
|
case MotionNotify:
|
||
|
|
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) continue;
|
||
|
|
lasttime = ev.xmotion.time;
|
||
|
|
nx = ocx + (ev.xmotion.x - x);
|
||
|
|
ny = ocy + (ev.xmotion.y - y);
|
||
|
|
if (abs(selmon->wx - nx) < (int)snap) nx = selmon->wx;
|
||
|
|
else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < (int)snap)
|
||
|
|
nx = selmon->wx + selmon->ww - WIDTH(c);
|
||
|
|
if (abs(selmon->wy - ny) < (int)snap) ny = selmon->wy;
|
||
|
|
else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < (int)snap)
|
||
|
|
ny = selmon->wy + selmon->wh - HEIGHT(c);
|
||
|
|
if (!c->isfloating && selmon->lt[selmon->sellt]->arrange &&
|
||
|
|
(abs(nx - c->x) > (int)snap || abs(ny - c->y) > (int)snap))
|
||
|
|
togglefloating(NULL);
|
||
|
|
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
|
||
|
|
resize(c, nx, ny, c->w, c->h, 1);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
} while (ev.type != ButtonRelease);
|
||
|
|
XUngrabPointer(dpy, CurrentTime);
|
||
|
|
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
|
||
|
|
sendmon(c, m);
|
||
|
|
selmon = m;
|
||
|
|
focus(NULL);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static Client *nexttiled(Client *c) {
|
||
|
|
for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next) ;
|
||
|
|
return c;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void pop(Client *c) {
|
||
|
|
detach(c);
|
||
|
|
attach(c);
|
||
|
|
focus(c);
|
||
|
|
arrange(c->mon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void propertynotify(XEvent *e) {
|
||
|
|
Client *c;
|
||
|
|
Window trans;
|
||
|
|
XPropertyEvent *ev = &e->xproperty;
|
||
|
|
|
||
|
|
if ((c = wintosystrayicon(ev->window))) {
|
||
|
|
if (ev->atom == XA_WM_NORMAL_HINTS) {
|
||
|
|
updatesizehints(c);
|
||
|
|
updatesystrayicongeom(c, c->w, c->h);
|
||
|
|
} else {
|
||
|
|
updatesystrayiconstate(c, ev);
|
||
|
|
}
|
||
|
|
updatesystray(1);
|
||
|
|
drawbars();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((ev->window == root) && (ev->atom == XA_RESOURCE_MANAGER) &&
|
||
|
|
ev->state != PropertyDelete) {
|
||
|
|
reloadxres(NULL);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ev->state != PropertyDelete &&
|
||
|
|
(ev->atom == netatom[NetWMStrutPartial] || ev->atom == netatom[NetWMStrut])) {
|
||
|
|
dockupdate(ev->window);
|
||
|
|
} else if (ev->state != PropertyDelete && ev->atom == netatom[NetWMWindowType] &&
|
||
|
|
isdockwin(ev->window) && !wintoclient(ev->window)) {
|
||
|
|
XSelectInput(dpy, ev->window, StructureNotifyMask | PropertyChangeMask);
|
||
|
|
dockadd(ev->window);
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((ev->window == root) && (ev->atom == XA_WM_NAME)) {
|
||
|
|
updatestatus();
|
||
|
|
} else if (ev->state == PropertyDelete) {
|
||
|
|
return;
|
||
|
|
} else if ((c = wintoclient(ev->window))) {
|
||
|
|
switch (ev->atom) {
|
||
|
|
case XA_WM_TRANSIENT_FOR:
|
||
|
|
if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) &&
|
||
|
|
(c->isfloating = (wintoclient(trans) != NULL)))
|
||
|
|
arrange(c->mon);
|
||
|
|
break;
|
||
|
|
case XA_WM_NORMAL_HINTS:
|
||
|
|
c->hintsvalid = 0;
|
||
|
|
break;
|
||
|
|
case XA_WM_HINTS:
|
||
|
|
updatewmhints(c);
|
||
|
|
drawbars();
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
|
||
|
|
updatetitle(c);
|
||
|
|
if (c == c->mon->sel) drawbar(c->mon);
|
||
|
|
}
|
||
|
|
if (ev->atom == netatom[NetWMWindowType])
|
||
|
|
updatewindowtype(c);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void quit(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
running = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static Monitor *recttomon(int x, int y, int w, int h) {
|
||
|
|
Monitor *m, *r = selmon;
|
||
|
|
int a, area = 0;
|
||
|
|
for (m = mons; m; m = m->next) {
|
||
|
|
if ((a = INTERSECT(x, y, w, h, m)) > area) {
|
||
|
|
area = a;
|
||
|
|
r = m;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return r;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void removesystrayicon(Client *i) {
|
||
|
|
Client **ii;
|
||
|
|
if (!showsystray || !i || !systray) return;
|
||
|
|
for (ii = &systray->icons; *ii && *ii != i; ii = &(*ii)->next) ;
|
||
|
|
if (*ii) *ii = i->next;
|
||
|
|
free(i);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void resize(Client *c, int x, int y, int w, int h, int interact) {
|
||
|
|
if (applysizehints(c, &x, &y, &w, &h, interact))
|
||
|
|
resizeclient(c, x, y, w, h);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void resizebarwin(Monitor *m) {
|
||
|
|
unsigned int w = (unsigned int)m->ww;
|
||
|
|
if (showsystray && m == systraytomon(m) && !systrayonleft)
|
||
|
|
w -= getsystraywidth();
|
||
|
|
XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, (unsigned int)bh);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void resizeclient(Client *c, int x, int y, int w, int h) {
|
||
|
|
XWindowChanges wc;
|
||
|
|
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;
|
||
|
|
XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
|
||
|
|
configure(c);
|
||
|
|
XSync(dpy, False);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void resizemouse(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
int ocx, ocy, nw, nh;
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
XEvent ev;
|
||
|
|
Time lasttime = 0;
|
||
|
|
|
||
|
|
if (!(c = selmon->sel) || c->isfullscreen) return;
|
||
|
|
restack(selmon);
|
||
|
|
ocx = c->x;
|
||
|
|
ocy = c->y;
|
||
|
|
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||
|
|
None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
|
||
|
|
return;
|
||
|
|
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
|
||
|
|
do {
|
||
|
|
XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
||
|
|
switch (ev.type) {
|
||
|
|
case ConfigureRequest:
|
||
|
|
case Expose:
|
||
|
|
case MapRequest:
|
||
|
|
handler[ev.type](&ev);
|
||
|
|
break;
|
||
|
|
case MotionNotify:
|
||
|
|
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) continue;
|
||
|
|
lasttime = ev.xmotion.time;
|
||
|
|
nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
|
||
|
|
nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 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 &&
|
||
|
|
(abs(nw - c->w) > (int)snap || abs(nh - c->h) > (int)snap))
|
||
|
|
togglefloating(NULL);
|
||
|
|
}
|
||
|
|
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
|
||
|
|
resize(c, c->x, c->y, nw, nh, 1);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
} while (ev.type != ButtonRelease);
|
||
|
|
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, 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) {
|
||
|
|
sendmon(c, m);
|
||
|
|
selmon = m;
|
||
|
|
focus(NULL);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void resizerequest(XEvent *e) {
|
||
|
|
XResizeRequestEvent *ev = &e->xresizerequest;
|
||
|
|
Client *i;
|
||
|
|
if ((i = wintosystrayicon(ev->window))) {
|
||
|
|
updatesystrayicongeom(i, ev->width, ev->height);
|
||
|
|
resizebarwin(selmon);
|
||
|
|
updatesystray(0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void restack(Monitor *m) {
|
||
|
|
Client *c;
|
||
|
|
XEvent ev;
|
||
|
|
XWindowChanges wc;
|
||
|
|
drawbar(m);
|
||
|
|
if (!m->sel) return;
|
||
|
|
if (m->sel->isfloating || !m->lt[m->sellt]->arrange)
|
||
|
|
XRaiseWindow(dpy, m->sel->win);
|
||
|
|
if (m->lt[m->sellt]->arrange) {
|
||
|
|
wc.stack_mode = Below;
|
||
|
|
wc.sibling = m->barwin;
|
||
|
|
for (c = m->stack; c; c = c->snext) {
|
||
|
|
if (!c->isfloating && ISVISIBLE(c)) {
|
||
|
|
XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
|
||
|
|
wc.sibling = c->win;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
XSync(dpy, False);
|
||
|
|
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)) ;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void run(void) {
|
||
|
|
XEvent ev;
|
||
|
|
struct pollfd pfd = { .fd = ConnectionNumber(dpy), .events = POLLIN };
|
||
|
|
XSync(dpy, False);
|
||
|
|
while (running) {
|
||
|
|
if (reload_pending) {
|
||
|
|
reload_pending = 0;
|
||
|
|
reloadxres(NULL);
|
||
|
|
}
|
||
|
|
if (super_latched && now_ms() > super_latch_until) {
|
||
|
|
super_latched = 0;
|
||
|
|
grabkeys();
|
||
|
|
}
|
||
|
|
while (XPending(dpy) > 0) {
|
||
|
|
XNextEvent(dpy, &ev);
|
||
|
|
if (handler[ev.type])
|
||
|
|
handler[ev.type](&ev);
|
||
|
|
}
|
||
|
|
if (!running) break;
|
||
|
|
int timeout_ms = super_latched ? 250 : -1;
|
||
|
|
int pr = poll(&pfd, 1, timeout_ms);
|
||
|
|
if (pr < 0 && errno != EINTR) break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void scan(void) {
|
||
|
|
unsigned int i, num;
|
||
|
|
Window d1, d2, *wins = NULL;
|
||
|
|
XWindowAttributes wa;
|
||
|
|
if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
|
||
|
|
for (i = 0; i < num; i++) {
|
||
|
|
if (!XGetWindowAttributes(dpy, wins[i], &wa))
|
||
|
|
continue;
|
||
|
|
if (wa.map_state == IsViewable && isdockwin(wins[i])) {
|
||
|
|
XSelectInput(dpy, wins[i], StructureNotifyMask | PropertyChangeMask);
|
||
|
|
dockadd(wins[i]);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
|
||
|
|
continue;
|
||
|
|
if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
|
||
|
|
manage(wins[i], &wa);
|
||
|
|
}
|
||
|
|
for (i = 0; i < num; i++) {
|
||
|
|
if (!XGetWindowAttributes(dpy, wins[i], &wa)) continue;
|
||
|
|
if (!wa.override_redirect && XGetTransientForHint(dpy, wins[i], &d1) &&
|
||
|
|
(wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
|
||
|
|
manage(wins[i], &wa);
|
||
|
|
}
|
||
|
|
if (wins) XFree(wins);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void sendmon(Client *c, Monitor *m) {
|
||
|
|
if (c->mon == m) return;
|
||
|
|
unfocus(c, 1);
|
||
|
|
detach(c);
|
||
|
|
detachstack(c);
|
||
|
|
c->mon = m;
|
||
|
|
c->tags = m->tagset[m->seltags];
|
||
|
|
attach(c);
|
||
|
|
attachstack(c);
|
||
|
|
focus(NULL);
|
||
|
|
arrange(NULL);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void setclientstate(Client *c, long state) {
|
||
|
|
long data[] = { state, None };
|
||
|
|
XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
|
||
|
|
PropModeReplace, (unsigned char *)data, 2);
|
||
|
|
}
|
||
|
|
|
||
|
|
static int sendevent(Window w, Atom proto, int mask, long d0, long d1, long d2, long d3, long d4) {
|
||
|
|
int n;
|
||
|
|
Atom *protocols, mt;
|
||
|
|
int exists = 0;
|
||
|
|
XEvent ev;
|
||
|
|
|
||
|
|
if (proto == wmatom[WMTakeFocus] || proto == wmatom[WMDelete]) {
|
||
|
|
mt = wmatom[WMProtocols];
|
||
|
|
if (XGetWMProtocols(dpy, w, &protocols, &n)) {
|
||
|
|
while (!exists && n--) exists = (protocols[n] == proto);
|
||
|
|
XFree(protocols);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
exists = True;
|
||
|
|
mt = proto;
|
||
|
|
}
|
||
|
|
if (exists) {
|
||
|
|
ev.type = ClientMessage;
|
||
|
|
ev.xclient.window = w;
|
||
|
|
ev.xclient.message_type = mt;
|
||
|
|
ev.xclient.format = 32;
|
||
|
|
ev.xclient.data.l[0] = d0;
|
||
|
|
ev.xclient.data.l[1] = d1;
|
||
|
|
ev.xclient.data.l[2] = d2;
|
||
|
|
ev.xclient.data.l[3] = d3;
|
||
|
|
ev.xclient.data.l[4] = d4;
|
||
|
|
XSendEvent(dpy, w, False, mask, &ev);
|
||
|
|
}
|
||
|
|
return exists;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void setfocus(Client *c) {
|
||
|
|
if (!c->neverfocus) {
|
||
|
|
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
||
|
|
XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32,
|
||
|
|
PropModeReplace, (unsigned char *)&(c->win), 1);
|
||
|
|
}
|
||
|
|
sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, (long)wmatom[WMTakeFocus], CurrentTime, 0, 0, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void setfullscreen(Client *c, int fullscreen) {
|
||
|
|
if (fullscreen && !c->isfullscreen) {
|
||
|
|
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
|
||
|
|
PropModeReplace, (unsigned char *)&netatom[NetWMFullscreen], 1);
|
||
|
|
c->isfullscreen = 1;
|
||
|
|
c->oldstate = c->isfloating;
|
||
|
|
c->oldbw = c->bw;
|
||
|
|
c->bw = 0;
|
||
|
|
c->isfloating = 1;
|
||
|
|
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
|
||
|
|
XRaiseWindow(dpy, c->win);
|
||
|
|
} else if (!fullscreen && c->isfullscreen) {
|
||
|
|
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
|
||
|
|
PropModeReplace, (unsigned char *)0, 0);
|
||
|
|
c->isfullscreen = 0;
|
||
|
|
c->isfloating = c->oldstate;
|
||
|
|
c->bw = c->oldbw;
|
||
|
|
c->x = c->oldx; c->y = c->oldy;
|
||
|
|
c->w = c->oldw; c->h = c->oldh;
|
||
|
|
resizeclient(c, c->x, c->y, c->w, c->h);
|
||
|
|
arrange(c->mon);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void setlayout(const Arg *arg) {
|
||
|
|
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
|
||
|
|
selmon->sellt ^= 1;
|
||
|
|
if (arg && arg->v)
|
||
|
|
selmon->lt[selmon->sellt] = (const Layout *)arg->v;
|
||
|
|
snprintf(selmon->ltsymbol, sizeof selmon->ltsymbol, "%s", selmon->lt[selmon->sellt]->symbol);
|
||
|
|
if (selmon->sel) arrange(selmon);
|
||
|
|
else drawbar(selmon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void setmfact(const Arg *arg) {
|
||
|
|
float f;
|
||
|
|
if (!arg || !selmon->lt[selmon->sellt]->arrange) return;
|
||
|
|
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
|
||
|
|
if (f < 0.05 || f > 0.95) return;
|
||
|
|
selmon->mfact = f;
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void setup(void) {
|
||
|
|
XSetWindowAttributes wa;
|
||
|
|
Atom utf8string;
|
||
|
|
struct sigaction sa;
|
||
|
|
|
||
|
|
sigemptyset(&sa.sa_mask);
|
||
|
|
sa.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART;
|
||
|
|
sa.sa_handler = sigchld_handler;
|
||
|
|
sigaction(SIGCHLD, &sa, NULL);
|
||
|
|
while (waitpid(-1, NULL, WNOHANG) > 0) ;
|
||
|
|
|
||
|
|
sigemptyset(&sa.sa_mask);
|
||
|
|
sa.sa_flags = 0;
|
||
|
|
sa.sa_handler = sigusr1_handler;
|
||
|
|
sigaction(SIGUSR1, &sa, NULL);
|
||
|
|
|
||
|
|
sigemptyset(&sa.sa_mask);
|
||
|
|
sa.sa_flags = 0;
|
||
|
|
sa.sa_handler = sighup_handler;
|
||
|
|
sigaction(SIGHUP, &sa, NULL);
|
||
|
|
|
||
|
|
loadxres();
|
||
|
|
|
||
|
|
screen = DefaultScreen(dpy);
|
||
|
|
sw = DisplayWidth(dpy, screen);
|
||
|
|
sh = DisplayHeight(dpy, screen);
|
||
|
|
root = RootWindow(dpy, screen);
|
||
|
|
drw = drw_create(dpy, screen, root, (unsigned int)sw, (unsigned int)sh);
|
||
|
|
dwmfont = drw_font_create(drw, font);
|
||
|
|
drw_setfont(drw, dwmfont);
|
||
|
|
lrpad = (int)dwmfont->h + anode_scale_px(4, ui_scale);
|
||
|
|
bh = MAX((int)dwmfont->h + anode_scale_px(12, ui_scale), anode_scale_px(30, ui_scale));
|
||
|
|
updategeom();
|
||
|
|
|
||
|
|
{
|
||
|
|
char trayatom[64];
|
||
|
|
snprintf(trayatom, sizeof(trayatom), "_NET_SYSTEM_TRAY_S%d", screen);
|
||
|
|
netatom[NetSystemTray] = XInternAtom(dpy, trayatom, False);
|
||
|
|
}
|
||
|
|
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
|
||
|
|
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||
|
|
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||
|
|
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
|
||
|
|
wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
|
||
|
|
netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
|
||
|
|
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||
|
|
netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
|
||
|
|
netatom[NetSystemTrayOrientation] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION", False);
|
||
|
|
netatom[NetSystemTrayOrientationHorz] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION_HORZ", False);
|
||
|
|
netatom[NetSystemTrayVisual] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_VISUAL", False);
|
||
|
|
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||
|
|
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||
|
|
netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
|
||
|
|
netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
||
|
|
netatom[NetWorkarea] = XInternAtom(dpy, "_NET_WORKAREA", False);
|
||
|
|
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
|
||
|
|
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
||
|
|
netatom[NetWMWindowTypeDock] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
|
||
|
|
netatom[NetWMStrutPartial] = XInternAtom(dpy, "_NET_WM_STRUT_PARTIAL", False);
|
||
|
|
netatom[NetWMStrut] = XInternAtom(dpy, "_NET_WM_STRUT", False);
|
||
|
|
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
|
||
|
|
xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
|
||
|
|
xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
|
||
|
|
xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False);
|
||
|
|
|
||
|
|
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
|
||
|
|
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
|
||
|
|
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
|
||
|
|
|
||
|
|
scheme = ecalloc(2, sizeof(Clr *));
|
||
|
|
scheme[SchemeNorm] = drw_scm_create(drw, (const char **)colors[SchemeNorm], 3);
|
||
|
|
scheme[SchemeSel] = drw_scm_create(drw, (const char **)colors[SchemeSel], 3);
|
||
|
|
|
||
|
|
updatesystray(0);
|
||
|
|
updatebars();
|
||
|
|
updateworkarea();
|
||
|
|
updatestatus();
|
||
|
|
|
||
|
|
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
|
||
|
|
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
|
||
|
|
PropModeReplace, (unsigned char *)&wmcheckwin, 1);
|
||
|
|
XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8,
|
||
|
|
PropModeReplace, (unsigned char *)"dwm", 3);
|
||
|
|
XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
|
||
|
|
PropModeReplace, (unsigned char *)&wmcheckwin, 1);
|
||
|
|
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
|
||
|
|
PropModeReplace, (unsigned char *)netatom, NetLast);
|
||
|
|
XDeleteProperty(dpy, root, netatom[NetClientList]);
|
||
|
|
|
||
|
|
wa.cursor = cursor[CurNormal]->cursor;
|
||
|
|
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
|
||
|
|
ButtonPressMask | PointerMotionMask | EnterWindowMask |
|
||
|
|
LeaveWindowMask | StructureNotifyMask | PropertyChangeMask |
|
||
|
|
FocusChangeMask;
|
||
|
|
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
||
|
|
XSelectInput(dpy, root, wa.event_mask);
|
||
|
|
grabkeys();
|
||
|
|
focus(NULL);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void seturgent(Client *c, int urg) {
|
||
|
|
XWMHints *wmh;
|
||
|
|
c->isurgent = urg;
|
||
|
|
if (!(wmh = XGetWMHints(dpy, c->win))) return;
|
||
|
|
wmh->flags = urg ? (wmh->flags | XUrgencyHint) : (wmh->flags & ~XUrgencyHint);
|
||
|
|
XSetWMHints(dpy, c->win, wmh);
|
||
|
|
XFree(wmh);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void showhide(Client *c) {
|
||
|
|
if (!c) return;
|
||
|
|
if (ISVISIBLE(c)) {
|
||
|
|
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 {
|
||
|
|
showhide(c->snext);
|
||
|
|
XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void sigchld_handler(int sig) {
|
||
|
|
(void)sig;
|
||
|
|
while (waitpid(-1, NULL, WNOHANG) > 0) ;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void sigusr1_handler(int sig) {
|
||
|
|
(void)sig;
|
||
|
|
reload_pending = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void sighup_handler(int sig) {
|
||
|
|
(void)sig;
|
||
|
|
restart_dwm = 1;
|
||
|
|
running = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void spawn(const Arg *arg) {
|
||
|
|
struct sigaction sa;
|
||
|
|
if (fork() == 0) {
|
||
|
|
if (dpy) close(ConnectionNumber(dpy));
|
||
|
|
setsid();
|
||
|
|
sigemptyset(&sa.sa_mask);
|
||
|
|
sa.sa_flags = 0;
|
||
|
|
sa.sa_handler = SIG_DFL;
|
||
|
|
sigaction(SIGCHLD, &sa, NULL);
|
||
|
|
execvp(((char **)arg->v)[0], (char **)arg->v);
|
||
|
|
die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static Monitor *systraytomon(Monitor *m) {
|
||
|
|
Monitor *t;
|
||
|
|
unsigned int i, n;
|
||
|
|
if (!systraypinning) {
|
||
|
|
if (!m) return selmon;
|
||
|
|
return m == selmon ? m : NULL;
|
||
|
|
}
|
||
|
|
for (n = 1, t = mons; t && t->next; n++, t = t->next) ;
|
||
|
|
for (i = 1, t = mons; t && t->next && i < systraypinning; i++, t = t->next) ;
|
||
|
|
if (systraypinningfailfirst && n < systraypinning) return mons;
|
||
|
|
return t;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void tag(const Arg *arg) {
|
||
|
|
if (selmon->sel && (arg->ui & TAGMASK)) {
|
||
|
|
selmon->sel->tags = arg->ui & TAGMASK;
|
||
|
|
focus(NULL);
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void tagmon(const Arg *arg) {
|
||
|
|
if (!selmon->sel || !mons->next) return;
|
||
|
|
sendmon(selmon->sel, dirtomon(arg->i));
|
||
|
|
}
|
||
|
|
|
||
|
|
static void tile(Monitor *m) {
|
||
|
|
unsigned int i, n, h, mw, my, ty;
|
||
|
|
Client *c;
|
||
|
|
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
|
||
|
|
if (n == 0) return;
|
||
|
|
|
||
|
|
if (n > (unsigned int)m->nmaster)
|
||
|
|
mw = m->nmaster ? (unsigned int)(m->ww * m->mfact) : 0;
|
||
|
|
else
|
||
|
|
mw = (unsigned int)m->ww;
|
||
|
|
for (i = 0, my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||
|
|
if (i < (unsigned int)m->nmaster) {
|
||
|
|
h = ((unsigned int)m->wh - my) / (MIN(n, (unsigned int)m->nmaster) - i);
|
||
|
|
resize(c, m->wx, m->wy + (int)my, (int)mw - 2 * c->bw, (int)h - 2 * c->bw, 0);
|
||
|
|
if (my + (unsigned int)HEIGHT(c) < (unsigned int)m->wh)
|
||
|
|
my += (unsigned int)HEIGHT(c);
|
||
|
|
} else {
|
||
|
|
h = ((unsigned int)m->wh - ty) / (n - i);
|
||
|
|
resize(c, m->wx + (int)mw, m->wy + (int)ty, m->ww - (int)mw - 2 * c->bw, (int)h - 2 * c->bw, 0);
|
||
|
|
if (ty + (unsigned int)HEIGHT(c) < (unsigned int)m->wh)
|
||
|
|
ty += (unsigned int)HEIGHT(c);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void togglebar(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
selmon->showbar = !selmon->showbar;
|
||
|
|
updatebarpos(selmon);
|
||
|
|
resizebarwin(selmon);
|
||
|
|
if (showsystray && systray) {
|
||
|
|
XWindowChanges wc;
|
||
|
|
if (!selmon->showbar) wc.y = -bh;
|
||
|
|
else if (selmon->showbar) {
|
||
|
|
wc.y = 0;
|
||
|
|
if (!selmon->topbar) wc.y = selmon->mh - bh;
|
||
|
|
}
|
||
|
|
XConfigureWindow(dpy, systray->win, CWY, &wc);
|
||
|
|
}
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void togglefloating(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
if (!selmon->sel || selmon->sel->isfullscreen) return;
|
||
|
|
selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
|
||
|
|
if (selmon->sel->isfloating)
|
||
|
|
resize(selmon->sel, selmon->sel->x, selmon->sel->y, selmon->sel->w, selmon->sel->h, 0);
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void toggletag(const Arg *arg) {
|
||
|
|
unsigned int newtags;
|
||
|
|
if (!selmon->sel) return;
|
||
|
|
newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
|
||
|
|
if (newtags) {
|
||
|
|
selmon->sel->tags = newtags;
|
||
|
|
focus(NULL);
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void toggleview(const Arg *arg) {
|
||
|
|
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
|
||
|
|
if (newtagset) {
|
||
|
|
selmon->tagset[selmon->seltags] = newtagset;
|
||
|
|
focus(NULL);
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void unfocus(Client *c, int setfocus) {
|
||
|
|
if (!c) return;
|
||
|
|
grabbuttons(c, 0);
|
||
|
|
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
|
||
|
|
if (setfocus) {
|
||
|
|
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||
|
|
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void unmanage(Client *c, int destroyed) {
|
||
|
|
Monitor *m = c->mon;
|
||
|
|
XWindowChanges wc;
|
||
|
|
detach(c);
|
||
|
|
detachstack(c);
|
||
|
|
if (!destroyed) {
|
||
|
|
wc.border_width = c->oldbw;
|
||
|
|
XGrabServer(dpy);
|
||
|
|
XSetErrorHandler(xerrordummy);
|
||
|
|
XSelectInput(dpy, c->win, NoEventMask);
|
||
|
|
XConfigureWindow(dpy, c->win, CWBorderWidth, &wc);
|
||
|
|
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||
|
|
setclientstate(c, WithdrawnState);
|
||
|
|
XSync(dpy, False);
|
||
|
|
XSetErrorHandler(xerror);
|
||
|
|
XUngrabServer(dpy);
|
||
|
|
}
|
||
|
|
free(c);
|
||
|
|
focus(NULL);
|
||
|
|
updateclientlist();
|
||
|
|
arrange(m);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void unmapnotify(XEvent *e) {
|
||
|
|
Client *c;
|
||
|
|
XUnmapEvent *ev = &e->xunmap;
|
||
|
|
if ((c = wintoclient(ev->window))) {
|
||
|
|
if (ev->send_event) setclientstate(c, WithdrawnState);
|
||
|
|
else unmanage(c, 0);
|
||
|
|
} else if ((c = wintosystrayicon(ev->window))) {
|
||
|
|
if (c->tags) {
|
||
|
|
c->tags = 0;
|
||
|
|
setclientstate(c, WithdrawnState);
|
||
|
|
updatesystray(1);
|
||
|
|
drawbars();
|
||
|
|
}
|
||
|
|
} else if (dockremove(ev->window)) {
|
||
|
|
recalcworkareas();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatebars(void) {
|
||
|
|
unsigned int w;
|
||
|
|
Monitor *m;
|
||
|
|
XSetWindowAttributes wa = {
|
||
|
|
.override_redirect = True,
|
||
|
|
.background_pixmap = ParentRelative,
|
||
|
|
.event_mask = ButtonPressMask | ExposureMask
|
||
|
|
};
|
||
|
|
XClassHint ch = {"dwm", "dwm"};
|
||
|
|
for (m = mons; m; m = m->next) {
|
||
|
|
if (m->barwin) continue;
|
||
|
|
w = (unsigned int)m->ww;
|
||
|
|
if (showsystray && m == systraytomon(m) && !systrayonleft) w -= getsystraywidth();
|
||
|
|
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, w, (unsigned int)bh, 0,
|
||
|
|
DefaultDepth(dpy, screen), CopyFromParent,
|
||
|
|
DefaultVisual(dpy, screen),
|
||
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||
|
|
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
|
||
|
|
if (showsystray && m == systraytomon(m) && systray && getsystraywidth() > 0)
|
||
|
|
XMapRaised(dpy, systray->win);
|
||
|
|
XMapRaised(dpy, m->barwin);
|
||
|
|
XSetClassHint(dpy, m->barwin, &ch);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatebarpos(Monitor *m) {
|
||
|
|
m->wx = m->mx;
|
||
|
|
m->wy = m->my;
|
||
|
|
m->ww = m->mw;
|
||
|
|
m->wh = m->mh;
|
||
|
|
if (m->showbar) {
|
||
|
|
m->wh -= bh;
|
||
|
|
m->by = m->topbar ? m->wy : m->wy + m->wh;
|
||
|
|
m->wy = m->topbar ? m->wy + bh : m->wy;
|
||
|
|
} else {
|
||
|
|
m->by = -bh;
|
||
|
|
}
|
||
|
|
for (DockWin *d = docks; d; d = d->next) {
|
||
|
|
unsigned long left = d->strut[0], right = d->strut[1];
|
||
|
|
unsigned long top = d->strut[2], bottom = d->strut[3];
|
||
|
|
unsigned long lsy = d->strut[4], ley = d->strut[5];
|
||
|
|
unsigned long rsy = d->strut[6], rey = d->strut[7];
|
||
|
|
unsigned long tsx = d->strut[8], tex = d->strut[9];
|
||
|
|
unsigned long bsx = d->strut[10], bex = d->strut[11];
|
||
|
|
int m_x2 = m->mx + m->mw, m_y2 = m->my + m->mh;
|
||
|
|
|
||
|
|
if (left > 0 && ((ley == 0 && lsy == 0) || ((long)lsy < m_y2 && (long)ley >= m->my))) {
|
||
|
|
int nx = MAX(m->wx, (int)left);
|
||
|
|
if (nx > m->wx && nx < m->wx + m->ww) {
|
||
|
|
m->ww -= (nx - m->wx);
|
||
|
|
m->wx = nx;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (right > 0 && ((rey == 0 && rsy == 0) || ((long)rsy < m_y2 && (long)rey >= m->my))) {
|
||
|
|
int rx = sw - (int)right;
|
||
|
|
if (rx < m->wx + m->ww && rx > m->wx)
|
||
|
|
m->ww = rx - m->wx;
|
||
|
|
}
|
||
|
|
if (top > 0 && ((tex == 0 && tsx == 0) || ((long)tsx < m_x2 && (long)tex >= m->mx))) {
|
||
|
|
int ny = MAX(m->wy, (int)top);
|
||
|
|
if (ny > m->wy && ny < m->wy + m->wh) {
|
||
|
|
m->wh -= (ny - m->wy);
|
||
|
|
m->wy = ny;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (bottom > 0 && ((bex == 0 && bsx == 0) || ((long)bsx < m_x2 && (long)bex >= m->mx))) {
|
||
|
|
int by_lim = sh - (int)bottom;
|
||
|
|
if (by_lim < m->wy + m->wh && by_lim > m->wy)
|
||
|
|
m->wh = by_lim - m->wy;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (m->ww < 64) m->ww = 64;
|
||
|
|
if (m->wh < 64) m->wh = 64;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updateclientlist(void) {
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
XDeleteProperty(dpy, root, netatom[NetClientList]);
|
||
|
|
for (m = mons; m; m = m->next)
|
||
|
|
for (c = m->clients; c; c = c->next)
|
||
|
|
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32,
|
||
|
|
PropModeAppend, (unsigned char *)&(c->win), 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
static int updategeom(void) {
|
||
|
|
int dirty = 0;
|
||
|
|
#ifdef XINERAMA
|
||
|
|
if (XineramaIsActive(dpy)) {
|
||
|
|
int i, j, n, nn;
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn);
|
||
|
|
XineramaScreenInfo *unique = ecalloc((size_t)nn, sizeof(XineramaScreenInfo));
|
||
|
|
|
||
|
|
for (n = 0, m = mons; m; m = m->next, n++) ;
|
||
|
|
for (i = 0, j = 0; i < nn; i++) {
|
||
|
|
int dup = 0;
|
||
|
|
for (int k = 0; k < j; k++) {
|
||
|
|
if (unique[k].x_org == info[i].x_org && unique[k].y_org == info[i].y_org &&
|
||
|
|
unique[k].width == info[i].width && unique[k].height == info[i].height) {
|
||
|
|
dup = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!dup) memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));
|
||
|
|
}
|
||
|
|
XFree(info);
|
||
|
|
nn = j;
|
||
|
|
if (n <= nn) {
|
||
|
|
for (i = 0; i < (nn - n); i++) {
|
||
|
|
for (m = mons; m && m->next; m = m->next) ;
|
||
|
|
if (m) m->next = createmon();
|
||
|
|
else mons = createmon();
|
||
|
|
}
|
||
|
|
for (i = 0, m = mons; i < nn && m; m = m->next, i++) {
|
||
|
|
if (i >= n || unique[i].x_org != m->mx || unique[i].y_org != m->my ||
|
||
|
|
unique[i].width != m->mw || unique[i].height != m->mh) {
|
||
|
|
dirty = 1;
|
||
|
|
m->num = i;
|
||
|
|
m->mx = m->wx = unique[i].x_org;
|
||
|
|
m->my = m->wy = unique[i].y_org;
|
||
|
|
m->mw = m->ww = unique[i].width;
|
||
|
|
m->mh = m->wh = unique[i].height;
|
||
|
|
updatebarpos(m);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
for (i = nn; i < n; i++) {
|
||
|
|
for (m = mons; m && m->next; m = m->next) ;
|
||
|
|
while ((c = m->clients)) {
|
||
|
|
dirty = 1;
|
||
|
|
m->clients = c->next;
|
||
|
|
detachstack(c);
|
||
|
|
c->mon = mons;
|
||
|
|
attach(c);
|
||
|
|
attachstack(c);
|
||
|
|
}
|
||
|
|
if (m == selmon) selmon = mons;
|
||
|
|
cleanupmon(m);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
free(unique);
|
||
|
|
} else
|
||
|
|
#endif
|
||
|
|
{
|
||
|
|
if (!mons) mons = createmon();
|
||
|
|
if (mons->mw != sw || mons->mh != sh) {
|
||
|
|
dirty = 1;
|
||
|
|
mons->mw = mons->ww = sw;
|
||
|
|
mons->mh = mons->wh = sh;
|
||
|
|
updatebarpos(mons);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (dirty) {
|
||
|
|
selmon = mons;
|
||
|
|
selmon = wintomon(root);
|
||
|
|
}
|
||
|
|
return dirty;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatenumlockmask(void) {
|
||
|
|
unsigned int i;
|
||
|
|
int j;
|
||
|
|
XModifierKeymap *modmap = XGetModifierMapping(dpy);
|
||
|
|
numlockmask = 0;
|
||
|
|
for (i = 0; i < 8; i++)
|
||
|
|
for (j = 0; j < modmap->max_keypermod; j++)
|
||
|
|
if (modmap->modifiermap[i * modmap->max_keypermod + j] ==
|
||
|
|
XKeysymToKeycode(dpy, XK_Num_Lock))
|
||
|
|
numlockmask = (1U << i);
|
||
|
|
XFreeModifiermap(modmap);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatesizehints(Client *c) {
|
||
|
|
long msize;
|
||
|
|
XSizeHints size;
|
||
|
|
if (!XGetWMNormalHints(dpy, c->win, &size, &msize))
|
||
|
|
size.flags = PSize;
|
||
|
|
if (size.flags & PBaseSize) { c->basew = size.base_width; c->baseh = size.base_height; }
|
||
|
|
else if (size.flags & PMinSize) { c->basew = size.min_width; c->baseh = size.min_height; }
|
||
|
|
else c->basew = c->baseh = 0;
|
||
|
|
|
||
|
|
if (size.flags & PResizeInc) { c->incw = size.width_inc; c->inch = size.height_inc; }
|
||
|
|
else c->incw = c->inch = 0;
|
||
|
|
|
||
|
|
if (size.flags & PMaxSize) { c->maxw = size.max_width; c->maxh = size.max_height; }
|
||
|
|
else c->maxw = c->maxh = 0;
|
||
|
|
|
||
|
|
if (size.flags & PMinSize) { c->minw = size.min_width; c->minh = size.min_height; }
|
||
|
|
else if (size.flags & PBaseSize) { c->minw = size.base_width; c->minh = size.base_height; }
|
||
|
|
else c->minw = c->minh = 0;
|
||
|
|
|
||
|
|
if (size.flags & PAspect) {
|
||
|
|
c->mina = (float)size.min_aspect.y / size.min_aspect.x;
|
||
|
|
c->maxa = (float)size.max_aspect.x / size.max_aspect.y;
|
||
|
|
} else {
|
||
|
|
c->maxa = c->mina = 0.0;
|
||
|
|
}
|
||
|
|
c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh);
|
||
|
|
c->hintsvalid = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatestatus(void) {
|
||
|
|
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
|
||
|
|
strcpy(stext, "ANODE");
|
||
|
|
drawbar(selmon);
|
||
|
|
updatesystray(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
static unsigned long systray_bg_pixel(void) {
|
||
|
|
if (systray && systray->use_argb) {
|
||
|
|
XRenderColor rc = scheme[SchemeNorm][ColBg].color;
|
||
|
|
unsigned long r = (unsigned long)(rc.red >> 8) & 0xff;
|
||
|
|
unsigned long g = (unsigned long)(rc.green >> 8) & 0xff;
|
||
|
|
unsigned long b = (unsigned long)(rc.blue >> 8) & 0xff;
|
||
|
|
return 0xff000000UL | (r << 16) | (g << 8) | b;
|
||
|
|
}
|
||
|
|
return scheme[SchemeNorm][ColBg].pixel;
|
||
|
|
}
|
||
|
|
|
||
|
|
static int getxembedflags(Window w, long *flags_out) {
|
||
|
|
int di;
|
||
|
|
unsigned long dl, n = 0;
|
||
|
|
unsigned char *p = NULL;
|
||
|
|
Atom da = None;
|
||
|
|
if (XGetWindowProperty(dpy, w, xatom[XembedInfo], 0L, 2L, False, AnyPropertyType,
|
||
|
|
&da, &di, &n, &dl, &p) == Success && p) {
|
||
|
|
int ok = (di == 32 && n >= 2);
|
||
|
|
if (ok && flags_out)
|
||
|
|
*flags_out = (long)((unsigned long *)p)[1];
|
||
|
|
XFree(p);
|
||
|
|
return ok;
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static int isdockwin(Window w) {
|
||
|
|
int di;
|
||
|
|
unsigned long dl, n = 0;
|
||
|
|
unsigned char *p = NULL;
|
||
|
|
Atom da = None;
|
||
|
|
if (XGetWindowProperty(dpy, w, netatom[NetWMWindowType], 0L, 16L, False, XA_ATOM,
|
||
|
|
&da, &di, &n, &dl, &p) == Success && p) {
|
||
|
|
int is_dock = 0;
|
||
|
|
if (di == 32 && da == XA_ATOM) {
|
||
|
|
Atom *atoms = (Atom *)p;
|
||
|
|
for (unsigned long i = 0; i < n; i++) {
|
||
|
|
if (atoms[i] == netatom[NetWMWindowTypeDock]) {
|
||
|
|
is_dock = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
XFree(p);
|
||
|
|
return is_dock;
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void readdocks_strut(Window w, unsigned long strut[12]) {
|
||
|
|
int di;
|
||
|
|
unsigned long dl, n = 0;
|
||
|
|
unsigned char *p = NULL;
|
||
|
|
Atom da = None;
|
||
|
|
memset(strut, 0, sizeof(unsigned long) * 12);
|
||
|
|
if (XGetWindowProperty(dpy, w, netatom[NetWMStrutPartial], 0L, 12L, False, XA_CARDINAL,
|
||
|
|
&da, &di, &n, &dl, &p) == Success && p) {
|
||
|
|
if (di == 32 && n >= 4) {
|
||
|
|
unsigned long *vals = (unsigned long *)p;
|
||
|
|
unsigned long lim = MIN(n, 12UL);
|
||
|
|
for (unsigned long i = 0; i < lim; i++) strut[i] = vals[i];
|
||
|
|
}
|
||
|
|
XFree(p);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (XGetWindowProperty(dpy, w, netatom[NetWMStrut], 0L, 4L, False, XA_CARDINAL,
|
||
|
|
&da, &di, &n, &dl, &p) == Success && p) {
|
||
|
|
if (di == 32 && n >= 4) {
|
||
|
|
unsigned long *vals = (unsigned long *)p;
|
||
|
|
for (int i = 0; i < 4; i++) strut[i] = vals[i];
|
||
|
|
}
|
||
|
|
XFree(p);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updateworkarea(void) {
|
||
|
|
Monitor *m = selmon ? selmon : mons;
|
||
|
|
if (!m) return;
|
||
|
|
unsigned long data[LENGTH(tags) * 4];
|
||
|
|
for (size_t i = 0; i < LENGTH(tags); i++) {
|
||
|
|
data[i * 4 + 0] = (unsigned long)MAX(0, m->wx);
|
||
|
|
data[i * 4 + 1] = (unsigned long)MAX(0, m->wy);
|
||
|
|
data[i * 4 + 2] = (unsigned long)MAX(1, m->ww);
|
||
|
|
data[i * 4 + 3] = (unsigned long)MAX(1, m->wh);
|
||
|
|
}
|
||
|
|
XChangeProperty(dpy, root, netatom[NetWorkarea], XA_CARDINAL, 32,
|
||
|
|
PropModeReplace, (unsigned char *)data, (int)(LENGTH(tags) * 4));
|
||
|
|
}
|
||
|
|
|
||
|
|
static void recalcworkareas(void) {
|
||
|
|
for (Monitor *m = mons; m; m = m->next)
|
||
|
|
updatebarpos(m);
|
||
|
|
updateworkarea();
|
||
|
|
arrange(NULL);
|
||
|
|
drawbars();
|
||
|
|
}
|
||
|
|
|
||
|
|
static void dockadd(Window w) {
|
||
|
|
for (DockWin *d = docks; d; d = d->next) {
|
||
|
|
if (d->win == w) {
|
||
|
|
readdocks_strut(w, d->strut);
|
||
|
|
recalcworkareas();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
DockWin *d = ecalloc(1, sizeof(DockWin));
|
||
|
|
d->win = w;
|
||
|
|
readdocks_strut(w, d->strut);
|
||
|
|
d->next = docks;
|
||
|
|
docks = d;
|
||
|
|
recalcworkareas();
|
||
|
|
}
|
||
|
|
|
||
|
|
static int dockremove(Window w) {
|
||
|
|
DockWin **pp = &docks;
|
||
|
|
while (*pp) {
|
||
|
|
if ((*pp)->win == w) {
|
||
|
|
DockWin *victim = *pp;
|
||
|
|
*pp = victim->next;
|
||
|
|
free(victim);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
pp = &(*pp)->next;
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void dockupdate(Window w) {
|
||
|
|
for (DockWin *d = docks; d; d = d->next) {
|
||
|
|
if (d->win == w) {
|
||
|
|
readdocks_strut(w, d->strut);
|
||
|
|
recalcworkareas();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatesystray(int updatebar) {
|
||
|
|
XSetWindowAttributes wa;
|
||
|
|
XWindowChanges wc;
|
||
|
|
Client *i;
|
||
|
|
Monitor *m = systraytomon(NULL);
|
||
|
|
unsigned int x = (unsigned int)(m->mx + m->mw);
|
||
|
|
unsigned int sw_tray = TEXTW(stext) - (unsigned int)lrpad + systrayspacing;
|
||
|
|
unsigned int w = 0;
|
||
|
|
|
||
|
|
if (!showsystray) return;
|
||
|
|
if (!systrayonleft) x -= sw_tray;
|
||
|
|
if (!systray) {
|
||
|
|
XVisualInfo vinfo;
|
||
|
|
unsigned long orient = 0;
|
||
|
|
VisualID vid;
|
||
|
|
if (!(systray = (Systray *)calloc(1, sizeof(Systray))))
|
||
|
|
die("fatal: could not malloc() %zu bytes\n", sizeof(Systray));
|
||
|
|
if (XMatchVisualInfo(dpy, screen, 32, TrueColor, &vinfo)) {
|
||
|
|
systray->visual = vinfo.visual;
|
||
|
|
systray->depth = 32;
|
||
|
|
systray->colormap = XCreateColormap(dpy, root, vinfo.visual, AllocNone);
|
||
|
|
systray->use_argb = 1;
|
||
|
|
} else {
|
||
|
|
systray->visual = DefaultVisual(dpy, screen);
|
||
|
|
systray->depth = DefaultDepth(dpy, screen);
|
||
|
|
systray->colormap = DefaultColormap(dpy, screen);
|
||
|
|
systray->use_argb = 0;
|
||
|
|
}
|
||
|
|
memset(&wa, 0, sizeof(wa));
|
||
|
|
wa.event_mask = SubstructureNotifyMask | ButtonPressMask | ExposureMask;
|
||
|
|
wa.override_redirect = True;
|
||
|
|
wa.border_pixel = 0;
|
||
|
|
wa.colormap = systray->colormap;
|
||
|
|
wa.background_pixel = systray_bg_pixel();
|
||
|
|
systray->win = XCreateWindow(dpy, root, (int)x, m->by, 1, (unsigned int)bh, 0,
|
||
|
|
systray->depth, InputOutput, systray->visual,
|
||
|
|
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
|
||
|
|
&wa);
|
||
|
|
XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
|
||
|
|
PropModeReplace, (unsigned char *)&orient, 1);
|
||
|
|
vid = XVisualIDFromVisual(systray->visual);
|
||
|
|
XChangeProperty(dpy, systray->win, netatom[NetSystemTrayVisual], XA_VISUALID, 32,
|
||
|
|
PropModeReplace, (unsigned char *)&vid, 1);
|
||
|
|
XSetSelectionOwner(dpy, netatom[NetSystemTray], systray->win, CurrentTime);
|
||
|
|
if (XGetSelectionOwner(dpy, netatom[NetSystemTray]) == systray->win) {
|
||
|
|
sendevent(root, xatom[Manager], StructureNotifyMask, CurrentTime,
|
||
|
|
(long)netatom[NetSystemTray], (long)systray->win, 0, 0);
|
||
|
|
XSync(dpy, False);
|
||
|
|
} else {
|
||
|
|
fprintf(stderr, "dwm: unable to obtain system tray.\n");
|
||
|
|
XDestroyWindow(dpy, systray->win);
|
||
|
|
if (systray->use_argb && systray->colormap)
|
||
|
|
XFreeColormap(dpy, systray->colormap);
|
||
|
|
free(systray);
|
||
|
|
systray = NULL;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
for (w = 0, i = systray->icons; i; i = i->next) {
|
||
|
|
if (!i->tags) continue;
|
||
|
|
int iy = MAX(0, (bh - i->h) / 2);
|
||
|
|
w += systrayspacing;
|
||
|
|
i->x = (int)w;
|
||
|
|
i->y = iy;
|
||
|
|
XMoveResizeWindow(dpy, i->win, i->x, i->y, (unsigned int)i->w, (unsigned int)i->h);
|
||
|
|
XMapRaised(dpy, i->win);
|
||
|
|
w += (unsigned int)i->w;
|
||
|
|
if (i->mon != m) i->mon = m;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (w == 0) {
|
||
|
|
XUnmapWindow(dpy, systray->win);
|
||
|
|
if (updatebar) resizebarwin(m);
|
||
|
|
XSync(dpy, False);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
w += systrayspacing;
|
||
|
|
x = (unsigned int)(m->wx + m->ww) - w;
|
||
|
|
XMoveResizeWindow(dpy, systray->win, (int)x, m->by, w, (unsigned int)bh);
|
||
|
|
wc.x = (int)x; wc.y = m->by; wc.width = (int)w; wc.height = bh;
|
||
|
|
wc.stack_mode = Above; wc.sibling = m->barwin;
|
||
|
|
XConfigureWindow(dpy, systray->win, CWX | CWY | CWWidth | CWHeight | CWSibling | CWStackMode, &wc);
|
||
|
|
XSetWindowBackground(dpy, systray->win, systray_bg_pixel());
|
||
|
|
XClearWindow(dpy, systray->win);
|
||
|
|
XMapRaised(dpy, systray->win);
|
||
|
|
if (updatebar) resizebarwin(m);
|
||
|
|
XSync(dpy, False);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatesystrayicongeom(Client *i, int w, int h) {
|
||
|
|
if (i) {
|
||
|
|
int pad = anode_scale_px(2, ui_scale);
|
||
|
|
int target_h = MAX(8, bh - pad * 2);
|
||
|
|
if (w < 1) w = target_h;
|
||
|
|
if (h < 1) h = target_h;
|
||
|
|
i->h = target_h;
|
||
|
|
if (w == h) i->w = target_h;
|
||
|
|
else i->w = MAX(8, (int)((float)target_h * ((float)w / (float)h)));
|
||
|
|
applysizehints(i, &i->x, &i->y, &i->w, &i->h, False);
|
||
|
|
if (i->h > target_h || i->h < 8) {
|
||
|
|
i->w = (i->w == i->h) ? target_h : MAX(8, (int)((float)target_h * ((float)i->w / (float)(i->h ? i->h : 1))));
|
||
|
|
i->h = target_h;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatesystrayiconstate(Client *i, XPropertyEvent *ev) {
|
||
|
|
long flags = 0;
|
||
|
|
int code = 0;
|
||
|
|
if (!showsystray || !i || ev->atom != xatom[XembedInfo])
|
||
|
|
return;
|
||
|
|
if (!getxembedflags(i->win, &flags))
|
||
|
|
return;
|
||
|
|
if ((flags & XEMBED_MAPPED) && !i->tags) {
|
||
|
|
i->tags = 1;
|
||
|
|
code = XEMBED_WINDOW_ACTIVATE;
|
||
|
|
XMapRaised(dpy, i->win);
|
||
|
|
setclientstate(i, NormalState);
|
||
|
|
} else if (!(flags & XEMBED_MAPPED) && i->tags) {
|
||
|
|
i->tags = 0;
|
||
|
|
code = XEMBED_WINDOW_DEACTIVATE;
|
||
|
|
XUnmapWindow(dpy, i->win);
|
||
|
|
setclientstate(i, WithdrawnState);
|
||
|
|
} else {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0, (long)systray->win, XEMBED_EMBEDDED_VERSION_VAL);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatetitle(Client *c) {
|
||
|
|
if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
|
||
|
|
gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name);
|
||
|
|
if (c->name[0] == '\0') strcpy(c->name, broken);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatewindowtype(Client *c) {
|
||
|
|
Atom state = getatomprop(c, netatom[NetWMState]);
|
||
|
|
Atom wtype = getatomprop(c, netatom[NetWMWindowType]);
|
||
|
|
if (state == netatom[NetWMFullscreen]) setfullscreen(c, 1);
|
||
|
|
if (wtype == netatom[NetWMWindowTypeDialog]) c->isfloating = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void updatewmhints(Client *c) {
|
||
|
|
XWMHints *wmh;
|
||
|
|
if ((wmh = XGetWMHints(dpy, c->win))) {
|
||
|
|
if (c == selmon->sel && (wmh->flags & XUrgencyHint)) {
|
||
|
|
wmh->flags &= ~XUrgencyHint;
|
||
|
|
XSetWMHints(dpy, c->win, wmh);
|
||
|
|
} else {
|
||
|
|
c->isurgent = (wmh->flags & XUrgencyHint) ? 1 : 0;
|
||
|
|
}
|
||
|
|
if (wmh->flags & InputHint) c->neverfocus = !wmh->input;
|
||
|
|
else c->neverfocus = 0;
|
||
|
|
XFree(wmh);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static void view(const Arg *arg) {
|
||
|
|
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
|
||
|
|
return;
|
||
|
|
selmon->seltags ^= 1;
|
||
|
|
if (arg->ui & TAGMASK)
|
||
|
|
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
|
||
|
|
focus(NULL);
|
||
|
|
arrange(selmon);
|
||
|
|
}
|
||
|
|
|
||
|
|
static Client *wintoclient(Window w) {
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
for (m = mons; m; m = m->next)
|
||
|
|
for (c = m->clients; c; c = c->next)
|
||
|
|
if (c->win == w) return c;
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
static Client *wintosystrayicon(Window w) {
|
||
|
|
Client *i = NULL;
|
||
|
|
if (!showsystray || !w || !systray) return i;
|
||
|
|
for (i = systray->icons; i && i->win != w; i = i->next) ;
|
||
|
|
return i;
|
||
|
|
}
|
||
|
|
|
||
|
|
static Monitor *wintomon(Window w) {
|
||
|
|
int x, y;
|
||
|
|
Client *c;
|
||
|
|
Monitor *m;
|
||
|
|
if (w == root && getrootptr(&x, &y)) return recttomon(x, y, 1, 1);
|
||
|
|
for (m = mons; m; m = m->next)
|
||
|
|
if (w == m->barwin) return m;
|
||
|
|
if ((c = wintoclient(w))) return c->mon;
|
||
|
|
return selmon;
|
||
|
|
}
|
||
|
|
|
||
|
|
static int xerror(Display *dpy, XErrorEvent *ee) {
|
||
|
|
if (ee->error_code == BadWindow ||
|
||
|
|
(ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) ||
|
||
|
|
(ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) ||
|
||
|
|
(ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) ||
|
||
|
|
(ee->request_code == X_PolySegment && ee->error_code == BadDrawable) ||
|
||
|
|
(ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) ||
|
||
|
|
(ee->request_code == X_GrabButton && ee->error_code == BadAccess) ||
|
||
|
|
(ee->request_code == X_GrabKey && ee->error_code == BadAccess) ||
|
||
|
|
(ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
|
||
|
|
return 0;
|
||
|
|
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
|
||
|
|
ee->request_code, ee->error_code);
|
||
|
|
return xerrorxlib(dpy, ee);
|
||
|
|
}
|
||
|
|
|
||
|
|
static int xerrordummy(Display *dpy, XErrorEvent *ee) {
|
||
|
|
(void)dpy; (void)ee;
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static int xerrorstart(Display *dpy, XErrorEvent *ee) {
|
||
|
|
(void)dpy; (void)ee;
|
||
|
|
die("dwm: another window manager is already running");
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void zoom(const Arg *arg) {
|
||
|
|
(void)arg;
|
||
|
|
Client *c = selmon->sel;
|
||
|
|
if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating) return;
|
||
|
|
if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next))) return;
|
||
|
|
pop(c);
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char *argv[]) {
|
||
|
|
if (argc == 2 && !strcmp("-v", argv[1])) {
|
||
|
|
die("dwm-" VERSION);
|
||
|
|
} else if (argc != 1) {
|
||
|
|
die("usage: dwm [-v]");
|
||
|
|
}
|
||
|
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||
|
|
fputs("warning: no locale support\n", stderr);
|
||
|
|
if (!(dpy = XOpenDisplay(NULL)))
|
||
|
|
die("dwm: cannot open display");
|
||
|
|
checkotherwm();
|
||
|
|
setup();
|
||
|
|
scan();
|
||
|
|
run();
|
||
|
|
cleanup();
|
||
|
|
XCloseDisplay(dpy);
|
||
|
|
if (restart_dwm) {
|
||
|
|
execvp(argv[0], argv);
|
||
|
|
}
|
||
|
|
return EXIT_SUCCESS;
|
||
|
|
}
|