8000 Xkeyboard use variant by dvermd · Pull Request #2521 · polybar/polybar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Xkeyboard use variant #2521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 5, 2021
Merged

Conversation

dvermd
Copy link
Contributor
@dvermd dvermd commented Oct 3, 2021

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

The new configuration can use variant.

; layout-icon-[0-9]+ = layout;icon
; layout-icon-[0-9]+ = layout;variant;icon
; Assign each layout an icon that will be available as %icon% token for the
; <label-layout> tag. 
; In the first configuration form, the `layout` will try to match %layout% value without using any variant
; In the second configuration form, 
;     the `layout` will try to match %layout% value and the `variant` will try to match %variant%.
;     the `variant` can be empty to match against a %layout% with an empty %variant%
;     the `variant` can be the wildcard '_' to match a %layout% and any variant. 
;         This is equivalent to the first configuration form
;     the `layout` can be the wildcard '_' to match any %layout% with a specific %variant%
;     if both the `layout` and the `variant` are '_', the layout-icon-default it overwritten
; The ';variant;icon' is an invalid configuration because there can't be a %variant% without a %layout% and a warning is logged
; The ';icon' and ';_;icon' are  invalid configuration because they define a default icon and layout-icon-default must be used for that. A configuration error is issued and the module is not loaded.

Related Issues & Documents

Closes #2414

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

@dvermd
Copy link
Contributor Author
dvermd commented Oct 3, 2021

Part of the configuration I used for validating warning and errors:

[bar/bar_test_issue]
monitor = ${env:MONITOR:HDMI-1}
width = 100%
height = 18

font-0 = fixed:pixelsize=10;1

modules-center = i3 xkeyboard_test_issue xkb_test2 xkb_test3 xkb_test4 xkb_test5 xkb_test6 xkb_test7
scroll-up = #i3.prev
scroll-down = #i3.next

;==========================================================
[module/xkb_test_issue]
type = internal/xkeyboard
blacklist-0 = scroll lock

label-layout = %layout%-%icon%-%variant%

layout-icon-0 = us;U
layout-icon-1 = us;colemak;U2  

;==========================================================
[module/xkb_test2]
type = internal/xkeyboard
blacklist-0 = num lock
label-layout = 2-%layout%-%icon%
layout-icon-0 = us;U
layout-icon-1 = us;_;U2

;==========================================================
[module/xkb_test3]
type = internal/xkeyboard
blacklist-0 = num lock
label-layout = 3-%layout%-%icon%
layout-icon-0 = us;U
layout-icon-1 = us;U2

;==========================================================
[module/xkb_test4]
type = internal/xkeyboard
blacklist-0 = num lock
label-layout = 4-%layout%-%icon%
layout-icon-0 = us;colemak;U
layout-icon-1 = us;colemak;U2

;==========================================================
[module/xkb_test5]
type = internal/xkeyboard
blacklist-0 = num lock
label-layout = 5-%layout%-%icon%
layout-icon-default = DEF
layout-icon-0 = _;_;U

;==========================================================
[module/xkb_test6]
type = internal/xkeyboard
blacklist-0 = num lock
label-layout = 6-%layout%-%icon%
layout-icon-default = DEF
layout-icon-0 = _;U

;==========================================================
[module/xkb_test7]
type = internal/xkeyboard
blacklist-0 = num lock
label-layout = 7-%layout%-%icon%
layout-icon-0 = malformed value
layout-icon-1 = too;many;items;to;unpack
layout-icon-2 = ;_;icon

Edit: indicator-icon-default -> layout-icon-default

@codecov
Copy link
codecov bot commented Oct 3, 2021

Codecov Report

Merging #2521 (5d43ba1) into master (8afd5b7) will increase coverage by 0.20%.
The diff coverage is 30.23%.

❗ Current head 5d43ba1 differs from pull request most recent head aa461d5. Consider uploading reports for the commit aa461d5 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2521      +/-   ##
==========================================
+ Coverage   10.24%   10.44%   +0.20%     
==========================================
  Files         145      147       +2     
  Lines       10096    10155      +59     
==========================================
+ Hits         1034     1061      +27     
- Misses       9062     9094      +32     
Flag Coverage Δ
unittests 10.44% <30.23%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
include/components/config.hpp 0.00% <0.00%> (ø)
include/components/controller.hpp 0.00% <0.00%> (ø)
include/components/eventloop.hpp 0.00% <ø> (ø)
include/modules/ipc.hpp 0.00% <ø> (ø)
include/modules/menu.hpp 0.00% <ø> (ø)
include/modules/meta/base.hpp 0.00% <ø> (ø)
include/modules/meta/base.inl 0.00% <0.00%> (ø)
include/modules/meta/static_module.hpp 0.00% <0.00%> (ø)
include/modules/xworkspaces.hpp 0.00% <ø> (ø)
include/tags/action_context.hpp 100.00% <ø> (ø)
... and 37 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8afd5b7...aa461d5. Read the comment docs.

Copy link
Member
@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some reorganizing in parse_icons and applied clang-format.

The logic seems sound thought the layouticonset.get function is quite complicated and there are some redundancies. I added some comments for that.

8000
@@ -62,6 +62,7 @@ namespace string_util {
using hash_type = unsigned long;

bool contains(const string& haystack, const string& needle);
bool contains_nocase(const string& haystack, const string& needle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to contains_ignore_case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

@dvermd
Copy link
Contributor Author
dvermd commented Oct 4, 2021

Once reviewed, some commits may be merged to keep a nice history

variant = vec[1];
icon = vec[2];
}
const string& variant = size == 2 ? layouticonset::VARIANT_ANY : vec[1];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be a problem with this solution because VARIANT_ANY is a static constexpr const char* and the compiler will need to create a string from it to assign this const reference but this string may be created on the stack and the reference may not live long enough to be used correctly once the ternary operator finishes.
I may be wrong as I'm not fluent in c++ const_expr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is an issue here. The way I understand it is that from VARIANT_ANY a string object is created, a reference to which is stored in variant. The lifetime of this object is prolonged to match the lifetime of the reference.

@patrick96
Copy link
Member

I rewrote the best-match function because it bothered me that we have so many flags that we have to check. I also slightly changed the semantics that once we have a match of a certain priority, we can't have another match of the same priority. In practice this means if we have multiple case-insensitive matches, the first one is used.

Copy link
Member
@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add an entry in the changelog under the Added section.

@patrick96 patrick96 merged commit 98dffc2 into polybar:master Oct 5, 2021
quentino18 pushed a commit to quentino18/polybar that referenced this pull request Oct 6, 2021
* feat(string_util): add contains_nocase

* feat(xkeyboard): Enable icon by variant

* Cleanup

* string_util: add some cases to string test

* string_util: rename contains_nocase -> contains_ignore_case

* layouticonset: use contains_ignore_case

* layouticonset: apply renamings and remove dead code

* remove VARIANT_NONE and use empty string instead

* use emplace_back and add assert

* layouticonset: precompute condition

* xkeyboard: restore missing continue

* Cleanup parse_icons

* Always choose the first case-insensitive match

* Cleanup layouticonset.get

* update the changelog

Co-authored-by: patrick96 <p.ziegler96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xkeyboard extend icon str-match to variant
2 participants
0