helloSystem / Menu

Global menu bar written in Qt
43 stars 14 forks source link

Update the System menu when SIGUSR1 is received #16

Closed probonopd closed 3 years ago

probonopd commented 3 years ago

Update the System menu when SIGUSR1 is received. Especially the applications.

image

How?

probonopd commented 3 years ago

https://doc.qt.io/qt-5/unix-signals.html in connection with

https://github.com/helloSystem/Menu/blob/aaf84275a9eb1c3aed494bc30b8665b2afe9440c/src/appmenuwidget.cpp#L191

?

PreyK commented 3 years ago

That would be a way to do it. But since we are not calling Qt functions directly as far as i read we can just use C++ signals in main like:

//call the update menu function when we get a signal
void SignalHandler(int sig){
    std::cout << "Signal called, update the menu";
    window->m_mainPanel->m_appMenuWidget->updateMenu();
}

//set up a signal for SIGUSR1
signal(SIGUSR1, SignalHandler);

Wich is a lot simpler than having to set up something to handle a singal then having to emit a Qt signal that eventually does something.

Just tested it, seems to work, if it's still actual feel free to assign it to me. What would be the use-case for this? (for validation and testing)

probonopd commented 3 years ago

Thanks @PreyK, a pull requiest would be highly appreciated. :+1: It would allow us to do something more elegant (send SIGUSR1 rather than killing and then restarting the menu), e.g., here:

https://github.com/helloSystem/ISO/blob/6c18ab8c7474750b43847e9345eccd492a10a1f3/overlays/uzip/hello/files/usr/local/bin/desktop2app#L230-L243

Test case:

probonopd commented 3 years ago

Stretch goal: Remove the need for SIGUSR1 as well, https://github.com/helloSystem/Menu/issues/15. But even changing from what we have now to using SIGUSR1 would already be a welcome improvement.

PreyK commented 3 years ago

@probonopd Sounds great! Just opened a PR for the update on SIGUSR1. Turns out https://github.com/helloSystem/Menu/blob/aaf84275a9eb1c3aed494bc30b8665b2afe9440c/src/appmenuwidget.cpp#L191 Doesn't update the menu so I ended up just reinitializing the system menu widget. New applications on SIGUSR1 now gets populated in the menu bar.

I'll look into https://github.com/helloSystem/Menu/issues/15 next as it should be easier now.

probonopd commented 3 years ago

I'll look into #15 next as it should be easier now.

Basically we "just" need to find a way to call window->m_mainPanel->rebuildSystemMenu(); from within

https://github.com/helloSystem/Menu/blob/a3f423a61967de6d44dd29278d01bdf17253588f/src/appmenuwidget.cpp#L454-L458

How to do that?

PreyK commented 3 years ago

Essentially yes. Since we are Qt widgets (and app menu lives in the main panel) we can just do

 qobject_cast<MainPanel*>(parent())->rebuildSystemMenu();

Just opened a PR for this https://github.com/helloSystem/Menu/pull/54 , it now detects new apps automatically https://youtu.be/dcmdzED3mIA I left in SIGUSR1 too, It doesn't needed anymore for this but I guess it's useful for development to have a way to rebuild the menu whenever we want to.

probonopd commented 3 years ago

Awesome! Works exactly as intendeed. Thank you so much!

PreyK commented 3 years ago

Great! Glad I could help :D