在全屏应用程序中关闭超级键


8

通常,是否可以在游戏会话或全屏应用程序中关闭SUPER键?


是的,有可能。我将很快开始为此编写脚本,并在工作后将其发布
Sergiy Kolodyazhnyy

那将是真棒!
凯T

1
发布答案,让我知道您的想法
Sergiy Kolodyazhnyy

2
请注意未来的访问者,我之前已经编写了一个相关的脚本,用于在每个特定窗口中禁用超级键。如果您有兴趣,请查看:askubuntu.com/q/754884/295286
Sergiy Kolodyazhnyy

Answers:


11

介绍

Super如果任何X11窗口处于全屏模式,则以下脚本禁用键。它打算作为启动应用程序添加,但也可以独立运行。

用法

要手动运行脚本,只需执行以下操作:

python disable_super_key.py

为了使脚本在登录时自动启动,请参阅如何在登录时自动启动应用程序?

获取脚本源代码

可以从这个答案中复制脚本源,或者通过克隆我的GitHub存储库获得脚本源。

对于那些谁的说明git

  1. cd /opt
  2. sudo git clone https://github.com/SergKolo/sergrep.git
  3. chmod -R +x sergrep

该脚本将位于 /opt/sergrep/disable_super_key.py

脚本源代码

#!/usr/bin/env python
#
###########################################################
# Author: Serg Kolo , contact: 1047481448@qq.com 
# Date: August 1st , 2016
# Purpose: Disable Super key that calls Unity Dash, when any 
#          X11 window is in fullscreen state
# 
# Written for: https://askubuntu.com/q/805807/295286
# Tested on: Ubuntu 16.04 LTS 
###########################################################
# Copyright: Serg Kolo , 2016
#    
#     Permission to use, copy, modify, and distribute this software is hereby granted
#     without fee, provided that  the copyright notice above and this permission statement
#     appear in all copies.
#
#     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
#     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#     DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import  Gdk,Gio
import subprocess
import signal
import time
import sys

debug = False

def gsettings_get(schema,path,key):
    """ fetches 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 gsettings_set(schema,path,key,value):
    """ sets value of gsettings schema """
    if path is None:
        gsettings = Gio.Settings.new(schema)
    else:
        gsettings = Gio.Settings.new_with_path(schema,path)
    return gsettings.set_string(key,value)


def gsettings_reset(schema,path,key):
    """ resets schema:key value to default"""
    if path is None:
        gsettings = Gio.Settings.new(schema)
    else:
        gsettings = Gio.Settings.new_with_path(schema,path)
    return gsettings.reset(key)

def run_cmd(cmdlist):
    """ reusable function for running shell commands"""
    try:
        stdout = subprocess.check_output(cmdlist)
    except subprocess.CalledProcessError:
        pass
    else:
        if stdout:
            return stdout


def main():
    """ defines entry point of the program """
    screen = Gdk.Screen.get_default()
    while True:

        key_state = str(gsettings_get('org.compiz.unityshell', 
                                  '/org/compiz/profiles/unity/plugins/unityshell/', 
                                  'show-launcher'))
        active_xid = str(screen.get_active_window().get_xid())
        wm_state =  run_cmd( ['xprop', '-root', '-notype','-id',active_xid, '_NET_WM_STATE'])  

        if debug : print(key_state,wm_state)

        if 'FULLSCREEN' in wm_state:
            if "Super" in  key_state:    
                gsettings_set('org.compiz.unityshell', 
                              '/org/compiz/profiles/unity/plugins/unityshell/',
                              'show-launcher', 
                              'Disabled')

        else:
            if "Disabled" in key_state :
               gsettings_reset( 'org.compiz.unityshell', 
                                '/org/compiz/profiles/unity/plugins/unityshell/',
                                'show-launcher')


        time.sleep(0.25)


def sigterm_handler(*args):
    """ ensures that Super key has been reset upon exit"""
    gsettings_reset( 'org.compiz.unityshell', 
                     '/org/compiz/profiles/unity/plugins/unityshell/',
                     'show-launcher')

    if debug: print('CAUGHT SIGTERM')
    sys.exit(0)


if __name__ == "__main__":
    signal.signal(signal.SIGTERM,sigterm_handler)
    main()

调试

如果需要调试,请将第32行从更改debug = Falsedebug = True并从命令行运行脚本


我被要求使该脚本在每个特定的工作区中工作。对于有兴趣的人,您可以在这里找到解决方案askubuntu.com/a/816512/295286请注意,此脚本已经更新,可以处理脚本终止,以便在脚本退出后重新启用SUPER键
Sergiy 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.