]> git.corax.cc Git - mwm/commitdiff
x, common: Add convenience functions and common types
authorMatthias Kruk <m@m10k.eu>
Mon, 3 May 2021 00:29:40 +0000 (09:29 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 3 May 2021 00:29:40 +0000 (09:29 +0900)
This commit adds convenience functions that wrap functionality provided
by Xlib. Further, it adds a structure that defines the geometry of an
object.

common.h [new file with mode: 0644]
x.c [new file with mode: 0644]
x.h [new file with mode: 0644]

diff --git a/common.h b/common.h
new file mode 100644 (file)
index 0000000..3bb5368
--- /dev/null
+++ b/common.h
@@ -0,0 +1,11 @@
+#ifndef COMMON_H
+#define COMMON_H 1
+
+struct geom {
+       int x;
+       int y;
+       unsigned int w;
+       unsigned int h;
+};
+
+#endif /* COMMON_H */
diff --git a/x.c b/x.c
new file mode 100644 (file)
index 0000000..c2e8750
--- /dev/null
+++ b/x.c
@@ -0,0 +1,46 @@
+#include <X11/Xlib.h>
+#include <string.h>
+#include <errno.h>
+#include "common.h"
+
+void x_configure_notify(Display *display, Window window,
+                       struct geom *geom, unsigned int border)
+{
+       XConfigureEvent event;
+
+       memset(&event, 0, sizeof(event));
+
+       event.type = ConfigureNotify;
+       event.display = display;
+       event.event = window;
+       event.window = window;
+
+       if(geom) {
+               event.x = geom->x;
+               event.y = geom->y;
+               event.width = geom->w;
+               event.height = geom->h;
+       }
+
+       event.border_width = border;
+       event.above = None;
+       event.override_redirect = False;
+
+       XSendEvent(display, window, False, StructureNotifyMask, (XEvent*)&event);
+
+       return;
+}
+
+int x_get_geom(Display *display, Window window, struct geom *geom)
+{
+       Window root;
+       unsigned int border;
+       unsigned int depth;
+
+       if(XGetGeometry(display, window, &root, &geom->x, &geom->y,
+                       &geom->w, &geom->h, &border, &depth) == False) {
+               return(-EIO);
+       }
+
+       return(0);
+}
diff --git a/x.h b/x.h
new file mode 100644 (file)
index 0000000..fb99e13
--- /dev/null
+++ b/x.h
@@ -0,0 +1,11 @@
+#ifndef MWM_X_H
+#define MWM_X_H 1
+
+#include <X11/Xlib.h>
+#include "common.h"
+
+void x_configure_notify(Display *display, Window window,
+                       struct geom *geom, unsigned int border);
+int x_get_geom(Display *display, Window window, struct geom *geom);
+
+#endif /* MWM_X_H */