sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-qubesdecorations-6.3.diff (7080B)


      1 From: 3o14r473 <3o14@pm.me> E4FE E61C 3B02 F4CA B6D8  0CA7 F105 757D 34BE FA98
      2 Donate: monero:41rMoMLvk8hEJYP2vbv3dNUGzN95CLXoANAtmAVaUxzse5KfPjhkE7d4PUwh8kCkF16FwwqfZTmS4ZKmYCjrsFAcGXTPpwH
      3 Subject: [PATCH] dwm-qubesdecorations-6.3.diff
      4 
      5 This patch enables dwm to read QubesOS-specific window properties and use the
      6 windowborders, titlebar and tagbar to indicate to the user what qube the
      7 focused window belongs to.
      8 
      9 Each qube-label gets its own SchemeSel colorscheme that can be conviniently configured in config.def.h
     10 ---
     11  config.def.h | 23 ++++++++++++++++++++---
     12  dwm.c        | 47 ++++++++++++++++++++++++++++++++++++++++++++---
     13  2 files changed, 64 insertions(+), 6 deletions(-)
     14 
     15 diff --git a/config.def.h b/config.def.h
     16 index a2ac963..42dce05 100644
     17 --- a/config.def.h
     18 +++ b/config.def.h
     19 @@ -12,10 +12,27 @@ static const char col_gray2[]       = "#444444";
     20  static const char col_gray3[]       = "#bbbbbb";
     21  static const char col_gray4[]       = "#eeeeee";
     22  static const char col_cyan[]        = "#005577";
     23 +static const char col_black[]       = "#000000";
     24 +static const char col_blue[]        = "#4363d8";
     25 +static const char col_gray[]        = "#bebebe";
     26 +static const char col_green[]       = "#3cb44b";
     27 +static const char col_orange[]      = "#f58231";
     28 +static const char col_purple[]      = "#9a009a";
     29 +static const char col_red[]         = "#e6194b";
     30 +static const char col_white[]       = "#ffffff";
     31 +static const char col_yellow[]      = "#ffe119";
     32  static const char *colors[][3]      = {
     33 -	/*               fg         bg         border   */
     34 -	[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
     35 -	[SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
     36 +	/*fg         bg          border   */
     37 +	{ col_black, col_white,  col_white  }, /* SchemeSel dom0    */
     38 +	{ col_white, col_red,    col_red    }, /* SchemeSel label 1 */
     39 +	{ col_white, col_orange, col_orange }, /* SchemeSel label 2 */
     40 +	{ col_white, col_yellow, col_yellow }, /* SchemeSel label 3 */
     41 +	{ col_white, col_green,  col_green  }, /* SchemeSel label 4 */
     42 +	{ col_white, col_gray,   col_gray   }, /* SchemeSel label 5 */
     43 +	{ col_white, col_blue,   col_blue   }, /* SchemeSel label 6 */
     44 +	{ col_white, col_purple, col_purple }, /* SchemeSel label 7 */
     45 +	{ col_white, col_black,  col_black  }, /* SchemeSel label 8 */
     46 +	{ col_gray3, col_gray1,  col_gray2  }, /* SchemeNorm        */
     47  };
     48  
     49  /* tagging */
     50 diff --git a/dwm.c b/dwm.c
     51 index a96f33c..be99dde 100644
     52 --- a/dwm.c
     53 +++ b/dwm.c
     54 @@ -59,11 +59,11 @@
     55  
     56  /* enums */
     57  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     58 -enum { SchemeNorm, SchemeSel }; /* color schemes */
     59  enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     60         NetWMFullscreen, NetActiveWindow, NetWMWindowType,
     61         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
     62  enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
     63 +enum { QubesLabel, QubesVMName, QubesLast }; /* QubesOS atoms */
     64  enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
     65         ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
     66  
     67 @@ -85,6 +86,7 @@ typedef struct {
     68  typedef struct Monitor Monitor;
     69  typedef struct Client Client;
     70  struct Client {
     71 +	char vmname[256];
     72  	char name[256];
     73  	float mina, maxa;
     74  	int x, y, w, h;
     75 @@ -170,6 +172,7 @@ static void focusin(XEvent *e);
     76  static void focusmon(const Arg *arg);
     77  static void focusstack(const Arg *arg);
     78  static Atom getatomprop(Client *c, Atom prop);
     79 +static int getlabel(Client *c);
     80  static int getrootptr(int *x, int *y);
     81  static long getstate(Window w);
     82  static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
     83 @@ -237,6 +240,7 @@ static void zoom(const Arg *arg);
     84  
     85  /* variables */
     86  static const char broken[] = "broken";
     87 +static const char dom0[] = "dom0";
     88  static char stext[256];
     89  static int screen;
     90  static int sw, sh;           /* X display screen geometry width, height */
     91 @@ -260,8 +264,10 @@ static void (*handler[LASTEvent]) (XEvent *) = {
     92  	[PropertyNotify] = propertynotify,
     93  	[UnmapNotify] = unmapnotify
     94  };
     95 -static Atom wmatom[WMLast], netatom[NetLast];
     96 +static Atom wmatom[WMLast], netatom[NetLast], qubesatom[QubesLast];
     97  static int running = 1;
     98 +static int SchemeSel = 0;
     99 +static const int SchemeNorm = 9;
    100  static Cur *cursor[CurLast];
    101  static Clr **scheme;
    102  static Display *dpy;
    103 @@ -702,6 +708,9 @@ drawbar(Monitor *m)
    104  	unsigned int i, occ = 0, urg = 0;
    105  	Client *c;
    106  
    107 +	int size;
    108 +	char *fullname = NULL;
    109 +
    110  	if (!m->showbar)
    111  		return;
    112  
    113 @@ -735,7 +744,11 @@ drawbar(Monitor *m)
    114  	if ((w = m->ww - tw - x) > bh) {
    115  		if (m->sel) {
    116  			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
    117 -			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
    118 +			size = strlen(m->sel->vmname) + strlen(m->sel->name) + 4;
    119 +			fullname = ecalloc(size, 1);
    120 +			snprintf(fullname, size, "[%s] %s", m->sel->vmname, m->sel->name);
    121 +			drw_text(drw, x, 0, w, bh, lrpad / 2, fullname, 0);
    122 +			XFree(fullname);
    123  			if (m->sel->isfloating)
    124  				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
    125  		} else {
    126 @@ -799,6 +812,7 @@ focus(Client *c)
    127  		detachstack(c);
    128  		attachstack(c);
    129  		grabbuttons(c, 1);
    130 +		SchemeSel = getlabel(c);
    131  		XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
    132  		setfocus(c);
    133  	} else {
    134 @@ -875,6 +889,28 @@ getatomprop(Client *c, Atom prop)
    135  	return atom;
    136  }
    137  
    138 +int
    139 +getlabel(Client *c)
    140 +{
    141 +	Atom actual_type;
    142 +	int actual_format;
    143 +	unsigned long nitems;
    144 +	unsigned long nbytes;
    145 +	char *value = 0;
    146 +	int result;
    147 +
    148 +	XGetWindowProperty(dpy, c->win, qubesatom[QubesLabel], 0, 1, False, XA_CARDINAL,
    149 +		&actual_type, &actual_format, &nitems, &nbytes, (unsigned char **) &value);
    150 +
    151 +	if (nitems) {
    152 +		result = (int)*value;
    153 +	} else {
    154 +		result = 0;
    155 +	}
    156 +	XFree(value);
    157 +	return result;
    158 +}
    159 +
    160  int
    161  getrootptr(int *x, int *y)
    162  {
    163 @@ -1239,7 +1275,7 @@ propertynotify(XEvent *e)
    164  			drawbars();
    165  			break;
    166  		}
    167 -		if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
    168 +		if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName] || ev->atom == qubesatom[QubesVMName]) {
    169  			updatetitle(c);
    170  			if (c == c->mon->sel)
    171  				drawbar(c->mon);
    172 @@ -1566,6 +1602,9 @@ setup(void)
    173  	netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
    174  	netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
    175  	netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
    176 +	/* init QubesOS atoms */
    177 +	qubesatom[QubesLabel] = XInternAtom(dpy, "_QUBES_LABEL", False);
    178 +	qubesatom[QubesVMName] = XInternAtom(dpy, "_QUBES_VMNAME", False);
    179  	/* init cursors */
    180  	cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
    181  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
    182 @@ -2001,6 +2040,8 @@ updatestatus(void)
    183  void
    184  updatetitle(Client *c)
    185  {
    186 +	if (!gettextprop(c->win, qubesatom[QubesVMName], c->vmname, sizeof c->vmname))
    187 +		strcpy(c->vmname, dom0);
    188  	if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
    189  		gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name);
    190  	if (c->name[0] == '\0') /* hack to mark broken clients */
    191 -- 
    192 2.30.2
    193