如何在GDK中获取屏幕大小,不包括Unity侧面板

10

我正在尝试让Guake终端在Unity中正常工作。它的窗口宽度与屏幕宽度相等,但因为Unity左侧栏导致窗口右边框变得不可见。所以,我想设置适当的窗口宽度。它必须小于实际窗口大小。而且代码必须在有或没有Unity的情况下都正确运行。

以下是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

所以你想从总宽度中减去Unity启动器的宽度。可以使用gconf来确定此大小,以获取启动器图标的值:

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

当然,您也想知道当前运行的会话是否确实是Unity:

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

看起来是一个不错的解决方案。 (https://dev59.com/jUvSa4cB1Zd3GeqPczsH)


启动器的宽度大于“icon_size”值。现在我的启动器宽度为50,而“icon_size”为32。 - Pavel Strakhov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接