shod

mouse-based window manager that can tile windows inside floating containers
Log | Files | Refs | README | LICENSE

xsplash.c (2086B)


      1 #include "shod.h"
      2 
      3 /* create new splash screen */
      4 static struct Splash *
      5 splashnew(Window win, int w, int h)
      6 {
      7 	struct Splash *splash;
      8 
      9 	splash = emalloc(sizeof(*splash));
     10 	*splash = (struct Splash){
     11 		.obj.win = win,
     12 		.obj.type = TYPE_SPLASH,
     13 		.w = w,
     14 		.h = h,
     15 	};
     16 	splash->frame = XCreateWindow(
     17 		dpy,
     18 		root,
     19 		0, 0,
     20 		w, h,
     21 		0,
     22 		depth, CopyFromParent, visual,
     23 		clientmask, &clientswa
     24 	);
     25 	XReparentWindow(dpy, win, splash->frame, 0, 0);
     26 	XMapWindow(dpy, win);
     27 	TAILQ_INSERT_HEAD(&wm.splashq, (struct Object *)splash, entry);
     28 	return splash;
     29 }
     30 
     31 /* center splash screen on monitor and raise it above other windows */
     32 void
     33 splashplace(struct Monitor *mon, struct Splash *splash)
     34 {
     35 	fitmonitor(mon, &splash->x, &splash->y, &splash->w, &splash->h, 0.5);
     36 	splash->x = mon->wx + (mon->ww - splash->w) / 2;
     37 	splash->y = mon->wy + (mon->wh - splash->h) / 2;
     38 	XMoveWindow(dpy, splash->frame, splash->x, splash->y);
     39 }
     40 
     41 /* (un)hide splash screen */
     42 void
     43 splashhide(struct Splash *splash, int hide)
     44 {
     45 	if (hide)
     46 		XUnmapWindow(dpy, splash->frame);
     47 	else
     48 		XMapWindow(dpy, splash->frame);
     49 	icccmwmstate(splash->frame, (hide ? IconicState : NormalState));
     50 }
     51 
     52 void
     53 splashrise(struct Splash *splash)
     54 {
     55 	Window wins[2];
     56 
     57 	wins[1] = splash->frame;
     58 	wins[0] = wm.layers[LAYER_NORMAL].frame;
     59 	XRestackWindows(dpy, wins, 2);
     60 }
     61 
     62 /* delete splash screen window */
     63 int
     64 unmanagesplash(struct Object *obj, int dummy)
     65 {
     66 	struct Splash *splash;
     67 
     68 	splash = (struct Splash *)obj;
     69 	(void)dummy;
     70 	TAILQ_REMOVE(&wm.splashq, (struct Object *)splash, entry);
     71 	icccmdeletestate(splash->obj.win);
     72 	XDestroyWindow(dpy, splash->frame);
     73 	free(splash);
     74 	return 0;
     75 }
     76 
     77 /* add splash screen and center it on the screen */
     78 void
     79 managesplash(struct Tab *tab, struct Monitor *mon, int desk, Window win, Window leader, XRectangle rect, int state, int ignoreunmap)
     80 {
     81 	struct Splash *splash;
     82 
     83 	(void)tab;
     84 	(void)leader;
     85 	(void)state;
     86 	(void)ignoreunmap;
     87 	splash = splashnew(win, rect.width, rect.height);
     88 	splash->mon = mon;
     89 	splash->desk = desk;
     90 	splashplace(mon, splash);
     91 	splashrise(splash);
     92 	splashhide(splash, REMOVE);
     93 }