Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
xmacro: declare in header files, instantiate instead of include
Browse files Browse the repository at this point in the history
This works better with meson, where .h files can be declared as being part of an
executable easily, but I couldn’t find a way to declare
e.g. include/atoms.xmacro as a dependency.

related to #4086
  • Loading branch information
stapelberg committed May 17, 2020
1 parent 08052dd commit 1b8ddd5
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 74 deletions.
9 changes: 4 additions & 5 deletions Makefile.am
Expand Up @@ -378,7 +378,7 @@ i3_nagbar_i3_nagbar_LDADD = \
$(XCB_UTIL_CURSOR_LIBS)

i3_nagbar_i3_nagbar_SOURCES = \
i3-nagbar/atoms.xmacro \
i3-nagbar/i3-nagbar-atoms.xmacro.h \
i3-nagbar/main.c

i3bar_i3bar_CPPFLAGS = \
Expand Down Expand Up @@ -437,7 +437,7 @@ i3_config_wizard_i3_config_wizard_LDADD = \
$(XKBCOMMON_LIBS)

i3_config_wizard_i3_config_wizard_SOURCES = \
i3-config-wizard/atoms.xmacro \
i3-config-wizard/i3-config-wizard-atoms.xmacro.h \
i3-config-wizard/main.c \
i3-config-wizard/xcb.h

Expand Down Expand Up @@ -500,9 +500,8 @@ BUILT_SOURCES = $(command_parser_SOURCES) $(config_parser_SOURCES)
i3_SOURCES = \
include/all.h \
include/assignments.h \
include/atoms_NET_SUPPORTED.xmacro \
include/atoms_rest.xmacro \
include/atoms.xmacro \
include/i3-atoms_NET_SUPPORTED.xmacro.h \
include/i3-atoms_rest.xmacro.h \
include/bindings.h \
include/click.h \
include/cmdparse.h \
Expand Down
2 changes: 1 addition & 1 deletion docs/hacking-howto
Expand Up @@ -254,7 +254,7 @@ src/window.c::
Handlers to update X11 window properties like +WM_CLASS+, +_NET_WM_NAME+,
+CLIENT_LEADER+, etc.

include/atoms.xmacro::
include/*.xmacro.*::
A file containing all X11 atoms which i3 uses. This file will be included
various times (for defining, requesting and receiving the atoms), each time
with a different definition of xmacro().
Expand Down
8 changes: 8 additions & 0 deletions i3-config-wizard/i3-config-wizard-atoms.xmacro.h
@@ -0,0 +1,8 @@
// clang-format off
#define CONFIG_WIZARD_ATOMS_XMACRO \
xmacro(_NET_WM_NAME) \
xmacro(_NET_WM_WINDOW_TYPE) \
xmacro(_NET_WM_WINDOW_TYPE_DIALOG) \
xmacro(ATOM) \
xmacro(CARDINAL) \
xmacro(UTF8_STRING)
6 changes: 4 additions & 2 deletions i3-config-wizard/main.c
Expand Up @@ -51,6 +51,8 @@
#include <X11/Xlib.h>
#include <X11/keysym.h>

#include "i3-config-wizard-atoms.xmacro.h"

/* We need SYSCONFDIR for the path to the keycode config template, so raise an
* error if it’s not defined for whatever reason */
#ifndef SYSCONFDIR
Expand Down Expand Up @@ -843,7 +845,7 @@ int main(int argc, char *argv[]) {
/* Place requests for the atoms we need as soon as possible */
#define xmacro(atom) \
xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
#include "atoms.xmacro"
CONFIG_WIZARD_ATOMS_XMACRO
#undef xmacro

/* Init startup notification. */
Expand Down Expand Up @@ -900,7 +902,7 @@ int main(int argc, char *argv[]) {
A_##name = reply->atom; \
free(reply); \
} while (0);
#include "atoms.xmacro"
CONFIG_WIZARD_ATOMS_XMACRO
#undef xmacro

/* Set dock mode */
Expand Down
4 changes: 3 additions & 1 deletion i3-config-wizard/xcb.h
Expand Up @@ -3,6 +3,8 @@
/* from X11/keysymdef.h */
#define XCB_NUM_LOCK 0xff7f

#include "i3-config-wizard-atoms.xmacro.h"

#define xmacro(atom) xcb_atom_t A_##atom;
#include "atoms.xmacro"
CONFIG_WIZARD_ATOMS_XMACRO
#undef xmacro
8 changes: 8 additions & 0 deletions i3-nagbar/i3-nagbar-atoms.xmacro.h
@@ -0,0 +1,8 @@
// clang-format off
#define NAGBAR_ATOMS_XMACRO \
xmacro(_NET_WM_WINDOW_TYPE) \
xmacro(_NET_WM_WINDOW_TYPE_DOCK) \
xmacro(_NET_WM_STRUT_PARTIAL) \
xmacro(I3_SOCKET_PATH) \
xmacro(ATOM) \
xmacro(CARDINAL)
8 changes: 5 additions & 3 deletions i3-nagbar/main.c
Expand Up @@ -35,6 +35,8 @@ xcb_visualtype_t *visual_type = NULL;
#define SN_API_NOT_YET_FROZEN 1
#include <libsn/sn-launchee.h>

#include "i3-nagbar-atoms.xmacro.h"

#define MSG_PADDING logical_px(8)
#define BTN_PADDING logical_px(3)
#define BTN_BORDER logical_px(3)
Expand All @@ -43,7 +45,7 @@ xcb_visualtype_t *visual_type = NULL;
#define BAR_BORDER logical_px(2)

#define xmacro(atom) xcb_atom_t A_##atom;
#include "atoms.xmacro"
NAGBAR_ATOMS_XMACRO
#undef xmacro

#define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
Expand Down Expand Up @@ -426,7 +428,7 @@ int main(int argc, char *argv[]) {
/* Place requests for the atoms we need as soon as possible */
#define xmacro(atom) \
xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
#include "atoms.xmacro"
NAGBAR_ATOMS_XMACRO
#undef xmacro

/* Init startup notification. */
Expand Down Expand Up @@ -508,7 +510,7 @@ int main(int argc, char *argv[]) {
A_##name = reply->atom; \
free(reply); \
} while (0);
#include "atoms.xmacro"
NAGBAR_ATOMS_XMACRO
#undef xmacro

/* Set dock mode */
Expand Down
2 changes: 0 additions & 2 deletions include/atoms.xmacro

This file was deleted.

35 changes: 0 additions & 35 deletions include/atoms_NET_SUPPORTED.xmacro

This file was deleted.

20 changes: 0 additions & 20 deletions include/atoms_rest.xmacro

This file was deleted.

37 changes: 37 additions & 0 deletions include/i3-atoms_NET_SUPPORTED.xmacro.h
@@ -0,0 +1,37 @@
// clang-format off
#define I3_NET_SUPPORTED_ATOMS_XMACRO \
xmacro(_NET_SUPPORTED) \
xmacro(_NET_SUPPORTING_WM_CHECK) \
xmacro(_NET_WM_NAME) \
xmacro(_NET_WM_VISIBLE_NAME) \
xmacro(_NET_WM_MOVERESIZE) \
xmacro(_NET_WM_STATE_STICKY) \
xmacro(_NET_WM_STATE_FULLSCREEN) \
xmacro(_NET_WM_STATE_DEMANDS_ATTENTION) \
xmacro(_NET_WM_STATE_MODAL) \
xmacro(_NET_WM_STATE_HIDDEN) \
xmacro(_NET_WM_STATE_FOCUSED) \
xmacro(_NET_WM_STATE) \
xmacro(_NET_WM_WINDOW_TYPE) \
xmacro(_NET_WM_WINDOW_TYPE_NORMAL) \
xmacro(_NET_WM_WINDOW_TYPE_DOCK) \
xmacro(_NET_WM_WINDOW_TYPE_DIALOG) \
xmacro(_NET_WM_WINDOW_TYPE_UTILITY) \
xmacro(_NET_WM_WINDOW_TYPE_TOOLBAR) \
xmacro(_NET_WM_WINDOW_TYPE_SPLASH) \
xmacro(_NET_WM_WINDOW_TYPE_MENU) \
xmacro(_NET_WM_WINDOW_TYPE_DROPDOWN_MENU) \
xmacro(_NET_WM_WINDOW_TYPE_POPUP_MENU) \
xmacro(_NET_WM_WINDOW_TYPE_TOOLTIP) \
xmacro(_NET_WM_WINDOW_TYPE_NOTIFICATION) \
xmacro(_NET_WM_DESKTOP) \
xmacro(_NET_WM_STRUT_PARTIAL) \
xmacro(_NET_CLIENT_LIST) \
xmacro(_NET_CLIENT_LIST_STACKING) \
xmacro(_NET_CURRENT_DESKTOP) \
xmacro(_NET_NUMBER_OF_DESKTOPS) \
xmacro(_NET_DESKTOP_NAMES) \
xmacro(_NET_DESKTOP_VIEWPORT) \
xmacro(_NET_ACTIVE_WINDOW) \
xmacro(_NET_CLOSE_WINDOW) \
xmacro(_NET_MOVERESIZE_WINDOW)
22 changes: 22 additions & 0 deletions include/i3-atoms_rest.xmacro.h
@@ -0,0 +1,22 @@
// clang-format off
#define I3_REST_ATOMS_XMACRO \
xmacro(_NET_WM_USER_TIME) \
xmacro(_NET_STARTUP_ID) \
xmacro(_NET_WORKAREA) \
xmacro(WM_PROTOCOLS) \
xmacro(WM_DELETE_WINDOW) \
xmacro(UTF8_STRING) \
xmacro(WM_STATE) \
xmacro(WM_CLIENT_LEADER) \
xmacro(WM_TAKE_FOCUS) \
xmacro(WM_WINDOW_ROLE) \
xmacro(I3_SOCKET_PATH) \
xmacro(I3_CONFIG_PATH) \
xmacro(I3_SYNC) \
xmacro(I3_SHMLOG_PATH) \
xmacro(I3_PID) \
xmacro(I3_FLOATING_WINDOW) \
xmacro(_NET_REQUEST_FRAME_EXTENTS) \
xmacro(_NET_FRAME_EXTENTS) \
xmacro(_MOTIF_WM_HINTS) \
xmacro(WM_CHANGE_STATE)
6 changes: 5 additions & 1 deletion include/xcb.h
Expand Up @@ -49,8 +49,12 @@
XCB_EVENT_MASK_FOCUS_CHANGE | \
XCB_EVENT_MASK_ENTER_WINDOW)

#include "i3-atoms_rest.xmacro.h"
#include "i3-atoms_NET_SUPPORTED.xmacro.h"

#define xmacro(atom) extern xcb_atom_t A_##atom;
#include "atoms.xmacro"
I3_NET_SUPPORTED_ATOMS_XMACRO
I3_REST_ATOMS_XMACRO
#undef xmacro

extern unsigned int xcb_numlock_mask;
Expand Down
4 changes: 3 additions & 1 deletion src/ewmh.c
Expand Up @@ -9,6 +9,8 @@
*/
#include "all.h"

#include "i3-atoms_NET_SUPPORTED.xmacro.h"

xcb_window_t ewmh_window;

#define FOREACH_NONINTERNAL \
Expand Down Expand Up @@ -305,7 +307,7 @@ void ewmh_update_focused(xcb_window_t window, bool is_focused) {
void ewmh_setup_hints(void) {
xcb_atom_t supported_atoms[] = {
#define xmacro(atom) A_##atom,
#include "atoms_NET_SUPPORTED.xmacro"
I3_NET_SUPPORTED_ATOMS_XMACRO
#undef xmacro
};

Expand Down
12 changes: 9 additions & 3 deletions src/main.c
Expand Up @@ -31,6 +31,9 @@

#include "sd-daemon.h"

#include "i3-atoms_NET_SUPPORTED.xmacro.h"
#include "i3-atoms_rest.xmacro.h"

/* The original value of RLIMIT_CORE when i3 was started. We need to restore
* this before starting any other process, since we set RLIMIT_CORE to
* RLIM_INFINITY for i3 debugging versions. */
Expand Down Expand Up @@ -98,7 +101,8 @@ bool force_xinerama = false;

/* Define all atoms as global variables */
#define xmacro(atom) xcb_atom_t A_##atom;
#include "atoms.xmacro"
I3_NET_SUPPORTED_ATOMS_XMACRO
I3_REST_ATOMS_XMACRO
#undef xmacro

/*
Expand Down Expand Up @@ -559,7 +563,8 @@ int main(int argc, char *argv[]) {
/* Place requests for the atoms we need as soon as possible */
#define xmacro(atom) \
xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom);
#include "atoms.xmacro"
I3_NET_SUPPORTED_ATOMS_XMACRO
I3_REST_ATOMS_XMACRO
#undef xmacro

root_depth = root_screen->root_depth;
Expand Down Expand Up @@ -605,7 +610,8 @@ int main(int argc, char *argv[]) {
A_##name = reply->atom; \
free(reply); \
} while (0);
#include "atoms.xmacro"
I3_NET_SUPPORTED_ATOMS_XMACRO
I3_REST_ATOMS_XMACRO
#undef xmacro

load_configuration(override_configpath, C_LOAD);
Expand Down

0 comments on commit 1b8ddd5

Please sign in to comment.