pyGTK检测所有窗口移动事件

发布于 2024-09-07 09:31:57 字数 2218 浏览 3 评论 0原文

我正在尝试捕获每个窗口的配置事件以创建 Windows 7 风格的快照功能。我知道有涉及 compiz-fusion 的解决方案,但我的安装是在 vmware 中运行,并且没有硬件加速来运行 compiz。我认为一个简单的 python 脚本可以做我想做的事情,但我似乎找不到绑定配置事件的正确位置。

如何/绑定配置事件回调,或者是否有我需要监视的不同事件?我尝试使用 get_root_window() 将其绑定到屏幕和根窗口,但没有成功。

EDIT2

现在我可以捕获所有事件,问题是返回的每个事件都是 GDK_NOTHING 类型,所以我无法区分焦点事件、移动事件、关闭事件等之间的区别。

#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk, wnck
import inspect

def move_event(e):
    print e.type, e.window
    print inspect.getmembers(e)
    return gtk.gdk.FILTER_CONTINUE

def bind_win(screen, win):
    w = gtk.gdk.window_foreign_new(win.get_xid())
    if w:
        w.set_events(w.get_events() | gtk.gdk.ALL_EVENTS_MASK)
        w.add_filter(move_event)


if __name__ == "__main__":
    screen = wnck.screen_get_default()
    screen.connect("window_opened", bind_win)
    gtk.main()

一次迭代move_event(e) 拖动窗口时:

[('copy', <0x7f3900513d00 处的 gtk.gdk.Event 对象的内置方法副本>), ('free', <0x7f3900513d00 处的 gtk.gdk.Event 对象的内置方法免费>), ( 'get_axis', <位于 0x7f3900513d00 的 gtk.gdk.Event 对象的内置方法 get_axis>), ('get_coords', <位于 0x7f3900513d00 的 gtk.gdk.Event 对象的内置方法 get_coords>), ('get_root_coords ', <位于 0x7f3900513d00 的 gtk.gdk.Event 对象的内置方法 get_root_coords>), ('get_screen', <位于 0x7f3900513d00 的 gtk.gdk.Event 对象的内置方法 get_screen>), ('get_state', <位于 0x7f3900513d00 的 gtk.gdk.Event 对象的内置方法 get_state>), ('get_time', <位于 0x7f3900513d00 的 gtk.gdk.Event 对象的内置方法 get_time>), ('put', <位于 0x7f3900513d00> 的 gtk.gdk.Event 对象的内置方法 put,('send_client_message', <位于 0x7f3900513d00 的 gtk.gdk.Event 对象的内置方法 send_client_message>), ('send_clientmessage_toall',的 gtk.gdk.Event 对象的方法 send_clientmessage_toall 中), ('send_event', 1), ('set_screen', <0x7f3900513d00> 的 gtk.gdk.Event 对象的内置方法 set_screen>), ('type ',), ('window',)]

I'm trying to capture the configure-event for every window to create a windows 7-esque snap feature. I know there are solutions involving compiz-fusion, but my installation is running within vmware and doesn't have hardware acceleration to run compiz. I figured a simple python script could do what I wanted, but I can't seem to find the right place to bind the configure-event to.

How/to what do you bind the configure-event callback, or is there a different event I need to watch for? I've tried binding it to the screen and the root window using get_root_window() with no luck.

EDIT2

Now I can capture all events, the problem is that every event returned is of type GDK_NOTHING, so I can't tell the difference between focus events, move events, close events, etc.

#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk, wnck
import inspect

def move_event(e):
    print e.type, e.window
    print inspect.getmembers(e)
    return gtk.gdk.FILTER_CONTINUE

def bind_win(screen, win):
    w = gtk.gdk.window_foreign_new(win.get_xid())
    if w:
        w.set_events(w.get_events() | gtk.gdk.ALL_EVENTS_MASK)
        w.add_filter(move_event)


if __name__ == "__main__":
    screen = wnck.screen_get_default()
    screen.connect("window_opened", bind_win)
    gtk.main()

One iteration of move_event(e) while dragging a window:

<enum GDK_NOTHING of type GdkEventType> <gtk.gdk.Window object at 0x7f38f72f8730 (GdkWindow at 0x196ce20)>
[('copy', <built-in method copy of gtk.gdk.Event object at 0x7f3900513d00>), ('free', <built-in method free of gtk.gdk.Event object at 0x7f3900513d00>), ('get_axis', <built-in method get_axis of gtk.gdk.Event object at 0x7f3900513d00>), ('get_coords', <built-in method get_coords of gtk.gdk.Event object at 0x7f3900513d00>), ('get_root_coords', <built-in method get_root_coords of gtk.gdk.Event object at 0x7f3900513d00>), ('get_screen', <built-in method get_screen of gtk.gdk.Event object at 0x7f3900513d00>), ('get_state', <built-in method get_state of gtk.gdk.Event object at 0x7f3900513d00>), ('get_time', <built-in method get_time of gtk.gdk.Event object at 0x7f3900513d00>), ('put', <built-in method put of gtk.gdk.Event object at 0x7f3900513d00>), ('send_client_message', <built-in method send_client_message of gtk.gdk.Event object at 0x7f3900513d00>), ('send_clientmessage_toall', <built-in method send_clientmessage_toall of gtk.gdk.Event object at 0x7f3900513d00>), ('send_event', 1), ('set_screen', <built-in method set_screen of gtk.gdk.Event object at 0x7f3900513d00>), ('type', <enum GDK_NOTHING of type GdkEventType>), ('window', <gtk.gdk.Window object at 0x7f38f72f8730 (GdkWindow at 0x196ce20)>)]

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

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

发布评论

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

评论(1

兮颜 2024-09-14 09:31:57

快速搜索就会发现页面,虽然是用 C 编写的,但很好地传达了基础知识(您必须grep它才能找到“移动窗口”)

configure-event 绑定到您的应用程序的窗口。

为了做你想做的事情,你还必须找出屏幕尺寸,它位于 gtk.gdk.screen 中,记录在 此处

A quick search reveals this page, which, though written in C, communicates the basics pretty well (you'll have to grep it to find for "Moving Window")

The configure-event is binded to your application's window.

To do what you're going to want to do, you'll also have to find out the screen size, which resides in gtk.gdk.screen, documented here.

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