]> git.corax.cc Git - mwm/commitdiff
client: Add data type for keeping track of clients
authorMatthias Kruk <m@m10k.eu>
Mon, 3 May 2021 21:26:48 +0000 (06:26 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 3 May 2021 21:26:48 +0000 (06:26 +0900)
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 [new file with mode: 0644]
client.h [new file with mode: 0644]

diff --git a/client.c b/client.c
new file mode 100644 (file)
index 0000000..0ac205b
--- /dev/null
+++ b/client.c
@@ -0,0 +1,77 @@
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <X11/Xlib.h>
+#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 (file)
index 0000000..f1a338b
--- /dev/null
+++ b/client.h
@@ -0,0 +1,19 @@
+#ifndef MWM_CLIENT_H
+#define MWM_CLIENT_H 1
+
+#include <X11/Xlib.h>
+
+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 */