如何在GDK中获得不包含Unity侧面板的屏幕尺寸

时间:2023-01-24 14:19:46

I'm trying to make Guake terminal work correctly in Unity. Its window have width that is equal to screen width. But because of Unity left bar window's right border becomes invisible. So, I want to set proper width for window. It must be smaller than actual window size. And the code must work correctly with or without Unity.

我正在努力使呼客终端在统一中正确工作。它的窗口的宽度等于屏幕宽度。但由于统一,左栏窗口的右边框变得不可见。我想为窗口设置合适的宽度。它必须小于实际窗口大小。无论是否统一,代码都必须正确工作。

This is how Guake determines position and size of its window:

这就是Guake如何确定窗口的位置和大小:

def get_final_window_rect(self):

    """Gets the final size of the main window of guake. The height
    is the window_height property, width is window_width and the
    horizontal alignment is given by window_alignment.
    """
    screen = self.window.get_screen()
    height = self.client.get_int(KEY('/general/window_height'))
    width = 100
    halignment = self.client.get_int(KEY('/general/window_halignment'))

    # get the rectangle just from the first/default monitor in the
    # future we might create a field to select which monitor you
    # wanna use
    window_rect = screen.get_monitor_geometry(0)
    total_width = window_rect.width
    window_rect.height = window_rect.height * height / 100
    window_rect.width = window_rect.width * width / 100

    if width < total_width:
        if halignment == ALIGN_CENTER:
            window_rect.x = (total_width - window_rect.width) / 2
        elif halignment == ALIGN_LEFT:
            window_rect.x = 0
        elif halignment == ALIGN_RIGHT:
            window_rect.x = total_width - window_rect.width
    window_rect.y = 0
    window_rect.width = 250
    return window_rect

1 个解决方案

#1


1  

So you want to substract unity launcher width from your total_width. This size can be determined using gconf to get the value of launcher icons :

因此,您希望将unity启动程序的宽度从total_width中减去。可以使用gconf确定此大小,以获取启动图标的值:

self.client.get_int('/apps/compiz-1/plugins/unityshell/screen0/options/icon_size')

of course you also want to know if the current running session is indeed unity :

当然,您还想知道当前运行的会话是否确实是统一的:

os.environ.get('DESKTOP_SESSION')  == 'ubuntu'

seems to be a good solution. (http://*.com/questions/2035657/what-is-my-current-desktop-environment)

看来这是个好办法。(http://*.com/questions/2035657/what-is-my-current-desktop-environment)

#1


1  

So you want to substract unity launcher width from your total_width. This size can be determined using gconf to get the value of launcher icons :

因此,您希望将unity启动程序的宽度从total_width中减去。可以使用gconf确定此大小,以获取启动图标的值:

self.client.get_int('/apps/compiz-1/plugins/unityshell/screen0/options/icon_size')

of course you also want to know if the current running session is indeed unity :

当然,您还想知道当前运行的会话是否确实是统一的:

os.environ.get('DESKTOP_SESSION')  == 'ubuntu'

seems to be a good solution. (http://*.com/questions/2035657/what-is-my-current-desktop-environment)

看来这是个好办法。(http://*.com/questions/2035657/what-is-my-current-desktop-environment)