为什么python Wnck window.activate(int(time.time())) [英] Why python Wnck window.activate(int(time.time()))

查看:38
本文介绍了为什么python Wnck window.activate(int(time.time()))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对我来说很奇怪.有人可以解释为什么 activate() 函数需要时间戳吗?99.9% 的时间不是现在或尽快或在您方便的时候"吗?此外,如果你尝试 w.activate(0) 你会得到这个警告:

This to me is VERY strange. Could someone please explain why the activate() function should want a timestamp? Wouldn't 99.9% of the time be NOW or ASAP or "At your earliest convenience"? And furthermore, if you try w.activate(0) you get this warning:

Wnck-WARNING: Received a timestamp of 0; window activation may not function properly

我读过的有关此警告的每个论坛帖子都没有答案.但它们似乎都表明代码无法正常工作,除非您实际输入时间戳.如果你输入 (0),事情就不起作用了,你会收到警告.但是,对我来说,如果我输入时间戳,那就是事情不起作用的时候.如果我使用 (0),该程序可以正常工作,但会收到警告(仅当我在终端窗口中运行它时).

Every forum thread that I have read about this warning ends with no answer. But they all seem to indicate that the code does not work properly unless you actually put in the timestamp. And if you put in the (0), things don't work, and you get the warning. However, for me, if I put in a timestamp, that is when things don't work. If I use (0), the program works except that I get the Warning (only if I run it in a terminal window).

到底为什么 activate() 关心时间"?

Why on earth does activate() care about 'time' anyway?

我是唯一认为这很疯狂的人吗?

Am I the only person who thinks this is insane?

推荐答案

这实际上与 X11 和可序列化有关.时间戳用于对消息进行排序并判断哪些是迟到的并且可以安全地忽略.否则应该忽略过去的消息,因为它们的效果已被较新的消息覆盖,将错误地应用它们的效果.

This actually has to do with X11 and serializability. The timestamp is used to order messages and to tell which ones are late and can be safely ignored. Otherwise messages from the past which should be ignored, because their effect has been overwritten by a newer message, would apply their effect incorrectly.

在这种情况下,如果一个消息说激活窗口 X 和另一个激活窗口 Y 没有时间戳,则无法判断 X 的消息是发生在 Y 之前还是之后.

In this case if one message says activate window X and another activate window Y without the timestamp it is not possible to tell if the message for X happened before Y or after it.

请参阅为什么 X 不是我们理想的窗口系统 用于由于 X 协议中缺少时间戳和可序列化性而导致的竞争.

See section 3 in Why X Is Not Our Ideal Window System for races that result from lack of timestamps and serializability in the X protocol.

同样不应该使用int(time.time()),这是客户端的时间,在window.activate(int(time.time())) 而是服务器发送的最后一个时间戳.

Also one shouldn't use int(time.time()), which is the time on the client, in window.activate(int(time.time())) but rather the last timestamp sent from the server.

Wnck 包含此功能.这是需要服务器往返.将其转换为 Python 会起作用,并且完全是另一个问题,但 Wnck 的 Python 绑定不导出此函数是愚蠢的,因为它是唯一返回其他函数期望作为参数的时间戳的函数:

Wnck contains this function. This is needs a server round trip. Translating this into Python would work and would be reasonably an entirely another question but it is asinine that Wnck's Python binding don't export this function as it is the only function that returns the timestamp that the other functions expect as an argument:

/**
 * get_server_time:
 * @display: display from which to get the time
 * @window: a #Window, used for communication with the server.
 *          The window must have PropertyChangeMask in its
 *          events mask or a hang will result.
 * 
 * Routine to get the current X server time stamp. 
 * 
 * Return value: the time stamp.
 **/
static Time
get_server_time (Window window)
{
  unsigned char c = 'a';
  XEvent xevent;
  TimeStampInfo info;

  info.timestamp_prop_atom = _wnck_atom_get ("_TIMESTAMP_PROP");
  info.window = window;

  XChangeProperty (_wnck_get_default_display (), window,
           info.timestamp_prop_atom, info.timestamp_prop_atom,
           8, PropModeReplace, &c, 1);

  XIfEvent (_wnck_get_default_display (), &xevent,
        timestamp_predicate, (XPointer)&info);

  return xevent.xproperty.time;
}

但是如果处理 X 事件的循环只是跟踪来自服务器的消息的时间戳,则需要往返.我认为 Wnck 或 GDK 做到了这一点,并且具有获取价值的功能.

But if the loop that processes the X events just kept track of the timestamp from messages from the server, there would be a need for a round trip. And I thought Wnck or GDK did that and had a function for getting the value.

这篇关于为什么python Wnck window.activate(int(time.time()))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆