aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksa@vuckovic.cc>2024-01-21 04:02:10 +0100
committerAleksa Vuckovic <aleksa@vuckovic.cc>2024-01-21 04:02:10 +0100
commit566ea338dac813f93e559b0c8dc344c8a9063928 (patch)
tree59ba82c2fed12fd6cd6abeb30223e0b0422f0fab /src
Initial commitHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/wayland.c7
-rw-r--r--src/winapi.c7
-rw-r--r--src/x11.c81
3 files changed, 95 insertions, 0 deletions
diff --git a/src/wayland.c b/src/wayland.c
new file mode 100644
index 0000000..47440c3
--- /dev/null
+++ b/src/wayland.c
@@ -0,0 +1,7 @@
+#ifdef Wayland
+int main()
+{
+ printf("Wayland\n");
+ return 0;
+}
+#endif
diff --git a/src/winapi.c b/src/winapi.c
new file mode 100644
index 0000000..a5a7c52
--- /dev/null
+++ b/src/winapi.c
@@ -0,0 +1,7 @@
+#ifdef WinAPI
+int main()
+{
+ printf("WinAPI\n");
+ return 0;
+}
+#endif
diff --git a/src/x11.c b/src/x11.c
new file mode 100644
index 0000000..4779c08
--- /dev/null
+++ b/src/x11.c
@@ -0,0 +1,81 @@
+#ifdef X11
+#include <stdio.h>
+#include <time.h>
+#include <X11/Xlib.h>
+
+#include <X11/extensions/Xcomposite.h>
+#include <X11/extensions/Xfixes.h>
+#include <X11/extensions/shape.h>
+
+#include <cairo.h>
+#include <cairo-xlib.h>
+
+Display *d;
+Window overlay;
+Window root;
+int width, height;
+
+void allow_input_passthrough(Window w)
+{
+ XserverRegion region = XFixesCreateRegion(d, NULL, 0);
+
+ XFixesSetWindowShapeRegion(d, w, ShapeBounding, 0, 0, 0);
+ XFixesSetWindowShapeRegion(d, w, ShapeInput, 0, 0, region);
+
+ XFixesDestroyRegion(d, region);
+}
+
+void prep_overlay(void)
+{
+ overlay = XCompositeGetOverlayWindow(d, root);
+ allow_input_passthrough(overlay);
+}
+
+void draw(cairo_t *cr)
+{
+ int quarter_w = width / 4;
+ int quarter_h = height / 4;
+ cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
+ cairo_rectangle(cr, quarter_w, quarter_h, quarter_w * 2, quarter_h * 2);
+ cairo_fill(cr);
+}
+
+int main()
+{
+ printf("X11\n");
+
+ struct timespec ts = { 0, 5000 };
+
+ d = XOpenDisplay(NULL);
+
+ int s = DefaultScreen(d);
+ root = RootWindow(d, s);
+
+ XCompositeRedirectSubwindows(d, root, CompositeRedirectAutomatic);
+ XSelectInput(d, root, SubstructureNotifyMask);
+
+ width = DisplayWidth(d, s);
+ height = DisplayHeight(d, s);
+
+ prep_overlay();
+
+ cairo_surface_t *surf = cairo_xlib_surface_create(d, overlay, DefaultVisual(d, s), width, height);
+ cairo_t *cr = cairo_create(surf);
+
+ XSelectInput(d, overlay, ExposureMask);
+
+ XEvent ev;
+ while (1) {
+ overlay = XCompositeGetOverlayWindow(d, root);
+ draw(cr);
+ XCompositeReleaseOverlayWindow(d, root);
+ nanosleep(&ts, NULL);
+ }
+
+ cairo_destroy(cr);
+ cairo_surface_destroy(surf);
+ XCloseDisplay(d);
+
+ return 0;
+}
+#endif