From 282b0f4e73e9cbb68afd6e168c472e3f422e9a6f Mon Sep 17 00:00:00 2001
From: Patrick Ziegler
Date: Tue, 5 Oct 2021 13:07:19 +0200
Subject: [PATCH] Create default config (#2511)
* Create default config and install to /etc/polybar
Closes #2405
* Search for config in /etc
We search in XDG_CONFIG_DIRS, /etc/xdg, and /etc but only for config.ini
Closes #2016
* Remove config installation from build.sh
* Remove userconfig cmake file
* Cleanup
* Cleanup default config
* Update CHANGELOG.md
Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>
* Update src/main.cpp
Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>
* Add tests for string functions
* Support loading bars from fallbacks in /etc
* Combine duplicate string_util::contains test
Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>
---
CHANGELOG.md | 20 +-
CMakeLists.txt | 7 +-
README.md | 19 +-
build.sh | 15 -
cmake/common/utils.cmake | 42 ---
cmake/templates/userconfig.cmake.in | 8 -
config/CMakeLists.txt | 106 -------
config/config.cmake | 428 ----------------------------
contrib/bash/polybar | 32 ++-
contrib/zsh/_polybar | 20 +-
doc/CMakeLists.txt | 4 +
doc/_static/default.png | Bin 0 -> 18104 bytes
doc/config.ini | 170 +++++++++++
doc/man/polybar.1.rst | 10 +-
doc/man/polybar.5.rst | 3 +
include/utils/string.hpp | 1 +
src/main.cpp | 7 +
src/utils/file.cpp | 51 ++--
src/utils/string.cpp | 8 +
tests/unit_tests/utils/string.cpp | 14 +
20 files changed, 316 insertions(+), 649 deletions(-)
delete mode 100644 cmake/templates/userconfig.cmake.in
delete mode 100644 config/CMakeLists.txt
delete mode 100644 config/config.cmake
create mode 100644 doc/_static/default.png
create mode 100644 doc/config.ini
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01e7f2c2..cf29e645 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,7 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `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`)
- - `BUILD_CONFIG=ON` - Generates sample config
+ - `BUILD_CONFIG=ON` - Generates the default config
- `BUILD_SHELL=ON` - Generates shell completion files
- `DISABLE_ALL=OFF` - Disables all above targets by default. Individual
targets can still be enabled explicitly.
@@ -52,12 +52,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
whatever folder you invoked `cmake` from instead of in the root folder of the
repository.
- The `POLYBAR_FLAGS` cmake variable can be used to pass extra C++ compiler flags.
+- The sample config file has been removed.
+- Polybar now ships a default config that is installed to
+ `/etc/polybar/config.ini`, it lives in `doc/config.ini`.
+ It will also be placed in the `examples` directory in the documentation folder.
+ [`#2405`](https://github.com/polybar/polybar/issues/2405)
+- The `userconfig` target has been removed, you can no longer use `make
+ userconfig`. As an alternative, you can copy the default config from
+ `/etc/polybar/config.ini`.
### Deprecated
- `[settings]`: `throttle-output` and `throttle-output-for` have been removed.
The new event loop already does a similar thing where it coalesces update
triggers if they happen directly after one another, leading to only a single
bar update.
+- When not specifying the config file with `--config`, naming your config file
+ `config` is deprecated. Rename your config file to `config.ini`.
### Removed
- `DEBUG_SHADED` cmake variable and its associated functionality.
@@ -94,8 +104,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
speeds are displayed.
- `internal/xkeyboard`: `%variant%` can be used to parse the layout variant
([`#316`](https://github.com/polybar/polybar/issues/316))
-- Added .ini extension check to the default config search.
- ([`#2323`](https://github.com/polybar/polybar/issues/2323))
- Config option to hide a certain module
(`hidden = false`)
([`#2108`](https://github.com/polybar/polybar/issues/2108))
@@ -126,6 +134,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([`#2414`](https://github.com/polybar/polybar/issues/2414))
### Changed
+- Polybar now also reads `config.ini` when searching for config files.
+ ([`#2323`](https://github.com/polybar/polybar/issues/2323))
+- Polybar additionally searches in `XDG_CONFIG_DIRS/polybar` (or
+ `/etc/xdg/polybar` if it is not set) and `/etc/polybar` for config files
+ (only `config.ini`).
+ ([`#2016`](https://github.com/polybar/polybar/issues/2016))
- We rewrote polybar's main event loop. This shouldn't change any behavior for
the user, but be on the lookout for X events, click events, or ipc messages
not arriving and the bar not shutting down/restarting properly and let us
diff --git a/CMakeLists.txt b/CMakeLists.txt
index debe2ddf..f71801c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,8 +60,11 @@ if(BUILD_TESTS)
add_subdirectory(tests)
endif()
-if (BUILD_CONFIG)
- add_subdirectory(config)
+
+if(BUILD_CONFIG)
+ install(FILES ${CMAKE_SOURCE_DIR}/doc/config.ini
+ DESTINATION /etc/${PROJECT_NAME}
+ COMPONENT config)
endif()
include(05-summary)
diff --git a/README.md b/README.md
index 703a2ac5..fa2614d7 100644
--- a/README.md
+++ b/README.md
@@ -23,14 +23,8 @@ A fast and easy-to-use tool for creating status bars.
**Polybar** aims to help users build beautiful and highly customizable status bars
for their desktop environment, without the need of having a black belt in shell scripting.
-Here are a few screenshots showing you what it can look like:
-[![sample screenshot](https://i.imgur.com/xvlw9iHt.png)](https://i.imgur.com/xvlw9iH.png)
-[![sample screenshot](https://i.imgur.com/cYQOuRrt.png)](https://i.imgur.com/cYQOuRr.png)
-[![sample screenshot](https://i.imgur.com/A6spiZZt.png)](https://i.imgur.com/A6spiZZ.png)
-[![sample screenshot](https://i.imgur.com/TY5a5r9t.png)](https://i.imgur.com/TY5a5r9.png)
-
-You can find polybar configs for these example images (and other configs) [here](https://github.com/jaagr/dots/tree/master/.local/etc/themer/themes).
+![sample screenshot](doc/_static/default.png)
## Table of Contents
@@ -139,14 +133,13 @@ If you can't find your distro here, you will have to [build from source](https:/
Details on how to setup and configure the bar and each module have been moved to [the wiki](https://github.com/polybar/polybar/wiki/Configuration).
#### Install the example configuration
-Run the following inside the build directory:
-**WARNING:** This will overwrite your current configuration file!
+For a normal installation, polybar will install the example config to
+`/usr/share/doc/polybar/config` or ` /usr/local/share/doc/polybar/config`
+(depending on your install parameters)
-~~~ sh
-$ make userconfig
-~~~
-Or you can copy the example config from `/usr/share/doc/polybar/config` or ` /usr/local/share/doc/polybar/config` (depending on your install parameters)
+From there you can copy it to `~/.config/polybar/config` to get started (make
+sure to backup any existing config file there).
**Note:** This example file is meant to showcase available modules and
configuration options.
diff --git a/build.sh b/build.sh
index fb668e1c..d1bfbb74 100755
--- a/build.sh
+++ b/build.sh
@@ -46,8 +46,6 @@ usage() {
Remove existing build dir; disabled by default.
${COLORS[GREEN]}-I, --no-install${COLORS[OFF]}
Do not execute 'sudo make install'; enabled by default.
- ${COLORS[GREEN]}-C, --install-config${COLORS[OFF]}
- Install example configuration; disabled by default.
${COLORS[GREEN]}-A, --auto${COLORS[OFF]}
Automatic, non-interactive installation; disabled by default.
When set, script defaults options not explicitly set.
@@ -70,7 +68,6 @@ install() {
if [[ "$AUTO" == ON ]]; then
[[ -z "$INSTALL" ]] && INSTALL="ON"
- [[ -z "$INSTALL_CONF" ]] && INSTALL_CONF="OFF"
fi
if [[ -z "$INSTALL" ]]; then
@@ -78,19 +75,9 @@ install() {
[[ "${p^^}" != "N" ]] && INSTALL="ON" || INSTALL="OFF"
fi
- if [[ -z "$INSTALL_CONF" ]]; then
- read -r -p "$(msg "Install example configuration? [y/N]: ")" -n 1 p && echo
- [[ "${p^^}" != "Y" ]] && INSTALL_CONF="OFF" || INSTALL_CONF="ON"
- fi
-
-
if [[ "$INSTALL" == ON ]]; then
sudo make install || msg_err "Failed to install executables..."
fi
-
- if [[ "$INSTALL_CONF" == ON ]]; then
- make userconfig || msg_err "Failed to install user configuration..."
- fi
}
set_build_opts() {
@@ -253,8 +240,6 @@ while [[ "$1" == -* ]]; do
REMOVE_BUILD_DIR=ON; shift ;;
-I|--no-install)
INSTALL=OFF; shift ;;
- -C|--install-config)
- INSTALL_CONF=ON; shift ;;
-A|--auto)
AUTO=ON; shift ;;
-h|--help)
diff --git a/cmake/common/utils.cmake b/cmake/common/utils.cmake
index 7a748d80..a7cf77eb 100644
--- a/cmake/common/utils.cmake
+++ b/cmake/common/utils.cmake
@@ -26,48 +26,6 @@ endfunction()
# }}}
-# queryfont {{{
-
-function(queryfont output_variable fontname)
- set(multi_value_args FIELDS)
- cmake_parse_arguments(ARG "" "" "${multi_value_args}" ${ARGN})
-
- find_program(BIN_FCLIST fc-list)
- if(NOT BIN_FCLIST)
- message_colored(WARNING "Failed to locate `fc-list`" "33;1")
- return()
- endif()
-
- string(REPLACE ";" " " FIELDS "${ARG_FIELDS}")
- if(NOT FIELDS)
- set(FIELDS family)
- endif()
-
- execute_process(
- COMMAND sh -c "${BIN_FCLIST} : ${FIELDS}"
- RESULT_VARIABLE status
- OUTPUT_VARIABLE output
- ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
- STRING(REGEX REPLACE ";" "\\\\;" output "${output}")
- STRING(REGEX REPLACE "\n" ";" output "${output}")
- STRING(TOLOWER "${output}" output)
-
- foreach(match LISTS ${output})
- if(${match} MATCHES ".*${fontname}.*$")
- list(APPEND matches ${match})
- endif()
- endforeach()
-
- if(matches)
- list(GET matches 0 fst_match)
- set(${output_variable} "${fst_match}" PARENT_SCOPE)
- message(STATUS "Found font: ${fst_match}")
- else()
- message_colored(STATUS "Font not found: ${fontname}" "33;1")
- endif()
-endfunction()
-
-# }}}
# find_package_impl {{{
# Uses PkgConfig to search for pkg_config_name
diff --git a/cmake/templates/userconfig.cmake.in b/cmake/templates/userconfig.cmake.in
deleted file mode 100644
index 1e39fe61..00000000
--- a/cmake/templates/userconfig.cmake.in
+++ /dev/null
@@ -1,8 +0,0 @@
-set(USER_CONFIG_HOME "$ENV{XDG_CONFIG_HOME}")
-if(NOT USER_CONFIG_HOME)
- set(USER_CONFIG_HOME "$ENV{HOME}/.config")
-endif()
-set(USER_CONFIG_HOME "${USER_CONFIG_HOME}/polybar")
-
-file(INSTALL "@CMAKE_BINARY_DIR@/generated-sources/config"
- DESTINATION "${USER_CONFIG_HOME}")
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
deleted file mode 100644
index 7b14f98e..00000000
--- a/config/CMakeLists.txt
+++ /dev/null
@@ -1,106 +0,0 @@
-#
-# 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)
- list(REMOVE_ITEM MODULES_RIGHT "pulseaudio")
-endif()
-if(NOT ENABLE_ALSA)
- list(REMOVE_ITEM MODULES_RIGHT "alsa")
-endif()
-if(NOT ENABLE_I3)
- list(REMOVE_ITEM MODULES_LEFT "i3")
-endif()
-if(NOT ENABLE_MPD)
- list(REMOVE_ITEM MODULES_CENTER "mpd")
-endif()
-if(NOT ENABLE_NETWORK)
- list(REMOVE_ITEM MODULES_RIGHT "wlan" "eth")
-endif()
-if(NOT WITH_XKB)
- list(REMOVE_ITEM MODULES_RIGHT "xkeyboard")
-endif()
-
-string(REPLACE ";" " " MODULES_LEFT "${MODULES_LEFT}")
-string(REPLACE ";" " " MODULES_CENTER "${MODULES_CENTER}")
-string(REPLACE ";" " " MODULES_RIGHT "${MODULES_RIGHT}")
-
-# }}}
-# 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/config.cmake b/config/config.cmake
deleted file mode 100644
index a5472390..00000000
--- a/config/config.cmake
+++ /dev/null
@@ -1,428 +0,0 @@
-;==========================================================
-;
-;
-; ██████╗ ██████╗ ██╗ ██╗ ██╗██████╗ █████╗ ██████╗
-; ██╔══██╗██╔═══██╗██║ ╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗
-; ██████╔╝██║ ██║██║ ╚████╔╝ ██████╔╝███████║██████╔╝
-; ██╔═══╝ ██║ ██║██║ ╚██╔╝ ██╔══██╗██╔══██║██╔══██╗
-; ██║ ╚██████╔╝███████╗██║ ██████╔╝██║ ██║██║ ██║
-; ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
-;
-;
-; To learn more about how to configure Polybar
-; go to https://github.com/polybar/polybar
-;
-; The README contains a lot of information
-;
-;==========================================================
-
-[colors]
-;background = ${xrdb:color0:#222}
-background = #222
-background-alt = #444
-;foreground = ${xrdb:color7:#222}
-foreground = #dfdfdf
-foreground-alt = #555
-primary = #ffb52a
-secondary = #e60053
-alert = #bd2c40
-
-[bar/example]
-;monitor = ${env:MONITOR:HDMI-1}
-width = 100%
-height = 27
-;offset-x = 1%
-;offset-y = 1%
-radius = 6.0
-fixed-center = false
-
-background = ${colors.background}
-foreground = ${colors.foreground}
-
-line-size = 3
-line-color = #f00
-
-border-size = 4
-border-color = #00000000
-
-padding-left = 0
-padding-right = 2
-
-module-margin-left = 1
-module-margin-right = 2
-
-font-0 = @FONT_FIXED@;1
-font-1 = @FONT_UNIFONT@:size=8:antialias=false;0
-font-2 = @FONT_SIJI@;1
-
-modules-left = @MODULES_LEFT@
-modules-center = @MODULES_CENTER@
-modules-right = @MODULES_RIGHT@
-
-tray-position = right
-tray-padding = 2
-;tray-background = #0063ff
-
-;wm-restack = generic
-;wm-restack = bspwm
-;wm-restack = i3
-
-;override-redirect = true
-
-;scroll-up = bspwm-desknext
-;scroll-down = bspwm-deskprev
-
-;scroll-up = i3wm-wsnext
-;scroll-down = i3wm-wsprev
-
-cursor-click = pointer
-cursor-scroll = ns-resize
-
-enable-ipc = true
-
-[module/xwindow]
-type = internal/xwindow
-label = %title:0:30:...%
-
-[module/xkeyboard]
-type = internal/xkeyboard
-blacklist-0 = num lock
-
-format-prefix = " "
-format-prefix-foreground = ${colors.foreground-alt}
-format-prefix-underline = ${colors.secondary}
-
-label-layout = %layout%
-label-layout-underline = ${colors.secondary}
-
-label-indicator-padding = 2
-label-indicator-margin = 1
-label-indicator-background = ${colors.secondary}
-label-indicator-underline = ${colors.secondary}
-
-[module/filesystem]
-type = internal/fs
-interval = 25
-
-mount-0 = /
-
-label-mounted = %{F#0a81f5}%mountpoint%%{F-}: %percentage_used%%
-label-unmounted = %mountpoint% not mounted
-label-unmounted-foreground = ${colors.foreground-alt}
-
-[module/bspwm]
-type = internal/bspwm
-
-label-focused = %index%
-label-focused-background = ${colors.background-alt}
-label-focused-underline= ${colors.primary}
-label-focused-padding = 2
-
-label-occupied = %index%
-label-occupied-padding = 2
-
-label-urgent = %index%!
-label-urgent-background = ${colors.alert}
-label-urgent-padding = 2
-
-label-empty = %index%
-label-empty-foreground = ${colors.foreground-alt}
-label-empty-padding = 2
-
-; Separator in between workspaces
-; label-separator = |
-
-[module/i3]
-type = internal/i3
-format =
-index-sort = true
-wrapping-scroll = false
-
-; Only show workspaces on the same output as the bar
-;pin-workspaces = true
-
-label-mode-padding = 2
-label-mode-foreground = #000
-label-mode-background = ${colors.primary}
-
-; focused = Active workspace on focused monitor
-label-focused = %index%
-label-focused-background = ${colors.background-alt}
-label-focused-underline= ${colors.primary}
-label-focused-padding = 2
-
-; unfocused = Inactive workspace on any monitor
-label-unfocused = %index%
-label-unfocused-padding = 2
-
-; visible = Active workspace on unfocused monitor
-label-visible = %index%
-label-visible-background = ${self.label-focused-background}
-label-visible-underline = ${self.label-focused-underline}
-label-visible-padding = ${self.label-focused-padding}
-
-; urgent = Workspace with urgency hint set
-label-urgent = %index%
-label-urgent-background = ${colors.alert}
-label-urgent-padding = 2
-
-; Separator in between workspaces
-; label-separator = |
-
-
-[module/mpd]
-type = internal/mpd
-format-online =
-
-icon-prev =
-icon-stop =
-icon-play =
-icon-pause =
-icon-next =
-
-label-song-maxlen = 25
-label-song-ellipsis = true
-
-[module/xbacklight]
-type = internal/xbacklight
-
-format =