Xinqi Bao's Git
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.
11 * Calls to fetch an X event from the event queue of the X connection are
12 * blocking. Due the fact, that dwm reads status text from standard input, a
13 * select-driven main loop has been implemented which selects for reads on the
14 * X connection and STDIN_FILENO to handle all data smoothly and without
15 * busy-loop quirks. The event handlers of dwm are organized in an array which
16 * is accessed whenever a new event has been fetched. This allows event
17 * dispatching in O(1) time.
19 * Each child window of the root window is called a client in window manager
20 * terminology, except windows which have set the override_redirect flag.
21 * Clients are organized in a global doubly-linked client list, the focus
22 * history is remembered through a global stack list. Each client contains an
23 * array of Bools of the same size as the global tags array to indicate the
24 * tags of a client. There are no other data structures to organize the clients
25 * in tag lists. All clients which have at least one tag enabled of the current
26 * tags viewed, will be visible on the screen, all other clients are banned to
27 * the x-location x + 2 * screen width. This avoids having additional layers
28 * of workspace handling.
30 * For each client dwm creates a small title window which is resized whenever
31 * the WM_NAME or _NET_WM_NAME properties are updated or the client is resized.
32 * Keys and tagging rules are organized as arrays and defined in the config.h
33 * file. These arrays are kept static in event.o and tag.o respectively,
34 * because no other part of dwm needs access to them. The current mode is
35 * represented by the arrange function pointer which wether points to dofloat
38 * To understand everything else, start with reading main.c:main().
44 /* mask shorthands, used in event.c and client.c */
45 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
46 #define MOUSEMASK (BUTTONMASK | PointerMotionMask)
49 enum { NetSupported
, NetWMName
, NetLast
}; /* EWMH atoms */
50 enum { WMProtocols
, WMDelete
, WMLast
}; /* default atoms */
51 enum { CurNormal
, CurResize
, CurMove
, CurLast
}; /* cursor */
52 enum { ColFG
, ColBG
, ColLast
}; /* color */
55 TopLeft
, TopRight
, BotLeft
, BotRight
56 } Corner
; /* window corners */
61 } Arg
; /* argument type */
73 unsigned long norm
[ColLast
];
74 unsigned long sel
[ColLast
];
75 unsigned long status
[ColLast
];
79 } DC
; /* draw context */
81 typedef struct Client Client
;
86 int tx
, ty
, tw
, th
; /* title window geometry */
87 int basew
, baseh
, incw
, inch
, maxw
, maxh
, minw
, minh
;
90 unsigned int border
, weight
;
100 extern const char *tags
[]; /* all tags */
101 extern char stext
[1024]; /* status text */
102 extern int bx
, by
, bw
, bh
, bmw
; /* bar geometry, bar mode label width */
103 extern int mw
, screen
, sx
, sy
, sw
, sh
; /* screen geometry, master width */
104 extern unsigned int ntags
, numlockmask
; /* number of tags, dynamic lock mask */
105 extern void (*handler
[LASTEvent
])(XEvent
*); /* event handler */
106 extern void (*arrange
)(Arg
*); /* arrange function, indicates mode */
107 extern Atom wmatom
[WMLast
], netatom
[NetLast
];
108 extern Bool running
, issel
, maximized
, *seltag
; /* seltag is array of Bool */
109 extern Client
*clients
, *sel
, *stack
; /* global cleint list and stack */
110 extern Cursor cursor
[CurLast
];
111 extern DC dc
; /* global draw context */
113 extern Window root
, barwin
;
116 extern void ban(Client
*c
); /* ban c from screen */
117 extern void focus(Client
*c
); /* focus c, c may be NULL */
118 extern Client
*getclient(Window w
); /* return client of w */
119 extern Client
*getctitle(Window w
); /* return client of title window */
120 extern void gravitate(Client
*c
, Bool invert
); /* gravitate c */
121 extern void killclient(Arg
*arg
); /* kill c nicely */
122 extern void manage(Window w
, XWindowAttributes
*wa
); /* manage new client */
123 extern void resize(Client
*c
, Bool sizehints
, Corner sticky
); /* resize c*/
124 extern void updatesize(Client
*c
); /* update the size structs of c */
125 extern void updatetitle(Client
*c
); /* update the name of c */
126 extern void togglemax(Arg
*arg
); /* (un)maximize c */
127 extern void unmanage(Client
*c
); /* destroy c */
130 extern void drawall(); /* draw all visible client titles and the bar */
131 extern void drawstatus(); /* draw the bar */
132 extern void drawtitle(Client
*c
); /* draw title of c */
133 extern unsigned long getcolor(const char *colstr
); /* return color of colstr */
134 extern void setfont(const char *fontstr
); /* set the font for DC */
135 extern unsigned int textw(const char *text
); /* return the width of text in px*/
138 extern void grabkeys(); /* grab all keys defined in config.h */
139 extern void procevent(); /* process pending X events */
142 extern int getproto(Window w
); /* return protocol mask of WMProtocols property of w */
143 extern void quit(Arg
*arg
); /* quit dwm nicely */
144 extern void sendevent(Window w
, Atom a
, long value
); /* send synthetic event to w */
145 extern int xerror(Display
*dsply
, XErrorEvent
*ee
); /* dwm's X error handler */
148 extern void initrregs(); /* initialize regexps of rules defined in config.h */
149 extern Client
*getnext(Client
*c
); /* returns next visible client */
150 extern Client
*getprev(Client
*c
); /* returns previous visible client */
151 extern void settags(Client
*c
, Client
*trans
); /* sets tags of c */
152 extern void tag(Arg
*arg
); /* tags c with arg's index */
153 extern void toggletag(Arg
*arg
); /* toggles c tags with arg's index */
156 extern void *emallocz(unsigned int size
); /* allocates zero-initialized memory, exits on error */
157 extern void eprint(const char *errstr
, ...); /* prints errstr and exits with 1 */
158 extern void *erealloc(void *ptr
, unsigned int size
); /* reallocates memory, exits on error */
159 extern void spawn(Arg
*arg
); /* forks a new subprocess with to arg's cmd */
162 extern void detach(Client
*c
); /* detaches c from global client list */
163 extern void dofloat(Arg
*arg
); /* arranges all windows floating, arg is ignored */
164 extern void dotile(Arg
*arg
); /* arranges all windows, arg is ignored */
165 extern void focusnext(Arg
*arg
); /* focuses next visible client, arg is ignored */
166 extern void focusprev(Arg
*arg
); /* focuses previous visible client, arg is ignored */
167 extern Bool
isvisible(Client
*c
); /* returns True if client is visible */
168 extern void resizecol(Arg
*arg
); /* resizes the master width with arg's index value */
169 extern void restack(); /* restores z layers of all clients */
170 extern void togglemode(Arg
*arg
); /* toggles global arrange function (dotile/dofloat) */
171 extern void toggleview(Arg
*arg
); /* toggles the tag with arg's index (in)visible */
172 extern void view(Arg
*arg
); /* views the tag with arg's index */
173 extern void viewall(Arg
*arg
); /* views all tags, arg is ignored */
174 extern void zoom(Arg
*arg
); /* zooms the focused client to master column, arg is ignored */