TimerX icon indicating copy to clipboard operation
TimerX copied to clipboard

App doesn't redraw on unmaximize properly

Open rdbende opened this issue 3 years ago • 7 comments

@sumeshir26 i see, you copied this part from Tukaan, but did you ever test it? (No). This code won't work as it is.

https://github.com/Futura-Py/TimerX/blob/f1a83751a3f0ba2e334a48cc2c4b3b7be33408e2/main.py#L62-L69 tkinter.Tk (app in this case) doesn't have neither _dwm_set_window_attribute, DWMWA_TRANSITIONS_FORCEDISABLED, minimize nor restore attribute.

In tkinter you should use iconify instead of minimize and deiconify instead of restore. Instead of _dwm_set_window_attribute and DWMWA_TRANSITIONS_FORCEDISABLED you can use these two snippets:

# To disable transitions
true_value = ctypes.c_int(1)
ctypes.windll.dwmapi.DwmSetWindowAttribute(app.wm_frame(), 3, ctypes.byref(true_value), ctypes.sizeof(true_value))


# To enable transitions again
false_value = ctypes.c_int(0)
ctypes.windll.dwmapi.DwmSetWindowAttribute(app.wm_frame(), 3, ctypes.byref(false_value), ctypes.sizeof(false_value))

So the full function should look like this:

def fullredraw(e): 
    global prev_state 
    if prev_state == "zoomed": 
        true_value = ctypes.c_int(1)
        ctypes.windll.dwmapi.DwmSetWindowAttribute(app.wm_frame(), 3, ctypes.byref(true_value), ctypes.sizeof(true_value))

        app.iconify()
        app.deiconify()

        false_value = ctypes.c_int(0)
        ctypes.windll.dwmapi.DwmSetWindowAttribute(app.wm_frame(), 3, ctypes.byref(false_value), ctypes.sizeof(false_value))

        prev_state = app.state()

rdbende avatar Mar 06 '22 19:03 rdbende

I realized that, but I forgot to fix it before commiting. Fixing now... Thanks for reporting!

sumeshir26 avatar Mar 07 '22 03:03 sumeshir26

Well, it iconifies and deiconifies, but it turns out thta on Windows 11, the expose function gets called about 25 times with the prev_state as zoomed (Probably due to te smooth animation that playes while unmaximizing) and the animations dont get disabled properley, so my entire PC became unusable due to TimerX maximizing and unmaximizing, then the expose function gets called again due to the window showing up again and I couldent even click end task on taskmanger so I literallay had to restart my pc

sumeshir26 avatar Mar 07 '22 13:03 sumeshir26

Any idea on how to fix this?

sumeshir26 avatar Mar 07 '22 13:03 sumeshir26

Uhh, stange. Try binding to <Configure>.

Also, I updated the function (unindent the last line) because prev_state would have been updated only the first time the window was unmaximized (and not anymore), which could cause problems.

def fullredraw(e): 
    global prev_state 
    if prev_state == "zoomed": 
        true_value = ctypes.c_int(1)
        ctypes.windll.dwmapi.DwmSetWindowAttribute(app.wm_frame(), 3, ctypes.byref(true_value), ctypes.sizeof(true_value))

        app.iconify()
        app.deiconify()

        false_value = ctypes.c_int(0)
        ctypes.windll.dwmapi.DwmSetWindowAttribute(app.wm_frame(), 3, ctypes.byref(false_value), ctypes.sizeof(false_value))

    prev_state = app.state()

rdbende avatar Mar 07 '22 14:03 rdbende

Yeah, I also did that, will try soon

sumeshir26 avatar Mar 07 '22 14:03 sumeshir26

Configure does not work either, it just keeps maximizing and unmaximizing

sumeshir26 avatar Mar 09 '22 03:03 sumeshir26

What if you could control the minimum number of resizes? Maybe only once or twice, nothing more.

im-coder-lg avatar Mar 29 '22 15:03 im-coder-lg