Created
February 7, 2025 12:12
-
-
Save agent-kilo/83592798d75c7e14607e6502935d2d85 to your computer and use it in GitHub Desktop.
A simple fix for Jwno 0.9.10, to handle the WM_SETTINGCHANGE message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # work-area-fix.janet | |
| # | |
| # A simple fix for Jwno (https://github.com/agent-kilo/jwno) 0.9.10, to | |
| # handle the WM_SETTINGCHANGE message, which is sent when the Taskbar or | |
| # other third-party bars change the monitor work areas. | |
| # | |
| # To enable it, put this file alongside your config file, and | |
| # | |
| # (import work-area-fix) | |
| # (def waf (work-area-fix/work-area-fix jwno/context)) | |
| # (:enable waf) | |
| # | |
| # To disable it: | |
| # | |
| # (:disable waf) | |
| # | |
| (import jwno/util) | |
| (import jwno/log) | |
| (use jw32/_winuser) | |
| (use jw32/_errhandlingapi) | |
| ################## vvvv Runs in UI thread vvvv ################## | |
| (def TIMER-ID-DISPLAY-CHANGE (int/u64 1)) | |
| (def DISPLAY-CHANGE-DELAY-TIME 3000) | |
| (defn handle-wm-settingchange [hwnd _msg wparam _lparam hook-handler state] | |
| (log/debug "--------- WM_SETTINGCHANGE, wparam = %n" wparam) | |
| (unless (= wparam SPI_SETWORKAREA) | |
| (break)) | |
| (put state :desktop-rect nil) | |
| (when (= (int/u64 0) | |
| (SetTimer hwnd TIMER-ID-DISPLAY-CHANGE | |
| DISPLAY-CHANGE-DELAY-TIME | |
| nil)) | |
| (log/debug "SetTimer failed for TIMER-ID-DISPLAY-CHANGE: %n" (GetLastError)) | |
| (ev/give (in hook-handler :chan) :ui/display-changed)) | |
| 0) | |
| (defn handle-work-area-fix-init [_hwnd msg _wparam _lparam _hook-handler state] | |
| (def custom-msgs (in state :custom-messages)) | |
| (put custom-msgs WM_SETTINGCHANGE handle-wm-settingchange) | |
| (log/debug "--------- WM_SETTINGCHANGE handler registered") | |
| # Remove this one-shot handler | |
| (put custom-msgs msg nil) | |
| 0) | |
| (defn handle-work-area-fix-cleanup [_hwnd msg _wparam _lparam _hook-handler state] | |
| (def custom-msgs (in state :custom-messages)) | |
| (put custom-msgs WM_SETTINGCHANGE nil) | |
| (log/debug "--------- WM_SETTINGCHANGE handler unregistered") | |
| # Remove this one-shot handler | |
| (put custom-msgs msg nil) | |
| 0) | |
| ################## ^^^^ Runs in UI thread ^^^^ ################## | |
| (defn work-area-fix-enable [self] | |
| (:disable self) | |
| (def ui-man (in self :ui-manager)) | |
| (def init-msg (:add-custom-message ui-man handle-work-area-fix-init)) | |
| (if (< init-msg (int/s64 0)) | |
| (error "failed to register work-area-fix-init message") | |
| # else | |
| (:send-message ui-man init-msg 0 0))) | |
| (defn work-area-fix-disable [self] | |
| (def ui-man (in self :ui-manager)) | |
| (def cleanup-msg (:add-custom-message ui-man handle-work-area-fix-cleanup)) | |
| (if (< cleanup-msg (int/s64 0)) | |
| (error "failed to register work-area-fix-init message") | |
| # else | |
| (:send-message ui-man cleanup-msg 0 0))) | |
| (def work-area-fix-proto | |
| @{:enable work-area-fix-enable | |
| :disable work-area-fix-disable}) | |
| (defn work-area-fix [context] | |
| (def ui-man (in context :ui-manager)) | |
| (table/setproto | |
| @{:ui-manager ui-man} | |
| work-area-fix-proto)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment