【问题标题】:How do I detect clicks on the GNOME AppMenu?如何检测 GNOME AppMenu 上的点击?
【发布时间】:2018-04-30 12:27:44
【问题描述】:

我正在尝试禁用 GNOME 应用程序菜单(左侧的小部件,顶部面板中“活动”按钮的右侧),以便点击它通过它进入底层面板,所以人们会即使单击此按钮,也可以从最大化状态拖动窗口。有可能吗?

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

首先,我尝试设置Main.panel.statusArea.appMenu.container.enabled = false 和类似的东西,但我猜不出实际名称。一个指向这方面文档的链接会很棒。

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

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

尽管如此,我仍然没有弄清楚该物业将是什么或我应该在哪里寻找。

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

非常感谢。

【问题讨论】:

    标签: javascript ubuntu gnome gnome-3 gnome-shell


    【解决方案1】:

    相关事件是我在本文档中找到的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;
    

    也许它可以帮助人们缩短搜索文档的艰辛时间。

    【讨论】:

    • 仅供参考,您引用的文档较旧,这些天您应该更喜欢devdocs.baznga.org
    • 很难找到文档,更不用说最新的了。但是,是的,谢谢分享。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多