From a68a98df480df5c43127fbc632cc22f225dd71cd Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 2 May 2021 09:51:26 +0900 Subject: [PATCH] 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. --- monitor.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ monitor.h | 16 +++++++++ 2 files changed, 117 insertions(+) create mode 100644 monitor.c create mode 100644 monitor.h 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 */ -- 2.47.3