Commit Graph

1843 Commits

Author SHA1 Message Date
Mihir Lad
56619b94a4 README.md: Replace with info about fork 2020-12-19 20:20:36 -05:00
Mihir Lad
78475b7806 dwm: Refactor code for new action handling
This is since the polybar 3.5.0 release
2020-12-19 19:53:00 -05:00
brendo
254a23344a proper wrap in prev_scrollable_tag 2020-12-19 19:50:15 -05:00
brendo
e107a510e8 tag scroll wrap and reverse 2020-12-19 19:50:15 -05:00
brendo
6cbe60be3a scrollable tags with m_tags_scroll_empty 2020-12-19 19:50:15 -05:00
brendo
44d5b81d5d default to false 2020-12-19 19:50:15 -05:00
brendo
b49b3ae613 Enable scrolling through available tags by scrolling on the window title bar 2020-12-19 19:50:15 -05:00
Mihir Lad
6648f5d8d0 settings.cpp.cmake: Remove DWM_SOCKET_PATH
Should have been removed in 416bb9888ce9387bdef4a0fe46b62a569db062b6
2020-12-19 19:50:15 -05:00
Mihir Lad
81b569f912 dwm: Throw module_error if reconnect fails
If reconnect fails, the rest of the module is useless. Better to throw a
module_error in case of any predictable dwmipc errors.
2020-12-19 19:50:15 -05:00
Mihir Lad
81349d657d dwm: Don't swallow exceptions in stop()
Don't want to mask any nasty bugs.
2020-12-19 19:50:15 -05:00
Mihir Lad
6584710b1e dwm: Close commands in reverse order of opening
Just for consistency and style. Doesn't actually affect behavior at the moment.
2020-12-19 19:50:15 -05:00
Mihir Lad
7e78844a8f dwm: Use m_state_labels.emplace instead of .insert
Looks cleaner.
2020-12-19 19:50:15 -05:00
Mihir Lad
fbe05890e0 dwm: Don't use trailing return types
Keep it consistent with the rest of the code.
2020-12-19 19:50:15 -05:00
Mihir Lad
803fe549c6 dwm: Make urgent tag state override focused state
A window can have the urgent hint set while being in a focused tag if that
window is not in focus. As a result, the urgent state should overrule the
focused state.

I also added a pretty truth table.
2020-12-19 19:50:15 -05:00
Mihir Lad
567b31bcc6 Remove dwm make dependency
dwm is not required to compile; it is only required to run the module, so
there's no reason to add it as a hard dependency.
2020-12-19 19:50:12 -05:00
Mihir Lad
de3748122f dwm: Get socket path from config, not env or cmake
Don't get the socket path from cmake or from an environment variable. Instead,
get it from the polybar config. If it's not specified, the default is
/tmp/dwm.sock which is default for the IPC patch.

This way is easier for the user to configure.
2020-12-19 19:48:48 -05:00
Mihir Lad
a0fa04d6a6 dwm: Fix log typo
Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
2020-12-19 19:48:48 -05:00
Mihir Lad
f17aef943c src/CMakeLists.txt: Remove dwm.cpp if dwm disabled 2020-12-19 19:48:48 -05:00
Mihir Lad
56135fbf62 dwm: Make compatible with jsoncpp v1.7.4
This version of jsoncpp requires a cast when calling run_command to disambiguate
the function call.
2020-12-19 19:48:48 -05:00
Mihir Lad
48aede9f63 README.md: Add dwm module 2020-12-19 19:48:26 -05:00
Mihir Lad
30e5008450 Fix build fail when xcb-util-xrm not installed
When this package is not installed, the struct randr type never gets fully
defined because randr.hpp never gets included. This causes the build to fail in
update_monitor_ref.

See issue mihirlad55/polybar-dwm-module#10.
2020-12-19 19:46:47 -05:00
Mihir Lad
feadaecf88 build.sh: Add -d to all features echo 2020-12-19 19:46:47 -05:00
Mihir Lad
e60f8f6dc7 config.cmake: Imporove dwm module comments 2020-12-19 19:43:05 -05:00
Mihir Lad
d1cdd70dd8 dwmipcpp: Update submodule 2020-12-19 19:43:05 -05:00
Mihir Lad
8c1085d6bd dwm: Only find secondary_layout if m_layout_click
Secondary layout would not be used otherwise.
2020-12-19 19:43:05 -05:00
Mihir Lad
7342b03240 dwm: Remove duplicate get_layouts 2020-12-19 19:43:05 -05:00
Mihir Lad
7b1a384c22 dwm: Add more info logging
To help with debugging.
2020-12-19 19:43:05 -05:00
Mihir Lad
48d661d51a dwm: Remove duplicate update_floating_label
This already exists further down in the constructor
2020-12-19 19:43:05 -05:00
Mihir Lad
8e205eeb15 dwm: Connect to socket in try-catch
Catch dwmipc errors and throw a module error if connecting to the socket fails.
2020-12-19 19:43:05 -05:00
Mihir Lad
16f90bea83 dwm: Reset m_ipc with nullptr
Reset with nullptr to properly release and delete m_ipc.
2020-12-19 19:43:05 -05:00
Mihir Lad
565fc7f329 dwmipcpp: Update submodule 2020-12-19 19:43:05 -05:00
Mihir Lad
bacfca5c3a dwm: Sleep before attempting to reconnect to dwm
Sleep before trying to reconnect to the dwm socket after a detected
disconnection. If dwm is restarted in place, in most cases the reconnect will
fail before dwm gets a change to re-setup itself and the socket. A 1-second
delay can provide enough time for dwm to reinitalize itself before polybar
attempts to reconnect. As a result, the module can recovoer instead of the
entire application just quitting.
2020-12-19 19:43:05 -05:00
Mihir Lad
339d059441 dwm: Only initialize and use tags if label is used
Check the formatter for the tags label, and if it doesn't exist, there's no need
to initialize the tags array or listen to tag change events. Also, check to see
if tags are being used before trying to update them from the
on_monitor_focus_change function.
2020-12-19 19:43:05 -05:00
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
4533cf5003 dwm: Catch IPCError instead of generic exceptions
Don't catch generic exceptions to avoid masking bugs. Only catch IPCError
exceptions since those are all minor errors.
2020-12-19 19:43:05 -05:00
Mihir Lad
871b9f8ba2 dwm: Add comments to config.cmake
Add documentation and comments to describe labels and formatting options.
2020-12-19 19:43:05 -05:00
Mihir Lad
3b430ee962 dwm: Rename layout token from %layout% to %symbol%
This token name is more indicative of what the token will be replaced with.
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
3fa404e9ff dwmipcpp: Update submodule for IPC patch v1.5.0 2020-12-19 19:43:05 -05:00
Mihir Lad
b3bf969a0a dwm: Simplify layout scroll command build
This way reduces the code a couple lines, takes less indentation, while still
being clear in functionality.
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
b37ae4f25a dwm: Use notice to log socket reconnection
Info does not normally show this info which is useful to know after a
disconnection.
2020-12-19 19:43:05 -05:00