diff --git a/.editorconfig b/.editorconfig index 57c08e6e..ff6aa42b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,9 @@ indent_style = space indent_size = 2 charset = utf-8 +[*.py] +indent_size = 4 + [Makefile] indent_style = tab indent_size = 2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5136ae1c..c557059d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added experimental support for positioning the tray like a module - `internal/backlight`: `scroll-interval` option ([`#2696`](https://github.com/polybar/polybar/issues/2696), [`#2700`](https://github.com/polybar/polybar/pull/2700)) - `internal/temperature`: Added `zone-type` setting ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2752`](https://github.com/polybar/polybar/pull/2752)) by [@xphoniex](https://github.com/xphoniex) +- `internal/xwindow`: `%class%` and `%instance%` tokens, which show the contents of the `WM_CLASS` property of the active window ([`#2830`](https://github.com/polybar/polybar/pull/2830)) ### Changed - `internal/fs`: Use `/` as a fallback if no mountpoints are specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2705`](https://github.com/polybar/polybar/pull/2705)) @@ -40,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - config: - Error reporting for deprecated config values ([`#2724`](https://github.com/polybar/polybar/issues/2724)) - Also monitor include-files for changes when --reload is set ([`#675`](https://github.com/polybar/polybar/issues/675), [`#2759`](https://github.com/polybar/polybar/pull/2759)) +- `internal/xwindow`: module does not crash when a tag is not provided in format ([`#2826`](https://github.com/polybar/polybar/issues/2826), [`#2833`](https://github.com/polybar/polybar/pull/2833)) by [@VanillaViking](https://github.com/VanillaViking) ## [3.6.3] - 2022-05-04 ### Fixed diff --git a/cmake/04-targets.cmake b/cmake/04-targets.cmake index 7424341b..0c1e8f51 100644 --- a/cmake/04-targets.cmake +++ b/cmake/04-targets.cmake @@ -17,13 +17,23 @@ add_custom_target(uninstall # 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) {{{ +# Runs clang-format on all source files +add_custom_target( + clangformat + COMMAND ${PROJECT_SOURCE_DIR}/common/file-runner.py + --dirs ${CLANG_SEARCH_PATHS} + -- clang-format -style=file -i --verbose + ) -add_custom_target(codeformat) -add_custom_command(TARGET codeformat - COMMAND ${PROJECT_SOURCE_DIR}/common/clang-format.sh ${CLANG_SEARCH_PATHS}) +# Dry-runs clang-format on all source files +# Useful for CI since it will exit with an error code +add_custom_target( + clangformat-dryrun + COMMAND ${PROJECT_SOURCE_DIR}/common/file-runner.py + --dirs ${CLANG_SEARCH_PATHS} + -- clang-format -style=file --dry-run -Werror --verbose + ) -# }}} # Target: codecheck (clang-tidy) {{{ add_custom_target(codecheck) diff --git a/common/clang-format.sh b/common/clang-format.sh deleted file mode 100755 index 0a912c8e..00000000 --- a/common/clang-format.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/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/file-runner.py b/common/file-runner.py new file mode 100755 index 00000000..a4d97c9f --- /dev/null +++ b/common/file-runner.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import sys +import os +import argparse +import subprocess + +EXTENSIONS = set('.' + ext for ext in ['c', 'h', 'cpp', 'hpp', 'inl']) + + +def get_files(dirs): + """ + Generator which yields all files in the given directories with any of the + EXTENSIONS. + """ + for dir in dirs: + for root, _, files in os.walk(dir): + for file in files: + path = Path(os.path.join(root, file)) + if path.suffix in EXTENSIONS: + yield path + + +def main(): + parser = argparse.ArgumentParser( + description=""" + Run command on all C/C++ source files in the given directories + """) + parser.add_argument('--dirs', type=Path, nargs='+', + help='Directories to search in') + parser.add_argument('command', nargs='+', + help='Command to which to pass found files') + args = parser.parse_args() + + all_files = list(str(file) for file in get_files(args.dirs)) + + if not all_files: + print("No files found") + sys.exit(1) + + result = subprocess.run(args.command + all_files) + print(f'Formatted {len(all_files)} files') + + if result.returncode != 0: + sys.exit(result.returncode) + + +if __name__ == '__main__': + main() diff --git a/doc/conf.py b/doc/conf.py index 628fc172..70c2cf2e 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -96,7 +96,7 @@ master_doc = 'index' # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +# language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/include/modules/xwindow.hpp b/include/modules/xwindow.hpp index 80c45e44..8b447031 100644 --- a/include/modules/xwindow.hpp +++ b/include/modules/xwindow.hpp @@ -11,13 +11,15 @@ POLYBAR_NS class connection; namespace modules { - class active_window { + class active_window : public non_copyable_mixin, public non_movable_mixin { public: explicit active_window(xcb_connection_t* conn, xcb_window_t win); ~active_window(); - bool match(const xcb_window_t win) const; + bool match(xcb_window_t win) const; string title() const; + string instance_name() const; + string class_name() const; private: xcb_connection_t* m_connection{nullptr}; @@ -33,7 +35,7 @@ namespace modules { enum class state { NONE, ACTIVE, EMPTY }; explicit xwindow_module(const bar_settings&, string); - void update(bool force = false); + void update(); bool build(builder* builder, const string& tag) const; static constexpr auto TYPE = "internal/xwindow"; @@ -41,6 +43,8 @@ namespace modules { protected: void handle(const evt::property_notify& evt) override; + void reset_active_window(); + private: static constexpr const char* TAG_LABEL{"