Hot-reload the active skin when its file changes on disk - #5141
Open
axelfontaine wants to merge 1 commit into
Open
Hot-reload the active skin when its file changes on disk#5141axelfontaine wants to merge 1 commit into
axelfontaine wants to merge 1 commit into
Conversation
Currently, picking up a change to the current skin's .ini file requires restarting mc, or re-selecting the same skin from Options > Appearance. This is inconvenient for skins that are regenerated by an external process (e.g. a script that derives an mc skin from the desktop theme and wants it to apply live, without the user closing and reopening mc). On Linux, watch the active skin file with inotify and re-apply it automatically on change, reusing the same reload path (mc_skin_deinit + mc_skin_init + panel/filehighlight refresh + repaint_screen) already used by the interactive skin picker in the Appearance dialog, now exposed as mc_skin_reload(). The watch fd is integrated into the existing select() loop via add_select_channel()/delete_select_channel(), the same generic mechanism already used for background job and subshell pipes. The watch is armed once at startup and intentionally never re-armed on each event: our write pattern is an in-place truncate+write, which never invalidates the original watch descriptor. Re-arming from within the event callback was tried first and found to self-trigger forever, since inotify_rm_watch() itself raises IN_IGNORED on the same fd, which the next select() sees immediately. This is Linux-only (inotify has no equivalent on the other platforms mc supports), guarded with #ifdef __linux__, matching existing precedent elsewhere in the tree (cons.handler.c, key.c, subshell/proxyfunc.c). Signed-off-by: Axel Fontaine <axel@axelfontaine.com>
|
+1 to this. Omarchy needs a themed CLI commander for file management |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a prerequisite for mc following live theme-switches on Omarchy (something I've wanted for a while).
Made with Claude.
Notes from Claude:
Proposed changes
Currently, picking up a change to the current skin's
.inifile requires restarting mc, or re-selecting the same skin from Options > Appearance. This is inconvenient for skins that are regenerated by an external process — e.g. a script that derives an mc skin from the desktop theme and wants it to apply live, without the user closing and reopening mc.On Linux, this watches the active skin file with
inotifyand re-applies it automatically on change, reusing the same reload path (mc_skin_deinit+mc_skin_init+ panel/filehighlight refresh +repaint_screen) already used by the interactive skin picker in the Appearance dialog (src/filemanager/boxes.c'sskin_apply), now exposed asmc_skin_reload(). The watch fd is integrated into the existingselect()loop viaadd_select_channel()/delete_select_channel(), the same generic mechanism already used for background job and subshell pipes — no new event-loop machinery.The watch is armed once at startup and intentionally never re-armed on each event: the expected write pattern is an in-place truncate+write, which never invalidates the original watch descriptor. Re-arming from within the event callback was tried first and found to self-trigger forever, since
inotify_rm_watch()itself raisesIN_IGNOREDon the same fd, which the nextselect()sees immediately — worth calling out in case it comes up in review.This is Linux-only (
inotifyhas no equivalent on the other platforms mc supports), guarded with#ifdef __linux__, matching existing precedent elsewhere in the tree (cons.handler.c,key.c,subshell/proxyfunc.c).Manually verified: launched mc, edited the active skin file's colors on disk, and confirmed the running instance recolors in place with no restart, no keypress, and no measurable CPU overhead at idle or after reload.
Checklist
make indent && make check)