sites

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

dwm-twomonitorsetup-6.4.diff (5959B)


      1 From 4928b5e9f4e5666ed35e3aa3f61df25c503e921e Mon Sep 17 00:00:00 2001
      2 From: stojshic <stojshic@arch.pc>
      3 Date: Tue, 6 Feb 2024 19:54:47 +0100
      4 Subject: [PATCH] Modified to work with two monitors, 'ModKey + <' [or 'ModKey
      5  + Shift + <'] moves focus [or windows] to left monitor but doesn't bring it
      6  back to right monitor on another click
      7 
      8 ---
      9  dwm.c | 119 ++++++++++++++++++++++++++++++++++++++++------------------
     10  1 file changed, 82 insertions(+), 37 deletions(-)
     11 
     12 diff --git a/dwm.c b/dwm.c
     13 index e5efb6a..2234780 100644
     14 --- a/dwm.c
     15 +++ b/dwm.c
     16 @@ -160,7 +160,7 @@ static Monitor *createmon(void);
     17  static void destroynotify(XEvent *e);
     18  static void detach(Client *c);
     19  static void detachstack(Client *c);
     20 -static Monitor *dirtomon(int dir);
     21 +// static Monitor *dirtomon(int dir);
     22  static void drawbar(Monitor *m);
     23  static void drawbars(void);
     24  static void enternotify(XEvent *e);
     25 @@ -194,6 +194,7 @@ static void resizeclient(Client *c, int x, int y, int w, int h);
     26  static void resizemouse(const Arg *arg);
     27  static void restack(Monitor *m);
     28  static void run(void);
     29 +static void runAutostart(void);
     30  static void scan(void);
     31  static int sendevent(Client *c, Atom proto);
     32  static void sendmon(Client *c, Monitor *m);
     33 @@ -205,7 +206,6 @@ static void setmfact(const Arg *arg);
     34  static void setup(void);
     35  static void seturgent(Client *c, int urg);
     36  static void showhide(Client *c);
     37 -static void sigchld(int unused);
     38  static void spawn(const Arg *arg);
     39  static void tag(const Arg *arg);
     40  static void tagmon(const Arg *arg);
     41 @@ -681,6 +681,7 @@ detachstack(Client *c)
     42  	}
     43  }
     44  
     45 +/* 
     46  Monitor *
     47  dirtomon(int dir)
     48  {
     49 @@ -695,7 +696,7 @@ dirtomon(int dir)
     50  		for (m = mons; m->next != selmon; m = m->next);
     51  	return m;
     52  }
     53 -
     54 +*/
     55  void
     56  drawbar(Monitor *m)
     57  {
     58 @@ -737,7 +738,8 @@ drawbar(Monitor *m)
     59  
     60  	if ((w = m->ww - tw - x) > bh) {
     61  		if (m->sel) {
     62 -			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
     63 +			drw_setscheme(drw, scheme[SchemeNorm]);
     64 +			// drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
     65  			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
     66  			if (m->sel->isfloating)
     67  				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
     68 @@ -823,17 +825,22 @@ focusin(XEvent *e)
     69  }
     70  
     71  void
     72 -focusmon(const Arg *arg)
     73 -{
     74 -	Monitor *m;
     75 +focusmon(const Arg *arg) {
     76 +    Monitor *m = NULL;
     77  
     78 -	if (!mons->next)
     79 -		return;
     80 -	if ((m = dirtomon(arg->i)) == selmon)
     81 -		return;
     82 -	unfocus(selmon->sel, 0);
     83 -	selmon = m;
     84 -	focus(NULL);
     85 +    if (!mons->next)
     86 +        return;
     87 +
     88 +    if (arg->i > 0) {
     89 +        m = mons->next;
     90 +    } else if (arg->i < 0 && mons->next) {
     91 +        m = mons;
     92 +    }
     93 +
     94 +    if (m) {
     95 +        selmon = m;
     96 +        focus(NULL);
     97 +    }
     98  }
     99  
    100  void
    101 @@ -955,16 +962,26 @@ grabkeys(void)
    102  {
    103  	updatenumlockmask();
    104  	{
    105 -		unsigned int i, j;
    106 +		unsigned int i, j, k;
    107  		unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
    108 -		KeyCode code;
    109 +		int start, end, skip;
    110 +		KeySym *syms;
    111  
    112  		XUngrabKey(dpy, AnyKey, AnyModifier, root);
    113 -		for (i = 0; i < LENGTH(keys); i++)
    114 -			if ((code = XKeysymToKeycode(dpy, keys[i].keysym)))
    115 -				for (j = 0; j < LENGTH(modifiers); j++)
    116 -					XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
    117 -						True, GrabModeAsync, GrabModeAsync);
    118 +		XDisplayKeycodes(dpy, &start, &end);
    119 +		syms = XGetKeyboardMapping(dpy, start, end - start + 1, &skip);
    120 +		if (!syms)
    121 +			return;
    122 +		for (k = start; k <= end; k++)
    123 +			for (i = 0; i < LENGTH(keys); i++)
    124 +				/* skip modifier codes, we do that ourselves */
    125 +				if (keys[i].keysym == syms[(k - start) * skip])
    126 +					for (j = 0; j < LENGTH(modifiers); j++)
    127 +						XGrabKey(dpy, k,
    128 +							 keys[i].mod | modifiers[j],
    129 +							 root, True,
    130 +							 GrabModeAsync, GrabModeAsync);
    131 +		XFree(syms);
    132  	}
    133  }
    134  
    135 @@ -1381,6 +1398,12 @@ run(void)
    136  			handler[ev.type](&ev); /* call handler */
    137  }
    138  
    139 +void
    140 +runAutostart(void) {
    141 +	system("cd ~/.dwm; ./autostart_blocking.sh");
    142 +	system("cd ~/.dwm; ./autostart.sh &");
    143 +}
    144 +
    145  void
    146  scan(void)
    147  {
    148 @@ -1533,9 +1556,16 @@ setup(void)
    149  	int i;
    150  	XSetWindowAttributes wa;
    151  	Atom utf8string;
    152 +	struct sigaction sa;
    153 +
    154 +	/* do not transform children into zombies when they terminate */
    155 +	sigemptyset(&sa.sa_mask);
    156 +	sa.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART;
    157 +	sa.sa_handler = SIG_IGN;
    158 +	sigaction(SIGCHLD, &sa, NULL);
    159  
    160 -	/* clean up any zombies immediately */
    161 -	sigchld(0);
    162 +	/* clean up any zombies (inherited from .xinitrc etc) immediately */
    163 +	while (waitpid(-1, NULL, WNOHANG) > 0);
    164  
    165  	/* init screen */
    166  	screen = DefaultScreen(dpy);
    167 @@ -1628,21 +1658,23 @@ showhide(Client *c)
    168  	}
    169  }
    170  
    171 -void
    172 -sigchld(int unused)
    173 -{
    174 -	if (signal(SIGCHLD, sigchld) == SIG_ERR)
    175 -		die("can't install SIGCHLD handler:");
    176 -	while (0 < waitpid(-1, NULL, WNOHANG));
    177 -}
    178 -
    179  void
    180  spawn(const Arg *arg)
    181  {
    182 +	struct sigaction sa;
    183 +
    184 +	if (arg->v == dmenucmd)
    185 +		dmenumon[0] = '0' + selmon->num;
    186  	if (fork() == 0) {
    187  		if (dpy)
    188  			close(ConnectionNumber(dpy));
    189  		setsid();
    190 +
    191 +		sigemptyset(&sa.sa_mask);
    192 +		sa.sa_flags = 0;
    193 +		sa.sa_handler = SIG_DFL;
    194 +		sigaction(SIGCHLD, &sa, NULL);
    195 +
    196  		execvp(((char **)arg->v)[0], (char **)arg->v);
    197  		die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
    198  	}
    199 @@ -1658,14 +1690,26 @@ tag(const Arg *arg)
    200  	}
    201  }
    202  
    203 -void
    204 -tagmon(const Arg *arg)
    205 -{
    206 -	if (!selmon->sel || !mons->next)
    207 -		return;
    208 -	sendmon(selmon->sel, dirtomon(arg->i));
    209 +void tagmon(const Arg *arg) {
    210 +    if (!selmon->sel || !mons->next)
    211 +        return;
    212 +
    213 +    Monitor *m;
    214 +
    215 +    if (arg->i > 0) {
    216 +        m = mons->next;  // Move to mon1
    217 +    } else if (arg->i < 0 && mons->next) {
    218 +        m = mons;  // Move to mon2
    219 +    } else {
    220 +        return; // Do nothing for arg->i == 0
    221 +    }
    222 +
    223 +    sendmon(selmon->sel, m);
    224 +    focus(NULL);
    225 +    arrange(selmon);
    226  }
    227  
    228 +
    229  void
    230  tile(Monitor *m)
    231  {
    232 @@ -2140,6 +2184,7 @@ main(int argc, char *argv[])
    233  		die("pledge");
    234  #endif /* __OpenBSD__ */
    235  	scan();
    236 +	runAutostart();
    237  	run();
    238  	cleanup();
    239  	XCloseDisplay(dpy);
    240 -- 
    241 2.43.0
    242