dwm.c
changeset 1514 2a8d8d41e50b
parent 1511 68386bda4854
child 1515 60ea8fed13ab
equal deleted inserted replaced
1513:1456ca0c94b7 1514:2a8d8d41e50b
    39 #ifdef XINERAMA
    39 #ifdef XINERAMA
    40 #include <X11/extensions/Xinerama.h>
    40 #include <X11/extensions/Xinerama.h>
    41 #endif /* XINERAMA */
    41 #endif /* XINERAMA */
    42 
    42 
    43 /* macros */
    43 /* macros */
    44 #define D                       if(1)
       
    45 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
    44 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
    46 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
    45 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
    47 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
    46 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
    48 #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
    47 #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
    49 #define LENGTH(X)               (sizeof X / sizeof X[0])
    48 #define LENGTH(X)               (sizeof X / sizeof X[0])
    56 #define TEXTW(X)                (textnw(X, strlen(X)) + dc.font.height)
    55 #define TEXTW(X)                (textnw(X, strlen(X)) + dc.font.height)
    57 
    56 
    58 /* enums */
    57 /* enums */
    59 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
    58 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
    60 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
    59 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
    61 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
    60 enum { NetSupported, NetWMName, NetWMState,
       
    61        NetWMFullscreen, NetLast };                      /* EWMH atoms */
    62 enum { WMProtocols, WMDelete, WMState, WMLast };        /* default atoms */
    62 enum { WMProtocols, WMDelete, WMState, WMLast };        /* default atoms */
    63 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
    63 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
    64        ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
    64        ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
    65 
    65 
    66 typedef union {
    66 typedef union {
   160 static void buttonpress(XEvent *e);
   160 static void buttonpress(XEvent *e);
   161 static void checkotherwm(void);
   161 static void checkotherwm(void);
   162 static void cleanup(void);
   162 static void cleanup(void);
   163 static void cleanupmon(Monitor *mon);
   163 static void cleanupmon(Monitor *mon);
   164 static void clearurgent(Client *c);
   164 static void clearurgent(Client *c);
       
   165 static void clientmessage(XEvent *e);
   165 static void configure(Client *c);
   166 static void configure(Client *c);
   166 static void configurenotify(XEvent *e);
   167 static void configurenotify(XEvent *e);
   167 static void configurerequest(XEvent *e);
   168 static void configurerequest(XEvent *e);
   168 static Monitor *createmon(void);
   169 static Monitor *createmon(void);
   169 static void destroynotify(XEvent *e);
   170 static void destroynotify(XEvent *e);
   248 static int bh, blw = 0;      /* bar geometry */
   249 static int bh, blw = 0;      /* bar geometry */
   249 static int (*xerrorxlib)(Display *, XErrorEvent *);
   250 static int (*xerrorxlib)(Display *, XErrorEvent *);
   250 static unsigned int numlockmask = 0;
   251 static unsigned int numlockmask = 0;
   251 static void (*handler[LASTEvent]) (XEvent *) = {
   252 static void (*handler[LASTEvent]) (XEvent *) = {
   252 	[ButtonPress] = buttonpress,
   253 	[ButtonPress] = buttonpress,
       
   254 	[ClientMessage] = clientmessage,
   253 	[ConfigureRequest] = configurerequest,
   255 	[ConfigureRequest] = configurerequest,
   254 	[ConfigureNotify] = configurenotify,
   256 	[ConfigureNotify] = configurenotify,
   255 	[DestroyNotify] = destroynotify,
   257 	[DestroyNotify] = destroynotify,
   256 	[EnterNotify] = enternotify,
   258 	[EnterNotify] = enternotify,
   257 	[Expose] = expose,
   259 	[Expose] = expose,
  1291 		}
  1293 		}
  1292 	}
  1294 	}
  1293 }
  1295 }
  1294 
  1296 
  1295 void
  1297 void
       
  1298 clientmessage(XEvent *e) {
       
  1299 	XClientMessageEvent *cme = &e->xclient;
       
  1300 
       
  1301 	if(cme->message_type == netatom[NetWMState] && cme->data.l[1] == netatom[NetWMFullscreen]) {
       
  1302 		if(cme->data.l[0])
       
  1303 			XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
       
  1304 			                PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
       
  1305 		else
       
  1306 			XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
       
  1307 			                PropModeReplace, (unsigned char*)0, 0);
       
  1308 	}
       
  1309 }
       
  1310 
       
  1311 void
  1296 quit(const Arg *arg) {
  1312 quit(const Arg *arg) {
  1297 	running = False;
  1313 	running = False;
  1298 }
  1314 }
  1299 
  1315 
  1300 void
  1316 void
  1390 void
  1406 void
  1391 run(void) {
  1407 run(void) {
  1392 	XEvent ev;
  1408 	XEvent ev;
  1393 	static const char *evname[LASTEvent] = {
  1409 	static const char *evname[LASTEvent] = {
  1394 		[ButtonPress] = "buttonpress",
  1410 		[ButtonPress] = "buttonpress",
       
  1411 		[ClientMessage] = "clientmessage",
  1395 		[ConfigureRequest] = "configurerequest",
  1412 		[ConfigureRequest] = "configurerequest",
  1396 		[ConfigureNotify] = "configurenotify",
  1413 		[ConfigureNotify] = "configurenotify",
  1397 		[DestroyNotify] = "destroynotify",
  1414 		[DestroyNotify] = "destroynotify",
  1398 		[EnterNotify] = "enternotify",
  1415 		[EnterNotify] = "enternotify",
  1399 		[Expose] = "expose",
  1416 		[Expose] = "expose",
  1405 		[UnmapNotify] = "unmapnotify"
  1422 		[UnmapNotify] = "unmapnotify"
  1406 	};
  1423 	};
  1407 	/* main event loop */
  1424 	/* main event loop */
  1408 	XSync(dpy, False);
  1425 	XSync(dpy, False);
  1409 	while(running && !XNextEvent(dpy, &ev)) {
  1426 	while(running && !XNextEvent(dpy, &ev)) {
  1410 		D fprintf(stderr, "run event %s %ld\n", evname[ev.type], ev.xany.window);
       
  1411 		if(handler[ev.type])
  1427 		if(handler[ev.type])
  1412 			handler[ev.type](&ev); /* call handler */
  1428 			handler[ev.type](&ev); /* call handler */
  1413 	}
  1429 	}
  1414 }
  1430 }
  1415 
  1431 
  1508 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  1524 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  1509 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  1525 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  1510 	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
  1526 	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
  1511 	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
  1527 	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
  1512 	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
  1528 	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
       
  1529 	netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
       
  1530 	netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
  1513 	/* init cursors */
  1531 	/* init cursors */
  1514 	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  1532 	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  1515 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  1533 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  1516 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  1534 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  1517 	/* init appearance */
  1535 	/* init appearance */