Commit Graph

823 Commits

Author SHA1 Message Date
Mihir Lad
b6c2dc0dee dwm: Use functions to update labels
To keep consistency, use functions to update all labels. Since the labels have
tokens that have to be replaced, if this needed to be changed, or if the label
updating code needed to be changed, it could easily be done in one place without
having to scour the code for all places where the label is updated. It improves
refactorability.

This decouples the token replacement of labels from other functions and keeps
that code contained to the update label functions.

Since functions like update_title_label and update_floating_label already exist,
it makes sense to stick with this pattern of using functions to update the
labels. For updating the labels in different ways, overloaded functions can
simply be used.
2020-12-19 19:43:05 -05:00
Mihir Lad
02bd2e060d dwm: Add label-floating
This label is visible when the currently focused client is in floating mode and
detached from the layout. It uses the focused_state_change_event as well as the
focused_client_change_event to check if the focused client is floating and
updates m_is_floating accordingly which will enable/disbale the floating label
in the final output.

update_floating_label is called when the floating state of the client is not
known. The function queries dwm for the properties of the focused client and
sets m_is_floating accordingly.

This fixes issue #2.
2020-12-19 19:43:05 -05:00
Mihir Lad
33c8fb2ac7 dwm: Define command name instead of event name
Instead of defining the event name for each event, define the command name that
is to be called for that event. This simplifies the code since many events call
the same command. It is already clear from the cmd function which event is being
registered, so it is more clear to see the association between the command and
the event in the code this way.
2020-12-19 19:43:05 -05:00
Mihir Lad
f3047ab1e5 dwm: Add layout-reverse-scroll option
This option simply reverses the direction in which the scroll cycles through the
layouts.
2020-12-19 19:43:05 -05:00
Mihir Lad
a22b2ffcc3 dwm: Add layout scroll; rename settings
Rename settings and allow more flexible configuration by allowing the user to
enable click handlers for the tags and the layout label separately.

Add a scroll handler for the layout label so the user can scroll through the
available layouts. Enabling layout-scroll-wrap allows wrapping back to the
beginning/end of the array of available layouts.

next_layout and prev_layout take the address of a layout and returns the
next/previous layout in the m_layouts array if possible, wrapping if specified,
otherwise returns the same layout. This is used to for the layout scroll
handlers to cycle through layouts.
2020-12-19 19:43:05 -05:00
Mihir Lad
33a8226827 dwm: Rename label-state to label-tags
label-tags is more indicative of what the label represents.
2020-12-19 19:43:05 -05:00
Mihir Lad
5967ac3b0b dwm: Remove id param from update_title_label
Use m_focused_client_id to update the label. It makes more sense to use this
variable instead of passing a client id to the function.
2020-12-19 19:43:05 -05:00
Mihir Lad
bc16268d30 dwm: Add click handlers to label-layout
secondary-layout-symbol is the symbol of the layout to switch to when the layout
symbol is left-clicked. This symbol is used to look up the memory address of the
layout to set. The default is the monocle layout.

setlayoutsafe is the dwm command name for setting layouts. The argument is the
layout memory address. Left-clicking switches to the layout represented by
secondary-layout-symbol, and right-clicking switches to the previous layout
(specified by an argument of 0).

To keep track of the different layouts, the layouts are retrieved in the
constructor if the layout label is included and stored in m_layouts.
m_current_layout is updated with the address of the current layout.
m_default_layout is updated in the constructor to the first layout in the array
which is the default layout in dwm. m_secondary_layout is updated to the address
of the layout identified by secondary-layout-symbol.

The builder adds click handlers (if layout label is included) to the layout
symbol as described above. Left-clicking toggles between the secondary layout
and the default layout. Right-clicking toggles between the previous layout and
the current layout.

find_layout are a pair of functions for finding a layout by address or symbol
from the m_layouts array.
2020-12-19 19:43:05 -05:00
Mihir Lad
ecc881b9b3 dwm: Add build_cmd helper and rename events
build_cmd simplifies building a command string and helps avoid typo errors when
adding new commands since most commands follow the same format.

Rename EVENT_LCLICK and EVENT_RCLICK and to EVENT_TAG_LCLICK and
EVENT_TAG_RCLICK for clarity and to allow specifying multiple click commands in
the future without confusion.

Also remove std:: from vector since it is not needed.
2020-12-19 19:43:05 -05:00
Mihir Lad
f91fc2c7ab dwm: Add comments and documentation 2020-12-19 19:43:05 -05:00
Mihir Lad
27ea9773c6 dwm: Use type aliases for bit mask and window id
Do this for consistency and to avoid potential bugs by using the incorrect type.
2020-12-19 19:43:05 -05:00
Mihir Lad
a30a9b1e1b dwm: Replace pin-tags with label-empty
If pin-tags is set, there is no format defined for tags that are not occupied.
However defining a format for unoccupied tags makes the pin-tags setting
redundant since then the label can just be set to empty to not show unoccupied
tags.

Following the above reasoning, the pin tags setting is removed, and
state_t::NONE is renamed to state_t::EMPTY. This way if a user wants to display
empty tags, they can specify the format, otherwise they can simply set the label
to an empty string.
2020-12-19 19:43:05 -05:00
Mihir Lad
7883ef82fe dwm: Rename DEFAULT_TAG_LABEL to ..._STATE_LABEL
State makes more sense than tag.
2020-12-19 19:43:05 -05:00
Mihir Lad
399a797b45 dwm: Fix input handling
The command strings were not updated since the event variable formats changed.

Also, the EVENT_PREFIX already contained a dash, so an extra character would be
erased when adding 1.

Don't move the cmd string into the check_send_cmd function since if the first
event doesn't match, the cmd string would have been modified when passed to
the function again to check if the second event matches.
2020-12-19 19:43:05 -05:00
Mihir Lad
866c88c1d3 dwm: Reorganize module
Remove EVENT_SCROLL_{UP_DOWN} since it is not being used.

Change EVENT_PREFIX to include dash and event names to be just the name without
the prefix, for simplified parsing. Use check_send_cmd function to parse the
cmd, using the event name as the IPC command name, and the section after the
event name to be the argument. The format of a cmd would be "dwm-<event
name>-<arg>", so the cmd can easily be translated into an IPC command.

Call member functions for all dwmipc events for better organization and to avoid
cluttering the constructor. The dwmipc event functions are now just assigned to
a lambda that calls a member function.

Add update_tag_labels function for updating the tag labels based on their state
since this code is repetetive.

Add update_title_labels function since that code is also somewhat repetetive.

Move reconnect code to reconnect_dwm for better organization.

Use pointers to m_monitors array elements instead of holding onto indices, since
most of the time, a member of the Monitor element will need to be accessed.
These variables should always hold a valid address starting in the constructor,
so checks for nullptr should not be necessary. A monitor will always be active
and the bar will always be mapped onto a monitor.

Add some comments where needed.

Reorganize the constructor into a more logical format

Only subscribe to events if their labels are included in the default format.

Follow clang-tidy warnings and use trailing return types.

Move m_ipc->get_monitors to update_monitor_ref since in most cases where the
monitor references would need to be updated using geometry, m_ipc->get_monitors
would need to be called.
2020-12-19 19:43:05 -05:00
Mihir Lad
8e5b5258e2 Use focused_title_change_event to update titles
This fixes issue mihirlad55/polybar-dwm-module#4 where the title would not
update if the title of the currently focused window changed. The
focused_title_change_event is raised exactly when the focused window's
title changes, so this should automatically update the title using the callback
when necessary.
2020-12-19 19:43:05 -05:00
Mihir Lad
79f262fb18 Add dwm module
The module is currently working, but not fully stable. All tags specified in
config.cmake for internal/dwm are supported. This was implemented following the
i3 and bspwm modules. There is still some cleaning/refactoring to do to polish
the module up.
2020-12-19 19:43:01 -05:00
Mihir Lad
af6b2754b4 Add dwm module to unsupported.hpp 2020-12-19 19:30:00 -05:00
Mihir Lad
ad3666ed47 Update cmake/config files to include dwmipcpp
Include dwmipcpp as a library in cmake and config files, so it can be built
automatically. The configuration of dwmicpp was added to match that of i3 and
bspwm to maintain the same cmake workflow and style.
2020-12-19 19:28:34 -05: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
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
patrick96
4d2bdaa0bd
Merge branch 'hotfix/3.5.2' 2020-12-14 10:53:13 +01:00
Bjoern Hiller
7c662ec44f feat(conf) Properties for {bottom,top}-{left,right} radius 2020-12-13 17:02:23 +01:00
patrick96
94e1c64dff fix: Module type always empty string
The change in #2270 accidentally broke how we access module types.
module<Impl>::TYPE always points to the module superclass and it thus
accesses its empty TYPE field.

This mainly broke legacy action handling.

Ref #2270
2020-12-13 15:57:03 +01:00
patrick96
1c554dd0e0
Merge branch 'hotfix/3.5.1' 2020-12-12 13:28:57 +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
Vlad Glagolev
d665634484
Fix build with clang++ 3.4 (#2279) 2020-12-12 01:07:51 +01:00
Vlad Glagolev
f6231f351f
Add missing header (#2280) 2020-12-12 01:07:13 +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
Vlad Glagolev
3d6a7ffd4d
Fix linking when built with clang++ 3.4 (#2270) 2020-12-05 01:07:12 +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
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
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
patrick96
c9efd09f71 Load rgba from config instead of strings. 2020-11-27 22:08:03 +01:00
patrick96
8e10c046fa Move all channel functions into rgba class
Since we use rgba everywhere, extracting channels from uint32_t directly
is not necessary anymore.
2020-11-27 22:08:03 +01:00
patrick96
3655106a14 Adapt the renderer side to always use rgba 2020-11-27 22:08:03 +01:00
patrick96
64fa6469ab Remove unused hex function
This allows us to also remove the cache class which was only used here
2020-11-27 22:08:03 +01:00
patrick96
b238ec3403 Move most color_util functions into rgba class
The intent is for every color to be stored in a rgba instance

The rgba class now stores the color in a 32 bit integer to save space

This also removes the unused class rgb and moves everything else into a
cpp file.

Many functions also had weird template parameters. For example
alpha_channel<unsigned short int> would give a 2 byte number with the
alpha channel byte in both bytes.
color_util::hex would return a hex string with alpha channel if unsigned
short int was given and without if unsigned char was given. Even more
curiously those parameters were passed to *_channel and the result
nevertheless truncated to 8bits.
2020-11-27 22:08:03 +01:00
patrick96
75eb41f5ad config: Better error messages when opening files
If a config file is a directory, ifstream would just read it as an empty
file without any errors.

Failing early here is a good idea.
2020-11-26 21:06:35 +01:00