From d09b60fdff0670bcac40d50f0a8b2a3c15ef066e Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 2 May 2021 09:53:37 +0900 Subject: [PATCH] mwm: Add datatype to manage global context 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 | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mwm.h | 16 +++++++++ 2 files changed, 119 insertions(+) create mode 100644 mwm.c create mode 100644 mwm.h diff --git a/mwm.c b/mwm.c new file mode 100644 index 0000000..df16faf --- /dev/null +++ b/mwm.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#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 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 */ -- 2.47.3