From: Matthias Kruk Date: Sun, 2 May 2021 00:51:26 +0000 (+0900) Subject: monitor: Add data type for monitor management X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=a68a98df480df5c43127fbc632cc22f225dd71cd;p=mwm monitor: Add data type for monitor management To keep track of connected monitors, a data type is necessary. This commit adds the monitor datatype that is used to keep track of the size and position of a monitor. --- diff --git a/monitor.c b/monitor.c new file mode 100644 index 0000000..9a618fc --- /dev/null +++ b/monitor.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include "monitor.h" + +struct monitor { + int id; + int x; + int y; + int w; + int h; +}; + +int monitor_new(int id, int x, int y, int w, int h, + struct monitor **monitor) +{ + struct monitor *mon; + + if(!monitor) { + return(-EINVAL); + } + + mon = malloc(sizeof(*mon)); + + if(!mon) { + return(-ENOMEM); + } + + mon->id = id; + mon->x = x; + mon->y = y; + mon->w = w; + mon->h = h; + + *monitor = mon; + + return(0); +} + +int monitor_free(struct monitor **monitor) +{ + if(!monitor) { + return(-EINVAL); + } + + if(!*monitor) { + return(-EALREADY); + } + + free(*monitor); + *monitor = NULL; + + return(0); +} + +int monitor_get_id(struct monitor *monitor) +{ + if(!monitor) { + return(-EINVAL); + } + + return(monitor->id); +} + +int monitor_get_geometry(struct monitor *monitor, + int *x, int *y, int *w, int *h) +{ + if(!monitor) { + return(-EINVAL); + } + + if(x) { + *x = monitor->x; + } + if(y) { + *y = monitor->y; + } + if(w) { + *w = monitor->w; + } + if(h) { + *h = monitor->h; + } + + return(0); +} + +int monitor_set_geometry(struct monitor *monitor, + int x, int y, int w, int h) +{ + if(!monitor) { + return(-EINVAL); + } + + monitor->x = x; + monitor->y = y; + monitor->w = w; + monitor->h = h; + + return(0); +} diff --git a/monitor.h b/monitor.h new file mode 100644 index 0000000..04f32bd --- /dev/null +++ b/monitor.h @@ -0,0 +1,16 @@ +#ifndef MONITOR_H +#define MONITOR_H 1 + +struct monitor; + +int monitor_new(int id, int x, int y, int w, int h, + struct monitor **monitor); +int monitor_free(struct monitor **monitor); + +int monitor_get_id(struct monitor *monitor); +int monitor_get_geometry(struct monitor *monitor, + int *x, int *y, int *w, int *h); +int monitor_set_geometry(struct monitor *monitor, + int x, int y, int w, int h); + +#endif /* MONITOR_H */