Skip to content

Commit

Permalink
cache: hide details of struct atom_entry
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Feb 16, 2024
1 parent 9175489 commit 2b52edd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/atom.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include "log.h"
#include "utils.h"

struct atom_entry {
struct cache_handle entry;
xcb_atom_t atom;
};

static inline int atom_getter(struct cache *cache attr_unused, const char *atom_name,
struct cache_handle **value, void *user_data) {
xcb_connection_t *c = user_data;
Expand Down Expand Up @@ -45,6 +50,10 @@ xcb_atom_t get_atom(struct atom *a, const char *key, xcb_connection_t *c) {
return cache_entry(entry, struct atom_entry, entry)->atom;
}

xcb_atom_t get_atom_cached(struct atom *a, const char *key) {
return cache_entry(cache_get(&a->c, key), struct atom_entry, entry)->atom;
}

/**
* Create a new atom structure and fetch all predefined atoms
*/
Expand Down
13 changes: 2 additions & 11 deletions src/atom.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#pragma once
#include <stdlib.h>

#include <xcb/xcb.h>

#include "cache.h"
#include "log.h"
#include "meta.h"

// clang-format off
Expand Down Expand Up @@ -54,24 +51,18 @@

#define ATOM_DEF(x) xcb_atom_t a##x

struct atom_entry;
struct atom {
struct cache c;
LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST1);
LIST_APPLY(ATOM_DEF, SEP_COLON, ATOM_LIST2);
};

struct atom_entry {
struct cache_handle entry;
xcb_atom_t atom;
};

/// Create a new atom object with a xcb connection. `struct atom` does not hold
/// a reference to the connection.
struct atom *init_atoms(xcb_connection_t *c);

xcb_atom_t get_atom(struct atom *a, const char *key, xcb_connection_t *c);
static inline xcb_atom_t get_atom_cached(struct atom *a, const char *key) {
return cache_entry(cache_get(&a->c, key), struct atom_entry, entry)->atom;
}
xcb_atom_t get_atom_cached(struct atom *a, const char *key);

void destroy_atoms(struct atom *a);

0 comments on commit 2b52edd

Please sign in to comment.