From 8847f1b1d916b8a2febd627fa1144c795c44e62d Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 4 May 2021 06:26:48 +0900 Subject: [PATCH] client: Add data type for keeping track of clients A data type is needed to keep track of clients and associate them with workspaces. This commit adds the client type that serves that purpose. --- client.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ client.h | 19 ++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 client.c create mode 100644 client.h diff --git a/client.c b/client.c new file mode 100644 index 0000000..0ac205b --- /dev/null +++ b/client.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include "common.h" +#include "client.h" +#include "workspace.h" + +struct client { + struct geom geom; + Window window; + client_flags_t flags; + struct workspace *workspace; +}; + +int client_new(Window window, XWindowAttributes *attrs, struct client **client) +{ + struct client *cl; + + if(!client) { + return(-EINVAL); + } + + cl = malloc(sizeof(*cl)); + + if(!cl) { + return(-ENOMEM); + } + + memset(cl, 0, sizeof(*cl)); + + cl->window = window; + *client = cl; + + return(0); +} + +int client_free(struct client **client) +{ + if(!client) { + return(-EINVAL); + } + + if(!*client) { + return(-EALREADY); + } + + free(*client); + *client = NULL; + + return(0); +} + +int client_set_geometry(struct client *client, struct geom *geom) +{ + if(!client || !geom) { + return(-EINVAL); + } + + if(memcmp(&client->geom, geom, sizeof(*geom)) == 0) { + return(-EALREADY); + } + + memcpy(&client->geom, geom, sizeof(*geom)); + + return(0); +} + +int client_get_geometry(struct client *client, struct geom *geom) +{ + if(!client || !geom) { + return(-EINVAL); + } + + memcpy(geom, &client->geom, sizeof(*geom)); + return(0); +} diff --git a/client.h b/client.h new file mode 100644 index 0000000..f1a338b --- /dev/null +++ b/client.h @@ -0,0 +1,19 @@ +#ifndef MWM_CLIENT_H +#define MWM_CLIENT_H 1 + +#include + +typedef enum { + CLIENT_FIXED = (1 << 0), + CLIENT_FLOATING = (1 << 1), + CLIENT_URGENT = (1 << 2), + CLIENT_NEVERFOCUS = (1 << 3), + CLIENT_FULLSCREEN = (1 << 4) +} client_flags_t; + +struct client; + +int client_new(Window window, XWindowAttributes *attrs, struct client**); +int client_free(struct client**); + +#endif /* MWM_CLIENT_H */ -- 2.47.3