FelixKratz / SketchyBar

A highly customizable macOS status bar replacement
https://felixkratz.github.io/SketchyBar/
GNU General Public License v3.0
5.62k stars 86 forks source link

Popups not showing at all with external monitor #316

Closed chrisgrieser closed 1 year ago

chrisgrieser commented 1 year ago

So I have two devices: 1) iMac, macOS 13.0.1 (M1), uses only the built-in display / no external display 2) mac mini, macOS 13.0.1 (M1), with exactly one external display

On the Mac mini, popups do not show at all, on the iMac popups show. I tested it with this minimal config:

sketchybar \
    --default popup.drawing=true \
    --add item foo left --set foo label="bar" \
    --add item baz popup.foo --set baz label="nek"

on the iMac, I get:

Pasted image 2023-01-17 20 22 15

on the mac mini, I get with exactly the same config:

Pasted image 2023-01-17 20 22 45

I am not sure whether it's actually the external monitor that's causing this, but it's the only real difference between the two devices. Both are M1, both have the same macOS version, both are on sketchybar 2.13.2

FelixKratz commented 1 year ago

Popups only show on the display which is currently active. My external monitor shows popups fine if it is the active display.

I will try to find the problem, but it is a little bit hard to reproduce for me.

Maybe you can try to find the reason in the code by stepping through the popup.c file with a debugger.

Could you try to set the popup as topmost? Does this change anything?

chrisgrieser commented 1 year ago

Popups only show on the display which is currently active. My external monitor shows popups fine if it is the active display.

I have only one display at the mac mini though 🤔

Could you try to set the popup as topmost? Does this change anything?

I'll have a look when I am back in the office (where the mac mini is)

Maybe you can try to find the reason in the code by stepping through the popup.c file with a debugger.

yeah, with exactly zero knowledge of C, I think that's beyond my skillset 😅

FelixKratz commented 1 year ago

Everything else works on the mac mini setup? Could you post the query of the baz item from both setups? sketchybar --query baz it might contain some relevant information

FelixKratz commented 1 year ago

I have a strong suspicion as to why this happens, can you try to run the below commands on the problematic machine to see if the popup renders correctly afterwards:

sketchybar --set foo popup.drawing=off
sketchybar --set foo popup.drawing=on

I think the popup system needs a complete refactor along with the bar logic at some point, as I am not really happy with it anymore and there is some potential to decrease duplicate code and with that a lot of quirks could be resolved.

chrisgrieser commented 1 year ago

Okay, I am now in the office again with the mac mini.

I have a strong suspicion as to why this happens, can you try to run the below commands on the problematic machine to see if the popup renders correctly afterwards:

sketchybar --set foo popup.drawing=off
sketchybar --set foo popup.drawing=on

nothing happens, no changes in the menubar, and also no messages in the Terminal

Could you post the query of the baz item from both setups? sketchybar --query baz it might contain some relevant information

This is the output in the mac mini.

{
    "name": "baz",
    "type": "item",
    "geometry": {
        "drawing": "on",
        "position": "popup",
        "associated_space_mask": 0,
        "associated_display_mask": 0,
        "ignore_association": "off",
        "y_offset": 0,
        "width": 0,
        "padding_left": 0,
        "padding_right": -1,
        "background": {
            "drawing": "off",
            "color": "0x0",
            "border_color": "0x0",
            "border_width": 0,
            "height": 0,
            "corner_radius": 0,
            "padding_left": 0,
            "padding_right": 0,
            "y_offset": 0,
            "clip": 0.000000,
            "image": {
                "value": "(null)",
                "drawing": "off",
                "scale": 1.000000
            },
            "shadow": {
                "drawing": "off",
                "color": "0xff000000",
                "angle": 30,
                "distance": 5
            }
        }
    },
    "icon": {
        "value": "",
        "drawing": "on",
        "highlight": "off",
        "color": "0xffffffff",
        "highlight_color": "0xff000000",
        "padding_left": 0,
        "padding_right": 0,
        "y_offset": 0,
        "font": "Hack Nerd Font:Bold:14.0",
        "width": 0,
        "align": "left",
        "background": {
            "drawing": "off",
            "color": "0x0",
            "border_color": "0x0",
            "border_width": 0,
            "height": 0,
            "corner_radius": 0,
            "padding_left": 0,
            "padding_right": 0,
            "y_offset": 0,
            "clip": 0.000000,
            "image": {
                "value": "(null)",
                "drawing": "off",
                "scale": 1.000000
            },
            "shadow": {
                "drawing": "off",
                "color": "0xff000000",
                "angle": 30,
                "distance": 5
            }
        },
        "shadow": {
            "drawing": "off",
            "color": "0xff000000",
            "angle": 30,
            "distance": 5
        }
    },
    "label": {
        "value": "nek",
        "drawing": "on",
        "highlight": "off",
        "color": "0xffffffff",
        "highlight_color": "0xff000000",
        "padding_left": 0,
        "padding_right": 0,
        "y_offset": 0,
        "font": "Hack Nerd Font:Bold:14.0",
        "width": 0,
        "align": "left",
        "background": {
            "drawing": "off",
            "color": "0x0",
            "border_color": "0x0",
            "border_width": 0,
            "height": 0,
            "corner_radius": 0,
            "padding_left": 0,
            "padding_right": 0,
            "y_offset": 0,
            "clip": 0.000000,
            "image": {
                "value": "(null)",
                "drawing": "off",
                "scale": 1.000000
            },
            "shadow": {
                "drawing": "off",
                "color": "0xff000000",
                "angle": 30,
                "distance": 5
            }
        },
        "shadow": {
            "drawing": "off",
            "color": "0xff000000",
            "angle": 30,
            "distance": 5
        }
    },
    "scripting": {
        "script": "(null)",
        "click_script": "(null)",
        "update_freq": 0,
        "update_mask": 0,
        "updates": "on"
    },
    "bounding_rects": {
        "display-1": {
            "origin": [ -9999.000000, -9999.000000 ],
            "size": [ 1.000000, 1.000000 ]
        }
    }
}
FelixKratz commented 1 year ago

I think the problem is connected to defaulting popup.drawing=on, could you try this?

sketchybar --add item foo left --set foo label="bar" \
           --add item baz popup.foo --set baz label="nek"

sketchybar --set foo popup.drawing=on
FelixKratz commented 1 year ago

I have found a couple of problems with the inheritance system and popups and have tried to resolve them. Could you try with current master version by running:

brew services stop sketchybar
brew uninstall sketchybar
brew install sketchybar --head
brew services start sketchybar

after testing you can go back to the stable channel by running:

brew services stop sketchybar
brew uninstall sketchybar
brew install sketchybar
brew services start sketchybar
chrisgrieser commented 1 year ago

I'll only be back in the office next week, I will test it then

chrisgrieser commented 1 year ago

I think the problem is connected to defaulting popup.drawing=on, could you try this?

sketchybar --add item foo left --set foo label="bar" \
           --add item baz popup.foo --set baz label="nek"

sketchybar --set foo popup.drawing=on

no popup shown here: Pasted image 2023-01-24 13 59 19


I have found a couple of problems with the inheritance system and popups and have tried to resolve them.

no dice, still lacking the popup.

FelixKratz commented 1 year ago

no dice, still lacking the popup.

I will keep this in mind and go through the logic again some time soon, but I am out of ideas for now sadly.

chrisgrieser commented 1 year ago

hah! I think I found part of the solution.

On a hunch, I tried connecting a different monitor. And indeed, as soon as as there is a second monitor connected, the popups do show up on the one monitor designated as main screen. However, if there is only one monitor connected – regardless which one – the popups do not show up.

My suspicion is that while there is only one display connected, it is not marked as "main", and sketchybar therefore does not display the popups there. But as soon as a second monitor is connected, one of the two monitors gets marked as main, sketchybar picks up on it and displays the popups on the one marked as main. Could be an issue specific to the mac mini, since it has no built-in monitor which gets automatically registered as the main one by default maybe? (Cannot test this, since I do not have a second monitor at home.)

So I am not sure whether this is an issue with sketchybar or with how macOS registers displays, but if I am right, a potential solution might be to modify the "display popups on main display" logic with "if there is only one display, display popups on all displays".

FelixKratz commented 1 year ago

Thats a nice find! I have an idea what it might be, if your hypothesis is true that sketchybar fails to properly detect the active display then we can find out by associating an item with the primary display. If it shows, your hypothesis might be incorrect, but if it doesn't show than you are correct. I.e. try this:

sketchybar --add item test left --set test label="test" associated_display=1
chrisgrieser commented 1 year ago

running this on the stable branch (not the latest on master) displays test correctly on. :S

FelixKratz commented 1 year ago

running this on the stable branch (not the latest on master) displays test correctly on. :S

Ah, actually the test should be:

sketchybar --add item test left --set test label="test" associated_display=active
chrisgrieser commented 1 year ago

running this on the stable branch (not the latest on master) displays test correctly on. :S

Ah, actually the test should be:

sketchybar --add item test left --set test label="test" associated_display=active

ran it in the terminal, and nothing gets added to the sketchybar!

FelixKratz commented 1 year ago

Tried a fix with this commit: https://github.com/FelixKratz/SketchyBar/commit/f48e9217b6bbf3854590b6cd420070a7d5c59f70 can you try and let me know?

chrisgrieser commented 1 year ago

how do I try it? Again with brew install sketchybar --head ?

FelixKratz commented 1 year ago

how do I try it? Again with brew install sketchybar --head ?

Yes:

brew services stop sketchybar
brew uninstall sketchybar
brew install sketchybar --head
brew services start sketchybar
chrisgrieser commented 1 year ago

Tried a fix with this commit: f48e921 can you try and let me know?

just tried it, still not working, unfortunately

FelixKratz commented 1 year ago

Tried a fix with this commit: f48e921 can you try and let me know?

just tried it, still not working, unfortunately

Ok, but thats fine, I will now try progressively more aggressive ways to fix this, now that we know what it is. One interesting thing would be to know if clicks on the bar work or not.

chrisgrieser commented 1 year ago

sure, have standardized minimal config I should use for that?

(Also, I am leaving the office soon and most likely will not be in for a few days, so narrowing down the issue will potentially have to wait till next week)

FelixKratz commented 1 year ago

Ok, so I have now made some more aggressive changes that should make sure that the only connected display is always the active one. This is also a faster code path than the path for multiple displays, such that it is an improvement either way. It seems that for some reason your external display never got registered as the display that is active from the system menu bar point of view. Lets see if this fixes it.

For testing the click of an item you can use this snippet:

sketchybar --add item test left --set test label="test" click_script="sketchybar --set test label=TEST"

it should make the label upper case once you click it.

FelixKratz commented 1 year ago

I will for now assume that this is fixed, feel free to reopen the issue.

chrisgrieser commented 1 year ago

Back in the office, thank you, it now works 🥳