繁体   English   中英

如何检测GNOME AppMenu上的点击?

[英]How do I detect clicks on the GNOME AppMenu?

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

或者,更好的方法是将鼠标左键传递到基础面板。 我认为这也应该可行,尽管我更喜欢此选项,但我对API以及如何使用它并不熟悉。

首先,我尝试设置Main.panel.statusArea.appMenu.container.enabled = false和类似的设置,但是我无法猜出实际的名称。 链接到此文档将是很棒的。

之后,我想出了可以列举各种元素的所有成员的方法,例如:

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

虽然,我仍然没有弄清楚该物业将是什么,或者我应该在哪里看。

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

非常感谢你。

相关事件是我在本文档中找到的button-press-eventbutton-release-eventhttps: //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;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM