dwm.c
changeset 1033 a8efbb301ef4
parent 1032 08bc44d1f985
child 1036 e6188cb17fa1
equal deleted inserted replaced
1032:08bc44d1f985 1033:a8efbb301ef4
    23  *
    23  *
    24  * Keys and tagging rules are organized as arrays and defined in config.h.
    24  * Keys and tagging rules are organized as arrays and defined in config.h.
    25  *
    25  *
    26  * To understand everything else, start reading main().
    26  * To understand everything else, start reading main().
    27  */
    27  */
    28 #include "dwm.h"
       
    29 
       
    30 #include <errno.h>
    28 #include <errno.h>
    31 #include <locale.h>
    29 #include <locale.h>
    32 #include <stdarg.h>
    30 #include <stdarg.h>
    33 #include <stdio.h>
    31 #include <stdio.h>
    34 #include <stdlib.h>
    32 #include <stdlib.h>
    39 #include <sys/wait.h>
    37 #include <sys/wait.h>
    40 #include <regex.h>
    38 #include <regex.h>
    41 #include <X11/cursorfont.h>
    39 #include <X11/cursorfont.h>
    42 #include <X11/keysym.h>
    40 #include <X11/keysym.h>
    43 #include <X11/Xatom.h>
    41 #include <X11/Xatom.h>
       
    42 #include <X11/Xlib.h>
    44 #include <X11/Xproto.h>
    43 #include <X11/Xproto.h>
    45 #include <X11/Xutil.h>
    44 #include <X11/Xutil.h>
       
    45 
       
    46 #include "dwm.h"
    46 
    47 
    47 /* macros */
    48 /* macros */
    48 #define BUTTONMASK		(ButtonPressMask | ButtonReleaseMask)
    49 #define BUTTONMASK		(ButtonPressMask | ButtonReleaseMask)
    49 #define CLEANMASK(mask)		(mask & ~(numlockmask | LockMask))
    50 #define CLEANMASK(mask)		(mask & ~(numlockmask | LockMask))
    50 #define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
    51 #define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
    51 
    52 
    52 /* local typedefs */
       
    53 typedef struct {
       
    54 	const char *prop;
       
    55 	const char *tags;
       
    56 	Bool isfloating;
       
    57 } Rule;
       
    58 
       
    59 typedef struct {
       
    60 	regex_t *propregex;
       
    61 	regex_t *tagregex;
       
    62 } Regs;
       
    63 
       
    64 /* variables */
       
    65 char stext[256];
       
    66 double mwfact;
       
    67 int screen, sx, sy, sw, sh, wax, way, waw, wah;
       
    68 int (*xerrorxlib)(Display *, XErrorEvent *);
       
    69 unsigned int bh, bpos;
       
    70 unsigned int blw = 0;
       
    71 unsigned int ltidx = 0; /* default */
       
    72 unsigned int nlayouts = 0;
       
    73 unsigned int nrules = 0;
       
    74 unsigned int numlockmask = 0;
       
    75 void (*handler[LASTEvent]) (XEvent *) = {
       
    76 	[ButtonPress] = buttonpress,
       
    77 	[ConfigureRequest] = configurerequest,
       
    78 	[ConfigureNotify] = configurenotify,
       
    79 	[DestroyNotify] = destroynotify,
       
    80 	[EnterNotify] = enternotify,
       
    81 	[LeaveNotify] = leavenotify,
       
    82 	[Expose] = expose,
       
    83 	[KeyPress] = keypress,
       
    84 	[MappingNotify] = mappingnotify,
       
    85 	[MapRequest] = maprequest,
       
    86 	[PropertyNotify] = propertynotify,
       
    87 	[UnmapNotify] = unmapnotify
       
    88 };
       
    89 Atom wmatom[WMLast], netatom[NetLast];
       
    90 Bool otherwm, readin;
       
    91 Bool running = True;
       
    92 Bool selscreen = True;
       
    93 Client *clients = NULL;
       
    94 Client *sel = NULL;
       
    95 Client *stack = NULL;
       
    96 Cursor cursor[CurLast];
       
    97 Display *dpy;
       
    98 DC dc = {0};
       
    99 Window barwin, root;
       
   100 Regs *regs = NULL;
       
   101 
       
   102 /* configuration, allows nested code to access above variables */
       
   103 #include "config.h"
       
   104 
       
   105 /* Statically define the number of tags. */
       
   106 unsigned int ntags = sizeof tags / sizeof tags[0];
       
   107 Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True};
       
   108 Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True};
       
   109 
       
   110 /* functions*/
       
   111 void
    53 void
   112 applyrules(Client *c) {
    54 applyrules(Client *c) {
   113 	static char buf[512];
    55 	static char buf[512];
   114 	unsigned int i, j;
    56 	unsigned int i, j;
   115 	regmatch_t tmp;
    57 	regmatch_t tmp;
  1030 	readin = running = False;
   972 	readin = running = False;
  1031 }
   973 }
  1032 
   974 
  1033 void
   975 void
  1034 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
   976 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
  1035 	double dx, dy, max, min, ratio;
       
  1036 	XWindowChanges wc;
   977 	XWindowChanges wc;
  1037 
   978 
  1038 	if(sizehints) {
   979 	if(sizehints) {
  1039 		/* set minimum possible */
   980 		/* set minimum possible */
  1040 		if (w < 1)
   981 		if (w < 1)