Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm writing app for Ubuntu with C++ and Gtkmm. In my app i use libappindicator to show icon with simple menu in notification area. Icon and menu works ok, i can minimize window to panel (using iconify() method) with user action on popup menu, but deiconify() method not working, window stays minimized on panel. The only way to restore window is to activate it manually clicking on panel icon.

Here is some code:

class CMainWindow: public Gtk::Window {
...
    Glib::RefPtr<Gtk::StyleContext>     m_rStyle;
    Glib::RefPtr<Gtk::UIManager>        m_rUIManager;
    Glib::RefPtr<Gtk::ActionGroup>      m_rActionGroup;
...
public:
...
    void                TrayInit();
    void                TrayWinShow();
    void                TrayWinExit();
... 
};

// this method is called from CMainWindow constructor
void CMainWindow::TrayInit() {
    m_rActionGroup = Gtk::ActionGroup::create();

    m_rActionGroup->add(Gtk::Action::create("Show", "Show"),
        sigc::mem_fun(*this, &CMainWindow::TrayWinShow));
    m_rActionGroup->add(Gtk::Action::create("Hide", "Hide"),
        sigc::mem_fun(*this, &CMainWindow::TrayWinHide));

    m_rUIManager = Gtk::UIManager::create();
    m_rUIManager->insert_action_group(m_rActionGroup);
    add_accel_group(m_rUIManager->get_accel_group());

    Glib::ustring strUI =
            "<ui>"
            "  <popup name='IndicatorPopup'>"
                "    <menuitem action='Show' />"
            "    <menuitem action='Hide' />"
            "  </popup>"
            "</ui>";

    m_rUIManager->add_ui_from_string(strUI);

    Gtk::Widget *pWidget;
    pWidget = m_rUIManager->get_widget("/ui/IndicatorPopup");

    m_pAppIcon = app_indicator_new("sample", "sample_icon",
        APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
    app_indicator_set_status(m_pAppIcon, APP_INDICATOR_STATUS_ACTIVE);
    app_indicator_set_menu(m_pAppIcon, GTK_MENU(pWidget->gobj()));
}

void CMainWindow::TrayWinShow() {
    deiconify();
}

void CMainWindow::TrayWinHide() {
    iconify();
}

Also I tried to use hide()/show() methods:

void CMainWindow::TrayWinShow() {
    show();
    get_application()->release();
}

void CMainWindow::TrayWinHide() {
    get_application()->hold();
    hide();
}

This variant properly hides window but when it calls show() i get a segfault.

Can anyone point me to what i'm doing wrong?

share|improve this question

1 Answer 1

I have tried your iconify()/deiconify() code and it works. I have added minimal code to get it to run. Can you confirm that this version works?

#include <gtkmm.h>
#include <libappindicator/app-indicator.h>
#include <gtkmm/stylecontext.h>

class CMainWindow: public Gtk::Window {
  Glib::RefPtr<Gtk::StyleContext> m_rStyle;
  Glib::RefPtr<Gtk::UIManager>    m_rUIManager;
  Glib::RefPtr<Gtk::ActionGroup>  m_rActionGroup;
  AppIndicator*                   m_pAppIcon;
public:
  void TrayInit();
  void TrayWinShow();
  void TrayWinHide();
  void TrayWinExit();
};

void CMainWindow::TrayInit() {
  m_rActionGroup = Gtk::ActionGroup::create();
  m_rActionGroup->add(Gtk::Action::create("Show", "Show"),
    sigc::mem_fun(*this, &CMainWindow::TrayWinShow));
  m_rActionGroup->add(Gtk::Action::create("Hide", "Hide"),
    sigc::mem_fun(*this, &CMainWindow::TrayWinHide));
  m_rUIManager = Gtk::UIManager::create();
  m_rUIManager->insert_action_group(m_rActionGroup);
  add_accel_group(m_rUIManager->get_accel_group());
  Glib::ustring strUI =
    "<ui>"
    "  <popup name='IndicatorPopup'>"
    "    <menuitem action='Show' />"
    "    <menuitem action='Hide' />"
    "  </popup>"
    "</ui>";
  m_rUIManager->add_ui_from_string(strUI);
  Gtk::Widget *pWidget;
  pWidget = m_rUIManager->get_widget("/ui/IndicatorPopup");
  m_pAppIcon = app_indicator_new("sample", "weather-clear-night",
    APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
  app_indicator_set_status(m_pAppIcon, APP_INDICATOR_STATUS_ACTIVE);
  app_indicator_set_menu(m_pAppIcon, GTK_MENU(pWidget->gobj()));
}

void CMainWindow::TrayWinShow() {
  deiconify();
}

void CMainWindow::TrayWinHide() {
  iconify();
}

int main(int argc, char** argv) {
  Glib::RefPtr<Gtk::Application> app = 
    Gtk::Application::create(argc, argv,"org.gtkmm.examples.base");
  CMainWindow c;
  c.set_default_size(200, 200);
  c.TrayInit();
  return app->run(c);
}

I saved it as test.cpp and compiled it as follows:

g++ test.cpp  `pkg-config --cflags --libs gtkmm-3.0 appindicator3-0.1`
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.