From 918bc212ee2e5ab7fe60118d2f25f47c959a5ad1 Mon Sep 17 00:00:00 2001
From: Patrick Ziegler
Date: Mon, 19 Sep 2022 22:49:03 +0200
Subject: [PATCH 1/5] doc: Remove sphinx language setting (#2822)
Sphinx now emits a warning if `language` is set to `None`
---
doc/conf.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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.
From 3da26620222248bcf3252c039f1763869d399782 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 19 Sep 2022 22:45:31 +0200
Subject: [PATCH 2/5] xwindow: Also listen for WM_NAME changes
---
include/x11/atoms.hpp | 3 ++-
src/modules/xwindow.cpp | 5 ++---
src/x11/atoms.cpp | 4 +++-
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/include/x11/atoms.hpp b/include/x11/atoms.hpp
index ef42c1a6..f547710b 100644
--- a/include/x11/atoms.hpp
+++ b/include/x11/atoms.hpp
@@ -10,7 +10,7 @@ struct cached_atom {
xcb_atom_t& atom;
};
-extern std::array ATOMS;
+extern std::array ATOMS;
extern xcb_atom_t _NET_SUPPORTED;
extern xcb_atom_t _NET_CURRENT_DESKTOP;
@@ -48,3 +48,4 @@ extern xcb_atom_t ESETROOT_PMAP_ID;
extern xcb_atom_t _COMPTON_SHADOW;
extern xcb_atom_t _NET_WM_WINDOW_OPACITY;
extern xcb_atom_t WM_HINTS;
+extern xcb_atom_t WM_NAME;
diff --git a/src/modules/xwindow.cpp b/src/modules/xwindow.cpp
index 80383ce3..6deae450 100644
--- a/src/modules/xwindow.cpp
+++ b/src/modules/xwindow.cpp
@@ -42,6 +42,7 @@ namespace modules {
* Get the title by returning the first non-empty value of:
* _NET_WM_NAME
* _NET_WM_VISIBLE_NAME
+ * WM_NAME
*/
string active_window::title() const {
string title;
@@ -87,9 +88,7 @@ namespace modules {
update(true);
} else if (evt->atom == _NET_CURRENT_DESKTOP) {
update(true);
- } else if (evt->atom == _NET_WM_VISIBLE_NAME) {
- update();
- } else if (evt->atom == _NET_WM_NAME) {
+ } else if (evt->atom == _NET_WM_NAME || evt->atom == _NET_WM_VISIBLE_NAME || evt->atom == WM_NAME) {
update();
} else {
return;
diff --git a/src/x11/atoms.cpp b/src/x11/atoms.cpp
index 18641541..859c187e 100644
--- a/src/x11/atoms.cpp
+++ b/src/x11/atoms.cpp
@@ -39,9 +39,10 @@ xcb_atom_t ESETROOT_PMAP_ID;
xcb_atom_t _COMPTON_SHADOW;
xcb_atom_t _NET_WM_WINDOW_OPACITY;
xcb_atom_t WM_HINTS;
+xcb_atom_t WM_NAME;
// clang-format off
-std::array ATOMS = {{
+std::array ATOMS = {{
{"_NET_SUPPORTED", _NET_SUPPORTED},
{"_NET_CURRENT_DESKTOP", _NET_CURRENT_DESKTOP},
{"_NET_ACTIVE_WINDOW", _NET_ACTIVE_WINDOW},
@@ -78,5 +79,6 @@ std::array ATOMS = {{
{"_COMPTON_SHADOW", _COMPTON_SHADOW},
{"_NET_WM_WINDOW_OPACITY", _NET_WM_WINDOW_OPACITY},
{"WM_HINTS", WM_HINTS},
+ {"WM_NAME", WM_NAME},
}};
// clang-format on
From c44336573bf88c00230962204c3d8739cc03c54d Mon Sep 17 00:00:00 2001
From: patrick96
Date: Tue, 27 Sep 2022 23:42:29 +0200
Subject: [PATCH 3/5] build: Create clangformat(-dryrun) build targets
The clangformat target updates all files in-place while the
clangformat-dryrun target prints an error message for each format-change
clang-format would apply.
The latter exits with a non-zero error code if there are any changes.
---
.editorconfig | 3 +++
cmake/04-targets.cmake | 20 ++++++++++++-----
common/clang-format.sh | 20 -----------------
common/file-runner.py | 50 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 68 insertions(+), 25 deletions(-)
delete mode 100755 common/clang-format.sh
create mode 100755 common/file-runner.py
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/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()
From 5719d130fdab6d5cc7b4923097c8df7224bfa441 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 2 Oct 2022 12:13:32 +0200
Subject: [PATCH 4/5] feat(xwindow): %instance%, %class% from WM_CLASS
---
CHANGELOG.md | 1 +
include/modules/xwindow.hpp | 12 ++++++++----
include/x11/atoms.hpp | 3 ++-
include/x11/icccm.hpp | 3 ++-
src/modules/xwindow.cpp | 38 +++++++++++++++++++++++++------------
src/x11/atoms.cpp | 4 +++-
src/x11/icccm.cpp | 10 ++++++++++
7 files changed, 52 insertions(+), 19 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5136ae1c..1c05fc5b 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))
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{"