2007-09-15 23:33:46 +03:00
|
|
|
/* See LICENSE file for copyright and license details.
|
|
|
|
*
|
|
|
|
* dynamic window manager is designed like any other X client as well. It is
|
|
|
|
* driven through handling X events. In contrast to other X clients, a window
|
|
|
|
* manager selects for SubstructureRedirectMask on the root window, to receive
|
2017-01-07 18:21:28 +02:00
|
|
|
* events about window (dis-)appearance. Only one X connection at a time is
|
2007-09-15 23:33:46 +03:00
|
|
|
* allowed to select for this event mask.
|
|
|
|
*
|
2008-12-12 21:49:06 +02:00
|
|
|
* The event handlers of dwm are organized in an array which is accessed
|
|
|
|
* whenever a new event has been fetched. This allows event dispatching
|
|
|
|
* in O(1) time.
|
2007-09-15 23:33:46 +03:00
|
|
|
*
|
|
|
|
* Each child of the root window is called a client, except windows which have
|
2017-01-07 18:21:28 +02:00
|
|
|
* set the override_redirect flag. Clients are organized in a linked client
|
2009-07-02 22:37:26 +03:00
|
|
|
* list on each monitor, the focus history is remembered through a stack list
|
|
|
|
* on each monitor. Each client contains a bit array to indicate the tags of a
|
2008-05-26 13:43:51 +03:00
|
|
|
* client.
|
2007-09-15 23:33:46 +03:00
|
|
|
*
|
2007-09-17 17:42:37 +03:00
|
|
|
* Keys and tagging rules are organized as arrays and defined in config.h.
|
2007-09-15 23:33:46 +03:00
|
|
|
*
|
|
|
|
* To understand everything else, start reading main().
|
|
|
|
*/
|
2007-09-15 23:25:27 +03:00
|
|
|
#include <errno.h>
|
2008-08-25 11:37:39 +03:00
|
|
|
#include <locale.h>
|
2008-12-13 19:44:29 +02:00
|
|
|
#include <signal.h>
|
2015-11-08 21:38:00 +02:00
|
|
|
#include <stdarg.h>
|
2007-09-15 23:25:27 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2007-09-27 10:14:32 +03:00
|
|
|
#include <sys/types.h>
|
2007-09-15 23:25:27 +03:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/Xatom.h>
|
2007-10-17 12:19:14 +03:00
|
|
|
#include <X11/Xlib.h>
|
2007-09-15 23:25:27 +03:00
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/Xutil.h>
|
2008-05-19 17:05:46 +03:00
|
|
|
#ifdef XINERAMA
|
|
|
|
#include <X11/extensions/Xinerama.h>
|
2009-06-20 17:10:04 +03:00
|
|
|
#endif /* XINERAMA */
|
2015-03-06 06:26:11 +02:00
|
|
|
#include <X11/Xft/Xft.h>
|
2007-09-15 23:25:27 +03:00
|
|
|
|
2013-04-17 22:21:47 +03:00
|
|
|
#include "drw.h"
|
2012-12-08 11:13:01 +02:00
|
|
|
#include "util.h"
|
2012-11-17 20:01:22 +02:00
|
|
|
|
2007-09-15 23:25:27 +03:00
|
|
|
/* macros */
|
2008-07-16 20:33:51 +03:00
|
|
|
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
2011-06-27 22:12:42 +03:00
|
|
|
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
2011-11-06 21:31:29 +02:00
|
|
|
#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)))
|
2009-06-23 19:20:33 +03:00
|
|
|
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
|
2009-06-20 17:51:34 +03:00
|
|
|
#define LENGTH(X) (sizeof X / sizeof X[0])
|
2008-07-16 20:33:51 +03:00
|
|
|
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
2009-06-20 19:02:55 +03:00
|
|
|
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
|
|
|
|
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
|
2009-07-14 18:04:07 +03:00
|
|
|
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
2016-05-22 23:33:56 +03:00
|
|
|
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
2007-11-07 10:49:53 +02:00
|
|
|
|
2007-10-18 11:28:41 +03:00
|
|
|
/* enums */
|
2013-06-19 20:35:33 +03:00
|
|
|
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
2016-12-05 11:01:33 +02:00
|
|
|
enum { SchemeNorm, SchemeSel }; /* color schemes */
|
2016-12-05 11:09:49 +02:00
|
|
|
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
2011-11-02 14:01:28 +02:00
|
|
|
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
2013-06-19 20:35:33 +03:00
|
|
|
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
2011-04-12 23:19:32 +03:00
|
|
|
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
|
2008-06-20 18:52:07 +03:00
|
|
|
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
|
2013-06-19 20:35:33 +03:00
|
|
|
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
|
2007-10-18 11:28:41 +03:00
|
|
|
|
2008-06-11 22:41:28 +03:00
|
|
|
typedef union {
|
|
|
|
int i;
|
2008-07-16 20:17:42 +03:00
|
|
|
unsigned int ui;
|
2008-06-11 22:41:28 +03:00
|
|
|
float f;
|
2009-07-08 20:59:20 +03:00
|
|
|
const void *v;
|
2008-06-11 22:41:28 +03:00
|
|
|
} Arg;
|
|
|
|
|
|
|
|
typedef struct {
|
2008-07-16 20:17:42 +03:00
|
|
|
unsigned int click;
|
|
|
|
unsigned int mask;
|
|
|
|
unsigned int button;
|
2008-06-11 22:41:28 +03:00
|
|
|
void (*func)(const Arg *arg);
|
|
|
|
const Arg arg;
|
|
|
|
} Button;
|
|
|
|
|
2009-06-22 16:58:08 +03:00
|
|
|
typedef struct Monitor Monitor;
|
2007-10-18 11:28:41 +03:00
|
|
|
typedef struct Client Client;
|
|
|
|
struct Client {
|
|
|
|
char name[256];
|
2008-06-15 12:52:57 +03:00
|
|
|
float mina, maxa;
|
2007-10-18 11:28:41 +03:00
|
|
|
int x, y, w, h;
|
2010-05-30 12:02:56 +03:00
|
|
|
int oldx, oldy, oldw, oldh;
|
2007-10-18 11:28:41 +03:00
|
|
|
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
|
2008-05-22 13:50:18 +03:00
|
|
|
int bw, oldbw;
|
2008-07-16 20:17:42 +03:00
|
|
|
unsigned int tags;
|
2015-11-08 23:48:43 +02:00
|
|
|
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
|
2007-10-18 11:28:41 +03:00
|
|
|
Client *next;
|
|
|
|
Client *snext;
|
2009-06-23 19:17:25 +03:00
|
|
|
Monitor *mon;
|
2007-10-18 11:28:41 +03:00
|
|
|
Window win;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
2008-07-16 20:17:42 +03:00
|
|
|
unsigned int mod;
|
2007-10-18 11:28:41 +03:00
|
|
|
KeySym keysym;
|
2008-06-11 11:12:06 +03:00
|
|
|
void (*func)(const Arg *);
|
|
|
|
const Arg arg;
|
2007-10-18 11:28:41 +03:00
|
|
|
} Key;
|
|
|
|
|
|
|
|
typedef struct {
|
2009-06-22 16:58:08 +03:00
|
|
|
const char *symbol;
|
|
|
|
void (*arrange)(Monitor *);
|
|
|
|
} Layout;
|
|
|
|
|
|
|
|
struct Monitor {
|
2009-09-22 11:53:11 +03:00
|
|
|
char ltsymbol[16];
|
2009-06-20 18:18:02 +03:00
|
|
|
float mfact;
|
2011-10-25 22:40:46 +03:00
|
|
|
int nmaster;
|
2009-07-09 23:52:17 +03:00
|
|
|
int num;
|
2009-07-09 13:29:01 +03:00
|
|
|
int by; /* bar geometry */
|
2009-06-30 22:15:31 +03:00
|
|
|
int mx, my, mw, mh; /* screen size */
|
2009-06-20 17:10:04 +03:00
|
|
|
int wx, wy, ww, wh; /* window area */
|
2009-06-19 22:15:15 +03:00
|
|
|
unsigned int seltags;
|
|
|
|
unsigned int sellt;
|
2009-06-20 19:02:55 +03:00
|
|
|
unsigned int tagset[2];
|
2015-11-08 23:48:43 +02:00
|
|
|
int showbar;
|
|
|
|
int topbar;
|
2009-06-23 19:17:25 +03:00
|
|
|
Client *clients;
|
|
|
|
Client *sel;
|
|
|
|
Client *stack;
|
2009-06-22 16:58:08 +03:00
|
|
|
Monitor *next;
|
2009-06-23 19:17:25 +03:00
|
|
|
Window barwin;
|
2009-07-08 20:59:20 +03:00
|
|
|
const Layout *lt[2];
|
2009-06-22 16:58:08 +03:00
|
|
|
};
|
2009-06-20 17:10:04 +03:00
|
|
|
|
2007-10-18 11:28:41 +03:00
|
|
|
typedef struct {
|
2008-03-14 16:35:45 +02:00
|
|
|
const char *class;
|
|
|
|
const char *instance;
|
|
|
|
const char *title;
|
2008-07-16 20:17:42 +03:00
|
|
|
unsigned int tags;
|
2015-11-08 23:48:43 +02:00
|
|
|
int isfloating;
|
2009-07-09 23:52:17 +03:00
|
|
|
int monitor;
|
2007-10-18 11:28:41 +03:00
|
|
|
} Rule;
|
|
|
|
|
2007-10-18 18:02:19 +03:00
|
|
|
/* function declarations */
|
2008-06-11 11:12:06 +03:00
|
|
|
static void applyrules(Client *c);
|
2015-11-08 23:48:43 +02:00
|
|
|
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
|
2009-09-27 12:31:14 +03:00
|
|
|
static void arrange(Monitor *m);
|
|
|
|
static void arrangemon(Monitor *m);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void attach(Client *c);
|
|
|
|
static void attachstack(Client *c);
|
|
|
|
static void buttonpress(XEvent *e);
|
|
|
|
static void checkotherwm(void);
|
|
|
|
static void cleanup(void);
|
2009-09-22 22:33:42 +03:00
|
|
|
static void cleanupmon(Monitor *mon);
|
2010-05-30 12:02:56 +03:00
|
|
|
static void clientmessage(XEvent *e);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void configure(Client *c);
|
|
|
|
static void configurenotify(XEvent *e);
|
|
|
|
static void configurerequest(XEvent *e);
|
2009-09-21 21:51:17 +03:00
|
|
|
static Monitor *createmon(void);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void destroynotify(XEvent *e);
|
|
|
|
static void detach(Client *c);
|
|
|
|
static void detachstack(Client *c);
|
2009-07-02 22:37:26 +03:00
|
|
|
static Monitor *dirtomon(int dir);
|
2009-06-20 17:10:04 +03:00
|
|
|
static void drawbar(Monitor *m);
|
2009-06-27 20:39:03 +03:00
|
|
|
static void drawbars(void);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void enternotify(XEvent *e);
|
|
|
|
static void expose(XEvent *e);
|
|
|
|
static void focus(Client *c);
|
|
|
|
static void focusin(XEvent *e);
|
2009-07-01 21:15:20 +03:00
|
|
|
static void focusmon(const Arg *arg);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void focusstack(const Arg *arg);
|
2015-11-08 23:48:43 +02:00
|
|
|
static int getrootptr(int *x, int *y);
|
2008-06-11 11:12:06 +03:00
|
|
|
static long getstate(Window w);
|
2015-11-08 23:48:43 +02:00
|
|
|
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
|
|
|
static void grabbuttons(Client *c, int focused);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void grabkeys(void);
|
2011-10-25 22:40:46 +03:00
|
|
|
static void incnmaster(const Arg *arg);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void keypress(XEvent *e);
|
|
|
|
static void killclient(const Arg *arg);
|
|
|
|
static void manage(Window w, XWindowAttributes *wa);
|
|
|
|
static void mappingnotify(XEvent *e);
|
|
|
|
static void maprequest(XEvent *e);
|
2009-06-20 17:10:04 +03:00
|
|
|
static void monocle(Monitor *m);
|
2011-11-15 21:16:58 +02:00
|
|
|
static void motionnotify(XEvent *e);
|
2008-06-11 22:41:28 +03:00
|
|
|
static void movemouse(const Arg *arg);
|
2009-06-23 19:20:33 +03:00
|
|
|
static Client *nexttiled(Client *c);
|
2011-04-15 11:13:06 +03:00
|
|
|
static void pop(Client *);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void propertynotify(XEvent *e);
|
|
|
|
static void quit(const Arg *arg);
|
2011-11-06 21:31:29 +02:00
|
|
|
static Monitor *recttomon(int x, int y, int w, int h);
|
2015-11-08 23:48:43 +02:00
|
|
|
static void resize(Client *c, int x, int y, int w, int h, int interact);
|
2010-05-30 12:02:56 +03:00
|
|
|
static void resizeclient(Client *c, int x, int y, int w, int h);
|
2008-06-11 22:41:28 +03:00
|
|
|
static void resizemouse(const Arg *arg);
|
2009-06-20 17:10:04 +03:00
|
|
|
static void restack(Monitor *m);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void run(void);
|
|
|
|
static void scan(void);
|
2015-11-08 23:48:43 +02:00
|
|
|
static int sendevent(Client *c, Atom proto);
|
2009-06-27 20:39:03 +03:00
|
|
|
static void sendmon(Client *c, Monitor *m);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void setclientstate(Client *c, long state);
|
2011-04-12 23:19:32 +03:00
|
|
|
static void setfocus(Client *c);
|
2015-11-08 23:48:43 +02:00
|
|
|
static void setfullscreen(Client *c, int fullscreen);
|
2008-06-19 13:38:53 +03:00
|
|
|
static void setlayout(const Arg *arg);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void setmfact(const Arg *arg);
|
|
|
|
static void setup(void);
|
2016-12-05 11:16:46 +02:00
|
|
|
static void seturgent(Client *c, int urg);
|
2009-03-19 15:06:15 +02:00
|
|
|
static void showhide(Client *c);
|
2009-08-13 12:45:59 +03:00
|
|
|
static void sigchld(int unused);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void spawn(const Arg *arg);
|
|
|
|
static void tag(const Arg *arg);
|
2009-07-01 21:15:20 +03:00
|
|
|
static void tagmon(const Arg *arg);
|
2009-06-20 17:10:04 +03:00
|
|
|
static void tile(Monitor *);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void togglebar(const Arg *arg);
|
|
|
|
static void togglefloating(const Arg *arg);
|
|
|
|
static void toggletag(const Arg *arg);
|
|
|
|
static void toggleview(const Arg *arg);
|
2015-11-08 23:48:43 +02:00
|
|
|
static void unfocus(Client *c, int setfocus);
|
|
|
|
static void unmanage(Client *c, int destroyed);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void unmapnotify(XEvent *e);
|
2015-11-08 23:48:43 +02:00
|
|
|
static int updategeom(void);
|
2009-06-22 22:29:59 +03:00
|
|
|
static void updatebarpos(Monitor *m);
|
2009-06-22 16:58:08 +03:00
|
|
|
static void updatebars(void);
|
2012-03-25 18:49:35 +03:00
|
|
|
static void updateclientlist(void);
|
2008-08-25 11:44:23 +03:00
|
|
|
static void updatenumlockmask(void);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void updatesizehints(Client *c);
|
2008-12-12 21:49:06 +02:00
|
|
|
static void updatestatus(void);
|
2011-11-02 14:01:28 +02:00
|
|
|
static void updatewindowtype(Client *c);
|
2008-06-11 11:12:06 +03:00
|
|
|
static void updatetitle(Client *c);
|
|
|
|
static void updatewmhints(Client *c);
|
|
|
|
static void view(const Arg *arg);
|
2009-06-30 21:39:59 +03:00
|
|
|
static Client *wintoclient(Window w);
|
|
|
|
static Monitor *wintomon(Window w);
|
2008-06-11 11:12:06 +03:00
|
|
|
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);
|
2007-10-18 11:28:41 +03:00
|
|
|
|
|
|
|
/* variables */
|
2009-07-13 00:49:06 +03:00
|
|
|
static const char broken[] = "broken";
|
2009-09-16 17:59:54 +03:00
|
|
|
static char stext[256];
|
added some comments regarding FAQ about s{x,y,w,h}, w{x,y,w,h}, b{y,h,lw}
2008-08-18 11:10:21 +03:00
|
|
|
static int screen;
|
2009-07-09 23:52:17 +03:00
|
|
|
static int sw, sh; /* X display screen geometry width, height */
|
2009-06-20 17:10:04 +03:00
|
|
|
static int bh, blw = 0; /* bar geometry */
|
2016-05-22 23:33:56 +03:00
|
|
|
static int lrpad; /* sum of left and right padding for text */
|
2008-06-11 11:12:06 +03:00
|
|
|
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
2008-07-16 20:17:42 +03:00
|
|
|
static unsigned int numlockmask = 0;
|
2008-06-11 11:12:06 +03:00
|
|
|
static void (*handler[LASTEvent]) (XEvent *) = {
|
2007-10-18 11:28:41 +03:00
|
|
|
[ButtonPress] = buttonpress,
|
2010-05-30 12:02:56 +03:00
|
|
|
[ClientMessage] = clientmessage,
|
2007-10-18 11:28:41 +03:00
|
|
|
[ConfigureRequest] = configurerequest,
|
|
|
|
[ConfigureNotify] = configurenotify,
|
|
|
|
[DestroyNotify] = destroynotify,
|
|
|
|
[EnterNotify] = enternotify,
|
|
|
|
[Expose] = expose,
|
2007-11-17 20:59:13 +02:00
|
|
|
[FocusIn] = focusin,
|
2007-10-18 11:28:41 +03:00
|
|
|
[KeyPress] = keypress,
|
|
|
|
[MappingNotify] = mappingnotify,
|
|
|
|
[MapRequest] = maprequest,
|
2011-11-15 21:16:58 +02:00
|
|
|
[MotionNotify] = motionnotify,
|
2007-10-18 11:28:41 +03:00
|
|
|
[PropertyNotify] = propertynotify,
|
|
|
|
[UnmapNotify] = unmapnotify
|
|
|
|
};
|
2008-06-11 11:12:06 +03:00
|
|
|
static Atom wmatom[WMLast], netatom[NetLast];
|
2015-11-08 23:48:43 +02:00
|
|
|
static int running = 1;
|
2013-06-16 16:20:29 +03:00
|
|
|
static Cur *cursor[CurLast];
|
2017-11-03 22:20:48 +02:00
|
|
|
static Clr **scheme;
|
2008-06-11 11:12:06 +03:00
|
|
|
static Display *dpy;
|
2013-06-16 16:20:29 +03:00
|
|
|
static Drw *drw;
|
|
|
|
static Monitor *mons, *selmon;
|
2016-12-05 11:09:49 +02:00
|
|
|
static Window root, wmcheckwin;
|
2009-07-02 22:56:23 +03:00
|
|
|
|
2007-10-18 11:28:41 +03:00
|
|
|
/* configuration, allows nested code to access above variables */
|
|
|
|
#include "config.h"
|
2008-05-22 13:04:19 +03:00
|
|
|
|
2008-07-16 20:17:42 +03:00
|
|
|
/* compile-time check if all tags fit into an unsigned int bit array. */
|
2009-07-14 18:01:14 +03:00
|
|
|
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
|
2007-10-18 11:28:41 +03:00
|
|
|
|
2007-10-18 18:02:19 +03:00
|
|
|
/* function implementations */
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
applyrules(Client *c)
|
|
|
|
{
|
2009-07-13 00:49:06 +03:00
|
|
|
const char *class, *instance;
|
2008-07-16 20:17:42 +03:00
|
|
|
unsigned int i;
|
2009-07-08 20:59:20 +03:00
|
|
|
const Rule *r;
|
2009-07-09 23:52:17 +03:00
|
|
|
Monitor *m;
|
2011-08-15 19:44:12 +03:00
|
|
|
XClassHint ch = { NULL, NULL };
|
2007-09-15 23:25:27 +03:00
|
|
|
|
2007-09-16 12:53:14 +03:00
|
|
|
/* rule matching */
|
2015-11-08 23:48:43 +02:00
|
|
|
c->isfloating = 0;
|
2015-11-07 15:04:49 +02:00
|
|
|
c->tags = 0;
|
2011-08-15 19:44:12 +03:00
|
|
|
XGetClassHint(dpy, c->win, &ch);
|
|
|
|
class = ch.res_class ? ch.res_class : broken;
|
|
|
|
instance = ch.res_name ? ch.res_name : broken;
|
|
|
|
|
2015-11-09 00:11:48 +02:00
|
|
|
for (i = 0; i < LENGTH(rules); i++) {
|
2011-08-15 19:44:12 +03:00
|
|
|
r = &rules[i];
|
2015-11-09 00:11:48 +02:00
|
|
|
if ((!r->title || strstr(c->name, r->title))
|
2011-08-15 19:44:12 +03:00
|
|
|
&& (!r->class || strstr(class, r->class))
|
|
|
|
&& (!r->instance || strstr(instance, r->instance)))
|
|
|
|
{
|
|
|
|
c->isfloating = r->isfloating;
|
|
|
|
c->tags |= r->tags;
|
2015-11-09 00:11:48 +02:00
|
|
|
for (m = mons; m && m->num != r->monitor; m = m->next);
|
|
|
|
if (m)
|
2011-08-15 19:44:12 +03:00
|
|
|
c->mon = m;
|
2007-09-16 12:53:14 +03:00
|
|
|
}
|
2008-02-27 00:51:23 +02:00
|
|
|
}
|
2015-11-09 00:11:48 +02:00
|
|
|
if (ch.res_class)
|
2011-08-15 19:44:12 +03:00
|
|
|
XFree(ch.res_class);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (ch.res_name)
|
2011-08-15 19:44:12 +03:00
|
|
|
XFree(ch.res_name);
|
2009-06-23 19:17:25 +03:00
|
|
|
c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
|
2007-09-15 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
2015-11-08 23:48:43 +02:00
|
|
|
int
|
2015-11-09 00:11:48 +02:00
|
|
|
applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
|
|
|
|
{
|
2015-11-08 23:48:43 +02:00
|
|
|
int baseismin;
|
2009-06-30 22:15:31 +03:00
|
|
|
Monitor *m = c->mon;
|
2009-03-02 12:43:48 +02:00
|
|
|
|
|
|
|
/* set minimum possible */
|
|
|
|
*w = MAX(1, *w);
|
|
|
|
*h = MAX(1, *h);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (interact) {
|
|
|
|
if (*x > sw)
|
2009-07-02 20:30:01 +03:00
|
|
|
*x = sw - WIDTH(c);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*y > sh)
|
2009-07-02 20:30:01 +03:00
|
|
|
*y = sh - HEIGHT(c);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*x + *w + 2 * c->bw < 0)
|
2009-07-02 20:30:01 +03:00
|
|
|
*x = 0;
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*y + *h + 2 * c->bw < 0)
|
2009-07-02 20:30:01 +03:00
|
|
|
*y = 0;
|
2015-11-09 00:11:48 +02:00
|
|
|
} else {
|
|
|
|
if (*x >= m->wx + m->ww)
|
2011-11-04 21:02:35 +02:00
|
|
|
*x = m->wx + m->ww - WIDTH(c);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*y >= m->wy + m->wh)
|
2011-11-04 21:02:35 +02:00
|
|
|
*y = m->wy + m->wh - HEIGHT(c);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*x + *w + 2 * c->bw <= m->wx)
|
2011-11-04 21:02:35 +02:00
|
|
|
*x = m->wx;
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*y + *h + 2 * c->bw <= m->wy)
|
2011-11-04 21:02:35 +02:00
|
|
|
*y = m->wy;
|
2009-07-02 20:30:01 +03:00
|
|
|
}
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*h < bh)
|
2009-03-17 21:53:00 +02:00
|
|
|
*h = bh;
|
2015-11-09 00:11:48 +02:00
|
|
|
if (*w < bh)
|
2009-03-17 21:53:00 +02:00
|
|
|
*w = bh;
|
2015-11-09 00:11:48 +02:00
|
|
|
if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
|
2009-03-17 21:53:00 +02:00
|
|
|
/* see last two sentences in ICCCM 4.1.2.3 */
|
|
|
|
baseismin = c->basew == c->minw && c->baseh == c->minh;
|
2015-11-09 00:11:48 +02:00
|
|
|
if (!baseismin) { /* temporarily remove base dimensions */
|
2009-03-17 21:53:00 +02:00
|
|
|
*w -= c->basew;
|
|
|
|
*h -= c->baseh;
|
|
|
|
}
|
|
|
|
/* adjust for aspect limits */
|
2015-11-09 00:11:48 +02:00
|
|
|
if (c->mina > 0 && c->maxa > 0) {
|
|
|
|
if (c->maxa < (float)*w / *h)
|
2009-07-17 17:28:07 +03:00
|
|
|
*w = *h * c->maxa + 0.5;
|
2015-11-09 00:11:48 +02:00
|
|
|
else if (c->mina < (float)*h / *w)
|
2009-07-17 17:28:07 +03:00
|
|
|
*h = *w * c->mina + 0.5;
|
2009-03-17 21:53:00 +02:00
|
|
|
}
|
2015-11-09 00:11:48 +02:00
|
|
|
if (baseismin) { /* increment calculation requires this */
|
2009-03-17 21:53:00 +02:00
|
|
|
*w -= c->basew;
|
|
|
|
*h -= c->baseh;
|
|
|
|
}
|
|
|
|
/* adjust for increment value */
|
2015-11-09 00:11:48 +02:00
|
|
|
if (c->incw)
|
2009-03-17 21:53:00 +02:00
|
|
|
*w -= *w % c->incw;
|
2015-11-09 00:11:48 +02:00
|
|
|
if (c->inch)
|
2009-03-17 21:53:00 +02:00
|
|
|
*h -= *h % c->inch;
|
|
|
|
/* restore base dimensions */
|
2010-09-25 16:39:08 +03:00
|
|
|
*w = MAX(*w + c->basew, c->minw);
|
|
|
|
*h = MAX(*h + c->baseh, c->minh);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (c->maxw)
|
2009-03-17 21:53:00 +02:00
|
|
|
*w = MIN(*w, c->maxw);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (c->maxh)
|
2009-03-17 21:53:00 +02:00
|
|
|
*h = MIN(*h, c->maxh);
|
|
|
|
}
|
|
|
|
return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
|
2009-03-02 12:43:48 +02:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
arrange(Monitor *m)
|
|
|
|
{
|
|
|
|
if (m)
|
2009-09-27 12:31:14 +03:00
|
|
|
showhide(m->stack);
|
2015-11-09 00:11:48 +02:00
|
|
|
else for (m = mons; m; m = m->next)
|
2009-06-23 19:17:25 +03:00
|
|
|
showhide(m->stack);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (m) {
|
2009-09-27 12:31:14 +03:00
|
|
|
arrangemon(m);
|
2012-02-08 20:54:05 +02:00
|
|
|
restack(m);
|
2015-11-09 00:11:48 +02:00
|
|
|
} else for (m = mons; m; m = m->next)
|
2009-09-27 12:31:14 +03:00
|
|
|
arrangemon(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
arrangemon(Monitor *m)
|
|
|
|
{
|
2009-09-27 12:31:14 +03:00
|
|
|
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
|
2015-11-09 00:11:48 +02:00
|
|
|
if (m->lt[m->sellt]->arrange)
|
2009-09-27 12:31:14 +03:00
|
|
|
m->lt[m->sellt]->arrange(m);
|
2007-09-15 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
attach(Client *c)
|
|
|
|
{
|
2009-06-23 19:34:20 +03:00
|
|
|
c->next = c->mon->clients;
|
|
|
|
c->mon->clients = c;
|
2007-09-15 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
attachstack(Client *c)
|
|
|
|
{
|
2009-06-23 19:34:20 +03:00
|
|
|
c->snext = c->mon->stack;
|
|
|
|
c->mon->stack = c;
|
2007-09-15 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
buttonpress(XEvent *e)
|
|
|
|
{
|
2008-07-16 20:17:42 +03:00
|
|
|
unsigned int i, x, click;
|
2008-06-20 18:52:07 +03:00
|
|
|
Arg arg = {0};
|
2007-09-16 12:53:14 +03:00
|
|
|
Client *c;
|
2009-06-24 21:45:47 +03:00
|
|
|
Monitor *m;
|
2007-09-16 12:53:14 +03:00
|
|
|
XButtonPressedEvent *ev = &e->xbutton;
|
2007-09-15 23:25:27 +03:00
|
|
|
|
2008-06-15 12:52:57 +03:00
|
|
|
click = ClkRootWin;
|
2009-06-24 21:45:47 +03:00
|
|
|
/* focus monitor if necessary */
|
2015-11-09 00:11:48 +02:00
|
|
|
if ((m = wintomon(ev->window)) && m != selmon) {
|
2015-11-08 23:48:43 +02:00
|
|
|
unfocus(selmon->sel, 1);
|
2009-06-27 20:39:03 +03:00
|
|
|
selmon = m;
|
|
|
|
focus(NULL);
|
|
|
|
}
|
2015-11-09 00:11:48 +02:00
|
|
|
if (ev->window == selmon->barwin) {
|
2009-07-09 13:29:01 +03:00
|
|
|
i = x = 0;
|
2011-07-27 20:59:10 +03:00
|
|
|
do
|
2009-06-20 17:10:04 +03:00
|
|
|
x += TEXTW(tags[i]);
|
2015-11-09 00:11:48 +02:00
|
|
|
while (ev->x >= x && ++i < LENGTH(tags));
|
|
|
|
if (i < LENGTH(tags)) {
|
2008-06-20 18:52:07 +03:00
|
|
|
click = ClkTagBar;
|
|
|
|
arg.ui = 1 << i;
|
2015-11-09 00:11:48 +02:00
|
|
|
} else if (ev->x < x + blw)
|
2008-06-12 15:10:14 +03:00
|
|
|
click = ClkLtSymbol;
|
2015-11-09 00:11:48 +02:00
|
|
|
else if (ev->x > selmon->ww - TEXTW(stext))
|
2008-06-12 15:10:14 +03:00
|
|
|
click = ClkStatusText;
|
|
|
|
else
|
|
|
|
click = ClkWinTitle;
|
2015-11-09 00:11:48 +02:00
|
|
|
} else if ((c = wintoclient(ev->window))) {
|
2008-06-15 12:52:57 +03:00
|
|
|
focus(c);
|
2017-01-07 18:21:29 +02:00
|
|
|
restack(selmon);
|
|
|
|
XAllowEvents(dpy, ReplayPointer, CurrentTime);
|
2008-06-11 22:41:28 +03:00
|
|
|
click = ClkClientWin;
|
2008-06-15 12:52:57 +03:00
|
|
|
}
|
2015-11-09 00:11:48 +02:00
|
|
|
for (i = 0; i < LENGTH(buttons); i++)
|
|
|
|
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
|
2009-07-14 18:26:04 +03:00
|
|
|
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
|
2008-09-02 00:18:50 +03:00
|
|
|
buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
|
2007-09-15 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
checkotherwm(void)
|
|
|
|
{
|
2008-09-06 10:59:51 +03:00
|
|
|
xerrorxlib = XSetErrorHandler(xerrorstart);
|
2007-09-16 13:34:08 +03:00
|
|
|
/* this causes an error if some other window manager is running */
|
2007-12-22 16:30:47 +02:00
|
|
|
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
|
2007-09-16 13:34:08 +03:00
|
|
|
XSync(dpy, False);
|
2008-09-06 10:59:51 +03:00
|
|
|
XSetErrorHandler(xerror);
|
2007-09-16 13:34:08 +03:00
|
|
|
XSync(dpy, False);
|
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
cleanup(void)
|
|
|
|
{
|
2008-08-12 22:24:40 +03:00
|
|
|
Arg a = {.ui = ~0};
|
2008-06-11 12:26:57 +03:00
|
|
|
Layout foo = { "", NULL };
|
2009-06-23 19:17:25 +03:00
|
|
|
Monitor *m;
|
2015-10-21 00:27:31 +03:00
|
|
|
size_t i;
|
2008-06-11 12:25:02 +03:00
|
|
|
|
2008-06-11 11:12:06 +03:00
|
|
|
view(&a);
|
2009-07-06 22:12:47 +03:00
|
|
|
selmon->lt[selmon->sellt] = &foo;
|
2015-11-09 00:11:48 +02:00
|
|
|
for (m = mons; m; m = m->next)
|
|
|
|
while (m->stack)
|
2015-11-08 23:48:43 +02:00
|
|
|
unmanage(m->stack, 0);
|
2008-02-18 19:08:22 +02:00
|
|
|
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
2015-11-09 00:11:48 +02:00
|
|
|
while (mons)
|
2009-09-22 22:33:42 +03:00
|
|
|
cleanupmon(mons);
|
2015-11-09 00:11:48 +02:00
|
|
|
for (i = 0; i < CurLast; i++)
|
2015-10-21 00:27:31 +03:00
|
|
|
drw_cur_free(drw, cursor[i]);
|
2016-12-05 11:01:33 +02:00
|
|
|
for (i = 0; i < LENGTH(colors); i++)
|
2016-05-22 23:33:56 +03:00
|
|
|
free(scheme[i]);
|
2016-12-05 11:09:49 +02:00
|
|
|
XDestroyWindow(dpy, wmcheckwin);
|
2013-06-16 16:20:29 +03:00
|
|
|
drw_free(drw);
|
2008-02-18 19:08:22 +02:00
|
|
|
XSync(dpy, False);
|
|
|
|
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
2012-03-25 18:46:03 +03:00
|
|
|
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
2007-09-15 23:25:27 +03:00
|
|
|
}
|
|
|
|
|
2009-06-22 16:58:08 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
cleanupmon(Monitor *mon)
|
|
|
|
{
|
2009-06-22 16:58:08 +03:00
|
|
|
Monitor *m;
|
|
|
|
|
2015-11-09 00:11:48 +02:00
|
|
|
if (mon == mons)
|
2009-09-22 22:33:42 +03:00
|
|
|
mons = mons->next;
|
|
|
|
else {
|
2015-11-09 00:11:48 +02:00
|
|
|
for (m = mons; m && m->next != mon; m = m->next);
|
2009-09-22 22:33:42 +03:00
|
|
|
m->next = mon->next;
|
2009-06-22 16:58:08 +03:00
|
|
|
}
|
2009-09-22 22:33:42 +03:00
|
|
|
XUnmapWindow(dpy, mon->barwin);
|
|
|
|
XDestroyWindow(dpy, mon->barwin);
|
|
|
|
free(mon);
|
2009-06-22 16:58:08 +03:00
|
|
|
}
|
|
|
|
|
2011-04-15 11:12:20 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
clientmessage(XEvent *e)
|
|
|
|
{
|
2011-04-15 11:12:20 +03:00
|
|
|
XClientMessageEvent *cme = &e->xclient;
|
|
|
|
Client *c = wintoclient(cme->window);
|
|
|
|
|
2015-11-09 00:11:48 +02:00
|
|
|
if (!c)
|
2011-04-15 11:12:20 +03:00
|
|
|
return;
|
2015-11-09 00:11:48 +02:00
|
|
|
if (cme->message_type == netatom[NetWMState]) {
|
2017-01-07 18:21:28 +02:00
|
|
|
if (cme->data.l[1] == netatom[NetWMFullscreen]
|
|
|
|
|| cme->data.l[2] == netatom[NetWMFullscreen])
|
2011-11-06 21:30:06 +02:00
|
|
|
setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */
|
2017-05-08 22:08:27 +03:00
|
|
|
|| (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
|
2015-11-09 00:11:48 +02:00
|
|
|
} else if (cme->message_type == netatom[NetActiveWindow]) {
|
2016-12-05 11:16:46 +02:00
|
|
|
if (c != selmon->sel && !c->isurgent)
|
|
|
|
seturgent(c, 1);
|
2011-04-15 11:12:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
configure(Client *c)
|
|
|
|
{
|
2007-09-16 12:53:14 +03:00
|
|
|
XConfigureEvent ce;
|
2007-09-15 23:25:27 +03:00
|
|
|
|
2007-09-16 12:53:14 +03:00
|
|
|
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;
|
2008-03-17 18:29:50 +02:00
|
|
|
ce.border_width = c->bw;
|
2007-09-16 12:53:14 +03:00
|
|
|
ce.above = None;
|
|
|
|
ce.override_redirect = False;
|
|
|
|
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
|
|
|
|
}
|
|
|
|
|
2007-09-17 17:42:37 +03:00
|
|
|
void
|
2015-11-09 00:11:48 +02:00
|
|
|
configurenotify(XEvent *e)
|
|
|
|
{
|
2009-06-22 16:58:08 +03:00
|
|
|
Monitor *m;
|
2015-12-19 21:25:26 +02:00
|
|