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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Since the layout_change_event is raised for all monitors, check to make sure the
monitor of the bar matches the monitor on which the layout was changed before
setting the layout label.
When the module starts up, the title is not set until the client focus changes.
This commit fixes that by getting the window title of the currently selected
client in the module constructor.
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.
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.
label-state will be the label used for each tag. label-layout will show the
current layout. label-title will show the current window title.
label-title allows each monitor to show its selected window's title on the bar.
The xwindow module only shows the currently focused window on all monitors.
pin-tags will show all tags whether or not they are selected.
label-separator is inserted between workspaces.
enable-click will allow the user to view tags and toggle the view on tags.