]> git.corax.cc Git - mwm/commitdiff
workspace: Add type for keeping track of workspaces
authorMatthias Kruk <m@m10k.eu>
Mon, 3 May 2021 21:27:50 +0000 (06:27 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 3 May 2021 21:27:50 +0000 (06:27 +0900)
A data type is needed that clients can be attached to, and that monitors
can be associated with so that they display a set of clients.
This commit adds the workspace type that keeps track of a set of clients
and can be displayed by a monitor.

Makefile
workspace.c [new file with mode: 0644]
workspace.h [new file with mode: 0644]

index 0011f6e6576d2b216f5aed546709348e2ae89a0a..66db7e8eb8a9b5824221fc96a097394e6ec0bded 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 OUTPUT = mwm
-OBJECTS = main.o array.o x.o monitor.o mwm.o
+OBJECTS = main.o array.o x.o monitor.o mwm.o workspace.o loop.o client.o
 
 ifeq ($(PREFIX), )
        PREFIX = /usr/local
diff --git a/workspace.c b/workspace.c
new file mode 100644 (file)
index 0000000..3174c42
--- /dev/null
@@ -0,0 +1,69 @@
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "workspace.h"
+#include "client.h"
+#include "loop.h"
+
+struct workspace {
+       struct loop *clients;
+       struct client *focused;
+
+       int number;
+};
+
+int workspace_new(const int number, struct workspace **workspace)
+{
+       struct workspace *wspace;
+
+       if(!workspace) {
+               return(-EINVAL);
+       }
+
+       wspace = malloc(sizeof(*wspace));
+
+       if(!wspace) {
+               return(-ENOMEM);
+       }
+
+       wspace->number = number;
+
+       *workspace = wspace;
+
+       return(0);
+}
+
+int workspace_free(struct workspace **workspace)
+{
+       if(!workspace) {
+               return(-EINVAL);
+       }
+
+       if(!*workspace) {
+               return(-EALREADY);
+       }
+
+       free(*workspace);
+       *workspace = NULL;
+
+       return(0);
+}
+
+int workspace_add_client(struct workspace *workspace, struct client *client)
+{
+       if(!workspace || !client) {
+               return(-EINVAL);
+       }
+
+       return(loop_append(&workspace->clients, client));
+}
+
+
+int workspace_remove_client(struct workspace *workspace, struct client *client)
+{
+       if(!workspace || !client) {
+               return(-EINVAL);
+       }
+
+       return(loop_remove(&workspace->clients, client));
+}
diff --git a/workspace.h b/workspace.h
new file mode 100644 (file)
index 0000000..dabf011
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef MWM_WORKSPACE_H
+#define MWM_WORKSPACE_H 1
+
+struct client;
+struct workspace;
+
+int workspace_new(const int number, struct workspace **workspace);
+int workspace_free(struct workspace **workspace);
+
+int workspace_add_client(struct workspace *workspace,
+                        struct client *client);
+int workspace_remove_client(struct workspace *workspace,
+                           struct client *client);
+
+#endif /* MWM_WORKSPACE_H */