Kalmat / PyWinCtl

Cross-Platform module to get info on and control windows on screen
Other
179 stars 19 forks source link

Gravity bits (Xlib). #55

Closed elraymond closed 1 year ago

elraymond commented 1 year ago

Just fyi, the gravity bits you copied from the python ewmh module are wrong. Struggled myself with that a while ago. The correct bits are

1<<8  (= 0b100000000) for presence of x
1<<9  presence of y
1<<10 presence of width
1<<11 presence of height
1<<12 source indicator, application
1<<13 source indicator, pager

Reference: https://specifications.freedesktop.org/wm-spec/wm-spec-1.3.html#idm45140362862448

Kalmat commented 1 year ago

Thank you SO MUCH for your help!!!

I will follow your advice. Can you please help me a little bit more (my apologies because I'm not used to work at bit level with python)?

Can you please check if I understood you correctly and this is ok according to your experience?

    gravity_flags = gravity

    if x is None:
        x = 0
    else:
        gravity_flags = gravity_flags | (1 << 8)
    if y is None:
        y = 0
    else:
        gravity_flags = gravity_flags | (1 << 9)
    if width is None:
        width = 0
    else:
        gravity_flags = gravity_flags | (1 << 10)
    if height is None:
        height = 0
    else:
        gravity_flags = gravity_flags | (1 << 11)

    if userAction:
        gravity_flags = gravity_flags | (1 << 12)
    else:
        gravity_flags = gravity_flags | (1 << 13)

    self.sendMessage(winId, Props.Root.MOVERESIZE.value, [gravity_flags, x, y, width, height])

Thank you again!

elraymond commented 1 year ago

That's correct.

It's the second byte of the gravity_flags combo where individual bits are set to indicate the presence of certain geometry parameters and the source type. The first, lower byte holds the actual gravity.

So 1<<8 sets the first bit of the second byte, 1<<9 the second bit of the second byte and so forth up to the sixth bit, 1<<13. Bits 7 and 8 of the second byte are unused, is what the specification tells us. So the code you wrote does exactly how the specification says it works.

I stumbled across that issue when I used the ewmh module in a script to shuffle media player windows around on the desktop, and move/resize didn't work at all as expected. It took me a little time to figure out that the module itself sets those flags in a wrong manner.

Kalmat commented 1 year ago

Wonderful. Thank you!

Any additional comment or suggestion you may have is more than welcome!