xmacro: declare in header files, instantiate instead of include

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
This commit is contained in:
Michael Stapelberg 2020-05-17 16:38:43 +02:00
parent 08052ddeb9
commit 1b8ddd5fd1
15 changed files with 109 additions and 74 deletions

View File

@ -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 = \
@ -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
@ -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 \

View File

@ -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().

View File

@ -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)

View File

@ -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 its not defined for whatever reason */
#ifndef SYSCONFDIR
@ -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. */
@ -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 */

View File

@ -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

View File

@ -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)

View File

@ -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)
@ -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__);
@ -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. */
@ -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 */

View File

@ -1,2 +0,0 @@
#include "atoms_NET_SUPPORTED.xmacro"
#include "atoms_rest.xmacro"

View File

@ -1,35 +0,0 @@
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)

View File

@ -1,20 +0,0 @@
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)

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -9,6 +9,8 @@
*/
#include "all.h"
#include "i3-atoms_NET_SUPPORTED.xmacro.h"
xcb_window_t ewmh_window;
#define FOREACH_NONINTERNAL \
@ -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
};

View File

@ -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. */
@ -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
/*
@ -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;
@ -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);