From: Utkarsh Gupta Date: Mon, 1 Mar 2021 21:22:57 +0000 (+0000) Subject: Import polybar_3.5.5.orig.tar.gz X-Git-Tag: archive/raspbian/3.5.5-1+rpi1^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=81983e41cd28d808d57cc7624c9524abc3516faf;p=polybar.git Import polybar_3.5.5.orig.tar.gz [dgit import orig polybar_3.5.5.orig.tar.gz] --- 81983e41cd28d808d57cc7624c9524abc3516faf diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3caddce --- /dev/null +++ b/.clang-format @@ -0,0 +1,13 @@ +--- +Language: Cpp +Standard: Cpp11 +BasedOnStyle: Google +ColumnLimit: 120 +NamespaceIndentation: All +AlignAfterOpenBracket: DontAlign +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +BreakConstructorInitializersBeforeComma: true +DerivePointerAlignment: false +PointerAlignment: Left +--- diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..a12c09f --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,52 @@ +--- +Checks: ' + -*, + performance-*, + readability-*, + clang-analyzer-alpha.core*, + clang-analyzer-alpha.security*, + clang-analyzer-alpha.unix.cstring*, + clang-analyzer-core.uninitialized*, + clang-analyzer-cplusplus.*, + clang-analyzer-nullability*, + clang-analyzer-unix*, + cppcoreguidelines*, + modernize-use-*, + modernize-*, + -modernize-raw-string-literal, + -modernize-use-bool-literals, + -modernize-use-trailing-return-type, + -readability-implicit-bool-cast, + -readability-else-after-return, + -readability-named-parameter, + -readability-implicit-bool-conversion, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-pro-type-reinterpret-cast, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-bounds-constant-array-index + ' + +CheckOptions: + - key: modernize-loop-convert.NamingStyle + value: lower_case + - key: readability-identifier-naming.GlobalConstantPrefix + value: 'g_' + - key: readability-identifier-naming.ClassCase + value: lower_case + - key: readability-identifier-naming.ClassConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.ClassMethodCase + value: lower_case + - key: readability-identifier-naming.MemberCase + value: lower_case + - key: readability-identifier-naming.ProtectedMemberPrefix + value: 'm_' + - key: readability-identifier-naming.PrivateMemberPrefix + value: 'm_' +HeaderFilterRegex: '' +WarningsAsErrors: '' +AnalyzeTemporaryDtors: false +... diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..cb44c86 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,18 @@ +coverage: + status: + project: + default: + # Coverage can drop by 0.1% without failing the status + threshold: 0.1 + patch: + default: + # Patches don't need test coverage + # TODO remove once we have proper testing infrastructure and documentation + target: 0 + +ignore: + - "tests/*" + - "lib/*" + +comment: + require_changes: true diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..57c08e6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 +charset = utf-8 + +[Makefile] +indent_style = tab +indent_size = 2 diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..2442129 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,61 @@ +--- +name: Bug Report +about: Create a report for something that misbehaves + +--- + +## Checklist + + + +* [ ] I have read the appropriate section in the [contributing + guidelines](https://github.com/polybar/polybar/blob/master/CONTRIBUTING.md) +* [ ] I believe this issue is a problem with polybar itself and not a misconfiguration on my part. +* [ ] I have searched for other open and closed [issues](https://github.com/polybar/polybar/issues?q=is%3Aissue) that + may have already reported this problem. +* [ ] I have checked the [known issues](https://github.com/polybar/polybar/wiki/Known-Issues) page for this problem. + +## Describe the bug + + +**Expected behavior:** + + + +**Actual behavior:** + + + +**Was it working before?** +* Did you also experience this bug in an earlier version of polybar (yes/no/don't know)? +* If no, what was the last version where this worked correctly? + +## To Reproduce + + + +```dosini + +``` + + +## Polybar Log + +``` + +``` + +## Screenshots + + +## Environment: +* WM: +* Distro: +* Output of `polybar -vvv`: + +``` + +``` + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/build.md b/.github/ISSUE_TEMPLATE/build.md new file mode 100644 index 0000000..9e0c86a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/build.md @@ -0,0 +1,46 @@ +--- +name: Build Issues +about: Report issues while building polybar from source + +--- + +## Checklist + + + +* [ ] I have followed every step on the [compiling wiki page](https://github.com/polybar/polybar/wiki/Compiling) and + installed all necessary dependencies. +* [ ] My problem is not described on the [known issues page](https://github.com/polybar/polybar/wiki/Known-Issues) +* [ ] I have searched for other open and closed [issues](https://github.com/polybar/polybar/issues?q=is%3Aissue) that + may have already reported this problem. +* [ ] I was able to reproduce this build issue in a clean build + +## Build Process + +**How did you build polybar?** + + + +* [ ] From a release archive (Which version?) +* [ ] By cloning this repository (What is the of `git describe --tags`?) +* [ ] Some other way (How?) + + + + +## Build Log + +``` + +``` + +## Environment: +* Distro (with Version): + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..6a1549a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Polybar Gitter Room + url: https://gitter.im/polybar/polybar + about: Please ask and answer questions here. + - name: Polybar subreddit + url: https://www.reddit.com/r/polybar + about: Please ask and answer questions here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..0092b9f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +## Is your feature request related to a problem? Please describe. + + +## Why does polybar need this feature? + + +## Describe the solution you'd like + + +## Describe alternatives you've considered + + +## Additional context + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..442cf05 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## What type of PR is this? (check all applicable) + +* [ ] Refactor +* [ ] Feature +* [ ] Bug Fix +* [ ] Optimization +* [ ] Documentation Update +* [ ] Other: *Replace this with a description of the type of this PR* + +## Description + + +## Related Issues & Documents + + +## Documentation (check all applicable) + +* [ ] This PR requires changes to the Wiki documentation (describe the changes) +* [ ] This PR requires changes to the documentation inside the git repo (please add them to the PR). +* [ ] Does not require documentation changes diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9974676 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,98 @@ +name: CI +on: + workflow_dispatch: + inputs: + ref: + description: 'ref' + required: false + push: + pull_request: + +jobs: + docs: + runs-on: ubuntu-20.04 + env: + COLOR: "ON" + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.ref }} + - name: Install Dependencies + run: sudo apt-get install -y python3-sphinx + - name: Build Documentation + run: | + mkdir -p doc/build + cd doc/build + cmake .. + make doc + + build: + runs-on: ubuntu-20.04 + strategy: + matrix: + cxx: [g++, clang++] + polybar_build_type: ["full"] + build_type: ["Release"] + include: + - cxx: g++ + polybar_build_type: "tests" + build_type: "Coverage" + - cxx: g++ + polybar_build_type: "minimal" + build_type: "Release" + env: + CXX: ${{ matrix.cxx }} + BUILD_TYPE: ${{ matrix.build_type }} + POLYBAR_BUILD_TYPE: ${{ matrix.polybar_build_type }} + POLYBAR_DIR: ${{ github.workspace }} + BUILD_DIR: "${{ github.workspace}}/build" + MAKEFLAGS: "-j4" + COLOR: "ON" + steps: + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + libxcb-composite0-dev \ + libxcb-ewmh-dev \ + libxcb-icccm4-dev \ + libxcb-image0-dev \ + libxcb-randr0-dev \ + libxcb-util0-dev \ + libxcb1-dev \ + libcairo2-dev \ + python3-xcbgen \ + xcb-proto + + if [ "$POLYBAR_BUILD_TYPE" != "minimal" ]; then + sudo apt-get install -y \ + libxcb-xkb-dev \ + libxcb-cursor-dev \ + libxcb-xrm-dev \ + i3-wm \ + libcurl4-openssl-dev \ + libjsoncpp-dev \ + libasound2-dev \ + libpulse-dev \ + libiw-dev \ + libmpdclient-dev + fi + - uses: actions/checkout@v2 + with: + submodules: true + ref: ${{ github.event.inputs.ref }} + - name: Summary + run: ./common/ci/summary.sh + - name: Configure + run: ./common/ci/configure.sh + - name: Build + run: | + cd $BUILD_DIR + make + - name: Tests + if: ${{ matrix.polybar_build_type == 'tests' }} + run: | + cd $BUILD_DIR + make check + cd $POLYBAR_DIR + bash <(curl -s https://codecov.io/bash) -F unittests -a "-ap" -Z diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6db60c --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/build +/tags +/compile_commands.json +/config +*.bak +*.pyc +*.swp +*.tmp +.tags + +polybar-*.tar diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4b6f7f5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,8 @@ +[submodule "lib/i3ipcpp"] + path = lib/i3ipcpp + url = https://github.com/polybar/i3ipcpp + branch = master +[submodule "lib/xpp"] + path = lib/xpp + url = https://github.com/polybar/xpp + branch = master diff --git a/.valgrind-suppressions b/.valgrind-suppressions new file mode 100644 index 0000000..6d33fd4 --- /dev/null +++ b/.valgrind-suppressions @@ -0,0 +1,101 @@ +{ + xft/fontconfig + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:FcPatternCreate + fun:FcFontRenderPrepare + fun:FcFontMatch + fun:XftFontMatch + fun:XftFontOpenName + ... + ... + ... + ... + ... + ... +} +{ + xft/fontconfig + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/lib/libfontconfig.so.* + obj:/usr/lib/libfontconfig.so.* + fun:FcPatternAddDouble + obj:/usr/lib/libXft.so.* + obj:/usr/lib/libXft.so.* + obj:/usr/lib/libXft.so.* + obj:/usr/lib/libXft.so.* + fun:XftDefaultHasRender + fun:XftDefaultSubstitute + fun:XftFontMatch + fun:XftFontOpenName +} +{ + xft/fontconfig + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:XftFontCheckGlyph + fun:XftGlyphRender + fun:XftDrawGlyphs + fun:XftDrawString16 + ... + ... + ... + ... + ... + ... + ... +} +{ + xft/fontconfig + Memcheck:Leak + match-leak-kinds: definite + fun:realloc + obj:/usr/lib/libfontconfig.so.* + obj:/usr/lib/libfontconfig.so.* + fun:FcFontRenderPrepare + fun:FcFontMatch + fun:XftFontMatch + fun:XftFontOpenName + ... + ... + ... + ... + ... +} +{ + xresource manager + Memcheck:Leak + match-leak-kinds: definite + fun:realloc + obj:/usr/lib/libX11.so.* + obj:/usr/lib/libX11.so.* + obj:/usr/lib/libX11.so.* + fun:_XlcCreateLC + fun:_XlcDefaultLoader + fun:_XOpenLC + fun:_XrmInitParseInfo + obj:/usr/lib/libX11.so.* + fun:XrmGetStringDatabase + ... + ... +} +{ + xft conditional jump + Memcheck:Cond + obj:/usr/lib/libfreetype.so.* + obj:/usr/lib/libfreetype.so.* + fun:FT_Outline_Decompose + obj:/usr/lib/libfreetype.so.* + obj:/usr/lib/libfreetype.so.* + obj:/usr/lib/libfreetype.so.* + obj:/usr/lib/libfreetype.so.* + obj:/usr/lib/libfreetype.so.* + fun:XftFontLoadGlyphs + fun:XftGlyphExtents + ... + ... +} diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py new file mode 100644 index 0000000..4942991 --- /dev/null +++ b/.ycm_extra_conf.py @@ -0,0 +1,126 @@ +import os +import ycm_core + +# Default flags +flags = [ + '-std=c++14', + '-Wall', + '-Wextra', + + # Relative paths are corrected by MakeRelativePathsInFlagsAbsolute + '-Isrc', + '-Iinclude', + '-Ilib/concurrentqueue/include', + '-Ilib/i3ipcpp/include', + '-Ilib/xpp/include', + '-Itests', + + '-I/usr/include', + '-I/usr/include/freetype2', + ] + +# Base directory of the project, parent directory of all source files +project_dir = os.path.dirname(os.path.abspath(__file__)) + +# This assumes that everyone coding for this project builds inside the 'build' +# directory +compilation_database_folder = project_dir + "/build" + +if os.path.exists(compilation_database_folder): + database = ycm_core.CompilationDatabase(compilation_database_folder) +else: + database = None + +SOURCE_EXTENSIONS = ['.cpp', '.cxx', '.cc', '.c', '.m', '.mm'] + +# Converts all relative paths in the given flag list to absolute paths with +# working_directory as the base directory +def MakeRelativePathsInFlagsAbsolute(flags, working_directory): + if not working_directory: + return list(flags) + new_flags = [] + make_next_absolute = False + path_flags = ['-isystem', '-I', '-iquote', '--sysroot='] + for flag in flags: + new_flag = flag + + if make_next_absolute: + make_next_absolute = False + if not flag.startswith('/'): + new_flag = os.path.join(working_directory, flag) + + for path_flag in path_flags: + if flag == path_flag: + make_next_absolute = True + break + + if flag.startswith(path_flag): + path = flag[len(path_flag):] + new_flag = path_flag + os.path.join(working_directory, path) + break + + if new_flag: + new_flags.append(new_flag) + return new_flags + +def IsHeaderFile(filename): + extension = os.path.splitext(filename)[1] + return extension in ['.h', '.hxx', '.hpp', '.hh', ".inl"] + +# Tries to query the compilation database for flags +# For header files it tries to use the flags for a corresponding source file +def GetCompilationInfoForFile(filename): + if not database: + return None + + # The compilation_commands.json file generated by CMake does not have entries + # for header files. We try to use the compile flags used for the corresponding + # source file. + # + # For this try to replace the file extension with an extension that + # corresponds to a source and we also try to replace the 'include' folder in + # the path with 'src' + if IsHeaderFile(filename) : + basename = os.path.splitext(filename)[0] + + # Absolute path of the include and source directories + include_dir = project_dir + "/include" + src_dir = project_dir + "/src" + + # Absolute path without file extension, with the 'include' folder replaced + # with 'src' in the path + src_basename = None + # If the header file is inside the include dir, try to search in the src dir + if basename.startswith(include_dir): + # file path relative to include dir + rel_path_include = os.path.relpath(basename, include_dir) + src_basename = os.path.join(src_dir, rel_path_include) + + for extension in SOURCE_EXTENSIONS: + # A list of all possible replacement files to be searched + replacement_files = [basename + extension] + + if src_basename: + replacement_files.append(src_basename + extension) + + for replacement_file in replacement_files: + if os.path.exists(replacement_file): + comp_info = database.GetCompilationInfoForFile(replacement_file) + if comp_info.compiler_flags_: + return comp_info + return database.GetCompilationInfoForFile(filename) + +def FlagsForFile(filename, **kwargs): + compilation_info = GetCompilationInfoForFile(filename) + if compilation_info and compilation_info.compiler_flags_: + # Bear in mind that compilation_info.compiler_flags_ does NOT return a + # python list, but a "list-like" StringVec object + final_flags = MakeRelativePathsInFlagsAbsolute( + [x for x in compilation_info.compiler_flags_ if x != "-Werror"], + compilation_info.compiler_working_dir_) + else: + # We use default flags if GetCompilationInfoForFile can't find any flags + relative_to = project_dir + final_flags = MakeRelativePathsInFlagsAbsolute(flags, relative_to) + + return {'flags': final_flags, 'do_cache': True} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..44988bd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,29 @@ +# Changelog + +All notable changes to this project will be documented in this file. +Each release should have the following subsections, if entries exist, in the +given order: `Breaking`, `Build`, `Deprecated`, `Removed`, `Added`, `Changed`, +`Fixed`, `Security`. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] +## [3.5.5] - 2021-03-01 +### Build +- Support older python sphinx versions again ([`#2356`](https://github.com/polybar/polybar/issues/2356)) + +## [3.5.4] - 2021-01-07 +### Fixed +- Wrong text displayed if module text ends with `}` ([`#2331`](https://github.com/polybar/polybar/issues/2331)) + +## [3.5.3] - 2020-12-23 +### Build +- Don't use `git` when building documentation ([`#2309`](https://github.com/polybar/polybar/issues/2309)) +### Fixed +- Empty color values are no longer treated as invalid and no longer produce an error. + +[Unreleased]: https://github.com/polybar/polybar/compare/3.5.5...HEAD +[3.5.5]: https://github.com/polybar/polybar/releases/tag/3.5.5 +[3.5.4]: https://github.com/polybar/polybar/releases/tag/3.5.4 +[3.5.3]: https://github.com/polybar/polybar/releases/tag/3.5.3 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d687cdd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,167 @@ +# +# Build configuration +# +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) + +# Enable ccache by default and as early as possible because project() performs +# checks on the compiler +option(ENABLE_CCACHE "Enable ccache support" ON) +if(ENABLE_CCACHE) + message(STATUS "Trying to enable ccache") + find_program(BIN_CCACHE ccache) + + string(ASCII 27 esc) + if(NOT BIN_CCACHE) + message(STATUS "${esc}[33mCouldn't locate ccache, disabling ccache...${esc}[0m") + else() + # Enable only if the binary is found + message(STATUS "${esc}[32mUsing compiler cache ${BIN_CCACHE}${esc}[0m") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${BIN_CCACHE}) + endif() +endif() + +project(polybar CXX) + +# Extract version information from version.txt. The first line that looks like +# a version string is used, so the file supports comments +file(STRINGS version.txt version_txt REGEX "^[0-9]+\\.[0-9]+\\.[0-9]+.*$" LIMIT_COUNT 1) + +# If we are in a git repo we can get the version information from git describe +execute_process(COMMAND git describe --tags --dirty=-dev + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_describe + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + +if(git_result EQUAL "0") + set(APP_VERSION "${git_describe}") +else() + message(STATUS "Could not detect version with git, falling back to built-in version information.") + set(APP_VERSION "${version_txt}") +endif() + +set(CMAKE_MODULE_PATH + ${CMAKE_MODULE_PATH} + ${PROJECT_SOURCE_DIR}/cmake + ${PROJECT_SOURCE_DIR}/cmake/common + ${PROJECT_SOURCE_DIR}/cmake/modules) + +include(GNUInstallDirs) +include(utils) +include(01-core) +include(02-opts) +include(03-libs) +include(04-targets) +include(05-summary) + +if(BUILD_DOC) + add_subdirectory(doc) +endif() +add_subdirectory(contrib/bash) +add_subdirectory(contrib/zsh) +add_subdirectory(include) +add_subdirectory(lib) +add_subdirectory(src bin) + +# We need to enable testing in the root folder so that 'ctest' and 'make test' +# can be run in the build directory +if(BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif() + + +# +# Generate configuration file +# + +set(MODULES_LEFT "bspwm i3") +set(MODULES_CENTER "mpd") +set(MODULES_RIGHT "filesystem xbacklight 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_XRANDR) + string(REPLACE "xbacklight " "backlight-acpi " 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/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..90c8672 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,123 @@ +# Contributing + +First of all, thank you very much for considering contributing to polybar. You +are awesome! :tada: + +**Table of Contents:** +* [Bug Reports](#bug-reports) +* [Pull Requests](#pull-requests) + + [Testing](#testing) + + [Documentation](#documentation) + + [Style](#style) + +## Bug Reports + +Bugs should be reported at the polybar issue tracker, using the [bug report +template](https://github.com/polybar/polybar/issues/new?template=bug_report.md). +Make sure you fill out all the required sections. + +Before opening a bug report, please search our [issue +tracker](https://github.com/polybar/polybar/issues?q=is%3Aissue) and [known +issues page](https://github.com/polybar/polybar/wiki/Known-Issues) for your +problem to avoid duplicates. + +If your issue has already been reported but is already marked as fixed and the +version of polybar you are using includes this supposed fix, feel free to open a +new issue. + +You should also go through our [debugging +guide](https://github.com/polybar/polybar/wiki/Debugging-your-Config) to confirm +what you are experiencing is indeed a polybar bug and not an issue with your +configuration. +This will also help you narrow down the issue which, in turn, will help us +resolve it, if it turns out to be a bug in polybar. + +If this bug was not present in a previous version of polybar and you know how +to, doing a `git bisect` and providing us with the commit ID that introduced the +issue would be immensely helpful. + +## Pull Requests + +If you want to start contributing to polybar, a good place to start are issues +labeled with +[help wanted](https://github.com/polybar/polybar/labels/help%20wanted) +or +[good first issue](https://github.com/polybar/polybar/labels/good%20first%20issue). + +Except for small changes, PRs should always address an already open and accepted +issue. +Otherwise you run the risk of spending time implementing something and then the +PR being rejected because the feature you implemented was not actually something +we want in polybar. + +Issues with any of the following labels are generally safe to start working on, +unless someone else has already claimed them: + +* [bug](https://github.com/polybar/polybar/labels/bug) +* [confirmed](https://github.com/polybar/polybar/labels/confirmed) +* [good first issue](https://github.com/polybar/polybar/labels/good%20first%20issue) +* [help wanted](https://github.com/polybar/polybar/labels/help%20wanted) + +For anything else, it's a good idea to first comment under the issue to ask +whether it is something that can/should be worked on right now. +This is especially true for issues labeled with `feature` (and none of the +labels listed above), here a feature may depend on some other things being +implemented first or it may need to be split into many smaller features, because +it is too big otherwise. +In particular, this means that you should not open a feature request and +immediately start working on that feature, unless you are very sure it will be +accepted or accept the risk of it being rejected. + +Things like documentation changes or refactorings, don't necessarily need an +issue associated with them. +These changes are less likely to be rejected since they don't change the +behavior of polybar. +Nevertheless, for bigger changes or when in doubt, open an issue and ask whether +such changes would be desirable. + +To claim an issue, comment under it to let others know that you are working on +it. + +Feel free to ask for feedback about your changes at any time. +Especially when implementing features, this can be very useful because it allows +us to make sure you are going in the direction we had envisioned for that +feature and you don't lose time on something that ultimately has to be +rewritten. +In that case, a [draft PR](https://github.blog/2019-02-14-introducing-draft-pull-requests/) +is a useful tool. + +When creating a PR, please fill out the PR template. + +### Testing + +Your PR must pass all existing tests. +If possible, you should also add tests for the things you write. +However, this is not always possible, for example when working on modules. +But at least isolated components should be tested. + +See the [testing page](https://github.com/polybar/polybar/wiki/Testing) on the +wiki for more information. +Also don't hesitate to ask for help, testing isn't that mature in polybar yet +and some things may be harder/impossible to test right now. + +### Documentation + +Right now, documentation for polybar lives in two places: The GitHub wiki and +the git repo itself. + +Ultimately, most of the documentation is supposed to live in the repo itself. + +For now, if your PR requires documentation changes in the repo, those changes +need to be in the PR as well. + +Changes on the wiki should not be made right away because the wiki should +reflect the currently released version and not the development version. +In that case, outline the documentation changes that need to be made (for +example, which new config options are available). +If your PR would introduce a lot of new documentation on the wiki, let us know +and we can decide if we want to put some of the documentation directly into the +repo. + +### Style + +Please read our [style guide](https://github.com/polybar/polybar/wiki/Style-Guide). diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..13e205a --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +The MIT License (MIT) +Copyright (c) 2016 Michael Carlberg + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a1a67b7 --- /dev/null +++ b/README.md @@ -0,0 +1,159 @@ +

+ Polybar +

+ +

+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). + +## Table of Contents + +* [Introduction](#introduction) +* [Getting Help](#getting-help) +* [Contributing](#contributing) +* [Getting started](#getting-started) + * [Installation](#installation) + * [Configuration](#configuration) + * [Running](#running) +* [Community](#community) +* [Contributors](#contributors) +* [License](#license) + + +## Introduction + +The main purpose of **Polybar** is to help users create awesome status bars. +It has built-in functionality to display information about the most commonly used services. +Some of the services included so far: + +- Systray icons +- Window title +- Playback controls and status display for [MPD](https://www.musicpd.org/) using [libmpdclient](https://www.musicpd.org/libs/libmpdclient/) +- [ALSA](https://www.alsa-project.org/main/index.php/Main_Page) and [PulseAudio](https://www.freedesktop.org/wiki/Software/PulseAudio/) volume controls +- Workspace and desktop panel for [bspwm](https://github.com/baskerville/bspwm) and [i3](https://github.com/i3/i3) +- Workspace module for [EWMH compliant](https://specifications.freedesktop.org/wm-spec/wm-spec-1.3.html#idm140130320786080) window managers +- Keyboard layout and indicator status +- CPU and memory load indicator +- Battery display +- Network connection details +- Backlight level +- Date and time label +- Time-based shell script execution +- Command output tailing +- User-defined menu tree +- Inter-process messaging +- And more... + +[See the wiki for more details](https://github.com/polybar/polybar/wiki). + +## Getting Help + +If you find yourself stuck, have a look at our [Support](SUPPORT.md) page for resources where you can find help. + +## Contributing + +Read our [contributing guidelines](CONTRIBUTING.md) for how to get started with contributing to polybar. + +## Getting started + + + Packaging status + + +Polybar was already packaged for the distros listed below. +If you can't find your distro here, you will have to [build from source](https://github.com/polybar/polybar/wiki/Compiling). + +If you are using **Debian** (unstable or testing), you can install [polybar](https://tracker.debian.org/pkg/polybar) using `sudo apt install polybar`. +If you are using **Debian** (buster/stable), you need to enable [backports](https://wiki.debian.org/Backports) and then install using `sudo apt -t buster-backports install polybar`. + +If you are using **Arch Linux**, you can install the AUR package [polybar-git](https://aur.archlinux.org/packages/polybar-git/) to get the latest version, or +[polybar](https://aur.archlinux.org/packages/polybar/) for the latest stable release. + +If you are using **Void Linux**, you can install [polybar](https://github.com/void-linux/void-packages/blob/master/srcpkgs/polybar/template) using `xbps-install -S polybar`. + +If you are using **NixOS**, polybar is available in both the stable and unstable channels and can be installed with the command `nix-env -iA nixos.polybar`. + +If you are using **Slackware**, polybar is available from the [SlackBuilds](https://slackbuilds.org/repository/14.2/desktop/polybar/) repository. + +If you are using **Source Mage GNU/Linux**, polybar spell is available in test grimoire and can be installed via `cast polybar`. + +If you are using **openSUSE**, polybar is available from [OBS](https://build.opensuse.org/package/show/X11:Utilities/polybar/) repository. Package is available for openSUSE Leap 15.1, openSUSE Leap 15.2 and Tumbleweed. + +If you are using **FreeBSD**, [polybar](https://svnweb.freebsd.org/ports/head/x11/polybar/) can be installed using `pkg install polybar`. Make sure you are using the `latest` package branch. + +If you are using **Gentoo**, both release and git-master versions are available in the [main](https://packages.gentoo.org/packages/x11-misc/polybar) repository. + +If you are using **Fedora**, you can install [polybar](https://src.fedoraproject.org/rpms/polybar) using `sudo dnf install polybar`. + +### Installation + +The [compiling page](https://github.com/polybar/polybar/wiki/Compiling) on the +wiki describes all steps necessary to build and install polybar. + +### Configuration + +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: +~~~ 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) + +#### Launch the example bar + ~~~ sh + $ polybar example + ~~~ + +### Running + +[See the wiki for details on how to run polybar](https://github.com/polybar/polybar/wiki). + +## Community +Want to get in touch? + +* Join our Gitter room at [gitter.im/polybar/polybar](https://gitter.im/polybar/polybar) +* We have our own subreddit at [r/polybar](https://www.reddit.com/r/polybar). +* Chat with us in the `#polybar` IRC channel on the `chat.freenode.net` server. + +## Contributors + +### Owner +* Michael Carlberg [**@jaagr**](https://github.com/jaagr/) + +### Maintainers +* [**@NBonaparte**](https://github.com/NBonaparte) +* Chase Geigle [**@skystrife**](https://github.com/skystrife) +* Patrick Ziegler [**@patrick96**](https://github.com/patrick96) + +### Logo Design by +* [**@Tobaloidee**](https://github.com/Tobaloidee) + + +### [All Contributors](https://github.com/polybar/polybar/graphs/contributors) + +## License + +Polybar is licensed under the MIT license. [See LICENSE for more information](https://github.com/polybar/polybar/blob/master/LICENSE). diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..c4e7c0c --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,14 @@ +Getting Help +============ + +If you need help or troubleshooting tips or just have a question: + +* If applicable, go through our [debugging guide](https://github.com/polybar/polybar/wiki/Debugging-your-Config). +* Read the [Known Issues page](https://github.com/polybar/polybar/wiki/Known-Issues), maybe others had the same issue before. +* Read the [Wiki page](https://github.com/polybar/polybar/wiki) for the thing you have problems with. +* Join our Gitter room at [gitter.im/polybar/polybar](https://gitter.im/polybar/polybar) +* Ask in our reddit community at [r/polybar](https://www.reddit.com/r/polybar) +* Join the official IRC channel `#polybar` on the `chat.freenode.net` network. If you don't get an answer try asking on [Gitter](https://gitter.im/polybar/polybar). +* Ask on [Unix & Linux StackExchange](https://unix.stackexchange.com/). Though not all questions may be suited over there, make sure you're [on topic](https://unix.stackexchange.com/help/on-topic). + +Please **do not** use the github issue tracker to ask for help or if you have a question, it is meant for bug reports and feature requests. Issues will be closed and you will be referred to the above resources. diff --git a/banner.png b/banner.png new file mode 100644 index 0000000..6fb984f Binary files /dev/null and b/banner.png differ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..50d1c0e --- /dev/null +++ b/build.sh @@ -0,0 +1,273 @@ +#!/usr/bin/env bash + +readonly SELF=${0##*/} +declare -rA COLORS=( + [RED]=$'\033[0;31m' + [GREEN]=$'\033[0;32m' + [BLUE]=$'\033[0;34m' + [PURPLE]=$'\033[0;35m' + [CYAN]=$'\033[0;36m' + [WHITE]=$'\033[0;37m' + [YELLOW]=$'\033[0;33m' + [BOLD]=$'\033[1m' + [OFF]=$'\033[0m' +) + +usage() { + echo " + Builds and installs polybar. + + ${COLORS[GREEN]}${COLORS[BOLD]}Usage:${COLORS[OFF]} + ${COLORS[CYAN]}${SELF}${COLORS[OFF]} [options] + + ${COLORS[GREEN]}${COLORS[BOLD]}Options:${COLORS[OFF]} + ${COLORS[GREEN]}-3, --i3${COLORS[OFF]} + Include support for internal/i3 (requires i3); disabled by default. + ${COLORS[GREEN]}-a, --alsa${COLORS[OFF]} + Include support for internal/alsa (requires alsalib); disabled by default. + ${COLORS[GREEN]}-p, --pulseaudio${COLORS[OFF]} + Include support for internal/pulseaudio (requires libpulse); disabled by default. + ${COLORS[GREEN]}-n, --network${COLORS[OFF]} + Include support for internal/network (requires libnl/libiw); disabled by default. + ${COLORS[GREEN]}-m, --mpd${COLORS[OFF]} + Include support for internal/mpd (requires libmpdclient); disabled by default. + ${COLORS[GREEN]}-c, --curl${COLORS[OFF]} + Include support for internal/github (requires libcurl); disabled by default. + ${COLORS[GREEN]}-i, --ipc${COLORS[OFF]} + Build polybar-msg used to send ipc messages; disabled by default. + ${COLORS[GREEN]}--all-features${COLORS[OFF]} + Enable all abovementioned features; + equal to -3 -a -p -n -m -c -i + ${COLORS[GREEN]}-g, --gcc${COLORS[OFF]} + Use GCC even if Clang is installed; disabled by default. + ${COLORS[GREEN]}-j, --jobs${COLORS[OFF]} + Use make -j to use make jobs with $(nproc) jobs; disabled by default. + ${COLORS[GREEN]}-f${COLORS[OFF]} + 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. + ${COLORS[GREEN]}-h, --help${COLORS[OFF]} + Displays this help. +" +} + +msg_err() { + echo -e "${COLORS[RED]}${COLORS[BOLD]}** ${COLORS[OFF]}$*\n" + exit 1 +} + +msg() { + echo -e "${COLORS[GREEN]}${COLORS[BOLD]}** ${COLORS[OFF]}$*\n" +} + +install() { + local p + + if [[ "$AUTO" == ON ]]; then + [[ -z "$INSTALL" ]] && INSTALL="ON" + [[ -z "$INSTALL_CONF" ]] && INSTALL_CONF="OFF" + fi + + if [[ -z "$INSTALL" ]]; then + read -r -p "$(msg "Execute 'sudo make install'? [Y/n] ")" -n 1 p && echo + [[ "${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() { + local p + + msg "Setting build options" + + if [[ "$AUTO" == ON ]]; then + [[ -z "$USE_GCC" ]] && USE_GCC="OFF" + [[ -z "$ENABLE_I3" ]] && ENABLE_I3="OFF" + [[ -z "$ENABLE_ALSA" ]] && ENABLE_ALSA="OFF" + [[ -z "$ENABLE_PULSEAUDIO" ]] && ENABLE_PULSEAUDIO="OFF" + [[ -z "$ENABLE_NETWORK" ]] && ENABLE_NETWORK="OFF" + [[ -z "$ENABLE_MPD" ]] && ENABLE_MPD="OFF" + [[ -z "$ENABLE_CURL" ]] && ENABLE_CURL="OFF" + [[ -z "$ENABLE_IPC_MSG" ]] && ENABLE_IPC_MSG="OFF" + [[ -z "$JOB_COUNT" ]] && JOB_COUNT=1 + fi + + if [[ -z "$USE_GCC" ]]; then + read -r -p "$(msg "Use GCC even if Clang is installed ----------------------------- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && USE_GCC="OFF" || USE_GCC="ON" + fi + + if [[ -z "$ENABLE_I3" ]]; then + read -r -p "$(msg "Include support for \"internal/i3\" (requires i3) ---------------- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && ENABLE_I3="OFF" || ENABLE_I3="ON" + fi + + if [[ -z "$ENABLE_ALSA" ]]; then + read -r -p "$(msg "Include support for \"internal/alsa\" (requires alsalib) --------- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && ENABLE_ALSA="OFF" || ENABLE_ALSA="ON" + fi + + if [[ -z "$ENABLE_PULSEAUDIO" ]]; then + read -r -p "$(msg "Include support for \"internal/pulseaudio\" (requires libpulse) -- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && ENABLE_PULSEAUDIO="OFF" || ENABLE_PULSEAUDIO="ON" + fi + + if [[ -z "$ENABLE_NETWORK" ]]; then + read -r -p "$(msg "Include support for \"internal/network\" (requires libnl/libiw) -- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && ENABLE_NETWORK="OFF" || ENABLE_NETWORK="ON" + fi + + if [[ -z "$ENABLE_MPD" ]]; then + read -r -p "$(msg "Include support for \"internal/mpd\" (requires libmpdclient) ----- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && ENABLE_MPD="OFF" || ENABLE_MPD="ON" + fi + + if [[ -z "$ENABLE_CURL" ]]; then + read -r -p "$(msg "Include support for \"internal/github\" (requires libcurl) ------- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && ENABLE_CURL="OFF" || ENABLE_CURL="ON" + fi + + if [[ -z "$ENABLE_IPC_MSG" ]]; then + read -r -p "$(msg "Build \"polybar-msg\" used to send ipc messages ------------------ [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && ENABLE_IPC_MSG="OFF" || ENABLE_IPC_MSG="ON" + fi + + if [[ -z "$JOB_COUNT" ]]; then + read -r -p "$(msg "Parallelize the build using make -j$(nproc) --------------------------- [y/N]: ")" -n 1 p && echo + [[ "${p^^}" != "Y" ]] && JOB_COUNT=1 || JOB_COUNT=$(nproc) + fi + + + CXX="c++" + + if [[ "$USE_GCC" == OFF ]]; then + if command -v clang++ >/dev/null; then + msg "Using compiler: clang++/clang" + CXX="clang++" + elif command -v g++ >/dev/null; then + msg "Using compiler: g++/gcc" + CXX="g++" + fi + else + CXX="g++" + fi +} + +main() { + [[ -d ./.git ]] && { + msg "Fetching submodules" + git submodule update --init --recursive || msg_err "Failed to clone submodules" + } + + [[ -d ./build ]] && { + if [[ "$REMOVE_BUILD_DIR" == ON ]]; then + msg "Removing existing build dir (-f)" + rm -rf ./build >/dev/null || msg_err "Failed to remove existing build dir" + else + msg "A build dir already exists (pass -f to replace)" + fi + } + + mkdir -p ./build || msg_err "Failed to create build dir" + cd ./build || msg_err "Failed to enter build dir" + + set_build_opts + + msg "Executing cmake command" + cmake \ + -DCMAKE_CXX_COMPILER="${CXX}" \ + -DENABLE_ALSA:BOOL="${ENABLE_ALSA}" \ + -DENABLE_PULSEAUDIO:BOOL="${ENABLE_PULSEAUDIO}"\ + -DENABLE_I3:BOOL="${ENABLE_I3}" \ + -DENABLE_MPD:BOOL="${ENABLE_MPD}" \ + -DENABLE_NETWORK:BOOL="${ENABLE_NETWORK}" \ + -DENABLE_CURL:BOOL="${ENABLE_CURL}" \ + -DBUILD_IPC_MSG:BOOL="${ENABLE_IPC_MSG}" \ + .. || msg_err "Failed to generate build... read output to get a hint of what went wrong" + + msg "Building project" + if [ -z ${JOB_COUNT} ]; then + make || msg_err "Failed to build project" + else + make -j$JOB_COUNT || msg_err "Failed to build project" + fi + install + msg "Build complete!" + + exit 0 +} + + +################# +###### Entry +################# +while [[ "$1" == -* ]]; do + case "$1" in + -3|--i3) + ENABLE_I3=ON; shift ;; + -a|--alsa) + ENABLE_ALSA=ON; shift ;; + -p|--pulseaudio) + ENABLE_PULSEAUDIO=ON; shift ;; + -n|--network) + ENABLE_NETWORK=ON; shift ;; + -m|--mpd) + ENABLE_MPD=ON; shift ;; + -c|--curl) + ENABLE_CURL=ON; shift ;; + -i|--ipc) + ENABLE_IPC_MSG=ON; shift ;; + --all-features) + ENABLE_I3=ON + ENABLE_ALSA=ON + ENABLE_PULSEAUDIO=ON + ENABLE_NETWORK=ON + ENABLE_MPD=ON + ENABLE_CURL=ON + ENABLE_IPC_MSG=ON + shift ;; + + -g|--gcc) + USE_GCC=ON; shift ;; + -j|--jobs) + JOB_COUNT=$(nproc); shift ;; + -f) + 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) + usage + exit 0 + ;; + --) shift; break ;; + *) + usage + [[ "$1" =~ ^-[0-9a-zA-Z]{2,}$ ]] && msg_err "don't combine options: ie do [-c -i] instead of [-ci]" || msg_err "unknown option [$1]" + ;; + esac +done + +main + diff --git a/cmake/01-core.cmake b/cmake/01-core.cmake new file mode 100644 index 0000000..282a559 --- /dev/null +++ b/cmake/01-core.cmake @@ -0,0 +1,93 @@ +# +# Core setup +# + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(THREADS_PREFER_PTHREAD_FLAG ON) + +# Export compile commands used for custom targets +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Set default build type if not specified +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") + message_colored(STATUS "No build type specified; using ${CMAKE_BUILD_TYPE}" 33) +endif() +string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) + +# Compiler flags +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") + +if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + # Need dprintf() for FreeBSD 11.1 and older + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WITH_DPRINTF") + # libinotify uses c99 extension, so suppress this error + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c99-extensions") + # Ensures that libraries from dependencies in LOCALBASE are used + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib") +endif() + +if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=parentheses-equality") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-zero-length-array") +endif() + +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g2") + +if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) + set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -fdata-sections -ffunction-sections") + set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} -Wl,--gc-sections,--icf=safe") +endif() + +# Check compiler +if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.4.0") + message_colored(FATAL_ERROR "Compiler not supported (Requires clang-3.4+ or gcc-5.1+)" 31) + else() + message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}" 32) + endif() +elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1.0") + message_colored(FATAL_ERROR "Compiler not supported (Requires clang-3.4+ or gcc-5.1+)" 31) + else() + message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}" 32) + endif() +else() + message_colored(WARNING "Using unsupported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION} !" 31) +endif() + +# Set compiler and linker flags for preferred C++ library +if(CXXLIB_CLANG) + message_colored(STATUS "Linking against libc++" 32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi") +elseif(CXXLIB_GCC) + message_colored(STATUS "Linking against libstdc++" 32) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++") +endif() + +# Custom build type ; SANITIZE +SET(CMAKE_CXX_FLAGS_SANITIZE "-O0 -g -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls" + CACHE STRING "Flags used by the C++ compiler during sanitize builds." FORCE) +SET(CMAKE_EXE_LINKER_FLAGS_SANITIZE "" + CACHE STRING "Flags used for linking binaries during sanitize builds." FORCE) +SET(CMAKE_SHARED_LINKER_FLAGS_SANITIZE "" + CACHE STRING "Flags used by the shared libraries linker during sanitize builds." FORCE) +MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_SANITIZE + CMAKE_EXE_LINKER_FLAGS_SANITIZE + CMAKE_SHARED_LINKER_FLAGS_SANITIZE) + +# Custom build type ; Coverage +SET(CMAKE_CXX_FLAGS_COVERAGE + "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_COVERAGE} --coverage") +SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CMAKE_EXE_LINKER_FLAGS_COVERAGE}") +SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${CMAKE_SHARED_LINKER_FLAGS_COVERAGE}") diff --git a/cmake/02-opts.cmake b/cmake/02-opts.cmake new file mode 100644 index 0000000..6aa7b7b --- /dev/null +++ b/cmake/02-opts.cmake @@ -0,0 +1,82 @@ +# +# Build options +# +set(SPHINX_BUILD "sphinx-build" CACHE STRING "Name/Path of the sphinx-build executable to use.") +checklib(BUILD_DOC "binary" "${SPHINX_BUILD}") + +checklib(ENABLE_ALSA "pkg-config" alsa) +checklib(ENABLE_CURL "pkg-config" libcurl) +checklib(ENABLE_I3 "binary" i3) +checklib(ENABLE_MPD "pkg-config" libmpdclient) +checklib(WITH_LIBNL "pkg-config" libnl-genl-3.0) +if(WITH_LIBNL) + checklib(ENABLE_NETWORK "pkg-config" libnl-genl-3.0) + set(WIRELESS_LIB "libnl") +else() + checklib(ENABLE_NETWORK "cmake" Libiw) + set(WIRELESS_LIB "wireless-tools") +endif() +checklib(ENABLE_PULSEAUDIO "pkg-config" libpulse) +checklib(WITH_XKB "pkg-config" xcb-xkb) +checklib(WITH_XRM "pkg-config" xcb-xrm) +checklib(WITH_XRANDR_MONITORS "pkg-config" "xcb-randr>=1.12") +checklib(WITH_XCURSOR "pkg-config" "xcb-cursor") + +if(NOT DEFINED ENABLE_CCACHE AND CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG) + set(ENABLE_CCACHE ON) +endif() + +option(CXXLIB_CLANG "Link against libc++" OFF) +option(CXXLIB_GCC "Link against stdlibc++" OFF) + +option(BUILD_IPC_MSG "Build ipc messager" ON) +option(BUILD_TESTS "Build testsuite" OFF) +option(BUILD_DOC "Build documentation" ON) + +option(ENABLE_ALSA "Enable alsa support" ON) +option(ENABLE_CURL "Enable curl support" ON) +option(ENABLE_I3 "Enable i3 support" ON) +option(ENABLE_MPD "Enable mpd support" ON) +option(WITH_LIBNL "Use netlink interface for wireless" ON) +option(ENABLE_NETWORK "Enable network support" ON) +option(ENABLE_XKEYBOARD "Enable xkeyboard support" ON) +option(ENABLE_PULSEAUDIO "Enable PulseAudio support" ON) + +option(WITH_XRANDR "xcb-randr support" ON) +option(WITH_XRANDR_MONITORS "xcb-randr monitor support" ON) +option(WITH_XCOMPOSITE "xcb-composite support" ON) +option(WITH_XKB "xcb-xkb support" ON) +option(WITH_XRM "xcb-xrm support" ON) +option(WITH_XCURSOR "xcb-cursor support" ON) + +option(DEBUG_LOGGER "Trace logging" ON) + +if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG) + option(DEBUG_LOGGER_VERBOSE "Trace logging (verbose)" OFF) + option(DEBUG_HINTS "Debug clickable areas" OFF) + option(DEBUG_WHITESPACE "Debug whitespace" OFF) + option(DEBUG_FONTCONFIG "Debug fontconfig" OFF) +endif() + +set(SETTING_ALSA_SOUNDCARD "default" + CACHE STRING "Name of the ALSA soundcard driver") +set(SETTING_BSPWM_SOCKET_PATH "/tmp/bspwm_0_0-socket" + CACHE STRING "Path to bspwm socket") +set(SETTING_BSPWM_STATUS_PREFIX "W" + CACHE STRING "Prefix prepended to the bspwm status line") +set(SETTING_CONNECTION_TEST_IP "8.8.8.8" + CACHE STRING "Address to ping when testing network connection") +set(SETTING_PATH_ADAPTER "/sys/class/power_supply/%adapter%" + CACHE STRING "Path to adapter") +set(SETTING_PATH_BACKLIGHT "/sys/class/backlight/%card%" + CACHE STRING "Path to backlight sysfs folder") +set(SETTING_PATH_BATTERY "/sys/class/power_supply/%battery%" + CACHE STRING "Path to battery") +set(SETTING_PATH_CPU_INFO "/proc/stat" + CACHE STRING "Path to file containing cpu info") +set(SETTING_PATH_MEMORY_INFO "/proc/meminfo" + CACHE STRING "Path to file containing memory info") +set(SETTING_PATH_MESSAGING_FIFO "/tmp/polybar_mqueue.%pid%" + CACHE STRING "Path to file containing the current temperature") +set(SETTING_PATH_TEMPERATURE_INFO "/sys/class/thermal/thermal_zone%zone%/temp" + CACHE STRING "Path to file containing the current temperature") diff --git a/cmake/03-libs.cmake b/cmake/03-libs.cmake new file mode 100644 index 0000000..1d620e9 --- /dev/null +++ b/cmake/03-libs.cmake @@ -0,0 +1,30 @@ +# +# Check libraries +# + +find_package(Threads REQUIRED) +list(APPEND libs ${CMAKE_THREAD_LIBS_INIT}) + +querylib(TRUE "pkg-config" cairo-fc libs dirs) + +querylib(ENABLE_ALSA "pkg-config" alsa libs dirs) +querylib(ENABLE_CURL "pkg-config" libcurl libs dirs) +querylib(ENABLE_MPD "pkg-config" libmpdclient libs dirs) +if(WITH_LIBNL) + querylib(ENABLE_NETWORK "pkg-config" libnl-genl-3.0 libs dirs) +else() + querylib(ENABLE_NETWORK "cmake" Libiw libs dirs) +endif() +querylib(ENABLE_PULSEAUDIO "pkg-config" libpulse libs dirs) + +querylib(WITH_XCOMPOSITE "pkg-config" xcb-composite libs dirs) +querylib(WITH_XKB "pkg-config" xcb-xkb libs dirs) +querylib(WITH_XRANDR "pkg-config" xcb-randr libs dirs) +querylib(WITH_XRANDR_MONITORS "pkg-config" "xcb-randr>=1.12" libs dirs) +querylib(WITH_XRM "pkg-config" xcb-xrm libs dirs) +querylib(WITH_XCURSOR "pkg-config" xcb-cursor libs dirs) + +# FreeBSD Support +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + querylib(TRUE "pkg-config" libinotify libs dirs) +endif() diff --git a/cmake/04-targets.cmake b/cmake/04-targets.cmake new file mode 100644 index 0000000..b1d6c3b --- /dev/null +++ b/cmake/04-targets.cmake @@ -0,0 +1,76 @@ +# +# 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( + ${PROJECT_SOURCE_DIR}/cmake/templates/uninstall.cmake.in + ${PROJECT_BINARY_DIR}/cmake/uninstall.cmake + ESCAPE_QUOTES @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/uninstall.cmake) + +# }}} + +# folders where the clang tools should operate +set(CLANG_SEARCH_PATHS ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/tests) + +# Target: codeformat (clang-format) {{{ + +add_custom_target(codeformat) +add_custom_command(TARGET codeformat + COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh ${CLANG_SEARCH_PATHS}) + +# }}} +# Target: codecheck (clang-tidy) {{{ + +add_custom_target(codecheck) +add_custom_command(TARGET codecheck + COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh + ${PROJECT_BINARY_DIR} ${CLANG_SEARCH_PATHS}) + +# }}} +# Target: codecheck-fix (clang-tidy + clang-format) {{{ + +add_custom_target(codecheck-fix) +add_custom_command(TARGET codecheck-fix + COMMAND ${PROJECT_SOURCE_DIR}/common/clang-tidy.sh + ${PROJECT_BINARY_DIR} -fix ${CLANG_SEARCH_PATHS}) + +# }}} + +# Target: memcheck (valgrind) {{{ + +add_custom_target(memcheck) +add_custom_command(TARGET memcheck + COMMAND valgrind + --leak-check=summary + --suppressions=${PROJECT_SOURCE_DIR}/.valgrind-suppressions + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME} + example --config=${PROJECT_SOURCE_DIR}/doc/config) + +add_custom_target(memcheck-full) +add_custom_command(TARGET memcheck-full + COMMAND valgrind + --leak-check=full + --track-origins=yes + --track-fds=yes + --suppressions=${PROJECT_SOURCE_DIR}/.valgrind-suppressions + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${PROJECT_NAME} + example --config=${PROJECT_SOURCE_DIR}/doc/config) + +# }}} diff --git a/cmake/05-summary.cmake b/cmake/05-summary.cmake new file mode 100644 index 0000000..ddcb2b0 --- /dev/null +++ b/cmake/05-summary.cmake @@ -0,0 +1,49 @@ +# +# Output build summary +# + +message(STATUS " Build:") +message_colored(STATUS " Version: ${APP_VERSION}" "32;1") +message_colored(STATUS " Type: ${CMAKE_BUILD_TYPE}" "37;2") +message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}" "37;2") +message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}" "37;2") + +message(STATUS " Install Paths:") +message_colored(STATUS " PREFIX: ${CMAKE_INSTALL_PREFIX}" "32") +message_colored(STATUS " BINDIR: ${CMAKE_INSTALL_FULL_BINDIR}" "32") +message_colored(STATUS " DATADIR: ${CMAKE_INSTALL_FULL_DATADIR}" "32") +message_colored(STATUS " DOCDIR: ${CMAKE_INSTALL_FULL_DOCDIR}" "32") +message_colored(STATUS " MANDIR: ${CMAKE_INSTALL_FULL_MANDIR}" "32") + +message(STATUS " Targets:") +colored_option(" polybar-msg" BUILD_IPC_MSG) +colored_option(" testsuite" BUILD_TESTS) +colored_option(" documentation" BUILD_DOC) + +message(STATUS " Module support:") +colored_option(" alsa" ENABLE_ALSA) +colored_option(" curl" ENABLE_CURL) +colored_option(" i3" ENABLE_I3) +colored_option(" mpd" ENABLE_MPD) +colored_option(" network (${WIRELESS_LIB})" ENABLE_NETWORK) +colored_option(" pulseaudio" ENABLE_PULSEAUDIO) +colored_option(" xkeyboard" WITH_XKB) + +message(STATUS " X extensions:") +colored_option(" xcb-randr" WITH_XRANDR) +colored_option(" xcb-randr (monitor support)" WITH_XRANDR_MONITORS) +colored_option(" xcb-composite" WITH_XCOMPOSITE) +colored_option(" xcb-xkb" WITH_XKB) +colored_option(" xcb-xrm" WITH_XRM) +colored_option(" xcb-cursor" WITH_XCURSOR) + +message(STATUS " Log options:") +colored_option(" Trace logging" DEBUG_LOGGER) + +if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG) + message(STATUS " Debug options:") + colored_option(" Trace logging (verbose)" DEBUG_LOGGER_VERBOSE) + colored_option(" Draw clickable areas" DEBUG_HINTS) + colored_option(" Print fc-match details" DEBUG_FONTCONFIG) + colored_option(" Enable window shading" DEBUG_SHADED) +endif() diff --git a/cmake/common/utils.cmake b/cmake/common/utils.cmake new file mode 100644 index 0000000..bc3cb7a --- /dev/null +++ b/cmake/common/utils.cmake @@ -0,0 +1,120 @@ +# +# Collection of cmake utility functions +# + +# message_colored {{{ + +function(message_colored message_level text color) + string(ASCII 27 esc) + message(${message_level} "${esc}[${color}m${text}${esc}[0m") +endfunction() + +# }}} +# colored_option {{{ + +function(colored_option text flag) + # Append version of option, if ${flag}_VERSION is set + set(version ${${flag}_VERSION}) + + if(NOT "${version}" STREQUAL "") + set(text "${text} (${version})") + endif() + + if(${flag}) + message_colored(STATUS "[X]${text}" "32;1") + else() + message_colored(STATUS "[ ]${text}" "37;2") + endif() +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() + +# }}} +# querylib {{{ + +function(querylib flag type pkg out_library out_include_dirs) + if(${flag}) + if(${type} STREQUAL "cmake") + find_package(${pkg} REQUIRED) + string(TOUPPER ${pkg} pkg_upper) + list(APPEND ${out_library} ${${pkg_upper}_LIBRARY}) + list(APPEND ${out_include_dirs} ${${pkg_upper}_INCLUDE_DIR}) + elseif(${type} STREQUAL "pkg-config") + find_package(PkgConfig REQUIRED) + pkg_check_modules(PKG_${flag} REQUIRED ${pkg}) + + # Set packet version so that it can be used in the summary + set(${flag}_VERSION ${PKG_${flag}_VERSION} PARENT_SCOPE) + list(APPEND ${out_library} ${PKG_${flag}_LIBRARIES}) + list(APPEND ${out_include_dirs} ${PKG_${flag}_INCLUDE_DIRS}) + else() + message(FATAL_ERROR "Invalid lookup type '${type}'") + endif() + set(${out_library} ${${out_library}} PARENT_SCOPE) + set(${out_include_dirs} ${${out_include_dirs}} PARENT_SCOPE) + endif() +endfunction() + +# }}} +# checklib {{{ + +function(checklib flag type pkg) + if(NOT DEFINED ${flag}) + if(${type} STREQUAL "cmake") + find_package(${pkg} QUIET) + set(${flag} ${${pkg}_FOUND} CACHE BOOL "") + elseif(${type} STREQUAL "pkg-config") + find_package(PkgConfig REQUIRED) + pkg_check_modules(PKG_${flag} QUIET ${pkg}) + set(${flag} ${PKG_${flag}_FOUND} CACHE BOOL "") + elseif(${type} STREQUAL "binary") + find_program(BIN_${flag} ${pkg}) + set(${flag} ${BIN_${flag}} CACHE BOOL "") + else() + message(FATAL_ERROR "Invalid lookup type '${type}'") + endif() + endif() +endfunction() + +# }}} diff --git a/cmake/modules/FindLibiw.cmake b/cmake/modules/FindLibiw.cmake new file mode 100644 index 0000000..c69b941 --- /dev/null +++ b/cmake/modules/FindLibiw.cmake @@ -0,0 +1,17 @@ +# This module defines +# LIBIW_FOUND - whether the libiw library was found +# LIBIW_LIBRARIES - the libiw library +# LIBIW_INCLUDE_DIR - the include path of the libiw library + +find_library(LIBIW_LIBRARY iw) + +if(LIBIW_LIBRARY) + set(LIBIW_LIBRARIES ${LIBIW_LIBRARY}) +endif(LIBIW_LIBRARY) + +find_path(LIBIW_INCLUDE_DIR NAMES iwlib.h) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libiw DEFAULT_MSG LIBIW_LIBRARY LIBIW_INCLUDE_DIR) + +mark_as_advanced(LIBIW_INCLUDE_DIR LIBIW_LIBRARY) diff --git a/cmake/templates/uninstall.cmake.in b/cmake/templates/uninstall.cmake.in new file mode 100644 index 0000000..79e6e89 --- /dev/null +++ b/cmake/templates/uninstall.cmake.in @@ -0,0 +1,23 @@ +set(INSTALL_MANIFEST "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +if(NOT EXISTS ${INSTALL_MANIFEST}) + message(FATAL_ERROR "Cannot find install manifest: ${INSTALL_MANIFEST}") +endif() + +file(READ ${INSTALL_MANIFEST} files) +string(REGEX REPLACE "\n" ";" files "${files}") +list(REVERSE files) + +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(EXISTS "$ENV{DESTDIR}${file}") + execute_process(COMMAND "@CMAKE_COMMAND@" + -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval) + if(NOT ${rm_retval} EQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif() + else() + message(STATUS "File $ENV{DESTDIR}${file} does not exist") + endif() +endforeach() diff --git a/cmake/templates/userconfig.cmake.in b/cmake/templates/userconfig.cmake.in new file mode 100644 index 0000000..9d05c60 --- /dev/null +++ b/cmake/templates/userconfig.cmake.in @@ -0,0 +1,8 @@ +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_SOURCE_DIR@/config" + DESTINATION "${USER_CONFIG_HOME}") diff --git a/common/ci/configure.sh b/common/ci/configure.sh new file mode 100755 index 0000000..9071874 --- /dev/null +++ b/common/ci/configure.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -eo pipefail + +if [ -d "$BUILD_DIR" ]; then + rm -Rf "$BUILD_DIR" +fi + +mkdir -p "${BUILD_DIR}" +cd "${BUILD_DIR}" + +if [ "$POLYBAR_BUILD_TYPE" != "minimal" ]; then + ENABLE_PULSEAUDIO=ON + ENABLE_NETWORK=ON + ENABLE_MPD=ON + ENABLE_CURL=ON + ENABLE_ALSA=ON + ENABLE_I3=ON + WITH_XRM=ON + WITH_XKB=ON + WITH_XRANDR_MONITORS=ON + WITH_XCURSOR=ON +fi + +if [ "$POLYBAR_BUILD_TYPE" = "tests" ]; then + BUILD_TESTS=ON +fi + +cmake \ + -DCMAKE_CXX_COMPILER="${CXX}" \ + -DCMAKE_CXX_FLAGS="${CXXFLAGS} -Werror" \ + -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ + -DBUILD_TESTS:BOOL="${BUILD_TESTS:-OFF}" \ + -DBUILD_DOC:BOOL="${BUILD_DOC:-OFF}" \ + -DWITH_XRANDR=ON \ + -DENABLE_PULSEAUDIO="${ENABLE_PULSEAUDIO:-OFF}" \ + -DENABLE_NETWORK="${ENABLE_NETWORK:-OFF}" \ + -DENABLE_MPD="${ENABLE_MPD:-OFF}" \ + -DENABLE_CURL="${ENABLE_CURL:-OFF}" \ + -DENABLE_ALSA="${ENABLE_ALSA:-OFF}" \ + -DENABLE_I3="${ENABLE_I3:-OFF}" \ + -DWITH_XRM="${WITH_XRM:-OFF}" \ + -DWITH_XKB="${WITH_XKB:-OFF}" \ + -DWITH_XRANDR_MONITORS="${WITH_XRANDR_MONITORS:-OFF}" \ + -DWITH_XCURSOR="${WITH_XCURSOR:-OFF}" \ + .. diff --git a/common/ci/summary.sh b/common/ci/summary.sh new file mode 100755 index 0000000..a6bfcf8 --- /dev/null +++ b/common/ci/summary.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -eo pipefail + +set -x + +"${CXX}" --version +cmake --version + +set +x + +echo "PATH=${PATH}" +echo "CXX=${CXX}" +echo "CXXFLAGS=${CXXFLAGS}" +echo "LDFLAGS=${LDFLAGS}" +echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" +echo "MAKEFLAGS=${MAKEFLAGS}" +echo "POLYBAR_BUILD_TYPE=${POLYBAR_BUILD_TYPE}" +echo "CMAKE_BUILD_TYPE=${BUILD_TYPE}" diff --git a/common/clang-format.sh b/common/clang-format.sh new file mode 100755 index 0000000..0a912c8 --- /dev/null +++ b/common/clang-format.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +main() { + if [ $# -lt 1 ]; then + echo "$0 DIR..." 1>&2 + exit 1 + fi + + # Search paths + search="${*:-.}" + + echo "$0 in $search" + + # shellcheck disable=2086 + find $search -regex ".*.[c|h]pp" \ + -exec printf "\\033[32;1m** \\033[0mFormatting %s\\n" {} \; \ + -exec clang-format -style=file -i {} \; +} + +main "$@" diff --git a/common/clang-tidy.sh b/common/clang-tidy.sh new file mode 100755 index 0000000..f0de51f --- /dev/null +++ b/common/clang-tidy.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +main() { + if [ $# -lt 2 ]; then + echo "$0 build_path [-fix] DIR..." 1>&2 + exit 1 + fi + + args="-p $1"; shift + + if [ "$1" = "-fix" ]; then + args="${args} -fix"; shift + fi + + # Search paths + search="${*:-.}" + + echo "$0 in $search" + + # shellcheck disable=2086 + find $search -iname "*.cpp" \ + -exec printf "\\033[32;1m** \\033[0mProcessing %s\\n" {} \; \ + -exec clang-tidy $args {} \; +} + +main "$@" diff --git a/common/release-archive.sh b/common/release-archive.sh new file mode 100755 index 0000000..222dc57 --- /dev/null +++ b/common/release-archive.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +set -euo pipefail + +git_url="https://github.com/polybar/polybar.git" +wd="$(realpath .)" + +usage() { + cat </dev/null + +find . -type d -name ".git" -exec rm -rf {} \+ + +cd "$tmp_dir" +tar cf "$archive" "polybar" +sha256sum "$archive" diff --git a/config.cmake b/config.cmake new file mode 100644 index 0000000..004bbdb --- /dev/null +++ b/config.cmake @@ -0,0 +1,423 @@ +;========================================================== +; +; +; ██████╗ ██████╗ ██╗ ██╗ ██╗██████╗ █████╗ ██████╗ +; ██╔══██╗██╔═══██╗██║ ╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗ +; ██████╔╝██║ ██║██║ ╚████╔╝ ██████╔╝███████║██████╔╝ +; ██╔═══╝ ██║ ██║██║ ╚██╔╝ ██╔══██╗██╔══██║██╔══██╗ +; ██║ ╚██████╔╝███████╗██║ ██████╔╝██║ ██║██║ ██║ +; ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ +; +; +; 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 = 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 + +[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 =