mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-24 21:05:40 +02:00
cmake: initial support for building wayland-only, or x11-only
This commit is contained in:
parent
f3b225adf7
commit
727d7b343f
7 changed files with 162 additions and 90 deletions
|
@ -23,24 +23,42 @@ set(CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}")
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(xcb REQUIRED IMPORTED_TARGET
|
|
||||||
xcb xcb-aux xcb-cursor xcb-event xcb-ewmh xcb-randr xcb-render)
|
|
||||||
pkg_check_modules(xcb-errors IMPORTED_TARGET xcb-errors)
|
|
||||||
pkg_check_modules(wayland REQUIRED IMPORTED_TARGET
|
|
||||||
wayland-client wayland-cursor wlroots)
|
|
||||||
pkg_check_modules(fontconfig REQUIRED IMPORTED_TARGET fontconfig)
|
pkg_check_modules(fontconfig REQUIRED IMPORTED_TARGET fontconfig)
|
||||||
pkg_check_modules(cairo REQUIRED IMPORTED_TARGET cairo cairo-xcb cairo-ft)
|
pkg_check_modules(cairo REQUIRED IMPORTED_TARGET cairo cairo-ft)
|
||||||
pkg_check_modules(yaml REQUIRED IMPORTED_TARGET yaml-0.1)
|
pkg_check_modules(yaml REQUIRED IMPORTED_TARGET yaml-0.1)
|
||||||
|
|
||||||
|
set(ENABLE_X11 1 CACHE BOOL "Enables support for the XCB (X11) backend")
|
||||||
|
set_property(DIRECTORY . APPEND PROPERTY
|
||||||
|
COMPILE_DEFINITIONS $<$<BOOL:${ENABLE_X11}>:ENABLE_X11>)
|
||||||
|
|
||||||
|
if (ENABLE_X11)
|
||||||
|
pkg_check_modules(xcb REQUIRED IMPORTED_TARGET
|
||||||
|
xcb xcb-aux xcb-cursor xcb-event xcb-ewmh xcb-randr xcb-render cairo-xcb)
|
||||||
|
pkg_check_modules(xcb-errors IMPORTED_TARGET xcb-errors)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(ENABLE_WAYLAND 1 CACHE BOOL "Enables support for the wayland backend")
|
||||||
|
set_property(DIRECTORY . APPEND PROPERTY
|
||||||
|
COMPILE_DEFINITIONS $<$<BOOL:${ENABLE_WAYLAND}>:ENABLE_WAYLAND>)
|
||||||
|
|
||||||
|
if (ENABLE_WAYLAND)
|
||||||
|
pkg_check_modules(wayland REQUIRED IMPORTED_TARGET
|
||||||
|
wayland-client wayland-cursor wlroots)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (ENABLE_X11)
|
||||||
add_library(xcb-stuff STATIC EXCLUDE_FROM_ALL xcb.c xcb.h)
|
add_library(xcb-stuff STATIC EXCLUDE_FROM_ALL xcb.c xcb.h)
|
||||||
if (XCB_ERRORS_FOUND)
|
if (XCB_ERRORS_FOUND)
|
||||||
target_compile_definitions(xcb-stuff PRIVATE HAVE_XCB_ERRORS)
|
target_compile_definitions(xcb-stuff PRIVATE HAVE_XCB_ERRORS)
|
||||||
endif ()
|
endif ()
|
||||||
|
target_link_libraries(xcb-stuff PkgConfig::xcb PkgConfig::xcb-errors)
|
||||||
|
|
||||||
add_library(bar-xcb STATIC EXCLUDE_FROM_ALL bar/xcb.c bar/xcb.h)
|
add_library(bar-xcb STATIC EXCLUDE_FROM_ALL bar/xcb.c bar/xcb.h)
|
||||||
target_link_libraries(bar-xcb
|
target_link_libraries(bar-xcb
|
||||||
xcb-stuff PkgConfig::xcb PkgConfig::xcb-errors PkgConfig::cairo)
|
xcb-stuff PkgConfig::cairo)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (ENABLE_WAYLAND)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT wlr-layer-shell-unstable-v1.c
|
OUTPUT wlr-layer-shell-unstable-v1.c
|
||||||
COMMAND wayland-scanner private-code < ${PROJECT_SOURCE_DIR}/external/wlroots/protocol/wlr-layer-shell-unstable-v1.xml > wlr-layer-shell-unstable-v1.c
|
COMMAND wayland-scanner private-code < ${PROJECT_SOURCE_DIR}/external/wlroots/protocol/wlr-layer-shell-unstable-v1.xml > wlr-layer-shell-unstable-v1.c
|
||||||
|
@ -85,6 +103,7 @@ add_library(bar-wayland STATIC EXCLUDE_FROM_ALL bar/wayland.c bar/wayland.h)
|
||||||
target_compile_definitions(bar-wayland PRIVATE _GNU_SOURCE)
|
target_compile_definitions(bar-wayland PRIVATE _GNU_SOURCE)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
bar-wayland wayland-protocols PkgConfig::wayland PkgConfig::cairo)
|
bar-wayland wayland-protocols PkgConfig::wayland PkgConfig::cairo)
|
||||||
|
endif ()
|
||||||
|
|
||||||
add_executable(f00bar
|
add_executable(f00bar
|
||||||
config.c config.h
|
config.c config.h
|
||||||
|
@ -104,7 +123,8 @@ add_executable(f00bar
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(f00bar
|
target_link_libraries(f00bar
|
||||||
bar-xcb bar-wayland
|
$<$<BOOL:${ENABLE_X11}>:bar-xcb>
|
||||||
|
$<$<BOOL:${ENABLE_WAYLAND}>:bar-wayland>
|
||||||
PkgConfig::cairo PkgConfig::fontconfig PkgConfig::yaml
|
PkgConfig::cairo PkgConfig::fontconfig PkgConfig::yaml
|
||||||
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
|
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
|
||||||
|
|
||||||
|
@ -117,13 +137,23 @@ set_property(TARGET f00bar PROPERTY
|
||||||
|
|
||||||
install(TARGETS f00bar DESTINATION bin)
|
install(TARGETS f00bar DESTINATION bin)
|
||||||
|
|
||||||
|
set(enabled_modules "")
|
||||||
|
set(enabled_particles "")
|
||||||
|
set(enabled_decorations "")
|
||||||
|
|
||||||
add_subdirectory(modules)
|
add_subdirectory(modules)
|
||||||
add_subdirectory(particles)
|
add_subdirectory(particles)
|
||||||
add_subdirectory(decorations)
|
add_subdirectory(decorations)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
if (NOT CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
||||||
target_link_libraries(f00bar background stack underline)
|
target_link_libraries(f00bar ${enabled_decorations})
|
||||||
target_link_libraries(f00bar dynlist empty list map progress-bar ramp string)
|
target_link_libraries(f00bar ${enabled_particles})
|
||||||
target_link_libraries(f00bar alsa backlight battery clock i3 label mpd network
|
target_link_libraries(f00bar ${enabled_modules})
|
||||||
removables xkb xwindow)
|
|
||||||
|
foreach (plug ${enabled_decorations} ${enabled_particles} ${enabled_modules})
|
||||||
|
string(REPLACE "-" "_" fixed "${plug}")
|
||||||
|
target_compile_definitions(f00bar PRIVATE "HAVE_PLUGIN_${fixed}")
|
||||||
|
endforeach ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
17
bar/bar.c
17
bar/bar.c
|
@ -14,8 +14,13 @@
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
|
|
||||||
|
#if defined(ENABLE_X11)
|
||||||
#include "xcb.h"
|
#include "xcb.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ENABLE_WAYLAND)
|
||||||
#include "wayland.h"
|
#include "wayland.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate total width of left/center/rigth groups.
|
* Calculate total width of left/center/rigth groups.
|
||||||
|
@ -382,12 +387,22 @@ bar_new(const struct bar_config *config)
|
||||||
priv->right.count = config->right.count;
|
priv->right.count = config->right.count;
|
||||||
priv->cursor_name = NULL;
|
priv->cursor_name = NULL;
|
||||||
|
|
||||||
#if 0
|
#if defined(ENABLE_X11) && !defined(ENABLE_WAYLAND)
|
||||||
priv->backend.data = bar_backend_xcb_new();
|
priv->backend.data = bar_backend_xcb_new();
|
||||||
priv->backend.iface = &xcb_backend_iface;
|
priv->backend.iface = &xcb_backend_iface;
|
||||||
#else
|
#else
|
||||||
|
#if !defined(ENABLE_X11) && defined(ENABLE_WAYLAND)
|
||||||
priv->backend.data = bar_backend_wayland_new();
|
priv->backend.data = bar_backend_wayland_new();
|
||||||
priv->backend.iface = &wayland_backend_iface;
|
priv->backend.iface = &wayland_backend_iface;
|
||||||
|
#else
|
||||||
|
if (getenv("WAYLAND_DISPLAY") != NULL) {
|
||||||
|
priv->backend.data = bar_backend_wayland_new();
|
||||||
|
priv->backend.iface = &wayland_backend_iface;
|
||||||
|
} else {
|
||||||
|
priv->backend.data = bar_backend_xcb_new();
|
||||||
|
priv->backend.iface = &xcb_backend_iface;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < priv->left.count; i++) {
|
for (size_t i = 0; i < priv->left.count; i++) {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.7)
|
||||||
|
|
||||||
add_library(decoration-sdk INTERFACE)
|
add_library(decoration-sdk INTERFACE)
|
||||||
target_compile_options(decoration-sdk INTERFACE ${CAIRO_CFLAGS_OTHER})
|
target_link_libraries(decoration-sdk INTERFACE PkgConfig::cairo)
|
||||||
target_include_directories(decoration-sdk INTERFACE ${CAIRO_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
set(CMAKE_SHARED_MODULE_PREFIX decoration_)
|
set(CMAKE_SHARED_MODULE_PREFIX decoration_)
|
||||||
|
|
||||||
|
@ -22,3 +21,5 @@ endforeach ()
|
||||||
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
||||||
install(TARGETS ${decorations} DESTINATION lib/f00bar)
|
install(TARGETS ${decorations} DESTINATION lib/f00bar)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
set(enabled_decorations ${decorations} PARENT_SCOPE)
|
||||||
|
|
|
@ -12,19 +12,25 @@ endif ()
|
||||||
|
|
||||||
set(CMAKE_SHARED_${lib_type}_PREFIX module_)
|
set(CMAKE_SHARED_${lib_type}_PREFIX module_)
|
||||||
|
|
||||||
|
set(enabled "")
|
||||||
|
|
||||||
pkg_check_modules(alsa REQUIRED IMPORTED_TARGET alsa)
|
pkg_check_modules(alsa REQUIRED IMPORTED_TARGET alsa)
|
||||||
add_library(alsa ${lib_type} alsa.c)
|
add_library(alsa ${lib_type} alsa.c)
|
||||||
target_link_libraries(alsa module-sdk PkgConfig::alsa)
|
target_link_libraries(alsa module-sdk PkgConfig::alsa)
|
||||||
|
list(APPEND enabled alsa)
|
||||||
|
|
||||||
pkg_check_modules(udev REQUIRED IMPORTED_TARGET libudev)
|
pkg_check_modules(udev REQUIRED IMPORTED_TARGET libudev)
|
||||||
add_library(backlight ${lib_type} backlight.c)
|
add_library(backlight ${lib_type} backlight.c)
|
||||||
target_link_libraries(backlight module-sdk PkgConfig::udev)
|
target_link_libraries(backlight module-sdk PkgConfig::udev)
|
||||||
|
list(APPEND enabled backlight)
|
||||||
|
|
||||||
add_library(battery ${lib_type} battery.c)
|
add_library(battery ${lib_type} battery.c)
|
||||||
target_link_libraries(battery module-sdk PkgConfig::udev)
|
target_link_libraries(battery module-sdk PkgConfig::udev)
|
||||||
|
list(APPEND enabled battery)
|
||||||
|
|
||||||
add_library(clock ${lib_type} clock.c)
|
add_library(clock ${lib_type} clock.c)
|
||||||
target_link_libraries(clock module-sdk)
|
target_link_libraries(clock module-sdk)
|
||||||
|
list(APPEND enabled clock)
|
||||||
|
|
||||||
pkg_check_modules(json REQUIRED IMPORTED_TARGET json-c)
|
pkg_check_modules(json REQUIRED IMPORTED_TARGET json-c)
|
||||||
find_file(I3_IPC_H i3/ipc.h)
|
find_file(I3_IPC_H i3/ipc.h)
|
||||||
|
@ -33,41 +39,43 @@ if (NOT I3_IPC_H)
|
||||||
endif ()
|
endif ()
|
||||||
add_library(i3 ${lib_type} i3.c)
|
add_library(i3 ${lib_type} i3.c)
|
||||||
target_link_libraries(i3 module-sdk dynlist PkgConfig::json)
|
target_link_libraries(i3 module-sdk dynlist PkgConfig::json)
|
||||||
|
if (ENABLE_X11)
|
||||||
|
target_link_libraries(i3 xcb-stuff)
|
||||||
|
endif ()
|
||||||
|
list(APPEND enabled i3)
|
||||||
|
|
||||||
add_library(label ${lib_type} label.c)
|
add_library(label ${lib_type} label.c)
|
||||||
target_link_libraries(label module-sdk)
|
target_link_libraries(label module-sdk)
|
||||||
|
list(APPEND enabled label)
|
||||||
|
|
||||||
pkg_check_modules(mpd REQUIRED IMPORTED_TARGET libmpdclient)
|
pkg_check_modules(mpd REQUIRED IMPORTED_TARGET libmpdclient)
|
||||||
add_library(mpd ${lib_type} mpd.c)
|
add_library(mpd ${lib_type} mpd.c)
|
||||||
target_link_libraries(mpd module-sdk PkgConfig::mpd)
|
target_link_libraries(mpd module-sdk PkgConfig::mpd)
|
||||||
|
list(APPEND enabled mpd)
|
||||||
|
|
||||||
add_library(network ${lib_type} network.c)
|
add_library(network ${lib_type} network.c)
|
||||||
target_link_libraries(network module-sdk)
|
target_link_libraries(network module-sdk)
|
||||||
|
list(APPEND enabled network)
|
||||||
|
|
||||||
add_library(removables ${lib_type} removables.c)
|
add_library(removables ${lib_type} removables.c)
|
||||||
target_link_libraries(removables module-sdk dynlist PkgConfig::udev)
|
target_link_libraries(removables module-sdk dynlist PkgConfig::udev)
|
||||||
|
list(APPEND enabled removables)
|
||||||
|
|
||||||
|
if (ENABLE_X11)
|
||||||
pkg_check_modules(xkb REQUIRED IMPORTED_TARGET xcb-xkb)
|
pkg_check_modules(xkb REQUIRED IMPORTED_TARGET xcb-xkb)
|
||||||
add_library(xkb ${lib_type} xkb.c)
|
add_library(xkb ${lib_type} xkb.c)
|
||||||
target_link_libraries(xkb module-sdk PkgConfig::xkb)
|
target_link_libraries(xkb module-sdk PkgConfig::xcb PkgConfig::xkb)
|
||||||
|
list(APPEND enabled xkb)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (ENABLE_X11)
|
||||||
add_library(xwindow ${lib_type} xwindow.c)
|
add_library(xwindow ${lib_type} xwindow.c)
|
||||||
target_link_libraries(xwindow module-sdk)
|
target_link_libraries(xwindow module-sdk xcb-stuff)
|
||||||
|
list(APPEND enabled xwindow)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
||||||
install(
|
install(TARGETS ${enabled} DESTINATION lib/f00bar)
|
||||||
TARGETS
|
|
||||||
alsa
|
|
||||||
backlight
|
|
||||||
battery
|
|
||||||
clock
|
|
||||||
i3
|
|
||||||
label
|
|
||||||
mpd
|
|
||||||
network
|
|
||||||
removables
|
|
||||||
xkb
|
|
||||||
xwindow
|
|
||||||
|
|
||||||
DESTINATION lib/f00bar)
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
set(enabled_modules ${enabled} PARENT_SCOPE)
|
||||||
|
|
15
modules/i3.c
15
modules/i3.c
|
@ -10,8 +10,11 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
#if defined(ENABLE_X11)
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xcb_aux.h>
|
#include <xcb/xcb_aux.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <i3/ipc.h>
|
#include <i3/ipc.h>
|
||||||
|
|
||||||
#include <json-c/json_tokener.h>
|
#include <json-c/json_tokener.h>
|
||||||
|
@ -26,7 +29,10 @@
|
||||||
#include "../config-verify.h"
|
#include "../config-verify.h"
|
||||||
#include "../particles/dynlist.h"
|
#include "../particles/dynlist.h"
|
||||||
#include "../plugin.h"
|
#include "../plugin.h"
|
||||||
|
|
||||||
|
#if defined(ENABLE_X11)
|
||||||
#include "../xcb.h"
|
#include "../xcb.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
struct ws_content {
|
struct ws_content {
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -371,6 +377,7 @@ handle_workspace_event(struct private *m, const struct json_object *json)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ENABLE_X11)
|
||||||
static bool
|
static bool
|
||||||
get_socket_address_x11(struct sockaddr_un *addr)
|
get_socket_address_x11(struct sockaddr_un *addr)
|
||||||
{
|
{
|
||||||
|
@ -419,6 +426,7 @@ get_socket_address_x11(struct sockaddr_un *addr)
|
||||||
xcb_disconnect(conn);
|
xcb_disconnect(conn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
get_socket_address(struct sockaddr_un *addr)
|
get_socket_address(struct sockaddr_un *addr)
|
||||||
|
@ -426,8 +434,13 @@ get_socket_address(struct sockaddr_un *addr)
|
||||||
*addr = (struct sockaddr_un){.sun_family = AF_UNIX};
|
*addr = (struct sockaddr_un){.sun_family = AF_UNIX};
|
||||||
|
|
||||||
const char *sway_sock = getenv("SWAYSOCK");
|
const char *sway_sock = getenv("SWAYSOCK");
|
||||||
if (sway_sock == NULL)
|
if (sway_sock == NULL) {
|
||||||
|
#if defined(ENABLE_X11)
|
||||||
return get_socket_address_x11(addr);
|
return get_socket_address_x11(addr);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
strncpy(addr->sun_path, sway_sock, sizeof(addr->sun_path));
|
strncpy(addr->sun_path, sway_sock, sizeof(addr->sun_path));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.7)
|
||||||
|
|
||||||
add_library(particle-sdk INTERFACE)
|
add_library(particle-sdk INTERFACE)
|
||||||
target_compile_options(particle-sdk INTERFACE ${CAIRO_CFLAGS_OTHER})
|
target_link_libraries(particle-sdk INTERFACE PkgConfig::cairo)
|
||||||
target_include_directories(particle-sdk INTERFACE ${CAIRO_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
||||||
set(lib_type MODULE)
|
set(lib_type MODULE)
|
||||||
|
@ -30,3 +29,5 @@ target_link_libraries(string ${CAIRO_LIBRARIES})
|
||||||
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
if (CORE_PLUGINS_AS_SHARED_LIBRARIES)
|
||||||
install(TARGETS ${particles} dynlist DESTINATION lib/f00bar)
|
install(TARGETS ${particles} dynlist DESTINATION lib/f00bar)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
set(enabled_particles "dynlist;${particles}" PARENT_SCOPE)
|
||||||
|
|
4
plugin.c
4
plugin.c
|
@ -112,8 +112,12 @@ init(void)
|
||||||
REGISTER_CORE_MODULE(mpd, mpd);
|
REGISTER_CORE_MODULE(mpd, mpd);
|
||||||
REGISTER_CORE_MODULE(network, network);
|
REGISTER_CORE_MODULE(network, network);
|
||||||
REGISTER_CORE_MODULE(removables, removables);
|
REGISTER_CORE_MODULE(removables, removables);
|
||||||
|
#if defined(HAVE_MODULE_xkb)
|
||||||
REGISTER_CORE_MODULE(xkb, xkb);
|
REGISTER_CORE_MODULE(xkb, xkb);
|
||||||
|
#endif
|
||||||
|
#if defined(HAVE_MODULE_xwindow)
|
||||||
REGISTER_CORE_MODULE(xwindow, xwindow);
|
REGISTER_CORE_MODULE(xwindow, xwindow);
|
||||||
|
#endif
|
||||||
|
|
||||||
REGISTER_CORE_PARTICLE(empty, empty);
|
REGISTER_CORE_PARTICLE(empty, empty);
|
||||||
REGISTER_CORE_PARTICLE(list, list);
|
REGISTER_CORE_PARTICLE(list, list);
|
||||||
|
|
Loading…
Add table
Reference in a new issue