Commits

Jan Christoph Ebersbach  committed 2a0455b

add pinning to systray patch

  • Participants
  • Parent commits a3da8f1

Comments (0)

Files changed (1)

File systray.patch

 URL: http://dwm.suckless.org/patches/systray
 Implements a system tray for dwm.
 
-diff -r b8a8d6ffb375 config.def.h
---- a/config.def.h	Thu Apr 04 21:05:59 2013 +0200
-+++ b/config.def.h	Thu Apr 04 21:06:02 2013 +0200
-@@ -12,6 +12,8 @@
+diff -r aa1078d7b9d7 config.def.h
+--- a/config.def.h	Sat Apr 06 19:49:59 2013 +0200
++++ b/config.def.h	Sat Apr 06 21:36:15 2013 +0200
+@@ -12,6 +12,10 @@
  static const char floatselbordercolor[]  = "#ff0000";
  static const unsigned int borderpx  = 1;        /* border pixel of windows */
  static const unsigned int snap      = 32;       /* snap pixel */
++static const unsigned int systraypinning = 0;   /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
 +static const unsigned int systrayspacing = 2;   /* systray spacing */
++static const Bool systraypinningfailfirst = True;   /* True: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
 +static const Bool showsystray       = True;     /* False means no systray */
  static const Bool showbar           = True;     /* False means no bar */
  static const Bool topbar            = True;     /* False means bottom bar */
  
-diff -r b8a8d6ffb375 dwm.c
---- a/dwm.c	Thu Apr 04 21:05:59 2013 +0200
-+++ b/dwm.c	Thu Apr 04 21:06:02 2013 +0200
+diff -r aa1078d7b9d7 config.mk
+--- a/config.mk	Sat Apr 06 19:49:59 2013 +0200
++++ b/config.mk	Sat Apr 06 21:36:15 2013 +0200
+@@ -20,8 +20,8 @@
+ 
+ # flags
+ CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
+-#CFLAGS   = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
+-CFLAGS   = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
++CFLAGS   = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
++# CFLAGS   = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
+ LDFLAGS  = -s ${LIBS}
+ 
+ # Solaris
+diff -r aa1078d7b9d7 dwm.c
+--- a/dwm.c	Sat Apr 06 19:49:59 2013 +0200
++++ b/dwm.c	Sat Apr 06 21:36:15 2013 +0200
 @@ -56,12 +56,30 @@
  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
  #define TEXTW(X)                (textnw(X, strlen(X)) + dc.font.height)
  static void sendmon(Client *c, Monitor *m);
  static void setclientstate(Client *c, long state);
  static void setfocus(Client *c);
-@@ -254,18 +283,24 @@
+@@ -236,6 +265,7 @@
+ static void sigchld(int unused);
+ static void spawn(const Arg *arg);
+ static void swapfocus();
++static Monitor *systraytomon(Monitor *m);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static int textnw(const char *text, unsigned int len);
+@@ -254,18 +284,24 @@
  static void updatenumlockmask(void);
  static void updatesizehints(Client *c);
  static void updatestatus(void);
  static Client *prevclient = NULL;
  static const char broken[] = "broken";
  static char stext[256];
-@@ -288,9 +323,10 @@
+@@ -288,9 +324,10 @@
  	[MapRequest] = maprequest,
  	[MotionNotify] = motionnotify,
  	[PropertyNotify] = propertynotify,
  static Bool running = True;
  static Bool restart = False;
  static Cursor cursor[CurLast];
-@@ -569,6 +605,11 @@
+@@ -569,6 +606,11 @@
  	XFreeCursor(dpy, cursor[CurMove]);
  	while(mons)
  		cleanupmon(mons);
  	XSync(dpy, False);
  	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
  	XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
-@@ -603,9 +644,49 @@
+@@ -603,9 +645,49 @@
  
  void
  clientmessage(XEvent *e) {
  	if(!c)
  		return;
  	if(cme->message_type == netatom[NetWMState]) {
-@@ -657,7 +738,7 @@
+@@ -657,7 +739,7 @@
  			dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
  			updatebars();
  			for(m = mons; m; m = m->next)
  			focus(NULL);
  			arrange(NULL);
  		}
-@@ -769,6 +850,11 @@
+@@ -769,6 +851,11 @@
  
  	if((c = wintoclient(ev->window)))
  		unmanage(c, True);
  }
  
  void
-@@ -824,6 +910,7 @@
+@@ -824,6 +911,7 @@
  	unsigned long *col;
  	Client *c;
  
  	for(c = m->cl->clients; c; c = c->next) {
  		occ |= c->tags;
  		if(c->isurgent)
-@@ -844,6 +931,9 @@
+@@ -844,6 +932,9 @@
  	x = dc.x;
  	dc.w = TEXTW(stext);
  	dc.x = m->ww - dc.w;
-+	if(showsystray && m == selmon) {
++	if(showsystray && m == systraytomon(m)) {
 +		dc.x -= getsystraywidth();
 +	}
  	if(dc.x < x) {
  		dc.x = x;
  		dc.w = m->ww - x;
-@@ -869,6 +959,7 @@
+@@ -869,6 +960,7 @@
  
  	for(m = mons; m; m = m->next)
  		drawbar(m);
  }
  
  void
-@@ -934,8 +1025,11 @@
+@@ -934,8 +1026,11 @@
  	Monitor *m;
  	XExposeEvent *ev = &e->xexpose;
  
  }
  
  void
-@@ -1021,10 +1115,17 @@
+@@ -1021,10 +1116,17 @@
  	unsigned long dl;
  	unsigned char *p = NULL;
  	Atom da, atom = None;
  		XFree(p);
  	}
  	return atom;
-@@ -1066,6 +1167,15 @@
+@@ -1066,6 +1168,15 @@
  	return result;
  }
  
  Bool
  gettextprop(Window w, Atom atom, char *text, unsigned int size) {
  	char **list = NULL;
-@@ -1200,7 +1310,7 @@
+@@ -1200,7 +1311,7 @@
  killclient(const Arg *arg) {
  	if(!selmon->sel)
  		return;
  		XGrabServer(dpy);
  		XSetErrorHandler(xerrordummy);
  		XSetCloseDownMode(dpy, DestroyAll);
-@@ -1294,6 +1404,12 @@
+@@ -1294,6 +1405,12 @@
  maprequest(XEvent *e) {
  	static XWindowAttributes wa;
  	XMapRequestEvent *ev = &e->xmaprequest;
  
  	if(!XGetWindowAttributes(dpy, ev->window, &wa))
  		return;
-@@ -1419,6 +1535,16 @@
+@@ -1419,6 +1536,16 @@
  	Window trans;
  	XPropertyEvent *ev = &e->xproperty;
  
  	if((ev->window == root) && (ev->atom == XA_WM_NAME))
  		updatestatus();
  	else if(ev->state == PropertyDelete)
-@@ -1470,12 +1596,33 @@
+@@ -1470,12 +1597,33 @@
  }
  
  void
  void
 +resizebarwin(Monitor *m) {
 +	unsigned int w = m->ww;
-+	if(showsystray && m == selmon)
++	if(showsystray && m == systraytomon(m))
 +		w -= getsystraywidth();
 +	XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, bh);
 +}
  resizeclient(Client *c, int x, int y, int w, int h) {
  	XWindowChanges wc;
  
-@@ -1542,6 +1689,18 @@
+@@ -1542,6 +1690,18 @@
  }
  
  void
  restack(Monitor *m) {
  	Client *c;
  	XEvent ev;
-@@ -1623,25 +1782,35 @@
+@@ -1623,25 +1783,35 @@
  }
  
  Bool
  	}
  	return exists;
  }
-@@ -1654,7 +1823,7 @@
+@@ -1654,7 +1824,7 @@
   		                XA_WINDOW, 32, PropModeReplace,
   		                (unsigned char *) &(c->win), 1);
  	}
  }
  
  void
-@@ -1739,12 +1908,18 @@
+@@ -1739,12 +1909,18 @@
  	wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
  	netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
  	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
  	/* init cursors */
  	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
-@@ -1763,6 +1938,8 @@
+@@ -1763,6 +1939,8 @@
  	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  	if(!dc.font.set)
  		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  	/* init bars */
  	updatebars();
  	updatestatus();
-@@ -1914,7 +2091,18 @@
+@@ -1823,6 +2001,22 @@
+ 		focus(prevclient);
+ }
+ 
++Monitor *
++systraytomon(Monitor *m) {
++	Monitor *t;
++	int i, n;
++	if(!systraypinning) {
++		if(!m)
++			return selmon;
++		return m == selmon ? m : NULL;
++	}
++	for(n = 1, t = mons; t && t->next; n++, t = t->next) ;
++	for(i = 1, t = mons; t && t->next && i < systraypinning; i++, t = t->next) ;
++	if(systraypinningfailfirst && n < systraypinning)
++		return mons;
++	return t;
++}
++
+ void
+ tag(const Arg *arg) {
+ 	Monitor *m;
+@@ -1914,7 +2108,18 @@
  togglebar(const Arg *arg) {
  	selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
  	updatebarpos(selmon);
  	arrange(selmon);
  }
  
-@@ -2057,11 +2245,18 @@
+@@ -2057,11 +2262,18 @@
  		else
  			unmanage(c, False);
  	}
  	XSetWindowAttributes wa = {
  		.override_redirect = True,
  		.background_pixmap = ParentRelative,
-@@ -2070,10 +2265,15 @@
+@@ -2070,10 +2282,15 @@
  	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)
++		if(showsystray && m == systraytomon(m))
 +			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]);
-+		if(showsystray && m == selmon)
++		if(showsystray && m == systraytomon(m))
 +			XMapRaised(dpy, systray->win);
  		XMapRaised(dpy, m->barwin);
  	}
  }
-@@ -2267,6 +2467,109 @@
+@@ -2267,6 +2484,110 @@
  }
  
  void
 +updatesystray(void) {
 +	XSetWindowAttributes wa;
 +	Client *i;
-+	unsigned int x = selmon->mx + selmon->mw;
++	Monitor *m = systraytomon(NULL);
++	unsigned int x = m->mx + m->mw;
 +	unsigned int w = 1;
 +
 +	if(!showsystray)
 +		/* 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.sel[ColBG]);
++		systray->win = XCreateSimpleWindow(dpy, root, x, m->by, w, bh, 0, 0, dc.sel[ColBG]);
 +		wa.event_mask        = ButtonPressMask | ExposureMask;
 +		wa.override_redirect = True;
 +		wa.background_pixel  = dc.norm[ColBG];
 +		w += systrayspacing;
 +		XMoveResizeWindow(dpy, i->win, (i->x = w), 0, i->w, i->h);
 +		w += i->w;
-+		if(i->mon != selmon)
-+			i->mon = selmon;
++		if(i->mon != m)
++			i->mon = m;
 +	}
 +	w = w ? w + systrayspacing : 1;
 + 	x -= w;
-+	XMoveResizeWindow(dpy, systray->win, x, selmon->by, w, bh);
++	XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh);
 +	/* redraw background */
 +	XSetForeground(dpy, dc.gc, dc.norm[ColBG]);
 +	XFillRectangle(dpy, systray->win, dc.gc, 0, 0, w, bh);
  updatewindowtype(Client *c) {
  	Atom state = getatomprop(c, netatom[NetWMState]);
  	Atom wtype = getatomprop(c, netatom[NetWMWindowType]);
-@@ -2377,6 +2680,16 @@
+@@ -2377,6 +2698,16 @@
  	return selmon;
  }