sites

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

dwm-windowmap-20221026.diff (2284B)


      1 diff --git a/dwm.c b/dwm.c
      2 index e5efb6a..eaf0333 100644
      3 --- a/dwm.c
      4 +++ b/dwm.c
      5 @@ -228,6 +228,9 @@ static void updatetitle(Client *c);
      6  static void updatewindowtype(Client *c);
      7  static void updatewmhints(Client *c);
      8  static void view(const Arg *arg);
      9 +static void window_set_state(Display *dpy, Window win, long state);
     10 +static void window_map(Display *dpy, Client *c, int deiconify);
     11 +static void window_unmap(Display *dpy, Window win, Window root, int iconify);
     12  static Client *wintoclient(Window w);
     13  static Monitor *wintomon(Window w);
     14  static int xerror(Display *dpy, XErrorEvent *ee);
     15 @@ -1617,14 +1620,12 @@ showhide(Client *c)
     16  		return;
     17  	if (ISVISIBLE(c)) {
     18  		/* show clients top down */
     19 -		XMoveWindow(dpy, c->win, c->x, c->y);
     20 -		if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
     21 -			resize(c, c->x, c->y, c->w, c->h, 0);
     22 +		window_map(dpy, c, 1);
     23  		showhide(c->snext);
     24  	} else {
     25  		/* hide clients bottom up */
     26  		showhide(c->snext);
     27 -		XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y);
     28 +		window_unmap(dpy, c->win, root, 1);
     29  	}
     30  }
     31  
     32 @@ -2032,6 +2033,51 @@ updatewmhints(Client *c)
     33  	}
     34  }
     35  
     36 +void
     37 +window_set_state(Display *dpy, Window win, long state)
     38 +{
     39 +	long data[] = { state, None };
     40 +
     41 +	XChangeProperty(dpy, win, wmatom[WMState], wmatom[WMState], 32,
     42 +		PropModeReplace, (unsigned char*)data, 2);
     43 +}
     44 +
     45 +void
     46 +window_map(Display *dpy, Client *c, int deiconify)
     47 +{
     48 +	Window win = c->win;
     49 +
     50 +	if (deiconify)
     51 +		window_set_state(dpy, win, NormalState);
     52 +
     53 +	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
     54 +	XSetInputFocus(dpy, win, RevertToPointerRoot, CurrentTime);
     55 +	XMapWindow(dpy, win);
     56 +}
     57 +
     58 +void
     59 +window_unmap(Display *dpy, Window win, Window root, int iconify)
     60 +{
     61 +	static XWindowAttributes ca, ra;
     62 +
     63 +	XGrabServer(dpy);
     64 +	XGetWindowAttributes(dpy, root, &ra);
     65 +	XGetWindowAttributes(dpy, win, &ca);
     66 +
     67 +	/* Prevent UnmapNotify events */
     68 +	XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
     69 +	XSelectInput(dpy, win, ca.your_event_mask & ~StructureNotifyMask);
     70 +
     71 +	XUnmapWindow(dpy, win);
     72 +
     73 +	if (iconify)
     74 +		window_set_state(dpy, win, IconicState);
     75 +
     76 +	XSelectInput(dpy, root, ra.your_event_mask);
     77 +	XSelectInput(dpy, win, ca.your_event_mask);
     78 +	XUngrabServer(dpy);
     79 +}
     80 +
     81  void
     82  view(const Arg *arg)
     83  {