Commit Graph

723 Commits

Author SHA1 Message Date
patrick96
51184c7ead ipc: Remove unused global setting
None of the payload fields seem to be used. They were the only place
where EVENT_SIZE was used and why it had to be a macro (no variable
length arrays).
2019-11-01 11:12:40 +01:00
patrick96
3ea7600412 build: Move all possible variables into settings.cpp
Anything that doesn't have to be used as a macro
2019-11-01 11:12:40 +01:00
patrick96
6f882ba3b2 build: Move non-macro variables into settings.cpp
Since APP_VERSION is different for every commit and almost all file
include settings.hpp, the whole project has to be rebuilt for every
commit. With this, hopefully, this can be greatly reduced and only
changed files need to be rebuilt. This will also help ccache
2019-11-01 11:12:40 +01:00
patrick96
587dc6c84d bar: Make module separator a label
Some people use text modules instead of the `separator` key in the bar
section to better configure the separator (colors, fonts).
Since we disallowed the same module being used multiple times in #1534,
this will now print an error message.

This should help with this a bit.

Ref #1913
2019-10-27 16:02:33 +01:00
patrick96
8b310cc05d fix(build): Ignore noexcept-type for malloc_ptr_t
Since all of polybar is built at once, there is no chance that this is
ever linked to an object that was compiled with another `-std=`

Ref: https://stackoverflow.com/a/46857525/5363071
2019-10-26 22:28:47 +02:00
patrick96
2b31a3f112 fix(backlight): Use 'brightness' with amdgpu_bl0
The amdgpu driver seems to set 'actual_brightness' wrong.

Fixes #1870
Ref: https://github.com/Alexays/Waybar/issues/335
2019-10-21 14:37:29 +02:00
patrick96
fea579ec85 fix(bar): Configure window before remapping
Some WMs like i3 discard position information when unmapping the bar and
because of that the bar would be at the wrong position after being
remapped.

Fixes #1484
Ref: https://github.com/i3/i3/pull/3834
2019-10-21 13:22:51 +02:00
Patrick Ziegler
a119c3386b
controller: Print error for duplicate modules (#1534)
* refactor: Use flat module list if possible

Before if you wanted to iterate over all loaded modules you had to first
iterate over all blocks and then over their modules even if you didn't
care about alignment.

* refactor: setup modules in separate function

* controller: Print error for duplicate modules

You can't use the same name twice inside the module lists

E.g.

  modules-left = a b c
  modules-center = a
  modules-right = b

would print an error.

We only print an error for now because we don't want to break existing
configs. But in the future this should be properly enforced.
2019-10-21 10:20:45 +02:00
Matthias Viehweger
52f0623315 feat(xworkspaces): Support occupied workspaces (#882)
A workspace is occupied if it is not active and there is at least one window managed by the WM (`_NET_CLIENT_LIST`) that has set `_NET_WM_DESKTOP` to that workspace.

The behavior when `_NET_WM_DESKTOP` is not set is not yet clear but this is unlikely to happen since most WMs will position windows on some desktop.

Closes #874
Fixes #1444
Fixes #1033 

* Set Desktop OCCUPIED if a window moves there

This covers more of an edge-case. I did this first by accident, it might
vanish later on.

* Replace tracking change of WS with currently used WS

* Untrack occupied workspaces

* Track windows and their desktops in pairs

* Match type of occupied_desktops with current_desktop

Because the index needs to be matched later on, type mismatches would be non-ideal.

* Recreate the occupied desktops everytime and remove duplicates

* Readd support for moving windows to other desktops

* Use less characters to empty the vector

* Rename variable storing the desktops

* Recount windows on every occasion

This alone simplifies the management and the lookup for occupation of a
workspace

* Keep track of number of windows in every workspace

* Add debugging output that shall be removed before merging

* Remove obsolete TODO

* m_client_list should always be diff'd, since the desktop may change

Therefore we update the desktop-count tally every time the client_list
changes. It may just be a desktop-change without a change of
clients.size()...

* Add more logging-spam to understand window/desktop lifecycle

* Lock event-handler to serialize handling of events

* Fix occupied workspace counting and change to bool array

Also, performance improvements when diffing new and old client lists

* Fix crash when all clients are removed

* Conform to linter and styleguide

* Shorten conditional as it is standard enough

Since this only guards against 0-divisions, it can be shortened
without risking too much confusion down the road.

* Guard against multiple threads accessing and modifying data

Fixes #1444

Modification of internal data happens through the handle-method, while
the build-method tries to access the data structures for display. Since
some modifications clear e.g. the m_viewports, references may become
invalid between looping over them an accessing them.

The mutex should guard against this simultanuous access.

* Do not 'adopt_lock', because calls come from very different threads

To my understanding, adopt_lock has some dependency on the mutex-ownership. Since
the lock is once called from the inside (in handle) and once from the outside (in
build), there might be a problem. After brief testing, the segfaults happened fewer
times.

See #1444

* Also listen to _NET_WM_DESKTOP

In order to move a window from one desktop to another, it is sufficient
to set the desktop-property of that window. xmonad fires a lot of events
in the case of moving a window, herbstluftwm only updates the
_NET_WM_DESKTOP-atom of the window.

This change reloads the clientlist in order to correctly set the
desktop state "occupied".

* Describe need and use of mutex

It might be possible to relieve the guard in xworkspaces_module::handle,
but I am unsure about this. Since xmonad emits a lot of events on almost
every minor change, I would let the guard keep its post, avoiding
race-conditions in event-handling.

* Give temporary variables better names

* Clarify purpose of loop

About 80% of this comment are taken from
https://github.com/jaagr/polybar/pull/882#discussion_r255317363

* Remove merge-remainder

* Use a simpler method to list occupied desktops.

Co-authored-by: Jérôme Boulmier <jerome.boulmier@outlook.fr>

* Document m_clients field
2019-10-21 10:00:38 +02:00
julio-b
751c21cd37 feat(pulse): Show volume in decibels (#1894)
Adds `%decibels%` token to the pulseaudio module
2019-10-09 02:13:57 +02:00
patrick96
4ea188b3f9 fix(modules): Only add reset tag on non-empty modules
Adding the reset tag to empty modules makes polybar add margins and
separators for that empty module.

Fixes #1857

Ref #1596
2019-08-22 22:42:30 +02:00
patrick96
211b0bbfd8 Incorporate Reviews 2019-08-06 21:36:20 +02:00
patrick96
57d364a2fc Reset all tags at the end of a module
The %{PR} tag is introduced for this. It resets all colors as well as
the activation of the underline and overline and font.

This has become necessary because we don't track what raw tags a user
injects into the formatting string and otherwise their raw tags could
bleed through.

This doesn't touch action tags because even before raw action tags
weren't being tracked. Action tags also have the requirement that they
have to be used in pairs, so closing them prematurely could break things
(for example with click actions for the entire bar)
2019-08-06 21:36:20 +02:00
patrick96
3ebb0b0b03 builder: Simplify open tag tracking
Using a bit vector to track the active attributes does not really give a
significant speed increase, especially for only two attributes

Checking if a syntaxtag or an attribute exists in the map just adds
unnecessary code
2019-08-06 21:36:20 +02:00
patrick96
f967cd5f59 builder: remove BUILDER_SPACE_TOKEN
Was around since the first commit but no documentation why. It was only
used in the text module and doesn't appear in any public documentation,
so this doesn't break anything.
2019-08-06 21:36:20 +02:00
Patrick Ziegler
56e24992df
config_parser: Introduce stricter syntax conventions (#1377)
This is the next step to merge #1237 in stages.

Currently there are barely any restrictions on how the config can be
written. This causes things like config files with DOS line endings to
not be parsed properly (#1366) because polybar splits by `\n` and when
parsing section headers, it can't deal with the `\r` at the end of the
line and thus doesn't recognize any section headers.

With this PR we introduce some rules as to what characters are allowed
in section names and keys.
Note: When talking about spaces I refer to any character for which
`isspace()` returns `true`.

The rules are as follows:
* A section name or a key name cannot contain any spaces as well as any
of there characters:`"'=;#[](){}:.$\%`
* Spaces at the beginning and end of lines are always ignored when
parsing
* Comment lines start with `;` or `#` and last for the whole line. The
whole line will be ignored by the parser. You cannot start a comment at
the end of a line.
* Section headers have the following form `[HEADER_NAME]`
* Key-value lines look like this:
`KEY_NAME{SPACES}={SPACES}VALUE_STRING` where `{SPACES}` represents any
number of spaces. `VALUE_STRING` can contain any characters. If it is
*surrounded* with double quotes (`"`), those quotes will be removed,
this can be used to add spaces to the beginning or end of the value
* Empty lines are lines with only spaces in them
* If the line has any other form, it is a syntax error

This will introduce the following breaking changes because of how
underdefined the config syntax was before:
* `key = ""` will get treated as an empty string instead of the literal
* string `""`
* Any section or key name with forbidden characters will now be syntax
errors.
* Certain strings will be forbidden as section names: `self`, `root`,
* `BAR`. Because they have a special meaning inside references and so a
* section `[root]` can never be referenced.

This replaces the current parser implementation with a new more robust
one that will later be expanded to also check for dependency cycles and
allow for values that contain references mixed with other strings.

This PR also now expands the config paths given over the command line so
that `--config=~/.config/polybar/config` resolves properly.

Closes #1032
Closes #1694

* config_parser: Add skeleton with tests

First step in the config_parser develoment. Only tests functions that
are easily testable without many outside dependencies. Integration tests
will follow.

* config_parser: Implement parse_header

* config_parser: Implement get_line_type

* feat(string): Add trim functions with predicate

Not only trimming based on single character matching but based on a
freely specifiable predicate. Will be used to trim all spaces (based on
isspace)

* config_parser: Implement parse_key

* config_parser: Implement parse_line for valid lines

* config_parser: Throw exception on invalid lines

* config_parser: Remove line_no and file_index from parse_line

Cleaner to let the caller catch and fill in the line number and file
path

* string: Clear up misleading description of trim

Before, trim would remove all characters that *didn't* match the
predicate and thus the predicate isspace wouldn't work correctly. But
because we used the inverse (isnospace_pred) it all worked out, but if
the function was used with any other function, it wouldn't have given
the desired output

* config_parser: Implement parse_file

* config_parser: Switch operation to config_parser

This changes the way the config is invoked. Now main.cpp creates a
config_parser object which then returns the singleton config object from
the parse method. Subsequent calls to config::make will return the
already created config object as before

The config_parser does not yet have all the functionality of the old
parser: `inherit` directives are not yet resolved. Other than that all
the old functionality is implemented (creating sectionmap and applying
include-file)

Any sort of dependency detection (except for include-file) are still
missing

* config: Move xrm initialization to constructor

config_parser handles the detection of xrdb references and passes that
info to the config object.

This finally allows us to delete the config::parse_file function because
everything in it has been implemented (except for xrdb detection and
file error handling)

* refactor(config_parser): Cleanup

* config_parser: Set config data after initialization

Looks much cleaner this way

* config_parser: Expand include-file paths

* config_parser: Init xrm if the config uses %{xrdb references

* config_parser: Use same type of maps as in old impl

Polybar has some weird, not yet fixed, inheriting behaviour and it
changes depending on the order in which the config stores its data.
Using the same type of maps ensures that the behaviour stays the same.

* refactor(config_parser): Clearer invalid name error message

* config_parser: Don't allow reserved section names

Sections with the names 'self', 'BAR', 'root' could never be referenced
because those strings have a special meaning inside references

* config_parser: Handle inherit directives

This uses the old copy_inherited function, so this still suffers from
crashes if there are cyclic dependencies.
This also fixes the behaviour where any key that starts with 'inherit'
would be treated as an inherit directive

* config_parser: Clearer dependency cycle error message

* refactor(config_parser): Handle file errors when parsing

This removes the need to check if the file exists separately

* fix(config): expand config file path

Now paths using ~ and environment variables can be used as the config
path

* fix(config): Properly recognize xrdb references

* config_parser: Make messages more informative

* doc(config): Improve commenting

Comments now describe what the config_parser actually does instead of
what it will do.

We also now follow the rule that single line comments inside functions
should use `//` comments

* refactor: Move else on same line as curly braces

* fix(config_parser): Don't duplicate paths in `files`

* refactor(config_parser): Use else if for clarity

* fix(config): Undefined behavior in syntax_error

Before the custom what() method produced undefined behavior because the
returned string became invalid once the function returned.

* refactor(config): descriptive name for useless lines

is_valid could easily be confused as meaning syntactically invalid
without it being clarified in a comment

* refactor(config): Use separate strings instead of key_value

Takes just as much space and is much better to read

* fix(config_parser): TestCase -> TestSuite and fix macro call

Ref: #1644

* config_parser: use const string& in method args

* config_parser: Improve comments

* config_parser: Incorporate review comments
2019-08-06 19:41:31 +02:00
Jérôme BOULMIER
58d72c4f19 feat(github): add support for github enterprise (#1841) 2019-08-04 20:58:25 +02:00
Patrick Ziegler
f0c65e6cf0
fix(config): Allow empty string as ref fallback (#1831) 2019-07-01 23:33:01 +02:00
Jérôme BOULMIER
c650513b67 fix(i3): Surround ws names with quotes (#1798)
Fixes #1797
2019-06-04 23:34:16 +02:00
patrick96
5be532c51b refactor(font): More robust font size calculation
Originally the size function returned the scaled `size` property for
scalable fonts and the non-scaled `pixelsize` property for non-scalable
fonts. This caused lots of issues when that property was 0 (empty bars,
characters not drawn without warning, see references at the bottom).
This behavior was mostly observed on debian where `size` is set to 0 if
`pixelsize` is set.

We now try to use both properties for both types, but prefering `size`
for scalable fonts and `pixelsize` for non-scalable ones.

This behavior doesn't break existing correct behavior but now never
returns 0. It will always try to fall back to the other property or to
some fallback value if both properties are 0.

I originally thought this could also make font patterns more expressive
by being able to specify the size of scalable fonts directly in pixels
like so:

  Unifont:size=0:pixelsize=20

or to scale non-scalable fonts by forcing polybar to fall back to the
`size` property (which is always scaled):

  Wuncon Siji:pixelsize=0:size=20

But how these two patterns are matched by `fc-match` depends both on the
font and on the distro/fontconfig setup.

Ref #706
Ref #1450
Ref #1257
2019-06-03 00:49:48 +02:00
patrick96
a3e2e51ac9 build: remove xdamage extension
Unused

Ref: #1730
2019-06-03 00:46:12 +02:00
patrick96
38af08d29a build: remove xsync extension
Unused

Ref: #1730
2019-06-03 00:46:12 +02:00
patrick96
6ff2b2b37f build: remove xrender extension
Some build recipes (exherbo, sourcemage) for some reason enable this
even though it doesn't do anything any only causes compilation issues.

Ref: #1730
2019-06-03 00:46:12 +02:00
Jérôme BOULMIER
28b8877edc cleanup(cmake): remove useless variables (#1767)
They also caused a cmake warning when compiling with debug symbols
2019-05-17 16:51:16 +02:00
patrick96
e1e28f09f3 refactor(build): Remove version number namespace
I don't know the original intention behind this but it clutters up debug
traces and basically makes ccache useless.

The only benefit it has, giving version info in stacktraces, is kind of
void since we already ask for version information on github issues.
2019-05-17 16:49:47 +02:00
Roberto Santalla
b2b73b5d91 feat(battery): add %percentage_raw% token (#1756)
Displays real percentage instead of being set to 100 if percentage > full-at

* battery: added percentage_raw token, which ignores full-at

* battery: current_percentage returns raw, added clamping function instead

* battery: clamp percentage used by build()
Made clamp_percentage() const to allow its usage inside build()

* battery: read and return percentage in one line
2019-05-14 15:01:54 +02:00
Sergi Jimenez
9f7840c7d6 fix(build): Uninitialized local variable (#1759)
Fixes #1758
2019-05-05 22:09:03 +02:00
patrick96
f68a5e6ccf build: Add build type specific flags to -vvv 2019-04-24 08:11:13 +02:00
patrick96
d5112c9b66 git: Remove include .gitignore
The settings.hpp file is now generated in the build folder and doesn't
need to be included in the gitignore

Ref #1726
2019-04-08 09:01:48 +02:00
patrick96
0ab9fcdc38 refactor: Remove all mentions of icon_t
Is exactly the same label_t
2019-04-08 09:01:48 +02:00
patrick96
d1fe97b90f git: Clean up gitignore
Each directory is responsible for ignoring files
2019-04-08 09:01:48 +02:00
Kazufumi NOTO
7414e98008 feat(temp): Configurable lower bound for ramp (#1706)
Similar to warn-temperature, temps below `base-temperature` will use the first ramp icon.

Closes #1703
2019-04-07 18:36:09 +02:00
Jérôme BOULMIER
fca4151f36 fix(window): remove useless operator= and add default copy cstr (#1729)
Fixes compilation under GCC 9

The default copy constructor implicit generation is deprecated by C++ standard.

The window& operator=(const xcb_window_t win); operator seems to be useless.

Fixes #1728
Ref jaagr/xpp#16
2019-04-07 17:32:55 +02:00
patrick96
fc2d2db76f refactor(cmake): Determine version in cmake
We need to have the version string available in multiple places not just
the source code. It is now hardcoded in the root CMakeLists.txt and all
files that need it will be configured with cmake.

This also removed the unecessary duality of GIT_TAG and APP_VERSION and
GIT_TAG_NAMESPACE and APP_VERSION_NAMESPACE.
2019-04-05 23:43:37 +02:00
Jérôme BOULMIER
57b8fcc7cd refactor(cmake): move generated files in build directory (#1726) 2019-04-04 22:53:54 +02:00
DrunkenChicken
25f99c0a61 fix(xworkspaces): active ws upon ws deletion (#1713)
Active desktop was tracked via it's index, but when desktops are removed from `_NET_DESKTOP_NAMES` that index may become invalid.

Fixes #1710
2019-04-01 18:04:44 +02:00
Jérôme BOULMIER
31a25af3d3 fix(tray): fix offset for negative percentage (#1669)
tray-offset-{x,y} were clamped between [0, max_value] rather than [-max_value, max_value]. Therefore negative percentage were ignored.

Fixes #1666
2019-03-22 09:55:08 +01:00
Jérôme BOULMIER
25ef0299cb fix(tray_client): remove copy ctor & assignment operator (#1675)
tray_client class contains a reference so copy assignment operator is implicitly deleted.
the dtor unembed the window so copying the class could lead to bug so the copy ctor is also deleted.

Fixes #1674
2019-03-06 09:00:11 +01:00
Gilad Naaman
db9a83a83b feat(xkeyboard): Customizable indicators and layouts (#1559)
* `layout-icon-*` list that maps layouts to icons.
* `indicator-icon-*` list that maps indicators to off and on icons
* `label-indicator-off`
* `label-indicator-on` which replaces the now deprecated `label-indicator`
* `label-indicator-[on|off]-*` for each indicator. Overrides `label-indicator-on` and `label-indicator-off` 

Fixes #1558 
Closes #1048

* add icon support for xkeyboard layouts

* removed unneeded #include

* add sperate %icon% token that can be used in <label-layout>

* removed unneeded #include

* added caps lock indicator (was mentioned in wiki, but not actually implememnted) and support for indicator icons

* a few more fixes to make sure existing user configs are not broken

* ready to go

* Added an option to replace xkb indicator names

* Added labels for each indicator state

* Removed print left on accident

* Fixed review comments

* Update src/modules/xkeyboard.cpp

Co-Authored-By: Gilnaa <gilad@naaman.io>
2019-02-24 22:35:39 +01:00
striker.sh
ca4426a962 fix(xworkspace): Fully support _NET_DESKTOP_NAMES spec (#1579)
Ref https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472706208

Fixes #1491
Fixes #248
Closes #904
2019-02-08 13:32:31 +01:00
patrick96
b636baf082 signal_emitter: Don't swallow exceptions
If any signal receiver throws an exception for any reason after
receiving a signal, no one would find out about it because the signal
emitter just ignored exceptions

Also actually delivering the signal caused some exceptions because not
all signals have a receiver.

Resolves #1593
2019-02-05 11:50:57 +01:00
patrick96
b3ceedde76 refactor(bar): Remove bar_settings.center
Not used anywhere
2019-02-05 11:50:25 +01:00
Joost Sijm
8ca36d9e16 typo: replace 'alot' with 'a lot' (#1634)
This is bothering me alot
2019-01-29 17:54:38 +01:00
NBonaparte
1145681cf5
feat(monitor): use primary monitor as default (#1426)
If the monitor option isn't set, the primary monitor (if connected) is chosen as the default display.
2019-01-20 11:20:30 -08:00
Benno Fünfstück
f74c524fff fix(renderer): Handling of missing root pixmap (#1608)
Polybar had issues when there is no background set or set by a tool like imagemagick which doesn't add the root pixmap to the root window properties.

There's not much we can do about it, but at least polybar doesn't crash anymore.

Fixes #1582 
Fixes #1585 

* fix(tray_manager): only enable transparency if neccessary

Previously, we always enabled transparency

* fix(background_manager): avoid needless fetching

* fix(renderer): move logging message to correct place

* fix(background_manager): handle dummy pixmap (_XSETROOT_ID) right

* fix(background_manager): more initialization + don't free on error

Freeing on error is incorrect, since we could still be called again later in
which case we still need the resources.

* fix(background_manager): add more infos to trace logs

* fix(background): correct typo (XROOTMAP -> XROOTPMAP)

* fix(background_manager): do not report "no background" as error

* style(background_manager): use braces for if

Co-Authored-By: bennofs <benno.fuenfstueck@gmail.com>

* fix(background_manager): better error message for dummy pixmap

Co-Authored-By: bennofs <benno.fuenfstueck@gmail.com>

* style(background): some more style fixes

* fix(connection): initialize pixmap in all cases in root_pixmap()

* style(connection): improve readability using early return
2019-01-17 14:22:48 +01:00
patrick96
a0b888b5e6 fix(fs): Calculate free bytes properly
Seems this was missed in a682d2af91

This is now also consistent with what df does

Closes #743
2019-01-17 08:31:48 +01:00
patrick96
67f1ceaaca feat: format-font
Resolves #19
2019-01-17 08:31:14 +01:00
Ddone
46b8bb84ed feat(border): Percentage and pixel offset (#1592)
Uses the same X%:Z format as width, height and offset-*

Resolves #1567
2019-01-12 11:48:09 +01:00
patrick96
4a506d429d xbacklight: Use monitor-strict from bar settings
monitor-strict in the xbacklight module was never documented anywhere so
it's fine to remove it.
2019-01-08 17:23:28 +01:00
patrick96
e793082008 randr: Add separate key for exact monitor matching
This adds `monitor-exact = true` in the bar section

This also properly does best-match instead of first-match if multiple
matches exists. For example if there are two monitors HDMI2 and HDMI-2
and we try to match HDMI-2 with monitor-exact = false, until now HDMI2
would be matched. Now exact matches are always preferred.

Fixes #1532
2019-01-08 17:23:28 +01:00