trying to clear the context menu, but that does not work
This commit is contained in:
+28
-5
@@ -567,7 +567,8 @@ void Rktwebview_qt::processCommand(Command *cmd)
|
||||
break;
|
||||
case COMMAND_TRAY_SET_MENU: {
|
||||
int tray_id = cmd->args[0].toInt();
|
||||
QString menu_json = cmd->args[1].toString();
|
||||
int has_menu = cmd->args[1].toInt();
|
||||
QString menu_json = cmd->args[2].toString();
|
||||
|
||||
if (!_trays.contains(tray_id)) {
|
||||
cmd->result = false;
|
||||
@@ -581,10 +582,20 @@ void Rktwebview_qt::processCommand(Command *cmd)
|
||||
delete old;
|
||||
}
|
||||
|
||||
QMenu *menu = buildMenuFromJson(this, menu_json, tray_id);
|
||||
QMenu *menu = (has_menu) ? buildMenuFromJson(this, menu_json, tray_id) : nullptr;
|
||||
if (menu == nullptr) {
|
||||
cmd->result = false;
|
||||
cmd->done = true;
|
||||
if (!has_menu) {
|
||||
INFO1("null menu, setting null menu on tray %d\n", tray_id);
|
||||
_trays[tray_id]->setContextMenu(nullptr);
|
||||
INFO0("Done setting tray menu to null menu\n");
|
||||
WARN0("Note: on Linux, this will not clear the context menu\n");
|
||||
cmd->result = true;
|
||||
cmd->done = true;
|
||||
} else {
|
||||
ERROR2("menu json '%s' for tray %d is not oke\n", menu_json.toUtf8().constData(), tray_id);
|
||||
cmd->result = false;
|
||||
cmd->done = true;
|
||||
}
|
||||
} else {
|
||||
_tray_menus[tray_id] = menu;
|
||||
_trays[tray_id]->setContextMenu(menu);
|
||||
@@ -606,6 +617,17 @@ void Rktwebview_qt::handleTrayActivation(QSystemTrayIcon::ActivationReason reaso
|
||||
{
|
||||
QObject *obj = sender();
|
||||
|
||||
QSystemTrayIcon *icn = qobject_cast<QSystemTrayIcon *>(obj);
|
||||
|
||||
// If a context menu has been set, pop it up and leave.
|
||||
/*if (reason == QSystemTrayIcon::ActivationReason::Context) {
|
||||
QMenu *mnu = icn->contextMenu();
|
||||
if (mnu != nullptr) {
|
||||
mnu->popup(QCursor::pos());
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
int tray_wv = obj->property("tray-id").toInt();
|
||||
QString evt = "tray-activated";
|
||||
QString reason_str = activationReasonToString(reason);
|
||||
@@ -1123,7 +1145,8 @@ result_t Rktwebview_qt::rktTraySetMenu(rktwebview_t tray, const char *menu_json)
|
||||
{
|
||||
Command c(COMMAND_TRAY_SET_MENU);
|
||||
c.args.push_back(tray);
|
||||
c.args.push_back(menu_json);
|
||||
c.args.push_back(menu_json != nullptr);
|
||||
c.args.push_back((menu_json == nullptr) ? "" : menu_json);
|
||||
|
||||
postCommand(&c);
|
||||
while(!c.done) { doEvents(); }
|
||||
|
||||
Reference in New Issue
Block a user