Xinqi Bao's Git
ee7ced192776319fab360c978e5281942a8de269
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
5 * dynamic window manager is designed like any other X client as well. It is
6 * driven through handling X events. In contrast to other X clients, a window
7 * manager like dwm selects for SubstructureRedirectMask on the root window, to
8 * receive events about child window appearance and disappearance. Only one X
9 * connection at a time is allowed to select for this event mask by any X
10 * server, thus only one window manager instance can be executed at a time.
11 * Any attempt to select for SubstructureRedirectMask by any connection after
12 * another connection already selected for those events, will result in an
13 * error generated by the server. Such errors are reported through calling the
14 * current X error handler.
16 * Calls to pop an X event from the event queue of the X connection are
17 * blocking. Due the fact, that dwm reads status text from standard input, a
18 * select-driven main loop has been implemented which selects for reads on the
19 * X connection and STDIN_FILENO to handle all data smoothly and without
20 * busy-loop quirks.. The event handlers of dwm are organized in an array
21 * which is accessed whenever a new event has been popped. This allows event
22 * dispatching in O(1) time.
24 * Each child window of the root window is called a client in window manager
25 * terminology, except windows which have set the override_redirect flag.
26 * Clients are organized in a global doubly-linked client list, the focus
27 * history is remembered through a global stack list. Each client contains an
28 * array of Bools of the same size as the global tags array to indicate the
29 * tags of a client. There are no other data structures to organize the clients
30 * in tag lists, because a single global list is most simple. All clients which
31 * have at least one tag enabled of the current tags viewed, will be visible on
32 * the screen, all other clients are banned to the x-location 2 * screen width.
33 * This avoids having additional layers of workspace handling.
35 * For each client dwm creates a small title window which is resized whenever
36 * the WM_NAME or _NET_WM_NAME properties are updated.
38 * Keys and tagging rules are organized as arrays as well and defined in the
39 * config.h file. These arrays are kept static in event.o and tag.o
40 * respectively, because no other part of dwm needs access to them.
42 * The current mode is represented by the arrange function pointer which wether
43 * points to dofloat or dotile.
49 /* mask shorthands, used in event.c and client.c */
50 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
51 #define MOUSEMASK (BUTTONMASK | PointerMotionMask)
54 enum { NetSupported
, NetWMName
, NetLast
}; /* EWMH atoms */
55 enum { WMProtocols
, WMDelete
, WMLast
}; /* default atoms */
56 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
57 enum { ColFG
, ColBG
, ColLast
}; /* color */
60 TopLeft
, TopRight
, BotLeft
, BotRight
61 } Corner
; /* window corners */
66 } Arg
; /* argument type */
78 unsigned long norm
[ColLast
];
79 unsigned long sel
[ColLast
];
80 unsigned long status
[ColLast
];
84 } DC
; /* draw context */
86 typedef struct Client Client
;
91 int tx
, ty
, tw
, th
; /* title window geometry */
92 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
95 unsigned int border
, weight
;
105 extern const char *tags
[]; /* all tags */
106 extern char stext
[1024]; /* status text */
107 extern int bx
, by
, bw
, bh
, bmw
; /* bar geometry, bar mode label width */
108 extern int mw
, screen
, sx
, sy
, sw
, sh
; /* screen geometry, master width */
109 extern unsigned int ntags
, numlockmask
; /* number of tags, dynamic lock mask */
110 extern void (*handler
[LASTEvent
])(XEvent
*); /* event handler */
111 extern void (*arrange
)(Arg
*); /* arrange function, indicates mode */
112 extern Atom wmatom
[WMLast
], netatom
[NetLast
];
113 extern Bool running
, issel
, maximized
, *seltag
; /* seltag is array of Bool */
114 extern Client
*clients
, *sel
, *stack
; /* global cleint list and stack */
115 extern Cursor cursor
[CurLast
];
116 extern DC dc
; /* global draw context */
118 extern Window root
, barwin
;
121 extern void ban(Client
*c
); /* ban c from screen */
122 extern void focus(Client
*c
); /* focus c, c may be NULL */
123 extern Client
*getclient(Window w
); /* return client of w */
124 extern Client
*getctitle(Window w
); /* return client of title window */
125 extern void gravitate(Client
*c
, Bool invert
); /* gravitate c */
126 extern void killclient(Arg
*arg
); /* kill c nicely */
127 extern void manage(Window w
, XWindowAttributes
*wa
); /* manage new client */
128 extern void resize(Client
*c
, Bool sizehints
, Corner sticky
); /* resize c*/
129 extern void updatesize(Client
*c
); /* update the size structs of c */
130 extern void updatetitle(Client
*c
); /* update the name of c */
131 extern void togglemax(Arg
*arg
); /* (un)maximize c */
132 extern void unmanage(Client
*c
); /* destroy c */
135 extern void drawall(); /* draw all visible client titles and the bar */
136 extern void drawstatus(); /* draw the bar */
137 extern void drawtitle(Client
*c
); /* draw title of c */
138 extern unsigned long getcolor(const char *colstr
); /* return color of colstr */
139 extern void setfont(const char *fontstr
); /* set the font for DC */
140 extern unsigned int textw(const char *text
); /* return the width of text in px*/
143 extern void grabkeys(); /* grab all keys defined in config.h */
144 extern void procevent(); /* process pending X events */
147 extern int getproto(Window w
); /* return protocol mask of WMProtocols property of w */
148 extern void quit(Arg
*arg
); /* quit dwm nicely */
149 extern void sendevent(Window w
, Atom a
, long value
); /* send synthetic event to w */
150 extern int xerror(Display
*dsply
, XErrorEvent
*ee
); /* dwm's X error handler */
153 extern void initrregs(); /* initialize regexps of rules defined in config.h */
154 extern Client
*getnext(Client
*c
); /* returns next visible client */
155 extern Client
*getprev(Client
*c
); /* returns previous visible client */
156 extern void settags(Client
*c
, Client
*trans
); /* sets tags of c */
157 extern void tag(Arg
*arg
); /* tags c with arg's index */
158 extern void toggletag(Arg
*arg
); /* toggles c tags with arg's index */
161 extern void *emallocz(unsigned int size
); /* allocates zero-initialized memory, exits on error */
162 extern void eprint(const char *errstr
, ...); /* prints errstr and exits with 1 */
163 extern void *erealloc(void *ptr
, unsigned int size
); /* reallocates memory, exits on error */
164 extern void spawn(Arg
*arg
); /* forks a new subprocess with to arg's cmd */
167 extern void detach(Client
*c
); /* detaches c from global client list */
168 extern void dofloat(Arg
*arg
); /* arranges all windows floating, arg is ignored */
169 extern void dotile(Arg
*arg
); /* arranges all windows, arg is ignored */
170 extern void focusnext(Arg
*arg
); /* focuses next visible client, arg is ignored */
171 extern void focusprev(Arg
*arg
); /* focuses previous visible client, arg is ignored */
172 extern Bool
isvisible(Client
*c
); /* returns True if client is visible */
173 extern void resizecol(Arg
*arg
); /* resizes the master width with arg's index value */
174 extern void restack(); /* restores z layers of all clients */
175 extern void togglemode(Arg
*arg
); /* toggles global arrange function (dotile/dofloat) */
176 extern void toggleview(Arg
*arg
); /* toggles the tag with arg's index (in)visible */
177 extern void view(Arg
*arg
); /* views the tag with arg's index */
178 extern void viewall(Arg
*arg
); /* views all tags, arg is ignored */
179 extern void zoom(Arg
*arg
); /* zooms the focused client to master column, arg is ignored */