簡體   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