diff --git a/.gitignore b/.gitignore index f6db60c3..df580e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ /build /tags /compile_commands.json -/config *.bak *.pyc *.swp diff --git a/CHANGELOG.md b/CHANGELOG.md index b719edf6..f902b2ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `BUILD_POLYBAR=ON` - Builds the `polybar` executable - `BUILD_POLYBAR_MSG=ON` - Builds the `polybar-msg` executable - `BUILD_TESTS=OFF` - Builds the test suite + - `BUILD_CONFIG=ON` - Generate sample config - `BUILD_DOC=ON` - Builds the documentation - `BUILD_DOC_HTML=BUILD_DOC` - Builds the html documentation (depends on `BUILD_DOC`) - `BUILD_DOC_MAN=BUILD_DOC` - Builds the manpages (depends on `BUILD_DOC`) @@ -81,4 +82,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Empty color values are no longer treated as invalid and no longer produce an error. [Unreleased]: https://github.com/polybar/polybar/compare/3.5.3...HEAD -[3.5.3]: https://github.com/polybar/polybar/releases/tag/3.5.3 \ No newline at end of file +[3.5.3]: https://github.com/polybar/polybar/releases/tag/3.5.3 diff --git a/CMakeLists.txt b/CMakeLists.txt index 700e361f..816d9f66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,96 +59,8 @@ if(BUILD_TESTS) add_subdirectory(tests) endif() +if (BUILD_CONFIG) + add_subdirectory(config) +endif() + include(05-summary) - -# -# Generate configuration file -# - -set(MODULES_LEFT "bspwm i3") -set(MODULES_CENTER "mpd") -set(MODULES_RIGHT "filesystem backlight-acpi alsa pulseaudio xkeyboard memory cpu wlan eth battery temperature date powermenu") - -set(FONT_FIXED "fixed:pixelsize=10") -set(FONT_UNIFONT "unifont:fontformat=truetype") -set(FONT_SIJI "siji:pixelsize=10") - -queryfont(FONT_FIXED ${FONT_FIXED} FIELDS family pixelsize) -queryfont(FONT_UNIFONT ${FONT_UNIFONT} FIELDS family fontformat) -queryfont(FONT_SIJI ${FONT_SIJI} FIELDS family pixelsize) - -# Strip disabled modules {{{ - -if(NOT ENABLE_PULSEAUDIO) - string(REPLACE " pulseaudio" "" MODULES_RIGHT ${MODULES_RIGHT}) -endif() -if(NOT ENABLE_ALSA) - string(REPLACE " alsa" "" MODULES_RIGHT ${MODULES_RIGHT}) -endif() -if(NOT ENABLE_I3) - string(REPLACE " i3" "" MODULES_LEFT ${MODULES_LEFT}) -endif() -if(NOT ENABLE_MPD) - string(REPLACE "mpd" "" MODULES_CENTER ${MODULES_CENTER}) -endif() -if(NOT ENABLE_NETWORK) - string(REPLACE " wlan eth" "" MODULES_RIGHT ${MODULES_RIGHT}) -endif() -if(NOT WITH_XKB) - string(REPLACE "xkeyboard " "" MODULES_RIGHT ${MODULES_RIGHT}) -endif() - -# }}} -# Get battery/adapter name {{{ - -string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY}) -string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER}) -file(GLOB BAT_LIST RELATIVE ${PATH_BAT} ${PATH_ADP}/B*) -file(GLOB ADP_LIST RELATIVE ${PATH_ADP} ${PATH_ADP}/A*) -if(BAT_LIST) - list(GET BAT_LIST 0 BATTERY) -else() - set(BATTERY BAT0) -endif() -if(ADP_LIST) - list(GET ADP_LIST 0 ADAPTER) -else() - set(ADAPTER ADP1) -endif() - -# }}} -# Get network interfaces {{{ - -if(ENABLE_NETWORK) - file(GLOB IFLIST RELATIVE /sys/class/net /sys/class/net/*) - foreach(INTERFACE ${IFLIST}) - if(NOT ${INTERFACE} STREQUAL "lo") - file(GLOB IS_WIRELESS /sys/class/net/${INTERFACE}/wireless) - if(IS_WIRELESS) - set(INTERFACE_WLAN ${INTERFACE}) - else() - set(INTERFACE_ETH ${INTERFACE}) - endif() - endif() - endforeach() - if(NOT INTERFACE_ETH) - set(INTERFACE_ETH net0) - endif() - if(NOT INTERFACE_WLAN) - set(INTERFACE_WLAN net1) - endif() -endif() - -# }}} -# Configure and install {{{ - -configure_file( - ${CMAKE_CURRENT_LIST_DIR}/config.cmake - ${CMAKE_CURRENT_LIST_DIR}/config - ESCAPE_QUOTES @ONLY) - -install(FILES config - DESTINATION ${CMAKE_INSTALL_DOCDIR} - COMPONENT config) - -# }}} diff --git a/cmake/01-core.cmake b/cmake/01-core.cmake index 4c94f1fd..e52acd9e 100644 --- a/cmake/01-core.cmake +++ b/cmake/01-core.cmake @@ -15,6 +15,7 @@ option(BUILD_POLYBAR "Build the main polybar executable" ${DEFAULT_ON}) option(BUILD_POLYBAR_MSG "Build polybar-msg" ${DEFAULT_ON}) option(BUILD_TESTS "Build testsuite" OFF) option(BUILD_DOC "Build documentation" ${DEFAULT_ON}) +option(BUILD_CONFIG "Generate sample configuration" ${DEFAULT_ON}) include(CMakeDependentOption) CMAKE_DEPENDENT_OPTION(BUILD_DOC_HTML "Build HTML documentation" ON "BUILD_DOC" OFF) diff --git a/cmake/04-targets.cmake b/cmake/04-targets.cmake index b1d6c3bb..7424341b 100644 --- a/cmake/04-targets.cmake +++ b/cmake/04-targets.cmake @@ -2,18 +2,6 @@ # Custom targets # -# Target: userconfig {{{ - -configure_file( - ${PROJECT_SOURCE_DIR}/cmake/templates/userconfig.cmake.in - ${PROJECT_BINARY_DIR}/cmake/userconfig.cmake - ESCAPE_QUOTES @ONLY) - -add_custom_target(userconfig - DEPENDS ${PROJECT_NAME} - COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/userconfig.cmake) - -# }}} # Target: uninstall {{{ configure_file( diff --git a/cmake/05-summary.cmake b/cmake/05-summary.cmake index 61d24c3e..2144b702 100644 --- a/cmake/05-summary.cmake +++ b/cmake/05-summary.cmake @@ -27,6 +27,7 @@ colored_option(" testsuite" BUILD_TESTS) colored_option(" documentation" BUILD_DOC) colored_option(" html" BUILD_DOC_HTML) colored_option(" man" BUILD_DOC_MAN) +colored_option(" sample config" BUILD_CONFIG) if (BUILD_LIBPOLY) message(STATUS " Module support:") diff --git a/cmake/templates/userconfig.cmake.in b/cmake/templates/userconfig.cmake.in index 9d05c60e..1e39fe61 100644 --- a/cmake/templates/userconfig.cmake.in +++ b/cmake/templates/userconfig.cmake.in @@ -4,5 +4,5 @@ if(NOT USER_CONFIG_HOME) endif() set(USER_CONFIG_HOME "${USER_CONFIG_HOME}/polybar") -file(INSTALL "@CMAKE_SOURCE_DIR@/config" +file(INSTALL "@CMAKE_BINARY_DIR@/generated-sources/config" DESTINATION "${USER_CONFIG_HOME}") diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 00000000..b75bbebb --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,103 @@ +# +# Generate configuration file +# + +set(MODULES_LEFT "bspwm i3") +set(MODULES_CENTER "mpd") +set(MODULES_RIGHT "filesystem backlight-acpi alsa pulseaudio xkeyboard memory cpu wlan eth battery temperature date powermenu") + +set(FONT_FIXED "fixed:pixelsize=10") +set(FONT_UNIFONT "unifont:fontformat=truetype") +set(FONT_SIJI "siji:pixelsize=10") + +queryfont(FONT_FIXED ${FONT_FIXED} FIELDS family pixelsize) +queryfont(FONT_UNIFONT ${FONT_UNIFONT} FIELDS family fontformat) +queryfont(FONT_SIJI ${FONT_SIJI} FIELDS family pixelsize) + +# Strip disabled modules {{{ + +if(NOT ENABLE_PULSEAUDIO) + string(REPLACE " pulseaudio" "" MODULES_RIGHT ${MODULES_RIGHT}) +endif() +if(NOT ENABLE_ALSA) + string(REPLACE " alsa" "" MODULES_RIGHT ${MODULES_RIGHT}) +endif() +if(NOT ENABLE_I3) + string(REPLACE " i3" "" MODULES_LEFT ${MODULES_LEFT}) +endif() +if(NOT ENABLE_MPD) + string(REPLACE "mpd" "" MODULES_CENTER ${MODULES_CENTER}) +endif() +if(NOT ENABLE_NETWORK) + string(REPLACE " wlan eth" "" MODULES_RIGHT ${MODULES_RIGHT}) +endif() +if(NOT WITH_XKB) + string(REPLACE "xkeyboard " "" MODULES_RIGHT ${MODULES_RIGHT}) +endif() + +# }}} +# Get battery/adapter name {{{ + +string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY}) +string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER}) +file(GLOB BAT_LIST RELATIVE ${PATH_BAT} ${PATH_ADP}/B*) +file(GLOB ADP_LIST RELATIVE ${PATH_ADP} ${PATH_ADP}/A*) +if(BAT_LIST) + list(GET BAT_LIST 0 BATTERY) +else() + set(BATTERY BAT0) +endif() +if(ADP_LIST) + list(GET ADP_LIST 0 ADAPTER) +else() + set(ADAPTER ADP1) +endif() + +# }}} +# Get network interfaces {{{ + +if(ENABLE_NETWORK) + file(GLOB IFLIST RELATIVE /sys/class/net /sys/class/net/*) + foreach(INTERFACE ${IFLIST}) + if(NOT ${INTERFACE} STREQUAL "lo") + file(GLOB IS_WIRELESS /sys/class/net/${INTERFACE}/wireless) + if(IS_WIRELESS) + set(INTERFACE_WLAN ${INTERFACE}) + else() + set(INTERFACE_ETH ${INTERFACE}) + endif() + endif() + endforeach() + if(NOT INTERFACE_ETH) + set(INTERFACE_ETH net0) + endif() + if(NOT INTERFACE_WLAN) + set(INTERFACE_WLAN net1) + endif() +endif() + +# }}} +# Configure and install {{{ + +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/config.cmake + ${CMAKE_BINARY_DIR}/generated-sources/config + ESCAPE_QUOTES @ONLY) + +install(FILES ${CMAKE_BINARY_DIR}/generated-sources/config + DESTINATION ${CMAKE_INSTALL_DOCDIR} + COMPONENT config) + +# }}} + +# Target: userconfig {{{ + +configure_file( + ${PROJECT_SOURCE_DIR}/cmake/templates/userconfig.cmake.in + ${PROJECT_BINARY_DIR}/cmake/userconfig.cmake + ESCAPE_QUOTES @ONLY) + +add_custom_target(userconfig + COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/userconfig.cmake) + +# }}} diff --git a/config.cmake b/config/config.cmake similarity index 100% rename from config.cmake rename to config/config.cmake