From f5ff543f4aa8c75ac9b7345d6a4d213449104b14 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 4 May 2021 06:27:50 +0900 Subject: [PATCH] workspace: Add type for keeping track of workspaces 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 | 2 +- workspace.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ workspace.h | 15 ++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 workspace.c create mode 100644 workspace.h diff --git a/Makefile b/Makefile index 0011f6e..66db7e8 100644 --- 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 index 0000000..3174c42 --- /dev/null +++ b/workspace.c @@ -0,0 +1,69 @@ +#include +#include +#include +#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 index 0000000..dabf011 --- /dev/null +++ b/workspace.h @@ -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 */ -- 2.47.3