如何在python中使用wnck将gtk窗口从一个工作区移动到另一个工作区?

2024-09-29 19:32:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试开发一个python应用程序,它允许在gnome工作区之间移动窗口。我正在使用wnck与windows交互,但我想知道如何将窗口从一个工作区移动到另一个工作区。有人能给我一个建议吗?在

我试着用下面的代码

screen = wnck.screen_get_default()
window_list = screen.get_windows()
titlePattern = re.compile('.*Downloads.*')
    if len(window_list) == 0:
        print "No Windows Found"
    for win in window_list:
        if(titlePattern.match(win.get_name())):
            win.move_to_workspace(screen.get_workspace(2))

但是screen.get_工作区(2) 返回'None',虽然它工作(但不移动窗口!)如果我使用screen.get_工作区(0)作为“移动到”工作区参数。在

我能解决我的问题吗?在

提前感谢大家。在


Tags: 代码应用程序defaultgetifwindowswindowscreen
1条回答
网友
1楼 · 发布于 2024-09-29 19:32:55

当您调用screen.get_workspace(2)时,窗口管理器根本没有工作区2。在

您的代码应该适用于实际存在的所有工作区。在gnome3中,这意味着所有已经有windows的工作区加上一个空的工作区。这意味着screen.get_workspace(screen.get_workspace_count() - 1)应该给你一个“空”的工作区,如果你正在寻找的话。请注意,没有规范说明最后一个工作区是empy,这正是gnomeshell当前所做的。在

您也可以要求窗口管理器增加屏幕上的工作区数量,但它没有义务这样做:gnome3窗口管理器不会这样做。在

哦,关于Wnck还有一件事要记住:

At its creation, a WnckScreen object will not have fetched information from the X server. If queried immediately after its creation (via wnck_screen_get_windows() or wnck_screen_get_workspaces(), for example), the WnckScreen object will look like there are no workspaces nor windows on the screen. This information is fetched in the main event loop with an idle source, to avoid an expensive synchronous operation on startup. If no main event loop is used, or if the information is needed as soon as possible after the creation of the object, wnck_screen_force_update() can be used to explicitly fetch the information.

我不认为这是你的问题(因为你已经有一个窗口列表),但我只是再次检查,因为这是一个严重的陷阱。在

相关问题 更多 >

    热门问题