Why python Wnck window.activate(int(time.time()))

2024/10/9 20:25:29

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

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).

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

Am I the only person who thinks this is insane?

Answer

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.

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.

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.

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 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;
}

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.

https://en.xdnf.cn/q/69983.html

Related Q&A

Regex subsequence matching

Im using python but code in any language will do as well for this question.Suppose I have 2 strings. sequence =abcd string = axyzbdclkdIn the above example sequence is a subsequence of stringHow can I …

Read a Bytes image from Amazon Kinesis output in python

I used imageio.get_reader(BytesIO(a), ffmpeg) to load a bytes image and save it as normal image.But the below error throws when I read the image using imageio.get_reader(BytesIO(a), ffmpeg)Traceback …

How to compute optical flow using tvl1 opencv function

Im trying to find python example for computing optical flow with tvl1 opencv function createOptFlow_DualTVL1 but it seems that there isnt enough documentation for it.Could anyone please let me do that?…

Python 3.3.4: python-daemon-3K ; How to use runner

Struggling to try and get a python daemon to work using Python 3.3.4. Im using the latest version of the python-daemon-3K from PyPi i.e. 1.5.8Starting point is the following code found How do you creat…

How to select specific data variables from xarray dataset

BACKGROUND I am trying to download GFS weather data netcdf4 files via xarray & OPeNDAP. Big thanks to Vorticity0123 for their prior post, which allowed me to get the bones of the python script sort…

List object has no attribute Values error

I would like to get the data to Excel worksheet. The problem is when I run the whole code I receive an error but when I run it separately no error it works. Here is what I want; from xlwings import Wor…

How to resize an image in python, while retaining aspect ratio, given a target size?

First off part of me feels like this is a stupid question, sorry about that. Currently the most accurate way Ive found of calculating the optimum scaling factor (best width and height for target pixel …

How to limit number of followed pages per site in Python Scrapy

I am trying to build a spider that could efficiently scrape text information from many websites. Since I am a Python user I was referred to Scrapy. However, in order to avoid scraping huge websites, I …

Why is Pythons sorted() slower than copy, then .sort()

Here is the code I ran:import timeitprint timeit.Timer(a = sorted(x), x = [(2, bla), (4, boo), (3, 4), (1, 2) , (0, 1), (4, 3), (2, 1) , (0, 0)]).timeit(number = 1000) print timeit.Timer(a=x[:];a.sort(…

How to efficiently unroll a matrix by value with numpy?

I have a matrix M with values 0 through N within it. Id like to unroll this matrix to create a new matrix A where each submatrix A[i, :, :] represents whether or not M == i.The solution below uses a lo…