为什么我绘制到根窗口后 X 会卡住

发布于 2024-08-01 22:22:07 字数 1634 浏览 15 评论 0原文

对于背景,我正在跑步 Debian Lenny,并已在 GNOME 和 Fluxbox 上尝试过此操作。

不管怎样,我一直在研究如何在桌面上绘图,我在这里找到并尝试了这段代码: http://blog.prashanthellina.com/2007/08 /24/drawing-on-your-desktop/

它工作得很好,除了终止它(通过按下 Control C),X 失去了创建新窗口的能力。

我原以为问题可能是 pygame 没有释放一些资源,所以我添加了一段代码来捕获终止信号,给我以下内容:

"""
Run the following command in the shell before executing this script
export SDL_WINDOWID=`xwininfo -root|grep "id:"|sed 's/^.*id: //'|sed 's/ (.*$//'`
"""
import pygame
import sys
import random
import time
import signal





pygame.init()

window = pygame.display.set_mode((1280, 1024))
screen = pygame.display.get_surface()


def handle_sigint(signum, frame):
   """I want to ensure resources are released before bailing."""
   print("SIGINT received.");
   pygame.display.quit()
   pygame.quit()
   sys.exit(0)


# Set handler to catch C^C Interupts
signal.signal(signal.SIGINT, handle_sigint)


while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit(0)

    x = random.choice(range(640))
    y = random.choice(range(480))
    radius = random.choice(range(100))
    col_r = random.choice(range(255))
    col_g = random.choice(range(255))
    col_b = random.choice(range(255))

    time.sleep(.03)
    rect = pygame.draw.circle(screen, (col_r, col_g, col_b), (x,y), radius)
    pygame.display.update(rect)

所以我再次尝试。 中断处理程序中的打印语句告诉我,当我退出时,处理程序确实运行,但我仍然遇到同样的问题。 更有趣的是,X 在运行时没有任何问题。 终止之后才这样。

可能有人知道发生了什么,以及我可以做些什么来修复代码,这样它就不会破坏我的 X 会话? 提前致谢。

For background, I'm running
Debian Lenny, and have tried this with both GNOME and Fluxbox.

Anyway, I've been looking at how to draw on the desktop, and I found and tried this code here:
http://blog.prashanthellina.com/2007/08/24/drawing-on-your-desktop/

It worked fine, except upon terminating it (by hitting control C), X loses it's ability to create new windows.

I had thought that maybe the problem was pygame not releasing some resource, so I added in a block of code to trap the kill signal, giving me the following:

"""
Run the following command in the shell before executing this script
export SDL_WINDOWID=`xwininfo -root|grep "id:"|sed 's/^.*id: //'|sed 's/ (.*$//'`
"""
import pygame
import sys
import random
import time
import signal





pygame.init()

window = pygame.display.set_mode((1280, 1024))
screen = pygame.display.get_surface()


def handle_sigint(signum, frame):
   """I want to ensure resources are released before bailing."""
   print("SIGINT received.");
   pygame.display.quit()
   pygame.quit()
   sys.exit(0)


# Set handler to catch C^C Interupts
signal.signal(signal.SIGINT, handle_sigint)


while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit(0)

    x = random.choice(range(640))
    y = random.choice(range(480))
    radius = random.choice(range(100))
    col_r = random.choice(range(255))
    col_g = random.choice(range(255))
    col_b = random.choice(range(255))

    time.sleep(.03)
    rect = pygame.draw.circle(screen, (col_r, col_g, col_b), (x,y), radius)
    pygame.display.update(rect)

And so I tried again. The print statement in the interrupt handler tells me that the handler does run when I quit, but I still have the same problem. And even more interestingly, X has no problems while it's running. It's only after terminating it.

Might anybody out there have any idea what's happening, and what I can do to fix the code so it doesn't wreck my X session? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心在旅行 2024-08-08 22:22:08

问题、想法和 值得尝试的事情:

  1. 如果在尝试 -c 之前您已经打开了终端,那么之后您还能输入吗? 如果是,则问题可能出在您的会话或窗口管理器中,而不是 x 服务器中。
  2. 您尝试过 Ctrl-Alt-Backspace 组合键吗? 这能解决您的问题吗?
  3. gtk-window-decorator 和 x-session-manager 是否仍在运行?

pygame 通常会在窗口外运行,并且通常会尝试自行清理。 您已添加对 pygame.display.quit() 的显式调用,但我认为这不会改变任何内容 - pygame 尝试删除 SDL_WINDOWID 变量引用的窗口。 实际上,成功删除根窗口可能是一件坏事。 我猜你从运行 ubuntu、pygame 那里得到这个的人无法删除窗口,因为他没有权限。 您可能在您的操作系统上。

既然杀死你的根窗口是不好的,那么将根窗口的控制权恢复到 nautilus (gnome) 怎么样? 像 gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop true 之类的东西?

Questions, ideas & things to try:

  1. If you have a terminal up before you try a -c, can you still type in it after? If yes, there's likely a problem in your session or window manager, not the x server.
  2. Have you tried Ctrl-Alt-Backspace? Does this fix your problem?
  3. Are gtk-window-decorator and x-session-manager still running?

pygame is typically run out of a window and is normally going to try to cleanup after itself. You've added an explicit call to pygame.display.quit(), but I don't think this changes anything - pygame tries to delete the window referred to by the SDL_WINDOWID variable. Actually succeeding in deleting your root window is probably a bad thing. I'm going to guess that the guy you got this from, running ubuntu, pygame fails to delete the window because he doesn't have permission. You might on your OS.

Since killing your root window is bad, how about just restoring control of the root window back to nautilus (gnome)? something like gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop true?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文