]> git.corax.cc Git - mwm/commitdiff
mwm: Add datatype to manage global context
authorMatthias Kruk <m@m10k.eu>
Sun, 2 May 2021 00:53:37 +0000 (09:53 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 2 May 2021 00:53:37 +0000 (09:53 +0900)
This commit adds the mwm data type, which stores the global state of
the window manager, and will be used to handle events.

mwm.c [new file with mode: 0644]
mwm.h [new file with mode: 0644]

diff --git a/mwm.c b/mwm.c
new file mode 100644 (file)
index 0000000..df16faf
--- /dev/null
+++ b/mwm.c
@@ -0,0 +1,103 @@
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <X11/Xlib.h>
+#include "mwm.h"
+#include "monitor.h"
+#include "array.h"
+
+struct mwm {
+       Display *display;
+
+       struct array *monitors;
+};
+
+int mwm_new(struct mwm **dst)
+{
+       struct mwm *mwm;
+
+       if(!dst) {
+               return(-EINVAL);
+       }
+
+       mwm = malloc(sizeof(*mwm));
+
+       if(!mwm) {
+               return(-ENOMEM);
+       }
+
+       memset(mwm, 0, sizeof(*mwm));
+
+       if(array_new(&(mwm->monitors)) < 0) {
+               free(mwm);
+               return(-ENOMEM);
+       }
+
+       *dst = mwm;
+
+       return(0);
+}
+
+int mwm_free(struct mwm **mwm)
+{
+       if(!mwm) {
+               return(-EINVAL);
+       }
+
+       if(!*mwm) {
+               return(-EALREADY);
+       }
+
+       free(*mwm);
+       *mwm = NULL;
+
+       return(0);
+}
+
+int mwm_init(struct mwm *mwm)
+{
+       return(-ENOSYS);
+}
+
+int mwm_run(struct mwm *mwm)
+{
+       return(-ENOSYS);
+}
+
+int mwm_attach_monitor(struct mwm *mwm, struct monitor *mon)
+{
+       int idx;
+
+       if(!mwm || !mon) {
+               return(-EINVAL);
+       }
+
+       idx = monitor_get_id(mon);
+
+       if(array_set(mwm->monitors, idx, mon) < 0) {
+               return(-ENOMEM);
+       }
+
+       /* register monitor */
+
+       return(0);
+}
+
+int mwm_detach_monitor(struct mwm *mwm, struct monitor *mon)
+{
+       int idx;
+
+       if(!mwm || !mon) {
+               return(-EINVAL);
+       }
+
+       idx = monitor_get_id(mon);
+
+       if(array_take(mwm->monitors, idx, NULL) < 0) {
+               return(-ENODEV);
+       }
+
+       /* unregister monitor */
+
+       return(0);
+}
diff --git a/mwm.h b/mwm.h
new file mode 100644 (file)
index 0000000..645ec08
--- /dev/null
+++ b/mwm.h
@@ -0,0 +1,16 @@
+#ifndef MWM_H
+#define MWM_H 1
+
+struct mwm;
+struct monitor;
+
+int mwm_new(struct mwm **mwm);
+int mwm_free(struct mwm **mwm);
+
+int mwm_init(struct mwm *mwm);
+int mwm_run(struct mwm *mwm);
+
+int mwm_attach_monitor(struct mwm *mwm, struct monitor *mon);
+int mwm_detach_monitor(struct mwm *mwm, struct monitor *mon);
+
+#endif /* MWM_H */