Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
overview
There are a number of use cases (#624 #707) where having more granular display events would be helpful. This PR aims to implement more specific display events, for use cases such as multi-monitor + window manager setups.
SketchyBar already had plumbing for several types of display events, but was only sending a
display_changeevent. This PR implements more of the display events:display_addeddisplay_removedWith some guidance, I'd also be open to adding the following, however haven't implemented them yet - just stubbed out.
display_moveddisplay_resizedI also would prefer not to have this PR held up on them, and so would be happy to revert them in this PR and implement in a separate one to get added/removed across the finish line faster.
My asks:
design decisions
Events approach
Currently, built-in sketchybar events include data in the
$INFOenv variable. When it comes todisplay_changethis is woefully inadequate for a number of reasons:$INFOalways includes the active display, which is unintuitive in many cases. For example, adding a 2nd display with ID2would fire adisplay_changeevent with$INFOof1, when nothing changed about display 1.To remedy this, there are 2 obvious (to me) possibilities:
display_changeevent. For example, a$TYPEthat contains added/removed/changed/etc. and then update the value provided via$INFOto be relevant and useful for the specific event type$INFOto provide the relevant data for that eventI believe option 1 (adding to
display_change) has several disadvantages:$INFOdisplay_changeevent requires users to write more code and therefore more bugs that lead to issues opened on SketchyBarFor these reasons, I opted for option 2 - add new event types for the other display events.
Monitor tracking
I wasn't able to find a cached store of the connected displays which would probably be the most reliable way to send events about monitor state changes. For display added/removed, I took a naive approach which is to:
display_active_display_count())uint32_t removed_display_id = bar_manager->active_displays;My M1 13" mac only supports 1 external display, so these assumptions are fine on my device. For users with multiple external displays, I don't know if this works correctly when monitor id 2 of 3 is disconnected:
I'm open to implementing something more complex to better handle these scenarios, but I don't have the hardware to test them so if someone knows where to find documentation on this behavior or has the hardware and wants to pull this fork, add event listeners, and figure out how it behaves, that would make it easier to design a good solution.
@FelixKratz if you have thoughts on how you'd like to see this implemented, I would appreciate that!
Display moved and resized events
I'm not sure what the intent is with these events, but @FelixKratz if you have an opinion of what data you'd like to have sent in
$INFOand where I can get that data, I'm happy to get these across the finish line too. I personally don't have a use case for these, so I am low confidence about what they should do.