1 
2 #include <yukon.h>
3 
4 yukonGlobalData yukonGlobal;
5 
6 static int doCapture;
7 static seomClient *client;
8 
yukonCoreEvent(Display * dpy,XEvent * event)9 void yukonCoreEvent(Display *dpy, XEvent *event)
10 {
11 	static Time lastEvent;
12 
13 	switch (event->type) {
14 	case KeyPress:
15 		if (event->xkey.keycode == XKeysymToKeycode(dpy, yukonGlobal.hotkey)) {
16 			if (event->xkey.time == lastEvent)
17 				return;
18 
19 			lastEvent = event->xkey.time;
20 			doCapture = !client;
21 			if (client) {
22 				seomClientDestroy(client);
23 				logMessage(3, "Yukon stopped capturing\n");
24 				client = NULL;
25 			} else {
26 				logMessage(3, "Yukon is starting to capture\n");
27 			}
28 		}
29 		break;
30 	default:
31 		break;
32 	}
33 }
34 
yukonCoreCapture(Display * dpy,GLXDrawable drawable)35 void yukonCoreCapture(Display *dpy, GLXDrawable drawable)
36 {
37 	if (client == NULL && doCapture) {
38 		doCapture = 0;
39 
40 		/* reload configuration in case it changed */
41 		updateConfiguration();
42 
43 		Window root;
44 		unsigned int width, height, unused;
45 		XGetGeometry(dpy, drawable, &root, (int *)&unused, (int *)&unused, &width, &height, &unused, &unused);
46 
47 		if (yukonGlobal.insets[0] + yukonGlobal.insets[2] > height || yukonGlobal.insets[1] + yukonGlobal.insets[3] > width) {
48 			logMessage(2, "%s(): insets too big, fix it!\n", __func__);
49 			return;
50 		}
51 
52 		seomClientConfig config = {
53 			.size = { width - (yukonGlobal.insets[1] + yukonGlobal.insets[3]), height - (yukonGlobal.insets[0] + yukonGlobal.insets[2]) },
54 			.scale = yukonGlobal.scale,
55 			.fps = yukonGlobal.fps,
56 			.output = yukonGlobal.output,
57 		};
58 
59 		client = seomClientCreate(&config);
60 		if (client == NULL)
61 			logMessage(1, "%s(): couldn't create seom client\n", __func__);
62 	}
63 
64 	if (client)
65 		seomClientCapture(client, yukonGlobal.insets[3], yukonGlobal.insets[2]);
66 }
67