AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 651188
Accepted
William
William
Asked: 2015-07-22 20:18:10 +0800 CST2015-07-22 20:18:10 +0800 CST 2015-07-22 20:18:10 +0800 CST

单击曝光

  • 772

默认情况下,是否可以单击停靠栏图标激活公开?

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

在此处输入图像描述

16.04
  • 1 1 个回答
  • 860 Views

1 个回答

  • Voted
  1. Best Answer
    Sergiy Kolodyazhnyy
    2016-09-29T10:36:53+08:002016-09-29T10:36:53+08:00

    内容:

    1. 概述
    2. 脚本源
    3. 补充说明

    一、概述

    如评论中所述,此功能显然自 12.04 起已被删除,现在单击启动器图标可最小化窗口(从我的在线搜索中可以看出,这显然是一个要求很高的功能)。但是,存在一个键盘可以为单个窗口打开 expo,即Super+ Ctrl+ W。知道了这一点,如果我们可以检测到在窗口升起时单击启动器或光标的位置,那么我们就可以通过该键盘快捷键模拟该单个窗口 expo。下面的脚本正是这样做的。

    这意味着保存为/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,因为在 expo Ctrl+W中 Expo 对应于“关闭窗口”命令。这里潜在的问题是频繁切换可能会导致窗口关闭。脚本也必须相应地进行调整。

    笔记:

    该脚本依赖于xdotool实用程序。您必须安装它。没有xdotool它就无法工作,因为xdotool它被用来模拟按键。通过安装它sudo apt-get install xdotool

    • 6

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve