单击公开


11

默认情况下,是否可以单击扩展坞图标来激活暴露?

如果您在ubuntu中打开了一个窗口,则它不会激活暴露,但是如果您有多个窗口打开,则它会激活。当我尝试在ubuntu的多个不同窗口上使用暴露时,这会导致问题。

在此处输入图片说明


1
您可以添加一个链接到您的问题所暴露的内容吗?
布鲁尼

因此,换句话说,即使该应用程序只有一个窗口打开,您也希望拥有这种视图?
Sergiy Kolodyazhnyy

@LiamWilliam是曝光还是缩放?
安华

1
@LiamWilliam不,很遗憾,到目前为止我还没有找到任何相关的东西:(
Sergiy Kolodyazhnyy

1
@LiamWilliam我仅通过快捷方式找到了“ spread”选项,但是您必须将窗口聚焦以实现此目的。我没有找到点击的方法
Sergiy Kolodyazhnyy

Answers:


6

内容:

  1. 总览
  2. 脚本源
  3. 补充说明

1.概述

正如评论中提到的那样,此功能从12.04开始已被删除,现在单击启动器图标可将窗口最小化(这是我在在线搜索中看到的要求很高的功能)。但是,有一个键盘可以打开一个窗口的EXPO,这是Super+ Ctrl+ W。知道这一点,如果我们可以检测到窗口升起时在启动器上的单击或光标的位置,那么我们可以通过该键盘快捷键来模拟单个窗口博览会。下面的脚本正是这样做的。

/usr/bin/single_click_expo.py文件应另存为文件并添加到启动应用程序中

在此处输入图片说明

2.脚本源

也可以在GitHub上使用

#!/usr/bin/env python3

# Author: Serg Kolo
# Date: Sept 28, 2016
# Purpose: activates
# Depends: python3-gi
#          xdotool
# Written for: http://askubuntu.com/q/651188/295286

# just in case user runs this with python 2
from __future__ import print_function
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk,Gio
import sys
import dbus
import subprocess

def run_cmd(cmdlist):
    """ Reusable function for running shell commands"""
    try:
        stdout = subprocess.check_output(cmdlist)
    except subprocess.CalledProcessError:
        print(">>> subprocess:",cmdlist)
        sys.exit(1)
    else:
        if stdout:
            return stdout

def gsettings_get(schema,path,key):
    """Get value of gsettings schema"""
    if path is None:
        gsettings = Gio.Settings.new(schema)
    else:
        gsettings = Gio.Settings.new_with_path(schema,path)
    return gsettings.get_value(key)


def get_launcher_object(screen):

    # Unity allows launcher to be on multiple
    # monitors, so we need to account for all 
    # window objects of the launcher
    launchers = []

    for window in screen.get_window_stack():
        xid = window.get_xid()
        command = ['xprop','-notype',
                   'WM_NAME','-id',str(xid)
        ]
        xprop = run_cmd(command).decode()
        title = xprop.replace("WM_NAME =","")
        if title.strip()  == '"unity-launcher"':
           launchers.append(window)
           #return window
    return launchers

def get_dbus(bus_type,obj,path,interface,method,arg):
    # Reusable function for accessing dbus
    # This basically works the same as 
    # dbus-send or qdbus. Just give it
    # all the info, and it will spit out output
    if bus_type == "session":
        bus = dbus.SessionBus() 
    if bus_type == "system":
        bus = dbus.SystemBus()
    proxy = bus.get_object(obj,path)
    method = proxy.get_dbus_method(method,interface)
    if arg:
        return method(arg)
    else:
        return method() 


def main():


    previous_xid = int()
    screen = Gdk.Screen.get_default()

    while True:

        current_xid = screen.get_active_window().get_xid()
        if  int(current_xid) == previous_xid:
            continue
        previous_xid = int(current_xid)
        icon_size = gsettings_get(
                        'org.compiz.unityshell',
                        '/org/compiz/profiles/unity/plugins/unityshell/',
                        'icon-size')
        icon_size = int(str(icon_size))
        position = str(gsettings_get(
                       'com.canonical.Unity.Launcher',
                       None,
                       'launcher-position'))
        screen = Gdk.Screen.get_default()
        launcher_objs = get_launcher_object(screen)

        # for faster processing,figure out which launcher is used
        # first before running xdotool command. We also need
        # to account for different launcher positions (available since 16.04)
        pointer_on_launcher = None
        for launcher in launcher_objs:
            if 'Left' in position and  \
               abs(launcher.get_pointer().x) <= icon_size:
                  pointer_on_launcher = True
            elif 'Bottom' in position and \
               abs(launcher.get_pointer().y) <= icon_size:
                  pointer_on_launcher = True
            else:
               continue


        active_xid = int(screen.get_active_window().get_xid())

        application = get_dbus('session',
                               'org.ayatana.bamf',
                               '/org/ayatana/bamf/matcher',
                               'org.ayatana.bamf.matcher',
                               'ApplicationForXid',
                               active_xid)

        # Apparently desktop window returns empty application
        # we need to account for that as well
        if application:
            xids = list(get_dbus('session',
                            'org.ayatana.bamf',
                            application,
                            'org.ayatana.bamf.application',
                            'Xids',None))

        if pointer_on_launcher and\
           len(xids) == 1:
               run_cmd(['xdotool','key','Ctrl+Super+W'])


if __name__ == '__main__':
    main()

3.附加说明

  • 这可能是最好的捷径重新映射到其他的东西Super+ Ctrl+ W,因为在世博Ctrl+ W世博对应于“关闭窗口”命令。这里的潜在问题是频繁切换可能会导致窗口关闭。脚本也必须相应地进行调整。

注意:

该脚本依赖xdotool实用程序。您必须已安装它。没有xdotool它就行不通,因为xdotool它用于模拟按键。通过安装sudo apt-get install xdotool


我知道了No module named gi
威廉

@LiamWilliam您可能需要安装python3-gi软件包。奇怪,因为它就像一个标准模块,并且默认情况下随Ubuntu一起提供。
Sergiy Kolodyazhnyy


您正在使用哪个版本的ubuntu?
威廉

@LiamWilliam 16.04 LTS,但python3-gi默认情况下也是14.04 LTS。我不知道早期版本
谢尔盖Kolodyazhnyy
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.