Commit Graph

1121 Commits

Author SHA1 Message Date
Patrick Ziegler
76ae61f892
xkb: Use xpp for xcb calls (#2536) 2021-10-14 15:57:46 +02:00
Tim Schumacher
281fdf6382
The xworkspaces module should wait for EWMH to become available (#2429)
* The xworkspaces module should wait for EWMH to become available

Before this change if EWMH wasn't available the xworkspaces module was
permanently disabled. When polybar was started alongside the window
manager e.g. from .xinitrc this caused a race condition between polybar
and the window manager and the xworkspaces module may or may not be
displayed. After this change polybar will wait for EWMH to become
available. This change closes #1915, see that issue for more details.

Curiously this only required the removal of the error condition which
used the be raised when EWMH wasn't available. The xworkspaces module
will show up on the bar as soon as the first EWMH event is processed by
the existing event handling code. I can't argue much about the
correctness of this patch but it seems to work flawlessly in my testing
with xmonad. I didn't test any other window managers. Note that removing
the error condition below which checks that _NET_DESKTOP_VIEWPORT is
available might make this work with pin-workspaces=true. I couldn't test
the effects of that change because I only tested with xmonad and xmonad
doesn't support _NET_DESKTOP_VIEWPORT, so I didn't make that change.

* xworkspaces: Remove check fo _NET_DESKTOP_VIEWPORT

Implementations that don't support it will just return an empty list for
get_desktop_viewports and pin-workspaces won't do anything.

* Update changelog

Fixes #1915

Co-authored-by: Tim Schumacher <tim@timakro.de>
Co-authored-by: patrick96 <p.ziegler96@gmail.com>
2021-10-11 14:40:14 +02:00
dvermd
231af35354
feat(ipc): hook, prev, next, reset module actions (#2528)
* WIP ipc actions

* feat(ipc): Add hook, prev, next and reset actions

Closes: #2464

* ipc: format code

* ipc: fix comparison

* Apply suggestions from code review

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* ipc: make index 0-based

* ipc: add 0-based indexing breaking change to Changelog

* ipc: restore 1-based index for  and  message

* ipc: fix initial=0 throwing an error

Co-authored-by: Martin Terneborg <martinterneborg@protonmail.com>
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2021-10-10 20:22:24 +02:00
dvermd
47b5910eda
Allow running polybar without BAR argument (#2526)
* Allow running polybar without BAR argument

The configuration file must declare a single bar to be able to not name
it.

* Check barname not in config and improve error message

* Revert README changes

* Add no bar in config file error detection
2021-10-07 14:48:47 +02:00
Patrick Ziegler
282b0f4e73
Create default config (#2511)
* Create default config and install to /etc/polybar

Closes #2405

* Search for config in /etc

We search in XDG_CONFIG_DIRS, /etc/xdg, and /etc but only for config.ini

Closes #2016

* Remove config installation from build.sh

* Remove userconfig cmake file

* Cleanup

* Cleanup default config

* Update CHANGELOG.md

Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>

* Update src/main.cpp

Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>

* Add tests for string functions

* Support loading bars from fallbacks in /etc

* Combine duplicate string_util::contains test

Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>
2021-10-05 13:07:19 +02:00
dvermd
98dffc292a
feat(xkeyboard): Icon matching using variant (#2521)
* 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>
2021-10-05 12:12:47 +02:00
dvermd
a2968127d1
fix typos (#2524) 2021-10-04 23:46:38 +02:00
Georgiy Komarov
40ae9b210b
config_parser: Improve error messages (#2522)
* config_parser: Improve error messages

This commit adds an additional context with configuration file name and
line number to some error messages in the config_parser.

* config_parser: Add file name and line number to invalid_name_error

* config_parser: Update unit tests to avoid crashes on regressions
2021-10-03 20:46:16 +02:00
Jérôme BOULMIER
2b1eb5337c fix(modules): move join in a new method 2021-10-03 12:00:41 +02:00
Madhav Prabhu C M
e5ab7e1c00
Notification string to a queue of strings (#2517)
Fixes #2469

* made inputdata to queue<string>

* changed back to front

* fixed move semantics issue while popping queue

* Removed ide file

* commented test lines

* review changes

* review changes

* Update CHANGELOG.md

* Cleanup

Co-authored-by: patrick96 <p.ziegler96@gmail.com>
2021-10-03 11:24:24 +02:00
patrick96
1a59599388 fix(modules): Avoid downcast in module constructor
The previous CAST_MOD(Impl) for the action_router constructor was
illegal because `this` is not yet of type Impl (because the subclass
constructor has not run yet).

The action_router now accepts std::function for its callbacks.

Fixes #2519
2021-10-03 03:18:39 +02:00
Patrick Ziegler
444120e664
script: Fix concurrency issues (#2518)
Fixes #1978

* Move tail and non-tail handler to method

Defining them in the constructor is ugly.

* script: Iterate over defined actions instead of fixed list

* Separate running logic and lock m_output

* Include POLYBAR_FLAGS in linker flags

* Stop using m_prev in script_runner

* Join module threads in stop function

Joining in the destructor may lead to UB because the subclass is already
deconstructed but the threads may still require it to be around (e.g.
for calling any functions on the instance)

* Cleanup script module

* Update changelog

* Remove AfterReturn class

* Remove m_stopping from script module

* Fix polybar not reading the entire line from child process.

For every `readline` call we created a new fd_streambuf. This means once
`readline` returns, the streambuf is destructed and and pending data in
its temporary buffer discarded and we never actually read it.

* Remove unused includes
2021-10-03 01:27:11 +02:00
patrick96
6b6bcf5080 Stop ipc_module subclassing static_module 2021-09-30 15:38:18 +02:00
patrick96
f55f584ef7 Remove main thread from static_module
This removes the need for any kind of synchronization because static
modules are completely running in the controller thread.
2021-09-30 15:38:18 +02:00
TheDoctor314
e798ed57a2 Implement 'env-*' option in script_module
This stores the key-value pairs specified for the script module.
The command to be executed must pass on this argument.
2021-09-28 22:16:07 +02:00
TheDoctor314
37cd63a356 Add env parameter in command::exec() 2021-09-28 22:16:07 +02:00
TheDoctor314
a7b978412c Add env parameter to exec_sh()
Before passing the cmd to exec() we set the required environment
variables.

Also add the test for it.
2021-09-28 22:16:07 +02:00
Patrick Ziegler
8afd5b71df
Integrate bar taskqueue into eventloop (#2510)
* Remove DEBUG_SHADED

Was disabled by default AND behind an #if 0

* Make TimerHandle expose more libuv functions

* Prepare for moving double clicks into eventloop

* Make eventloop available to bar

* Remove bar mutex

Everything in the bar is now in the same thread

* Move double-click handling to eventloop

* Extract double click deferred function into method

* Stop throttling clicks

* Increase double click interval to 400 and add option

double-click-interval in the bar section

Closes #1441

* Implement dimming using timer handles

* Remove taskqueue

* Remove unused dependencies

* Cleanup & Comments
2021-09-27 17:35:45 +02:00
TheDoctor314
55eb19fdc7
feat(ramp): Allow specifying ramp weights (#2505)
* feat(ramp) Implement ramp weights

*Add test for ramp weights

*[drawtypes/ramp] Implement ramp weights

Simply clone `label_t` weight no. of times in the icon list
This helps us not to change any of the calculations.

*Fix silly bug

Forgot to add a hyphen for the `weight` parameter.

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

*doc: add #1750 to CHANGELOG

* Fix compile error in ramp test

Use std::make_shared.
2021-09-22 21:46:20 +02:00
patrick96
98d9a882ea Fix polybar-msg compilation 2021-09-21 21:43:27 +02:00
patrick96
fa1240f4b6 Remove unused file_ptr 2021-09-21 21:43:27 +02:00
patrick96
3b6a950380 Remove unused factory.hpp imports 2021-09-21 21:43:27 +02:00
patrick96
0d1db206c6 Remove factory_util unique and shared
Equivalent to std::make_unique and std::make_shared
2021-09-21 21:43:27 +02:00
patrick96
560065540b Fix wrong assertion on network interface 2021-09-21 21:43:27 +02:00
patrick96
98919cbb77 Remove unused moodycamel concurrentqueue 2021-09-21 21:43:27 +02:00
patrick96
c922a94b67 Remove unused spin_lock 2021-09-21 21:43:27 +02:00
patrick96
0f72a2e0ea Remove unused throttle_util 2021-09-21 21:43:27 +02:00
patrick96
c29e4837df clang-format 2021-09-21 20:36:23 +02:00
patrick96
85d308cec8 Use libuv >= 1.3.0 2021-09-21 20:36:23 +02:00
patrick96
386eb57ba7 Reopen pipe path on EOF 2021-09-21 20:36:23 +02:00
patrick96
77b9cffaf8 Cleanup 2021-09-21 20:36:23 +02:00
patrick96
a158f0d7ec Add error callback for ipc handle 2021-09-21 20:36:23 +02:00
patrick96
52a3961602 Poll for X events in while loop
Otherwise we would only read a single event, even if multiple were
available causing delays.
2021-09-21 20:36:23 +02:00
patrick96
895c1a6b51 Handle fs_event and poll errors in handle wrapper 2021-09-21 20:36:23 +02:00
patrick96
db52106934 Support receiving IPC messages in multiple parts 2021-09-21 20:36:23 +02:00
patrick96
dd4088910e Deprecate throttle-output and throttle-output-for
The eventloop no longer uses them. libuv will coalesces multiple
uv_async_send if they happen one after another and this also leads to
coalescing of updates.
2021-09-21 20:36:23 +02:00
patrick96
511e73b3b5 Close handles in destructor 2021-09-21 20:36:23 +02:00
patrick96
91759a4c96 Store all handles inside eventloop
This is needed because the handle's lifetime has to be at least the
lifetime of the eventloop since the eventloop requires the handle's
memory during shutdown (for closing the handles).
2021-09-21 20:36:23 +02:00
patrick96
2551ea0205 Add wrapper for uv_async_t 2021-09-21 20:36:23 +02:00
patrick96
7b5285b51e Add wrapper for uv_timer_t 2021-09-21 20:36:23 +02:00
patrick96
309fd8221a Create wrapper for uv_pipe_t 2021-09-21 20:36:23 +02:00
patrick96
6d3bb2211e Only trigger async once eventloop has been setup 2021-09-21 20:36:23 +02:00
patrick96
2c7af2a60c Store reload flag in controller 2021-09-21 20:36:23 +02:00
patrick96
ce63305c1d Better way to notify controller 2021-09-21 20:36:23 +02:00
patrick96
e3cb94ef88 Use uv timer for delayed screenshot 2021-09-21 20:36:23 +02:00
patrick96
6ac5b7ebdd Remove config inotify_watch
We use libuv now for watching the file
2021-09-21 20:36:23 +02:00
patrick96
ba50bf0bc6 controller: Remove m_process_events field 2021-09-21 20:36:23 +02:00
patrick96
75ff5c3b14 Remove exit_terminate signal 2021-09-21 20:36:23 +02:00
patrick96
07da1a2967 Stop using sigabbrev_np
GNU extension
2021-09-21 20:36:23 +02:00
patrick96
b9642e4cf3 Move update events to eventloop
We can now completely remove the eventqueue thread
2021-09-21 20:36:23 +02:00
patrick96
f36224eaab Move quit event to eventloop 2021-09-21 20:36:23 +02:00
patrick96
ba341f584e Remove CHECK event
Not used
2021-09-21 20:36:23 +02:00
patrick96
c89fc7f73b Handle click commands in eventloop 2021-09-21 20:36:23 +02:00
patrick96
9d9fe8bffb Better error handling 2021-09-21 20:36:23 +02:00
patrick96
53ce1ae414 Move config watcher into eventloop 2021-09-21 20:36:23 +02:00
patrick96
f9d434052a Make UV handle wrappers more generic 2021-09-21 20:36:23 +02:00
patrick96
60ee63c0db eventloop: Throw exception for libuv errors 2021-09-21 20:36:23 +02:00
patrick96
3cc17a0e57 Move signal handling to eventloop class 2021-09-21 20:36:23 +02:00
patrick96
a2f50f3b90 Use uv_pipe_t for ipc 2021-09-21 20:36:23 +02:00
patrick96
249c3ec141 Use libuv for the controller's event loop 2021-09-21 20:36:23 +02:00
patrick96
2512123a6c
Merge remote-tracking branch 'origin/hotfix/3.5.7' 2021-09-21 18:22:57 +02:00
patrick96
a8cba9c43c fix(ipc): Replace all %pid% tokens
Fixes #2500
2021-09-13 14:18:18 +02:00
patrick96
6136c08d42 tray: Properly handle missing _XEMBED_INFO
The icon not supporting XEMBED is not fatal, we just treat is as always
mapped.

Fixes #2479
Fixes #2442
2021-09-13 00:12:33 +02:00
Patrick Ziegler
5011e66346
fix(net): Check if interface is valid first. (#2497)
Fixes #2496
2021-09-09 21:47:23 +02:00
Patrick Ziegler
9f828800fb
fix(xworkspaces): Fix scrolling (#2492)
The scroll handler had two issues:

* It did not respect the order the desktops where displayed in
* It would not wrap around on the first desktop because of an integer
  underflow

Fixes #2491
2021-09-04 14:36:01 +02:00
Luca Maltagliati
ddabe3f0f4
feat(memory): Tokens that switch between MiB and GiB (#2488)
* feat:add tokens to display memory in MiB when GiB val <= 1.0 (#2472)

* fix: correct swap_used calculation

* fix: pass variable by reference rather than by value

* fix: add precision arguments to filesize_gib_mib(); better condition

* doc: add #2472 to CHANGELOG

* fix: missing default argument values

* Apply suggestions from code review

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2021-09-04 13:14:13 +02:00
Vincent Bernat
151a263654
fix(monitor): do not include outputs when monitors are supported (#2485)
* fix(monitor): do not include outputs when monitors are supported

Previously, when splitting an output into two monitors, `polybar -m`
would report both the splitted monitors and the output. This was not
caught by the the clone detection as the detection works by removing
monitors contained into another monitors (and monitors were excluded
from that logic) and we want the other way around: outputs covered by
monitors should be ignored.

Instead of trying to detect covered outputs, the solution is quite
simple: when monitors are supported, do not consider outputs, unless
we request all outputs. A monitor can be set primary (and RandR
reports primary outputs as primary monitors). The only information we
would miss from monitors are things like refresh rate and EDID. We
don't need that, so we are fine.

As monitors are only created for connected output (and they are in
this case "active") or disconnected output if they are mapped (and
they are in this case "inactive"), I am a bit unsure if we have
exactly the same behaviour as previously when `connected_only` is set
to `false`.

As some modules require an output, we keep the output in the
`monitor_t` structure and we ensure it is correctly set when using
monitors. A monitor can have 0 or several outputs. We only handle the
0 and 1 cases. When a monitor has more outputs, only the first one is
used. AFAIK, only the xbacklight module needs that and I think we are
fine waiting for a user needing this module and merging monitors.

The C++ binding fail to expose the `outputs()` method to iterate over
the outputs of a monitor. This seems to be a bug in XPP. The field is
correctly defined in the RandR XML file and it works with the Python
binding.

```xml
	<struct name="MonitorInfo">
		<field type="ATOM" name="name" />
		<field type="BOOL" name="primary" />
		<field type="BOOL" name="automatic" />
		<field type="CARD16" name="nOutput" />
		<field type="INT16" name="x" />
		<field type="INT16" name="y" />
		<field type="CARD16" name="width" /> <!-- pixels -->
		<field type="CARD16" name="height" /> <!-- pixels -->
		<field type="CARD32" name="width_in_millimeters" />
		<field type="CARD32" name="height_in_millimeters" />
		<list type="OUTPUT" name="outputs">
		    <fieldref>nOutput</fieldref>
		</list>
	</struct>
```

Falling back to C only to access the list of outputs is not enough
because the list is appended to the structure and not visible through
the public API. When copied, the structure loses the list of monitors.

Also, change the mention "XRandR monitor" to "no output" when there is
no output attached. People using monitors know what it means and it is
useful to catch a future regression where we don't have an output at
all (which would break the brightness plugin).

Fix #2481

* Update CHANGELOG.md

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2021-09-02 18:07:21 +02:00
Vincent Bernat
5f3462240c
feat(ipc): allow receiving arbitrary text on IPC socket (#2463)
This adds the 'send' action to the ipc module that can be used to send arbitrary text to the module:

    polybar-msg action "#ipc.send.%{F#4444ff}hello%{F-}"

* feat(ipc): allow receiving arbitrary text on IPC socket

Instead of just allowing hook numbers to be executed, the user can
send arbitrary text and the IPC module will put it in the bar. The IPC
payload format is extended to accept an arbitrary string if the first
character after the module name is ':'.

    polybar-msg hook test :'%{F#4444ff}hello%{F-}'

Fix #2455

* Use actions for sending data to ipc module

* ipc: Don't use exceptions when no hooks are defined

* Update src/modules/ipc.cpp

Co-authored-by: patrick96 <p.ziegler96@gmail.com>
2021-07-11 20:42:28 +02:00
patrick96
523e4d6313 fix(fs): Only add spacing between shown mountpoints
Fixes #2458
2021-07-11 14:51:15 +02:00
patrick96
c901826317 Use CMAKE_EXE_LINKER_FLAGS
The newere target_link_options is not supported by our minimum cmake
version (3.5)
2021-07-11 14:47:26 +02:00
patrick96
3652d5fe0d cmake: Stop using CMAKE_* variables for flags
It is not recommended anyway and the -Werror flag set in CI was getting
set when compiling gtest, breaking our build.
2021-07-11 14:47:26 +02:00
Nolan Prochnau
06932007a0
Universal Visibility Action (#2320 cont'd) (#2426)
* Add toggle_visible action

* Add set_visible and set_invisible actions

* Rename toggle_visible method to match

`action_toggle_visible` -> `action_toggle_visibility`

Matches with `EVENT_TOGGLE_VISIBILITY`

* Update CHANGELOG

* Revert #2320 IPC commands

IPC commands are no longer necessary now that the actions are
implemented. Changed some method permissions as well to reflect this.

* Add logging and change action names

- `module_toggle`
- `module_show`
- `module_hide`

Delineate common actions to all modules with a `module_` prefix (for
future actions too)

* Update documentation
2021-07-07 21:43:49 +02:00
Carlos Gonzalez
bfa9b5d53e
Adding case to ignore T@ in bspwm (#2439)
* Adding case to ignore T@ in bspwm

* Adding entry to changelog for issue #2371
2021-05-27 20:05:37 +02:00
patrick96
c65f6857e1
Merge branch 'hotfix/3.5.6' 2021-05-24 01:07:24 +02:00
patrick96
cbe4521737 tray: Do not swallow clear_window exceptions 2021-05-24 00:47:22 +02:00
patrick96
ad987098ff fix(tray): Support clients with different depths
XCB_BACK_PIXMAP_PARENT_RELATIVE requires that the client has the same
depth as the tray window.

There was an issue with dropbox having a depth of 32 and the tray window
having a depth of 24 that caused the configuration of the icon to fail.
It would then be displayed outside of the bar because the catch block
was not hit (different exception).

We now just don't configure XCB_CW_BACK_PIXMAP. This seems to work and
is also what stalonetray does.

This does not fix the issue with dropbox having an arbitrary background.

Fixes #1679
Fixes #2430
2021-05-24 00:47:22 +02:00
Flexlolo
735a08ba7c
feat(bspwm): Option to scroll through occupied desktops only (#2428)
* Implement option occupied-scroll to bspwm module

* update changelog

* change default value of the setting
2021-05-13 12:59:13 +02:00
Tim Schumacher
2901e1e476
Add wm-restack=generic option that lowers polybar to the bottom of the stack (#2404)
* Add wm-restack=generic to lower polybar to the bottom of the stack

Previously wm-restack only supported bspwm and i3. Both have a special
top-level window that polybar detects and places itself directly above.
This patch adds wm-restack=generic which simply lowers polybar to the
very bottom of the stack. This option was tested and confirmed to work
with xmonad which doesn't have a special top-level window and therefore
doesn't require special handling like bspwm and i3.

Fixes #2205

* Update src/components/bar.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2021-04-02 00:48:48 +02:00
Ian Welker
97759ce585 Fixed issues with border corner radii 2021-03-29 20:17:48 +02:00
patrick96
2fd6d20999 fix(xworkspaces): Segfault for wrong _NET_CURRENT_DESKTOP
While it shouldn't happen with compliant WMs, it was possibe to crash
polybar with _NET_CURRENT_DESKTOP >= _NET_NUMBER_OF_DESKTOPS and this
should not be possible.

Includes polybar/xpp#31
Fixes #2398
2021-03-03 22:34:38 +01:00
patrick96
3f03b671bb fix(color): Rename type() function to get_type
In gcc5, this caused compilation errors because the type enum has the
same name.
2021-03-01 00:05:44 +01:00
patrick96
cf2653c8bd cmake: Do not use TARGET_EXISTS generator exprs
The TARGET_EXISTS generator expression was introduced only in cmake 3.12
2021-03-01 00:05:44 +01:00
Simon
cd71b96cf8
feat: Rounded bar border (#2359)
* Added rounded border

* Added feature to the changelog

* Changed implementation for better customisation

* Bugfixes

* Removed commented code

* Removed unused method

* Removed duplicate lines

* Moved degree to be a private constant

Co-authored-by: Simon <simondergruber@gmail.com>
2021-02-16 23:17:16 +01:00
the
698b96d17b
feat(backlight): add use-actual-brightness option (#2380)
* add use-actual-brightness option

* added to changelog

* added to changelog 2

* added to changelog 3
2021-02-16 10:02:33 +01:00
Patrick Ziegler
4f16a4fb6d
alsa: Call action_epilogue (#2381) 2021-02-15 23:49:21 +01:00
Jérôme BOULMIER
529843b6ba
Remove undefined behaviors and clean code (#1769)
* fix: avoid memory leaks in case of exceptions.

* fix(fs): remove undefined behavior when removing mounts in m_mounts

* cleanup: remove double checks

* fix: remove memory leaks

* cleanup(xresources): capture exception by reference

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2021-02-15 23:32:56 +01:00
zappolowski
99900323b7
feat(conf): Option to always show urgent workspaces in i3 (#2378)
When `pin-workspaces` is set to true using `show-urgent` will show
urgent workspaces on the bar even when the workspace is not associated
with the current monitor.
2021-02-15 21:31:34 +01:00
patrick96
50f127f1bc Cleanup 2021-02-12 20:01:22 +01:00
patrick96
c4fbf0023e Move action_context into separate file 2021-02-12 20:01:22 +01:00
patrick96
7a9f301830 Throw exception for unclosed action tags 2021-02-12 20:01:22 +01:00
patrick96
cd1d4fa183 Stop tracking action blocks in renderer
Dispatch can now directly get the current position from the renderer and
create action blocks with the proper coordinates.
2021-02-12 20:01:22 +01:00
patrick96
d89096c191 Remove tag headers from signal.hpp 2021-02-12 20:01:22 +01:00
patrick96
7a569c4b98 Remove mousebtn argument from action_open 2021-02-12 20:01:22 +01:00
patrick96
8fcd514168 dispatch: Add simple test 2021-02-12 20:01:22 +01:00
patrick96
464bedb33c Store all action info in action_context
The renderer is responsible for setting the start and end positions
while dispatch does the rest
2021-02-12 20:01:22 +01:00
patrick96
f359540b5d renderer: Move change_alignment into interface 2021-02-12 20:01:22 +01:00
patrick96
f0ee5ab8cd renderer: fix highlight_clickable_areas 2021-02-12 20:01:22 +01:00
patrick96
96239597ed Move most action state out of renderer
The renderer now only stores the positions of the actions because that
is specific to the renderer and because the actual position can only be
finalized after all the rendering is done because intitially the
positions are relative to the alignment and not the bar.
2021-02-12 20:01:22 +01:00
patrick96
0a474bb2f2 Move trivial formatting state into tags::context
The variables storing the current colors, attribute activations and font
were only used in a single place and can easily also be read from the
context.

This allows us to remove a lot of the state of the renderer.
2021-02-12 20:01:22 +01:00
patrick96
5d518e171e renderer: Use interface to render offset 2021-02-12 20:01:22 +01:00
tchici
c676d7e6f5
add reverse-scroll option for xworkspaces module (#2365)
* add reverse-scroll option for xworkspaces module

* move use of reverse-scroll option to when producing scroll action

* documented xworkspaces reverse-scroll option in changelog
2021-01-28 10:11:33 +01:00
Filip Banák
4ded401aab
Add initial support for an escape character (#2361)
Add a config parser method which, for now, deals only with escaping the
literal backslash character and logs an error message to inform the user
of the coming change.

The error message includes a properly escaped value for the user.

As a result of introducing an escape character('\'):

  - Warn the user of any unescaped backslashes, as they will not be
    treated as a literal character in the future

  - For now, still treat a single backslash as a literal character

  - Treat two consecutive backslashes as a single properly escaped
    literal backslash

Also:
  - Add documentation about the escape character to polybar(5) manpage
  - Add info about the escape character to changelog
  - Add testcases for ParseLineKeyTest
  - Add new test ParseEscapedValueTest

Resolves: First step in #2354

Improve value parsing

 - Take value arg in as an rvalue reference and move parsed value back
 - Remove unnecessary if statement
 - Rename function
 - Improve error message
 - Improve function description
 - Format

Add escape character documentation to manpages

Add information about the escape character to the polybar(5) manpage.

Add info about the esacape character to changelog

Add test cases for ParseLineKeyTest

Fix ParseLineKeyTest test cases

Also make config parser method parse_escaped_value private.

Add tests for escaped_value_parser method

Also remove unsued include statement

Simplify parse_escaped_value in config_parser

Remove unnecessary escaped value generation, so we do not have to keep
track of index differences.

Fix ParseEscapedValueTest test cases

Fix parse_escaped_value

Add more test cases for ParseLineKeyTest

Update CHANGELOG.md

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

Adress review

 - Adjust documentation
 - Small code changes

Improve parse_escaped_value

Add initial support for an escape character

Add a config parser method which, for now, deals only with escaping the
literal backslash character and logs an error message to inform the user
of the coming change.

The error message includes a properly escaped value for the user.

As a result of introducing an escape character('\'):

 - Warn the user of any unescaped backslashes, as they will not be
   treated as a literal character in the future

 - For now, still treat a single backslash as a literal character

 - Treat two consecutive backslashes as a single properly escaped
   literal backslash

Resolves: First step in #2354

Improve value parsing

 - Take value arg in as an rvalue reference and move parsed value back
 - Remove unnecessary if statement
 - Rename function
 - Improve error message
 - Improve function description
 - Format

Add info about the esacape character to changelog

Add test cases for ParseLineKeyTest

Fix ParseLineKeyTest test cases

Also make config parser method parse_escaped_value private.

Add tests for escaped_value_parser method

Also remove unsued include statement

Simplify parse_escaped_value in config_parser

Remove unnecessary escaped value generation, so we do not have to keep
track of index differences.

Fix ParseEscapedValueTest test cases

Add more test cases for ParseLineKeyTest

Adress review

 - Adjust documentation
 - Small code changes

Remove duplicate testcase from ParseLineKeyTest

Add initial support for an escape character

Add a config parser method which, for now, deals only with escaping the
literal backslash character and logs an error message to inform the user
of the coming change.

The error message includes a properly escaped value for the user.

As a result of introducing an escape character('\'):

 - Warn the user of any unescaped backslashes, as they will not be
   treated as a literal character in the future

 - For now, still treat a single backslash as a literal character

 - Treat two consecutive backslashes as a single properly escaped
   literal backslash

Resolves: First step in #2354

Improve value parsing

 - Take value arg in as an rvalue reference and move parsed value back
 - Remove unnecessary if statement
 - Rename function
 - Improve error message
 - Improve function description
 - Format

Fix ParseLineKeyTest test cases

Also make config parser method parse_escaped_value private.

Remove duplicate testcase from ParseLineKeyTest
2021-01-26 19:16:29 +01:00
patrick96
4154943f69 fix(xworkspaces): Handle -1 value for _NET_WM_DESKTOP
Fixes #2352
2021-01-15 20:34:15 +01:00
patrick96
74dcb4649d
Merge branch 'hotfix/3.5.4' 2021-01-07 13:52:28 +01:00
Patrick Ziegler
26be83f893
module: Implement action router (#2336)
* module: Implement proof of concept action router

Action implementation inside module becomes much cleaner because each
module just registers action names together with a callback (pointer to
member function) and the action router does the rest.

* Make input function final

This forces all modules to use the action router

* modules: Catch exceptions in action handlers

* Use action router for all modules

* Use action_ prefix for function names

The mpd module's 'stop' action overwrote the base module's stop function
which caused difficult to debug behavior.

To prevent this in the future we now prefix each function that is
responsible for an action with 'action_'

* Cleanup

* actions: Throw exception when re-registering action

Action names are unique inside modules. Unfortunately there is no way to
ensure this statically, the next best thing is to crash the module and
let the user know that this is a bug.

* Formatting

* actions: Ignore data for actions without data

This is the same behavior as before.

* action_router: Write tests
2021-01-04 10:25:52 +01:00
Bruno Cooper
7521da900f
Add support for %nwin% in xworkspaces label (#2329)
%nwin% tells the number of windows in a workspace
2021-01-04 10:17:27 +01:00
devsnek
f7c2d83ef2
feat(net): interface discovery (#2025) 2021-01-03 11:48:15 +01:00
Patrick Ziegler
412f4c723f
feat(xworkspaces): Persistent urgent hint (#2340)
* add urgent hint

* feat(xworkspaces): Fully implement urgency hint

Co-authored-by: Jérôme BOULMIER <jerome.boulmier@outlook.fr>
2020-12-31 15:49:39 +01:00
Nolan Prochnau
8e46e54cb3
feat: Module Visibility (#2320)
Modules can now also be shown and hidden using ipc commands:

    $ polybar-msg [-p PID] cmd hide.mymodule # Hides module mymodule
    $ polybar-msg [-p PID] cmd show.mymodule # Shows module mymodule
    $ polybar-msg [-p PID] cmd toggle.mymodule # Toggles visibility of mymodule

* Hopefully implement visibility checking

* Implement hide command

* Implement `show` and `toggle` commands

* Refactor and add some logging

* Run style checks and update CHANGELOG

* Get around unused parameter warnings

* Change `set_visible` to return nothing

* Make errors more informative

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update bar when changing module visibility

- Called in the module to maintain dependence on the signal emitter
- Update CHANGELOG to make changes more verbose

* wrong var

* Update include/modules/unsupported.hpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2020-12-27 16:05:26 +01:00
patrick96
e30d2c4c1f Remove tag compaction "optimizations"
The intention was to remove tags that won't have an effect and join
together consecutive tags.
However the patterns used can just as well appear in regular text, so
this can replace characters inside user defined text and not just
formatting tags.

Fixes #2331
2020-12-25 00:33:32 +01:00
patrick96
923d9ae061 Add cmake files for configuring individual targets
This makes the code a bit less messy. We barely need if(BUILD_...)
guards inside the cmake files, just the root CMakeLists.txt.
2020-12-24 02:20:38 +01:00
patrick96
c24a6999a4 refactor(cmake): Allow targets to be enabled individually
Each major target of polybar can now be enabled/disabled while
configuring (even polybar itself).

The cmake code specific to each target will only run if the target is
enabled.

This allows us to for example just build the documentation without
having to run all the cmake code related to compilation or having the
polybar dependencies installed (other than sphinx).
2020-12-24 02:20:38 +01:00
Kamui
89a723a4d9
feat(config): Try to load config.ini (#2324)
* Added .ini extension check to default config

* Added change to changelog and man page

* Added change to changelog and man page

* removed .vscode folder

* removed new lines in changelog
2020-12-23 17:52:30 +01:00
patrick96
218911c463
Merge remote-tracking branch 'origin/hotfix/3.5.3' 2020-12-23 17:42:12 +01:00
patrick96
1dc8d2f30e cmake: Make xrandr and xcomposite required
They were required before, but could technically be deactived (the
compilation would fail, but configuration was possible).

The WITH_XRANDR and WITH_XCOMPOSITE now no longer appear in the cmake
part. It still appears in the source code, but is always set to 1

Fixes #1536
2020-12-22 00:37:07 +01:00
patrick96
374716d329 cmake: Remove unused variables 2020-12-22 00:37:07 +01:00
patrick96
4f2a145f4f cmake: Update list of source files 2020-12-22 00:37:07 +01:00
Jérôme BOULMIER
b143e43491 enhancement(cmake): remove all mentions of "dirs" variable 2020-12-22 00:37:07 +01:00
Jérôme BOULMIER
cb728ac7c4 fix(cmake): restoring output directory 2020-12-22 00:37:07 +01:00
Jérôme BOULMIER
31fafa86f7 feat(cmake): removing globs and using imported targets 2020-12-22 00:37:07 +01:00
Nolan Prochnau
0d2838fcd5
feat(xkeyboard): Add variant support to layout label (#2163)
* Add variant support to xkeyboard layout label

Solves #316

* Run style checks, I guess?

* Add comment

* Return nothing if there is no variant

* Update CHANGELOG
2020-12-19 18:22:27 +01:00
Patrick Ziegler
33e691301d
fix(config): Don't treat an empty value as invalid (#2315)
An empty color value in the config should be treated as if no color was
specified (explicitly). This is the same behavior as before.
2020-12-18 23:33:03 +01:00
Filip Banák
6f13fe93a3
xkeyboard: Fix indicator spacing (#2306)
* Fix xkeyboard module spacing between the layout and indicators when indicators are empty.

* Simplify the empty label check.

* Remove permanently enabled SCROLL_LOCK, sorry.

* Another mistake.

* Update src/modules/xkeyboard.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update src/modules/xkeyboard.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update.

* Fix xkeyboard module spacing between the layout and indicators, when indicators are empty. And fix the spacing between indicators when some are empty.

* Add issue #2292 to fixed.

* Update CHANGELOG.md

Co-authored-by: Filip Banák <6111455-Filip62@users.noreply.gitlab.com>
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2020-12-17 20:49:10 +01:00
Patrick Ziegler
fd556525a8
New Tag Parser (#2303)
* refactor(color): Use enum class for color type

* Add testcases for tag parser

* Make tag parser a pull-style parser

Being able to parse single elements at a time gives us more fine-grained
error messages, we can also parse as much as possible and only stop
after an exception.

* fix(color): Parser did not check for invalid chars

* tag parser: First full implementation

* tag parser: Fix remaining failing tests

* tag parser: Replace old parser

* tag parser: Treat alignment as formatting tag

Makes the structure less complex and the alignment tags really are
formatting tags, they are structurally no different from the %{R} tag.

* tag parser: Cleanup type definitions

All type definitions for tags now live in tags/types.hpp, the parser.hpp
only contains the definitions necessary for actually calling the parser,
this shouldn't be included in many places (only places that actually do
parsing). But many places need the definitions for the tags themselves.

* Rename components/parser to tags/dispatch

* tag parser: Cleanup

* Add changelog
2020-12-17 20:37:28 +01:00
Bjoern Hiller
7c662ec44f feat(conf) Properties for {bottom,top}-{left,right} radius 2020-12-13 17:02:23 +01:00
patrick96
1c554dd0e0
Merge branch 'hotfix/3.5.1' 2020-12-12 13:28:57 +01:00
quandangv
ae1c6ca1b7 Fix 2283: Replace tokens at build() instread of update() 2020-12-12 12:33:21 +01:00
patrick96
47483a94f1 fix(process): fork_detached created zombie processes
Since the forked processes are still our children, we need to wait on
them, otherwise they become zombie processes.

We now fork twice, let the first fork immediately return and wait on it.
This reparents the second fork, which runs the actual code, to the init
process which then collects it.

Ref #770
2020-12-12 02:37:21 +01:00
patrick96
54e2490aa5 fix(logger): Wrong conversion function called
For some reason when passing some non-const strings to convert, the
convert(T&& arg) method was used instead of the one specialized for
strings.

This caused an error in clang because you can't pass objects with
non-trivial types to varargs functions.

The best solution I found was to just add a specialized function for
non-const strings.
2020-12-12 01:43:12 +01:00
patrick96
a45b5d0424 fix(build): UB when converting strings in logger
The memory returned was no longer valid because arg is destructed after
the function returns.
2020-12-12 01:43:12 +01:00
patrick96
df485f0a60 fix(module_formatter): Remove double moves 2020-12-07 15:35:38 +01:00
patrick96
bc87eb3b69 fix(battery): Crash when format-low not defined
This was a backwards-incompatible change introduced in #2199, however it
was caused because `module_formatter.has` throws an exception when the
format doesn't exist instead of just returning false.

Fixes #2262
Ref #2199
2020-12-07 15:35:38 +01:00
Patrick Ziegler
037f6e6c45
fix(xworkspaces): Never swallow updates (#2275)
If two WM events arrive withing 25ms of one-another, the second one does
not trigger a bar update.
The module state is still correct, it is just not reflected in the bar.

This somehow caused updates being swallowed in fluxbox, but only after
PR #882 was merged, even though that 25ms restriction existed long
before that.

Fixes #2272
2020-12-05 23:28:48 +01:00
Patrick Ziegler
82ebad5e7a
fix(timer_module): Ensure that interval > 0 (#2274)
Since 3.5.0, we use m_interval for a modulo operation, this crashes the
bar if the interval is 0. A non-positive interval shouldn't be allowed
anyway, so we now throw an exception in that case.

Fixes #2273
2020-12-05 22:58:38 +01:00
Patrick Ziegler
b2c515c73c
fix(config): Reintroduce multiple inheritance (#2271)
Pre 3.5.0, any key starting with 'inherit' was treated as an inherit
directive. This allowed for multiple inheritance even though it was
never inteded in that way.
3.5.0 removed that bug/feature by doing a strict check against 'inherit'

It seems people were relying on this behavior, so we are adding it back.
However multiple inheritance with multiple keys is also deprecated in
favor of the `inherit` key now supporting multiple space separated
sections.

This is because the config doesn't have a key order, but inheritance
does depend on the order the different section keys are copied over (if
multiple inherited sections define the same key).

Fixes #2269
2020-12-05 02:48:18 +01:00
Patrick Ziegler
c198859cd5
fix(menu): Wrong printf token in error message (#2264)
'level' is a string, not an integer
2020-12-03 15:12:59 +01:00
patrick96
11d1c2c5c7
Merge branch 'release/3.5.0' 2020-12-02 18:12:53 +01:00
Quan
39c73a8234
feat: Warn state for cpu, memory, fs, battery modules (#2199)
* [Temperature, Ramp] fix wrong icon for temperatures near base and warn temps

* [Temperature, Ramp] fix wrong icon for temperatures near base and warn temps

* Fix minor error

* Added WARN state for cpu module

* Implement WARN state for CPU, Memory modules, working on fs module

* Implement WARN state for fs module

* Simplify WARN state implementation for cpu and memory

* explicitly check percentage in get_by_percentage_with_borders

* Fixed silly error

* implement warn state on battery module, standardize the implementation on other modules

* minor fixes

* fix annoying error

* use more intuitive param name

* Fix percentage with borders bug

* Make requested changes
Hide the effect of warn states when unused

* Backward Compat: use no format instead of fallback label

* Reformat

* Refactor

* Reformat

* Reformat: convert tabs to spaces

* Reformat
2020-12-02 15:55:13 +01:00
Jan Palus
9f2459be8c
net: increase speedrate precision (#2054)
more granular units need lower precision, while less granular need
higher precision. assume sane default of:

unit | precision
KB   | 0
MB   | 1
GB   | 2

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2020-12-01 17:54:54 +01:00
Vlad Glagolev
5f67a8a12b
Respect interval default for tail = true (#2240) 2020-12-01 16:35:48 +01:00
patrick96
e89da58940
fix(builder): Properly apply alpha for fg and bg
It was not quite clear how try_apply_alpha should behave if the given
color was not ALPHA_ONLY. The implementation just returned 'this'.
However, the build relied on it returning the given color.

This broke all bg and fg settings in the entire bar.

To clear this up, we switch this around take the alpha channel of 'this'
and also return 'this' if it isn't ALPHA_ONLY.

Fixes #2255
2020-12-01 14:53:41 +01:00
Thibaut CHARLES
50d8a1ba06
feat(network): Ability to change speed unit text (B/s) (#2068)
New config option `speed-unit = B/s` will be used to suffix the upload and download speeds.

* mod::network: udspeed-unit to set network speed unit suffix

* Changed udspeed-unit to speed-unit
2020-11-29 14:15:27 +01:00
patrick96
52eee95bf8 controller: Detach shell commands from polybar
Shell commands triggered from action tags used to block polybar until
they finished.

Since we are not actually interested in the output of the commands, it
makes sense to run them completely detached from polybar and have
polybar not block when executing these commands.

Now the spawned child processes no longer get killed when polybar
exits. This is fine because polybar is not responsible for these
processes since they were explicitly started by the user through click
commands.

Ref: #770
Ref: #1680
2020-11-29 03:53:59 +01:00
Michał Drozd
0416093edc
Display correct(binary) unit prefixes in memory module (#2211) 2020-11-27 23:30:09 +01:00
patrick96
5007dae35a If bar bg, fg, border, or line color is alpha only, apply to default 2020-11-27 22:08:03 +01:00
patrick96
53c6f3b042 refactor(color): Better channel function names
(alpha|red|green|blue)_(d|i) are used for the four channels using
doubles or integers, respectively.
2020-11-27 22:08:03 +01:00
patrick96
477189e443 Cleanup 2020-11-27 22:08:03 +01:00
patrick96
4dfbba11c4 Make rgba class immutable 2020-11-27 22:08:03 +01:00
patrick96
413c911cd1 Move apply_alpha functionality into rgba 2020-11-27 22:08:03 +01:00
patrick96
eeab4f0d45 Print error message for invalid color strings 2020-11-27 22:08:03 +01:00