gpt4 book ai didi

javascript - 如何检测 GNOME AppMenu 上的点击?

转载 作者:行者123 更新时间:2023-12-04 18:45:02 26 4
gpt4 key购买 nike

我正在尝试禁用 GNOME 应用程序菜单(左侧的小部件,在顶部面板中的“事件”按钮的右侧),以便单击它通过它到达底层面板,这样就可以即使单击此按钮,也可以从最大化状态拖动窗口。可能吗?

或者,更好的方法是将左键单击传递到底层面板。我认为这也应该是可能的,但我不熟悉 API 以及我应该如何去做,即使我更喜欢这个选项。

首先,我尝试设置 Main.panel.statusArea.appMenu.container.enabled = false和类似的东西,但我猜不出真正的名字。到这方面的文档的链接会很棒。

之后,我发现我可以枚举各种元素的所有成员,如下所示:

for(var propertyName in this._appMenu.container) {
log(propertyName);
}

不过,我仍然没有弄清楚该属性(property)将是什么或我应该去哪里看。

我想将代码添加到扩展中,因此首选 JavaScript 代码。

非常感谢。

最佳答案

相关事件是button-press-eventbutton-release-event我在本文档中找到:https://people.gnome.org/~gcampagna/docs/Clutter-1.0/Clutter.Actor.htmlhttps://developer.gnome.org/clutter/stable/clutter-Events.html

一旦我使用以下方式订阅它们:

this._wmHandlerIDs.push(Main.panel.statusArea.appMenu.actor.connect(
'button-press-event', Lang.bind(this, this._click)
));

this._wmHandlerIDs.push(Main.panel.statusArea.appMenu.actor.connect(
'button-release-event', Lang.bind(this, this._clicked)
));

Main._handledClick = 1; // ignore first click on the panel
Main._cancelClick = 0; // indicates if the button is still held

然后我可以破解我的方式并使应用程序按钮的行为就像它是一个标题栏:
_click: function (actor, event) {
if (event.get_button() == 1) {
Main._cancelClick = 0;
if (event.get_click_count() == 1 && global.display.focus_window.get_maximized()) {
Mainloop.timeout_add(100, function () {
if (Main._handledClick == 1) {
Main._handledClick = 0;
} else {
if (Main._cancelClick == 0) {
/* disable the following mice temporarly so
that this hack works; a better way would be
nice; maybe that would also fix the mouse
button remaining stuck when dragging the
window */
Util.spawn(['xinput', '--disable', '12']);
Util.spawn(['xinput', '--disable', '15']);
Util.spawn(['xinput', '--disable', '16']);
Main.panel.statusArea.appMenu.hide();
Util.spawn(['xinput', '--enable', '12']);
Util.spawn(['xinput', '--enable', '15']);
Util.spawn(['xinput', '--enable', '16']);
Util.spawn(['xdotool', 'mousedown', '1']);
Mainloop.timeout_add(100, function () {
Main.panel.statusArea.appMenu.show();
});
}
}
});
}
} else if (event.get_button() == 2) {
global.display.focus_window.delete(global.get_current_time());
Mainloop.timeout_add(10, function () {
Util.spawn(['xdotool', 'key', 'Escape']);
});
}
},

_clicked: function (actor, event) {
if (event.get_button() == 1) {
Main._cancelClick = 1;
if (event.get_click_count() == 2) {
if (global.display.focus_window.get_maximized()) {
global.display.focus_window.unmaximize(MAXIMIZED);
} else {
global.display.focus_window.maximize(MAXIMIZED);
}
}
}
},

我相信需要这些进口:
const Main           = imports.ui.main;
const Mainloop = imports.mainloop;
const Meta = imports.gi.Meta;
const MAXIMIZED = Meta.MaximizeFlags.BOTH;

也许它可以帮助某人缩短搜索文档的艰辛努力。

关于javascript - 如何检测 GNOME AppMenu 上的点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50100546/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com