dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

vanitygaps.c (5453B)


      1 /* Settings */
      2 #if !(PERTAG_VANITYGAPS_PATCH || PERMON_VANITYGAPS_PATCH)
      3 static int enablegaps = 1;
      4 #endif // PERTAG_VANITYGAPS_PATCH
      5 
      6 static void
      7 setgaps(int oh, int ov, int ih, int iv)
      8 {
      9 	if (oh < 0) oh = 0;
     10 	if (ov < 0) ov = 0;
     11 	if (ih < 0) ih = 0;
     12 	if (iv < 0) iv = 0;
     13 
     14 	selmon->gappoh = oh;
     15 	selmon->gappov = ov;
     16 	selmon->gappih = ih;
     17 	selmon->gappiv = iv;
     18 
     19 	#if PERTAG_VANITYGAPS_PATCH && PERTAG_PATCH
     20 	selmon->pertag->gaps[selmon->pertag->curtag] =
     21 		((oh & 0xFF) << 0) | ((ov & 0xFF) << 8) | ((ih & 0xFF) << 16) | ((iv & 0xFF) << 24);
     22 	#endif // PERTAG_VANITYGAPS_PATCH
     23 
     24 	arrange(selmon);
     25 }
     26 
     27 #if IPC_PATCH || DWMC_PATCH
     28 /* External function that takes one integer and splits it
     29  * into four gap values:
     30  *    - outer horizontal (oh)
     31  *    - outer vertical (ov)
     32  *    - inner horizontal (ih)
     33  *    - inner vertical (iv)
     34  *
     35  * Each value is represented as one byte with the uppermost
     36  * bit of each byte indicating whether or not to keep the
     37  * current value.
     38  *
     39  * Example:
     40  *
     41  *   10000000   10000000   00001111   00001111
     42  *   |          |          |          |
     43  *   + keep oh  + keep ov  + ih 15px  + iv 15px
     44  *
     45  * This gives an int of:
     46  *   10000000100000000000111100001111 = 2155876111
     47  *
     48  * Thus this command should set inner gaps to 15:
     49  *   xsetroot -name "fsignal:setgaps i 2155876111"
     50  */
     51 static void
     52 setgapsex(const Arg *arg)
     53 {
     54 	int oh = selmon->gappoh;
     55 	int ov = selmon->gappov;
     56 	int ih = selmon->gappih;
     57 	int iv = selmon->gappiv;
     58 
     59 	if (!(arg->i & (1 << 31)))
     60 		oh = (arg->i & 0x7f000000) >> 24;
     61 	if (!(arg->i & (1 << 23)))
     62 		ov = (arg->i & 0x7f0000) >> 16;
     63 	if (!(arg->i & (1 << 15)))
     64 		ih = (arg->i & 0x7f00) >> 8;
     65 	if (!(arg->i & (1 << 7)))
     66 		iv = (arg->i & 0x7f);
     67 
     68 	/* Auto enable gaps if disabled */
     69 	#if PERTAG_VANITYGAPS_PATCH && PERTAG_PATCH
     70 	if (!selmon->pertag->enablegaps[selmon->pertag->curtag])
     71 		selmon->pertag->enablegaps[selmon->pertag->curtag] = 1;
     72 	#elif PERMON_VANITYGAPS_PATCH
     73 		selmon->enablegaps = 1;
     74 	#else
     75 	if (!enablegaps)
     76 		enablegaps = 1;
     77 	#endif // PERTAG_VANITYGAPS_PATCH | PERMON_VANITYGAPS_PATCH
     78 
     79 	setgaps(oh, ov, ih, iv);
     80 }
     81 #endif // IPC_PATCH | DWMC_PATCH
     82 
     83 static void
     84 togglegaps(const Arg *arg)
     85 {
     86 	#if PERTAG_VANITYGAPS_PATCH && PERTAG_PATCH
     87 	selmon->pertag->enablegaps[selmon->pertag->curtag] = !selmon->pertag->enablegaps[selmon->pertag->curtag];
     88 	#elif PERMON_VANITYGAPS_PATCH
     89 	selmon->enablegaps = !selmon->enablegaps;
     90 	#else
     91 	enablegaps = !enablegaps;
     92 	#endif // PERTAG_VANITYGAPS_PATCH | PERMON_VANITYGAPS_PATCH
     93 
     94 	#if BAR_PADDING_VANITYGAPS_PATCH
     95 	#if PERMON_VANITYGAPS_PATCH
     96 	updatebarpos(selmon);
     97 	for (Bar *bar = selmon->bar; bar; bar = bar->next)
     98 		XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh);
     99 	#else
    100 	for (Monitor *m = mons; m; m = m->next) {
    101 		updatebarpos(m);
    102 		for (Bar *bar = m->bar; bar; bar = bar->next)
    103 			XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh);
    104 	}
    105 	#endif // PERMON_VANITYGAPS_PATCH
    106 
    107 	#if BAR_SYSTRAY_PATCH
    108 	drawbarwin(systray->bar);
    109 	#endif // BAR_SYSTRAY_PATCH
    110 	#endif // BAR_PADDING_VANITYGAPS_PATCH
    111 
    112 	#if (PERTAG_VANITYGAPS_PATCH && PERTAG_PATCH) || PERMON_VANITYGAPS_PATCH
    113 	arrange(selmon);
    114 	#else
    115 	arrange(NULL);
    116 	#endif // PERTAG_VANITYGAPS_PATCH | PERMON_VANITYGAPS_PATCH
    117 }
    118 
    119 static void
    120 defaultgaps(const Arg *arg)
    121 {
    122 	setgaps(gappoh, gappov, gappih, gappiv);
    123 }
    124 
    125 static void
    126 incrgaps(const Arg *arg)
    127 {
    128 	setgaps(
    129 		selmon->gappoh + arg->i,
    130 		selmon->gappov + arg->i,
    131 		selmon->gappih + arg->i,
    132 		selmon->gappiv + arg->i
    133 	);
    134 }
    135 
    136 static void
    137 incrigaps(const Arg *arg)
    138 {
    139 	setgaps(
    140 		selmon->gappoh,
    141 		selmon->gappov,
    142 		selmon->gappih + arg->i,
    143 		selmon->gappiv + arg->i
    144 	);
    145 }
    146 
    147 static void
    148 incrogaps(const Arg *arg)
    149 {
    150 	setgaps(
    151 		selmon->gappoh + arg->i,
    152 		selmon->gappov + arg->i,
    153 		selmon->gappih,
    154 		selmon->gappiv
    155 	);
    156 }
    157 
    158 static void
    159 incrohgaps(const Arg *arg)
    160 {
    161 	setgaps(
    162 		selmon->gappoh + arg->i,
    163 		selmon->gappov,
    164 		selmon->gappih,
    165 		selmon->gappiv
    166 	);
    167 }
    168 
    169 static void
    170 incrovgaps(const Arg *arg)
    171 {
    172 	setgaps(
    173 		selmon->gappoh,
    174 		selmon->gappov + arg->i,
    175 		selmon->gappih,
    176 		selmon->gappiv
    177 	);
    178 }
    179 
    180 static void
    181 incrihgaps(const Arg *arg)
    182 {
    183 	setgaps(
    184 		selmon->gappoh,
    185 		selmon->gappov,
    186 		selmon->gappih + arg->i,
    187 		selmon->gappiv
    188 	);
    189 }
    190 
    191 static void
    192 incrivgaps(const Arg *arg)
    193 {
    194 	setgaps(
    195 		selmon->gappoh,
    196 		selmon->gappov,
    197 		selmon->gappih,
    198 		selmon->gappiv + arg->i
    199 	);
    200 }
    201 
    202 #if DRAGMFACT_PATCH || CENTEREDMASTER_LAYOUT || CENTEREDFLOATINGMASTER_LAYOUT || COLUMNS_LAYOUT || DECK_LAYOUT || FIBONACCI_DWINDLE_LAYOUT || FIBONACCI_SPIRAL_LAYOUT || GAPPLESSGRID_LAYOUT || NROWGRID_LAYOUT || HORIZGRID_LAYOUT || BSTACK_LAYOUT || BSTACKHORIZ_LAYOUT || GRIDMODE_LAYOUT || FLEXTILE_DELUXE_LAYOUT || TILE_LAYOUT || (VANITYGAPS_MONOCLE_PATCH && MONOCLE_LAYOUT)
    203 static void
    204 getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
    205 {
    206 	unsigned int n, oe, ie;
    207 	#if PERTAG_VANITYGAPS_PATCH && PERTAG_PATCH
    208 	oe = ie = m->pertag->enablegaps[m->pertag->curtag];
    209 	#elif PERMON_VANITYGAPS_PATCH
    210 	oe = ie = m->enablegaps;
    211 	#else
    212 	oe = ie = enablegaps;
    213 	#endif // PERTAG_VANITYGAPS_PATCH | PERMON_VANITYGAPS_PATCH
    214 	Client *c;
    215 
    216 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
    217 	if (n == 1) {
    218 		oe *= smartgaps_fact; // outer gaps disabled or multiplied when only one client
    219 	}
    220 
    221 	*oh = m->gappoh*oe; // outer horizontal gap
    222 	*ov = m->gappov*oe; // outer vertical gap
    223 	*ih = m->gappih*ie; // inner horizontal gap
    224 	*iv = m->gappiv*ie; // inner vertical gap
    225 	*nc = n;            // number of clients
    226 }
    227 #endif
    228