jokerboy avatar jokerboy committed 77fe9ba

trying out systray. adding centerwindow, an idea taken from monsterwm. :)

Comments (0)

Files changed (22)

01-dwm-6.0-pertag2.diff

 Homepage: http://hg.punctweb.ro
 
 --- a/dwm.c	2012-07-08 10:45:53.000000000 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.469072272 +0300
++++ b/dwm.c	2012-07-22 00:34:27.689836889 +0300
 @@ -127,8 +127,6 @@ typedef struct {
  
  struct Monitor {

02-dwm-6.0-push.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.499072274 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.503072274 +0300
+--- a/dwm.c	2012-07-22 00:34:27.702836888 +0300
++++ b/dwm.c	2012-07-22 00:34:27.704836890 +0300
 @@ -264,6 +264,9 @@ static int xerrordummy(Display *dpy, XEr
  static int xerrorstart(Display *dpy, XErrorEvent *ee);
  static void zoom(const Arg *arg);

03-dwm-6.0-cycle.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.514072275 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.517072275 +0300
+--- a/dwm.c	2012-07-22 00:34:27.716836890 +0300
++++ b/dwm.c	2012-07-22 00:34:27.719836890 +0300
 @@ -267,6 +267,9 @@ static void bstack(Monitor *m);
  static Client *prevtiled(Client *c);
  static void pushup(const Arg *arg);

04-dwm-6.0-gaplessgrid.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.538072277 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.541072277 +0300
+--- a/dwm.c	2012-07-22 00:34:27.731836892 +0300
++++ b/dwm.c	2012-07-22 00:34:27.734836890 +0300
 @@ -270,6 +270,7 @@ static void pushdown(const Arg *arg);
  static void cycle(const Arg *arg);
  static int shifttag(int dist);

05-dwm-6.0-pidgin.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.559072278 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.563072278 +0300
+--- a/dwm.c	2012-07-22 00:34:27.745836893 +0300
++++ b/dwm.c	2012-07-22 00:34:27.748836892 +0300
 @@ -271,6 +271,7 @@ static void cycle(const Arg *arg);
  static int shifttag(int dist);
  static void tagcycle(const Arg *arg);

06-dwm-6.0-monocle_count.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.578072279 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.582072279 +0300
+--- a/dwm.c	2012-07-22 00:34:27.759836893 +0300
++++ b/dwm.c	2012-07-22 00:34:27.762836894 +0300
 @@ -765,6 +765,7 @@ drawbar(Monitor *m) {
  	int x;
  	unsigned int i, occ = 0, urg = 0;

07-dwm-6.0-monocle_borderless.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.598072280 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.602072281 +0300
+--- a/dwm.c	2012-07-22 00:34:27.773836892 +0300
++++ b/dwm.c	2012-07-22 00:34:27.776836895 +0300
 @@ -1411,7 +1411,11 @@ resizeclient(Client *c, int x, int y, in
  	c->oldy = c->y; c->y = wc.y = y;
  	c->oldw = c->w; c->w = wc.width = w;

08-dwm-6.0-clicktofocus.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.615072281 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.619072282 +0300
+--- a/dwm.c	2012-07-22 00:34:27.787836894 +0300
++++ b/dwm.c	2012-07-22 00:34:27.790836894 +0300
 @@ -868,6 +868,8 @@ drawtext(const char *text, unsigned long
  
  void

09-dwm-6.0-viewontag.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.635072283 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.639072283 +0300
+--- a/dwm.c	2012-07-22 00:34:27.800836896 +0300
++++ b/dwm.c	2012-07-22 00:34:27.803836896 +0300
 @@ -1752,6 +1752,8 @@ tag(const Arg *arg) {
  		selmon->sel->tags = arg->ui & TAGMASK;
  		focus(NULL);

10-dwm-6.0-scratchpad.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.657072284 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.661072284 +0300
+--- a/dwm.c	2012-07-22 00:34:27.814836897 +0300
++++ b/dwm.c	2012-07-22 00:34:27.817836897 +0300
 @@ -272,6 +272,7 @@ static int shifttag(int dist);
  static void tagcycle(const Arg *arg);
  static void gaplessgrid(Monitor *m);

11-dwm-6.0-togglemax.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.859072297 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.865072297 +0300
+--- a/dwm.c	2012-07-22 00:34:27.829836896 +0300
++++ b/dwm.c	2012-07-22 00:34:27.831836898 +0300
 @@ -273,6 +273,7 @@ static void tagcycle(const Arg *arg);
  static void gaplessgrid(Monitor *m);
  static void pidgin(Monitor *m);

12-dwm-6.0-autoresize.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.896072299 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.901072299 +0300
+--- a/dwm.c	2012-07-22 00:34:27.843836898 +0300
++++ b/dwm.c	2012-07-22 00:34:27.846836898 +0300
 @@ -91,7 +91,7 @@ struct Client {
  	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
  	int bw, oldbw;

13-dwm-6.0-increase_mfact_limit.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.914072300 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.919072300 +0300
+--- a/dwm.c	2012-07-22 00:34:27.857836900 +0300
++++ b/dwm.c	2012-07-22 00:34:27.859836899 +0300
 @@ -1658,7 +1658,7 @@ setmfact(const Arg *arg) {
  	if(!arg || !selmon->lt[selmon->sellt]->arrange)
  		return;

14-dwm-6.0-remember-tags.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.942072302 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.946072302 +0300
+--- a/dwm.c	2012-07-22 00:34:27.870836900 +0300
++++ b/dwm.c	2012-07-22 00:34:27.873836901 +0300
 @@ -63,6 +63,7 @@ enum { NetSupported, NetWMName, NetWMSta
         NetWMFullscreen, NetActiveWindow, NetWMWindowType,
         NetWMWindowTypeDialog, NetClientList, NetLast };     /* EWMH atoms */

15-dwm-6.0-centred-floating.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.965072303 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.969072304 +0300
+--- a/dwm.c	2012-07-22 00:34:27.885836900 +0300
++++ b/dwm.c	2012-07-22 00:34:27.888836902 +0300
 @@ -92,7 +92,7 @@ struct Client {
  	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
  	int bw, oldbw;

16-dwm-6.0-focusurgent.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:39.982072304 +0300
-+++ b/dwm.c	2012-07-17 19:46:39.986072305 +0300
+--- a/dwm.c	2012-07-22 00:34:27.899836900 +0300
++++ b/dwm.c	2012-07-22 00:34:27.902836902 +0300
 @@ -277,6 +277,7 @@ static void pidgin(Monitor *m);
  static void togglescratch(const Arg *arg);
  static void togglemax(const Arg *arg);

17-dwm-6.0-statuscolors.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:40.000072306 +0300
-+++ b/dwm.c	2012-07-17 19:46:40.004072306 +0300
+--- a/dwm.c	2012-07-22 00:34:27.914836902 +0300
++++ b/dwm.c	2012-07-22 00:34:27.917836902 +0300
 @@ -55,6 +55,7 @@
  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)

18-dwm-6.0-save_floats.diff

 Homepage: http://hg.punctweb.ro
 
---- a/dwm.c	2012-07-17 19:46:40.016072307 +0300
-+++ b/dwm.c	2012-07-17 19:46:40.020072307 +0300
+--- a/dwm.c	2012-07-22 00:34:27.929836904 +0300
++++ b/dwm.c	2012-07-22 00:34:27.932836902 +0300
 @@ -90,6 +90,7 @@ struct Client {
  	float mina, maxa;
  	int x, y, w, h;

19-dwm-6.0-systray.diff

+Homepage: http://hg.punctweb.ro
+
+--- a/dwm.c	2012-07-22 00:34:27.944836905 +0300
++++ b/dwm.c	2012-07-22 00:34:27.947836903 +0300
+@@ -57,12 +57,31 @@
+ #define TEXTW(X)                (textnw(X, strlen(X)) + dc.font.height)
+ #define MAXCOLORS               8
+ 
++#define SYSTEM_TRAY_REQUEST_DOCK    0
++#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
++
++/* XEMBED messages */
++#define XEMBED_EMBEDDED_NOTIFY      0
++#define XEMBED_WINDOW_ACTIVATE      1
++#define XEMBED_FOCUS_IN             4
++#define XEMBED_MODALITY_ON         10
++
++#define XEMBED_MAPPED              (1 << 0)
++#define XEMBED_WINDOW_ACTIVATE      1
++#define XEMBED_WINDOW_DEACTIVATE    2
++
++#define VERSION_MAJOR               0
++#define VERSION_MINOR               0
++#define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
++
+ /* enums */
+ enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
+ enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
+ enum { NetSupported, NetWMName, NetWMState,
+        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+-       NetWMWindowTypeDialog, NetClientList, NetLast };     /* EWMH atoms */
++       NetWMWindowTypeDialog, NetClientList, NetSystemTray,
++       NetSystemTrayOP, NetSystemTrayOrientation, NetLast };     /* EWMH atoms */
++enum { Manager, Xembed, XembedInfo, XLast }; /* Xembed atoms */
+ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
+ enum { DWMTags, DWMLast };                              /* DWM atoms */
+ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
+@@ -168,6 +187,12 @@ typedef struct {
+ 	int monitor;
+ } Rule;
+ 
++typedef struct Systray   Systray;
++struct Systray {
++	Window win;
++	Client *icons;
++};
++
+ /* function declarations */
+ static void applyrules(Client *c);
+ static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact);
+@@ -228,7 +253,7 @@ static void resizemouse(const Arg *arg);
+ static void restack(Monitor *m);
+ static void run(void);
+ static void scan(void);
+-static Bool sendevent(Client *c, Atom proto);
++static Bool sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
+ static void sendmon(Client *c, Monitor *m);
+ static void setclientstate(Client *c, long state);
+ static void setfocus(Client *c);
+@@ -281,6 +306,15 @@ static void togglemax(const Arg *arg);
+ static void settagsatom(Window w, unsigned int tags);
+ static void focusurgent(const Arg *arg);
+ static void savefloat(Client *c);
++static Atom getatomprop(Client *c, Atom prop);
++static unsigned int getsystraywidth();
++static void removesystrayicon(Client *i);
++static void resizebarwin(Monitor *m);
++static void resizerequest(XEvent *e);
++static void updatesystray(void);
++static void updatesystrayicongeom(Client *i, int w, int h);
++static void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
++static Client *wintosystrayicon(Window w);
+ 
+ /* variables */
+ static const char broken[] = "broken";
+@@ -304,15 +338,18 @@ static void (*handler[LASTEvent]) (XEven
+ 	[MapRequest] = maprequest,
+ 	[MotionNotify] = motionnotify,
+ 	[PropertyNotify] = propertynotify,
++	[ResizeRequest] = resizerequest,
+ 	[UnmapNotify] = unmapnotify
+ };
+-static Atom wmatom[WMLast], netatom[NetLast], dwmatom[DWMLast];
++static Atom wmatom[WMLast], netatom[NetLast], dwmatom[DWMLast], xatom[XLast];
+ static Bool running = True;
+ static Cursor cursor[CurLast];
+ static Display *dpy;
+ static DC dc;
+ static Monitor *mons = NULL, *selmon = NULL;
+ static Window root;
++static Systray *systray = NULL;
++static unsigned long systrayorientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
+ 
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+@@ -531,6 +568,11 @@ cleanup(void) {
+ 	XFreeCursor(dpy, cursor[CurMove]);
+ 	while(mons)
+ 		cleanupmon(mons);
++	if(showsystray) {
++		XUnmapWindow(dpy, systray->win);
++		//XDestroyWindow(dpy, systray->win);
++		free(systray);
++	}
+ 	XSync(dpy, False);
+ 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+ 	XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+@@ -568,10 +610,49 @@ clearurgent(Client *c) {
+ 
+ void
+ clientmessage(XEvent *e) {
++	XWindowAttributes wa;
++	XSetWindowAttributes swa;
+ 	XClientMessageEvent *cme = &e->xclient;
+ 	Client *c = wintoclient(cme->window);
+ 	unsigned int i;
+ 
++	if(showsystray && cme->window == systray->win && cme->message_type == netatom[NetSystemTrayOP]) {
++		/* add systray icons */
++		if(cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) {
++			if(!(c = (Client *)calloc(1, sizeof(Client))))
++				die("fatal: could not malloc() %u bytes\n", sizeof(Client));
++			c->win = cme->data.l[2];
++			c->mon = selmon;
++			c->next = systray->icons;
++			systray->icons = c;
++			XGetWindowAttributes(dpy, c->win, &wa);
++			c->x = c->oldx = c->y = c->oldy = 0;
++			c->w = c->oldw = wa.width;
++			c->h = c->oldh = wa.height;
++			c->oldbw = wa.border_width;
++			c->bw = 0;
++			c->isfloating = True;
++			/* reuse tags field as mapped status */
++			c->tags = 1;
++			updatesizehints(c);
++			updatesystrayicongeom(c, wa.width, wa.height);
++			XAddToSaveSet(dpy, c->win);
++			XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
++			XReparentWindow(dpy, c->win, systray->win, 0, 0);
++			/* use parents background pixmap */
++			swa.background_pixmap = ParentRelative;
++			XChangeWindowAttributes(dpy, c->win, CWBackPixmap, &swa);
++			sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++			/* FIXME not sure if I have to send these events, too */
++			sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_FOCUS_IN, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++			sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++			sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_MODALITY_ON, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++			resizebarwin(selmon);
++			updatesystray();
++			setclientstate(c, NormalState);
++		}
++		return;
++	}
+ 	if(!c)
+ 		return;
+ 	if(cme->message_type == netatom[NetWMState]) {
+@@ -627,7 +708,7 @@ configurenotify(XEvent *e) {
+ 			dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
+ 			updatebars();
+ 			for(m = mons; m; m = m->next)
+-				XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
++				resizebarwin(m);
+ 			focus(NULL);
+ 			arrange(NULL);
+ 		}
+@@ -727,6 +808,11 @@ destroynotify(XEvent *e) {
+ 
+ 	if((c = wintoclient(ev->window)))
+ 		unmanage(c, True);
++	else if((c = wintosystrayicon(ev->window))) {
++		removesystrayicon(c);
++		resizebarwin(selmon);
++		updatesystray();
++	}
+ }
+ 
+ void
+@@ -783,6 +869,7 @@ drawbar(Monitor *m) {
+ 	unsigned int a = 0, s = 0;
+ 	Client *c;
+ 
++	resizebarwin(m);
+ 	for(c = m->clients; c; c = c->next) {
+ 		occ |= c->tags;
+ 		if(c->isurgent)
+@@ -811,6 +898,9 @@ drawbar(Monitor *m) {
+ 	if(m == selmon) { /* status is only drawn on selected monitor */
+ 		dc.w = textnw(stext, strlen(stext));
+ 		dc.x = m->ww - dc.w;
++		if(showsystray && m == selmon) {
++			dc.x -= getsystraywidth();
++		}
+ 		if(dc.x < x) {
+ 			dc.x = x;
+ 			dc.w = m->ww - x;
+@@ -839,6 +929,7 @@ drawbars(void) {
+ 
+ 	for(m = mons; m; m = m->next)
+ 		drawbar(m);
++	updatesystray();
+ }
+ 
+ void
+@@ -1014,10 +1105,17 @@ getatomprop(Client *c, Atom prop) {
+ 	unsigned long dl;
+ 	unsigned char *p = NULL;
+ 	Atom da, atom = None;
++	/* FIXME getatomprop should return the number of items and a pointer to
++	 * the stored data instead of this workaround */
++	Atom req = XA_ATOM;
++	if(prop == xatom[XembedInfo])
++		req = xatom[XembedInfo];
+ 
+-	if(XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
++	if(XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, req,
+ 	                      &da, &di, &dl, &dl, &p) == Success && p) {
+ 		atom = *(Atom *)p;
++		if(da == xatom[XembedInfo] && dl == 2)
++			atom = ((Atom *)p)[1];
+ 		XFree(p);
+ 	}
+ 	return atom;
+@@ -1193,7 +1291,7 @@ void
+ killclient(const Arg *arg) {
+ 	if(!selmon->sel)
+ 		return;
+-	if(!sendevent(selmon->sel, wmatom[WMDelete])) {
++	if(!sendevent(selmon->sel->win, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0 , 0, 0)) {
+ 		XGrabServer(dpy);
+ 		XSetErrorHandler(xerrordummy);
+ 		XSetCloseDownMode(dpy, DestroyAll);
+@@ -1304,7 +1402,13 @@ void
+ maprequest(XEvent *e) {
+ 	static XWindowAttributes wa;
+ 	XMapRequestEvent *ev = &e->xmaprequest;
++	Client *i;
+ 
++	if((i = wintosystrayicon(ev->window))) {
++		sendevent(i->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, systray->win, XEMBED_EMBEDDED_VERSION);
++		resizebarwin(selmon);
++		updatesystray();
++	}
+ 	if(!XGetWindowAttributes(dpy, ev->window, &wa))
+ 		return;
+ 	if(wa.override_redirect)
+@@ -1416,6 +1520,16 @@ propertynotify(XEvent *e) {
+ 	Window trans;
+ 	XPropertyEvent *ev = &e->xproperty;
+ 
++	if((c = wintosystrayicon(ev->window))) {
++		if(ev->atom == XA_WM_NORMAL_HINTS) {
++			updatesizehints(c);
++			updatesystrayicongeom(c, c->w, c->h);
++		}
++		else
++			updatesystrayiconstate(c, ev);
++		resizebarwin(selmon);
++		updatesystray();
++	}
+ 	if((ev->window == root) && (ev->atom == XA_WM_NAME))
+ 		updatestatus();
+ 	else if(ev->state == PropertyDelete)
+@@ -1624,25 +1738,35 @@ setclientstate(Client *c, long state) {
+ }
+ 
+ Bool
+-sendevent(Client *c, Atom proto) {
++sendevent(Window w, Atom proto, int mask, long d0, long d1, long d2, long d3, long d4) {
+ 	int n;
+-	Atom *protocols;
++	Atom *protocols, mt;
+ 	Bool exists = False;
+ 	XEvent ev;
+ 
+-	if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
+-		while(!exists && n--)
+-			exists = protocols[n] == proto;
+-		XFree(protocols);
++	if(proto == wmatom[WMTakeFocus] || proto == wmatom[WMDelete]) {
++		mt = wmatom[WMProtocols];
++		if(XGetWMProtocols(dpy, w, &protocols, &n)) {
++			while(!exists && n--)
++				exists = protocols[n] == proto;
++			XFree(protocols);
++		}
++	}
++	else {
++		exists = True;
++		mt = proto;
+ 	}
+ 	if(exists) {
+ 		ev.type = ClientMessage;
+-		ev.xclient.window = c->win;
+-		ev.xclient.message_type = wmatom[WMProtocols];
++		ev.xclient.window = w;
++		ev.xclient.message_type = mt;
+ 		ev.xclient.format = 32;
+-		ev.xclient.data.l[0] = proto;
+-		ev.xclient.data.l[1] = CurrentTime;
+-		XSendEvent(dpy, c->win, False, NoEventMask, &ev);
++		ev.xclient.data.l[0] = d0;
++		ev.xclient.data.l[1] = d1;
++		ev.xclient.data.l[2] = d2;
++		ev.xclient.data.l[3] = d3;
++		ev.xclient.data.l[4] = d4;
++		XSendEvent(dpy, w, False, mask, &ev);
+ 	}
+ 	return exists;
+ }
+@@ -1655,7 +1779,7 @@ setfocus(Client *c) {
+  		                XA_WINDOW, 32, PropModeReplace,
+  		                (unsigned char *) &(c->win), 1);
+ 	}
+-	sendevent(c, wmatom[WMTakeFocus]);
++	sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, wmatom[WMTakeFocus], CurrentTime, 0, 0, 0);
+ }
+ 
+ void
+@@ -1750,6 +1874,12 @@ setup(void) {
+ 	netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+ 	netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
+ 	dwmatom[DWMTags] = XInternAtom(dpy, "_DWM_TAGS", False);
++	netatom[NetSystemTray] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_S0", False);
++	netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
++	netatom[NetSystemTrayOrientation] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION", False);
++	xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
++	xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
++	xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False);
+ 	/* init cursors */
+ 	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
+ 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
+@@ -1765,6 +1895,8 @@ setup(void) {
+ 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
+ 	if(!dc.font.set)
+ 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
++	/* init system tray */
++	updatesystray();
+ 	/* init bars */
+ 	updatebars();
+ 	updatestatus();
+@@ -1894,7 +2026,18 @@ void
+ togglebar(const Arg *arg) {
+ 	selmon->showbar = !selmon->showbar;
+ 	updatebarpos(selmon);
+-	XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
++	resizebarwin(selmon);
++	if(showsystray) {
++		XWindowChanges wc;
++		if(!selmon->showbar)
++			wc.y = -bh;
++		else if(selmon->showbar) {
++			wc.y = 0;
++			if(!selmon->topbar)
++				wc.y = selmon->mh - bh;
++		}
++		XConfigureWindow(dpy, systray->win, CWY, &wc);
++	}
+ 	arrange(selmon);
+ }
+ 
+@@ -1998,10 +2141,16 @@ unmapnotify(XEvent *e) {
+ 		else
+ 			unmanage(c, False);
+ 	}
++	else if((c = wintosystrayicon(ev->window))) {
++		removesystrayicon(c);
++		resizebarwin(selmon);
++		updatesystray();
++	}
+ }
+ 
+ void
+ updatebars(void) {
++	unsigned int w;
+ 	Monitor *m;
+ 	XSetWindowAttributes wa = {
+ 		.override_redirect = True,
+@@ -2011,7 +2160,10 @@ updatebars(void) {
+ 	for(m = mons; m; m = m->next) {
+ 		if (m->barwin)
+ 			continue;
+-		m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
++		w = m->ww;
++		if(showsystray && m == selmon)
++			w -= getsystraywidth();
++		m->barwin = XCreateWindow(dpy, root, m->wx, m->by, w, bh, 0, DefaultDepth(dpy, screen),
+ 		                          CopyFromParent, DefaultVisual(dpy, screen),
+ 		                          CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+ 		XDefineCursor(dpy, m->barwin, cursor[CurNormal]);
+@@ -2639,6 +2791,155 @@ savefloat(Client *c) {
+ 	c->sfh = c->h;
+ }
+ 
++unsigned int
++getsystraywidth() {
++	unsigned int w = 0;
++	Client *i;
++	if(showsystray)
++		for(i = systray->icons; i; w += i->w + 1, i = i->next) ;
++	return w ? w + 1 : 1;
++}
++
++void
++removesystrayicon(Client *i) {
++	Client **ii;
++
++	if(!showsystray || !i)
++		return;
++	for(ii = &systray->icons; *ii && *ii != i; ii = &(*ii)->next);
++	if(ii)
++		*ii = i->next;
++	free(i);
++}
++
++void
++resizebarwin(Monitor *m) {
++	unsigned int w = m->ww;
++	if(showsystray && m == selmon)
++		w -= getsystraywidth();
++	XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, bh);
++}
++
++void
++resizerequest(XEvent *e) {
++	XResizeRequestEvent *ev = &e->xresizerequest;
++	Client *i;
++
++	if((i = wintosystrayicon(ev->window))) {
++		updatesystrayicongeom(i, ev->width, ev->height);
++		resizebarwin(selmon);
++		updatesystray();
++	}
++}
++
++void
++updatesystrayicongeom(Client *i, int w, int h) {
++	if(i) {
++		i->h = bh;
++		if(w == h)
++			i->w = bh;
++		else if(h == bh)
++			i->w = w;
++		else
++			i->w = (int) ((float)bh * ((float)w / (float)h));
++		applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False);
++		/* force icons into the systray dimenons if they don't want to */
++		if(i->h > bh) {
++			if(i->w == i->h)
++				i->w = bh;
++			else
++				i->w = (int) ((float)bh * ((float)i->w / (float)i->h));
++			i->h = bh;
++		}
++	}
++}
++
++void
++updatesystrayiconstate(Client *i, XPropertyEvent *ev) {
++	long flags;
++	int code = 0;
++
++	if(!showsystray || !i || ev->atom != xatom[XembedInfo] ||
++			!(flags = getatomprop(i, xatom[XembedInfo])))
++		return;
++
++	if(flags & XEMBED_MAPPED && !i->tags) {
++		i->tags = 1;
++		code = XEMBED_WINDOW_ACTIVATE;
++		XMapRaised(dpy, i->win);
++		setclientstate(i, NormalState);
++	}
++	else if(!(flags & XEMBED_MAPPED) && i->tags) {
++		i->tags = 0;
++		code = XEMBED_WINDOW_DEACTIVATE;
++		XUnmapWindow(dpy, i->win);
++		setclientstate(i, WithdrawnState);
++	}
++	else
++		return;
++	sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
++			systray->win, XEMBED_EMBEDDED_VERSION);
++}
++
++void
++updatesystray(void) {
++	XSetWindowAttributes wa;
++	Client *i;
++	unsigned int x = selmon->mx + selmon->mw;
++	unsigned int w = 1;
++
++	if(!showsystray)
++		return;
++	if(!systray) {
++		/* init systray */
++		if(!(systray = (Systray *)calloc(1, sizeof(Systray))))
++			die("fatal: could not malloc() %u bytes\n", sizeof(Systray));
++		systray->win = XCreateSimpleWindow(dpy, root, x, selmon->by, w, bh, 0, 0, dc.colors[1][ColBG]);
++		wa.event_mask        = ButtonPressMask | ExposureMask;
++		wa.override_redirect = True;
++		wa.background_pixmap = ParentRelative;
++		wa.background_pixel  = dc.colors[0][ColBG];
++		XSelectInput(dpy, systray->win, SubstructureNotifyMask);
++		XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
++				PropModeReplace, (unsigned char *)&systrayorientation, 1);
++		XChangeWindowAttributes(dpy, systray->win, CWEventMask | CWOverrideRedirect | CWBackPixel, &wa);
++		XMapRaised(dpy, systray->win);
++		XSetSelectionOwner(dpy, netatom[NetSystemTray], systray->win, CurrentTime);
++		if(XGetSelectionOwner(dpy, netatom[NetSystemTray]) == systray->win) {
++			sendevent(root, xatom[Manager], StructureNotifyMask, CurrentTime, netatom[NetSystemTray], systray->win, 0, 0);
++			XSync(dpy, False);
++		}
++		else {
++			fprintf(stderr, "dwm: unable to obtain system tray.\n");
++			free(systray);
++			systray = NULL;
++			return;
++		}
++	}
++	for(w = 0, i = systray->icons; i; i = i->next) {
++		XMapRaised(dpy, i->win);
++		w += 1;
++		XMoveResizeWindow(dpy, i->win, (i->x = w), 0, i->w, i->h);
++		w += i->w;
++		if(i->mon != selmon)
++			i->mon = selmon;
++	}
++	w = w ? w + 1 : 1;
++ 	x -= w;
++	XMoveResizeWindow(dpy, systray->win, x, selmon->by, w, bh);
++	XSync(dpy, False);
++}
++
++Client *
++wintosystrayicon(Window w) {
++	Client *i = NULL;
++
++	if(!showsystray || !w)
++		return i;
++	for(i = systray->icons; i && i->win != w; i = i->next) ;
++	return i;
++}
++
+ int
+ main(int argc, char *argv[]) {
+ 	if(argc == 2 && !strcmp("-v", argv[1]))

20-dwm-6.0-centerwindow.diff

+Homepage: http://hg.punctweb.ro
+
+--- a/dwm.c	2012-07-22 00:34:27.960836906 +0300
++++ b/dwm.c	2012-07-22 00:34:27.963836904 +0300
+@@ -315,6 +315,7 @@ static void updatesystray(void);
+ static void updatesystrayicongeom(Client *i, int w, int h);
+ static void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
+ static Client *wintosystrayicon(Window w);
++static void centerwindow(const Arg *arg);
+ 
+ /* variables */
+ static const char broken[] = "broken";
+@@ -2940,6 +2941,21 @@ wintosystrayicon(Window w) {
+ 	return i;
+ }
+ 
++void
++centerwindow(const Arg *arg) {
++	if(!selmon->sel)
++		return;
++	if(selmon->sel->isfullscreen) /* no support for fullscreen windows */
++		return;
++	selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
++	if(selmon->sel->isfloating) {
++		selmon->sel->x = selmon->sel->oldx = selmon->wx + (selmon->ww / 2 - selmon->sel->w / 2);
++		selmon->sel->y = selmon->sel->oldy = selmon->wy + (selmon->wh / 2 - selmon->sel->h / 2);
++		XMoveResizeWindow(dpy, selmon->sel->win, selmon->sel->x, selmon->sel->y, selmon->sel->w, selmon->sel->h);
++	}
++	arrange(selmon);
++}
++
+ int
+ main(int argc, char *argv[]) {
+ 	if(argc == 2 && !strcmp("-v", argv[1]))
         "15-${pkgname}-${pkgver}-centred-floating.diff"
         "16-${pkgname}-${pkgver}-focusurgent.diff"
         "17-${pkgname}-${pkgver}-statuscolors.diff"
-        "18-${pkgname}-${pkgver}-save_floats.diff")
+        "18-${pkgname}-${pkgver}-save_floats.diff"
+        "19-${pkgname}-${pkgver}-systray.diff"
+        "20-${pkgname}-${pkgver}-centerwindow.diff")
 sha256sums=('bb5c4bb7ba052a5498118eeb571165997f7dae62580c1be1a5cdf11e03bc8127'
-            '9c93657357f98a66490ed34e4593b9f3a9e2e5784529f70c75e0506ae7f81d76'
-            'e670e37715979260a320dc79017d281d033b065da35d2fc7d40857902af94433'
-            'd53eb38f77f0d6b5f183035dc17dbc07859fd8242876facf4056bbe4a0e8d1fb'
-            '7dcfcb01347a7eed710f98848796699b7c01deefb1011eb4201ac2b3d224046f'
-            '9870a55ab0ed22ce2b677746b3cd6b96ebb05f84d0a6d015b5c616fc0585c73d'
-            '9ecc1b121dbf31af0ace601398972dad93b27cdbe6e3648ef4efe66586386e0b'
-            'ae36b15520e761f1f3aa443a66c17abb2484c8ab8476a314726522ec55d1ea7c'
-            'fef9afae03f730f3091b0d25fed10b64f59f109f9a12c4e046a9f3091753ef4f'
-            '57ee899e602cc55945600511a3d72b3a197ef4fdbdd360e821ab043e98e051b8'
-            'd7d086cace639a955a4a76b52935c4841f92e2372a2f5d7f8b32519e7a6301ea'
-            '4ea735e7a213e8b2e0e520dad21be7db087d198ddf41977ae78bf54c6db29719'
-            'a1afba5d6743b308735c32b5832091449640b73270946648dae6e243beaa807c'
-            'c6502b17552c53bc8a3385e064aa7cc92eb3890576a63526700f151e22d5c7c4'
-            '1b2c3e7ce3a3a565abc8b6ae8939cd933615407b30345511858add8ef0bdc55c'
-            '6f85a0ee09f15eeebffa69fda8f954b0256270d9ee30166fe6da2bb624f3eec3'
-            '1ab44e29f97a44925158057dbaedb0a1dabd02ac6d44b4bc891cb817879b95c4'
-            '0ee43a71824b6a31b4429f3cacbe9bcc05cb1959ce77df4f197647b1d774fd46'
-            '1ce120dcc36996beed05b17048676ab6b8cc4092321106c30626808cd64415a0'
-            'f1a51e3125fbd9672302ec2554c1790ece76c56e8bce0a3040fcb8f9a8bb592e')
+            '3630d6b56f5fc5a3c0d7297233c675f4fad5e97454742c1874c33e1cd08345f1'
+            '562084007ab8882907cb6700e6e69d489e0db375e15bce180517a177bcb80141'
+            '210d8558e5de4e561b697938cf5d09c34307c72705517a6026c6a4e15e1b598b'
+            '056f2ef5e5e6f8b7cf14f2431b09171f964e0b73efb34b419c830db2ce45dd62'
+            '42b5180a16cb53fc95ef95283fc6b84a764b0a596eae3c09564494f6de66d739'
+            '2b64f85aac12a06679bc435abe1d84b3bf74885b8f87a045462d7439254b4b52'
+            '659adef65c1214abdec4180c9eee73c1418d628fe5bfbddb1c7413048f5ad3e3'
+            'eb44f3a4e64d5ca9beb7dc1a43e266da9566ad1e52fe7d3be3d08871f3424989'
+            '6df7e8226361313d39cdbc5bca304df79f3d629ddd0eca3849872822ef3bce2a'
+            '5ba48fa0e06c1ebe63e462f6da0b639b73d6c6ae56dbab79b96f3771db2daa9f'
+            '91d243c11a01a6e379ce2b8b551b4e51d70ba59ec5a88ae848225dbbfbd29ea3'
+            '50dcd38100da40f5426f764198d8a13e0285fddffe08417724a4d2029cb2ee08'
+            'b52444f873cd65ca7459ad12dfd10b1e7f84171429723b09a73dfd73271d906b'
+            '149ada07c01e38ae096c55490577e1767280aef7e7f9db96821778867e3dfa44'
+            '2f12effe4937131ea3eab47900ce9beefc3f3d084b4d5d4595cb1f373e7978a4'
+            'f622c2f5b72b0eb1ee7df7c36fa1d8f8dadfbcd3d67e720306168eba3ac6ca2b'
+            '9b1541709421a5504a47b7ad790c19e096b5872a60b22cd525d0958b95df8617'
+            'e73f1ea3df3d300fdeaabb52cdc7d4429994df80105268f33aeec4f577af159c'
+            '2a0852ed63b9582920d6178894484d2456bc055c368b8afd874f51f2fc0b1beb'
+            '416775c5e2e6006922a8000b4e1b52170599fa44dc0fc91164e661a7f2a32823'
+            'e737a3950dd0bc1b9c115b597842d11848dfe7b8169920916f18535db33c037f')
 
 build() {
   cd "${srcdir}" && cd "`find . -type d -name dwm-\*`"
 static const unsigned int borderpx  = 2;        /* border pixel of windows */
 static const unsigned int snap      = 8;        /* snap pixel */
 static const Bool showbar           = True;     /* False means no bar */
+static const Bool showsystray       = True;     /* False means no systray */
 static const Bool topbar            = True;     /* False means bottom bar */
 static const Bool clicktofocus      = True;     /* Change focus only on click */
 static const Bool viewontag         = True;     /* Switch view on tag switch */
 	{ MODKEY,                       XK_Tab,     view,           {0} },
 	{ ALTKEY,                       XK_Tab,     focusurgent,    {0} },
 	{ MODKEY,                       XK_Escape,  killclient,     {0} },
+	{ MODKEY|ShiftMask,             XK_c,       centerwindow,   {0} },
 	{ MODKEY|ControlMask,           XK_n,       setlayout,      {.v = &layouts[0]} },
 	{ MODKEY|ControlMask,           XK_m,       setlayout,      {.v = &layouts[1]} },
 	{ MODKEY|ControlMask,           XK_f,       setlayout,      {.v = &layouts[2]} },
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.